From nobody Mon Sep 29 21:09:05 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B530DC00140 for ; Tue, 16 Aug 2022 00:59:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233048AbiHPA7L (ORCPT ); Mon, 15 Aug 2022 20:59:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347674AbiHPAvw (ORCPT ); Mon, 15 Aug 2022 20:51:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96009DA3F3; Mon, 15 Aug 2022 13:47:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B734B60F60; Mon, 15 Aug 2022 20:47:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4976C433D6; Mon, 15 Aug 2022 20:47:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596440; bh=AXxqXUKNIERoCew8Y87JYI1nbz3dGpMZarK68vSCs0A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PsbZyJuPzwufhfY81tRvCHpBt+0oSgNFsdH69FOkSgkOfs2YGzdRJuqShLhUSaZnq w7QfTwJsfgHGrbq7FqZufBPyoyeK/0dWv440xFWHs3XSA6gsgjQFwGFs7G5JiEjfDo mID/WDhjlutGlaDf3viTcroZ4NiDE7TwjCXhgK8M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , Josef Bacik , David Sterba , Sasha Levin Subject: [PATCH 5.19 1079/1157] btrfs: tree-log: make the return value for log syncing consistent Date: Mon, 15 Aug 2022 20:07:15 +0200 Message-Id: <20220815180523.311733735@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Josef Bacik [ Upstream commit f31f09f6be1c6c1a673e0566e258281a7bbaaa51 ] Currently we will return 1 or -EAGAIN if we decide we need to commit the transaction rather than sync the log. In practice this doesn't really matter, we interpret any !0 and !BTRFS_NO_LOG_SYNC as needing to commit the transaction. However this makes it hard to figure out what the correct thing to do is. Fix this up by defining BTRFS_LOG_FORCE_COMMIT and using this in all the places where we want to force the transaction to be committed. CC: stable@vger.kernel.org # 5.15+ Reviewed-by: Filipe Manana Signed-off-by: Josef Bacik Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/file.c | 2 +- fs/btrfs/tree-log.c | 18 +++++++++--------- fs/btrfs/tree-log.h | 3 +++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 9dfde1af8a64..89c6d7ff1987 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2308,7 +2308,7 @@ int btrfs_sync_file(struct file *file, loff_t start, = loff_t end, int datasync) btrfs_release_log_ctx_extents(&ctx); if (ret < 0) { /* Fallthrough and commit/free transaction. */ - ret =3D 1; + ret =3D BTRFS_LOG_FORCE_COMMIT; } =20 /* we've logged all the items and now have a consistent diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 370388fadf96..c94713c811bb 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -171,7 +171,7 @@ static int start_log_trans(struct btrfs_trans_handle *t= rans, int index =3D (root->log_transid + 1) % 2; =20 if (btrfs_need_log_full_commit(trans)) { - ret =3D -EAGAIN; + ret =3D BTRFS_LOG_FORCE_COMMIT; goto out; } =20 @@ -194,7 +194,7 @@ static int start_log_trans(struct btrfs_trans_handle *t= rans, * writing. */ if (zoned && !created) { - ret =3D -EAGAIN; + ret =3D BTRFS_LOG_FORCE_COMMIT; goto out; } =20 @@ -3121,7 +3121,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, =20 /* bail out if we need to do a full commit */ if (btrfs_need_log_full_commit(trans)) { - ret =3D -EAGAIN; + ret =3D BTRFS_LOG_FORCE_COMMIT; mutex_unlock(&root->log_mutex); goto out; } @@ -3222,7 +3222,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, } btrfs_wait_tree_log_extents(log, mark); mutex_unlock(&log_root_tree->log_mutex); - ret =3D -EAGAIN; + ret =3D BTRFS_LOG_FORCE_COMMIT; goto out; } =20 @@ -3261,7 +3261,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, blk_finish_plug(&plug); btrfs_wait_tree_log_extents(log, mark); mutex_unlock(&log_root_tree->log_mutex); - ret =3D -EAGAIN; + ret =3D BTRFS_LOG_FORCE_COMMIT; goto out_wake_log_root; } =20 @@ -5848,7 +5848,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle = *trans, inode_only =3D=3D LOG_INODE_ALL && inode->last_unlink_trans >=3D trans->transid) { btrfs_set_log_full_commit(trans); - ret =3D 1; + ret =3D BTRFS_LOG_FORCE_COMMIT; goto out_unlock; } =20 @@ -6562,12 +6562,12 @@ static int btrfs_log_inode_parent(struct btrfs_tran= s_handle *trans, bool log_dentries =3D false; =20 if (btrfs_test_opt(fs_info, NOTREELOG)) { - ret =3D 1; + ret =3D BTRFS_LOG_FORCE_COMMIT; goto end_no_trans; } =20 if (btrfs_root_refs(&root->root_item) =3D=3D 0) { - ret =3D 1; + ret =3D BTRFS_LOG_FORCE_COMMIT; goto end_no_trans; } =20 @@ -6665,7 +6665,7 @@ static int btrfs_log_inode_parent(struct btrfs_trans_= handle *trans, end_trans: if (ret < 0) { btrfs_set_log_full_commit(trans); - ret =3D 1; + ret =3D BTRFS_LOG_FORCE_COMMIT; } =20 if (ret) diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h index 1620f8170629..57ab5f3b8dc7 100644 --- a/fs/btrfs/tree-log.h +++ b/fs/btrfs/tree-log.h @@ -12,6 +12,9 @@ /* return value for btrfs_log_dentry_safe that means we don't need to log = it at all */ #define BTRFS_NO_LOG_SYNC 256 =20 +/* We can't use the tree log for whatever reason, force a transaction comm= it */ +#define BTRFS_LOG_FORCE_COMMIT (1) + struct btrfs_log_ctx { int log_ret; int log_transid; --=20 2.35.1