From patchwork Wed May 22 14:36:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13670900 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D75CD1CD35 for ; Wed, 22 May 2024 14:36:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716388600; cv=none; b=sfzRxrgOC6iucz5qbUZ9vSCLNpPLuPS15eE2qP6cW0FkGpM3epPyZCf0+yTwm9qQib558//ONVF4sTR8gp9BPLn8k5M2YZUARWDEL7cHdwIORybnE+cPPMuXYSvh1fE740QJEzsNjhwvQBig4CiNFsprORzBjZd2ppa6EOmeKNw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716388600; c=relaxed/simple; bh=wngFHCEBILVr6mDg4GFHWtOr/JTDvrtguz47rWx7MqU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ed/4oq2Qx9eyPfTv69Et2DdXgWdjTuuhPyXE4aP8oJHsxdI4gIi1g3ypX052kIJgHeoUi/MDdCgqKApo/WQk592/J05Smkm1s6VdfacXFXxderZidpElzB3u0Cn1y9QfyaCyAudXrS32h1/XV2FasWIobAeSyDciPy4F+CSluG8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p36dXBEm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p36dXBEm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29B65C32782 for ; Wed, 22 May 2024 14:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716388600; bh=wngFHCEBILVr6mDg4GFHWtOr/JTDvrtguz47rWx7MqU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=p36dXBEmEtIF3iJZEtzhuN/Rh8IfPcRQuREnSdiEBEgctaIUKwOWaEFMdJZqibcxQ glRgBbGyya48qv24c/U6+YKyrTvJpdY8AypBUEHtruOCqvH7c0Vo79A/lUTTeSIw3h geMK/ZcD5c7HYobQxIBM7ILBN8/nUwmXOqNjU/5XNpA+4BjMfoN3gX8f36uiOnAa0F MuLJ+CB3dgIi341HaiOolQs7ZUHC84sF1f8lWmPgALbf1oKNjqB/Q8ZWM9/QF5sqFu KpzAsvW1YGw6eOVaCQjGq8EYubEYHqEMGHWeLF7ivYEnG8ift79LPanNVebiBL0N0B SJS1MgTPss+Iw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/7] btrfs: qgroup: avoid start/commit empty transaction when flushing reservations Date: Wed, 22 May 2024 15:36:29 +0100 Message-Id: <64ffcb8d6fe5a406c23d517eecd91436508a6c86.1716386100.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana When flushing reservations we are using btrfs_join_transaction() to get a handle for the current transaction and then commit it to try to release space. However btrfs_join_transaction() has some undesirable consequences: 1) If there's no running transaction, it will create one, and we will commit it right after. This is unncessary because it will not release any space, and it will result in unnecessary IO and rotation of backup roots in the superblock; 2) If there's a current transaction and that transaction is committing (its state is >= TRANS_STATE_COMMIT_DOING), it will wait for that transaction to almost finish its commit (for its state to be >= TRANS_STATE_UNBLOCKED) and then start and return a new transaction. We will then commit that new transaction, which is pointless because all we wanted was to wait for the current (previous) transaction to fully finish its commit (state == TRANS_STATE_COMPLETED), and by starting and committing a new transaction we are wasting IO too and causing unnecessary rotation of backup roots in the superblock. So improve this by using btrfs_attach_transaction_barrier() instead, which does not create a new transaction if there's none running, and if there's a current transaction that is committing, it will wait for it to fully commit and not create a new transaction. Signed-off-by: Filipe Manana --- fs/btrfs/qgroup.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index a2e329710287..391af9e79dd6 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -1341,12 +1341,14 @@ static int flush_reservations(struct btrfs_fs_info *fs_info) if (ret) return ret; btrfs_wait_ordered_roots(fs_info, U64_MAX, NULL); - trans = btrfs_join_transaction(fs_info->tree_root); - if (IS_ERR(trans)) - return PTR_ERR(trans); - ret = btrfs_commit_transaction(trans); - return ret; + trans = btrfs_attach_transaction_barrier(fs_info->tree_root); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + return (ret == -ENOENT) ? 0 : ret; + } + + return btrfs_commit_transaction(trans); } int btrfs_quota_disable(struct btrfs_fs_info *fs_info) From patchwork Wed May 22 14:36:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13670901 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 237C720DE8 for ; Wed, 22 May 2024 14:36:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716388602; cv=none; b=fYmxpQfGI4EgU0FbUuD02gBujTeLGoGBNwz3w8HOVaRbaoHAHpfeU2n6+41EwzGcKsvBzojsDKZIbBmcLXqZ2AGUGiEz40Vtjp9k2sjW6BGSKOteIflM98ErVuetfTF/1m1mkRBggS6c9TYZK0z/lbcbqUEQeDc+uSR8X4O84N8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716388602; c=relaxed/simple; bh=AlaVMhrGenbjgIxhogKFEKh3SPgAjYjsyy9wZ077veE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oqOVpSGDcuLTa6qp57llyg9L5lUdj0ypYythEInYNCxQ3eFcMNoy9HYluX60bDPqCWZ5Y+fH8tTaLQmyE5qEwmFhTc9d31jq1E0D0dvES3l7p4hLGtUh+sftc1VZ207ErsQVtXue8A2ep02vpFkLn5KlW5K3f4uVtQyP60G5kdk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e7u41+zW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="e7u41+zW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CD4DC2BBFC for ; Wed, 22 May 2024 14:36:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716388601; bh=AlaVMhrGenbjgIxhogKFEKh3SPgAjYjsyy9wZ077veE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=e7u41+zWnwvIjF+FGb4xQuYEpNg9dPSYNsyu8mzSCpPGL/hlEiwiNLzYDNg/84c1G OLzG65hVxDgcfQssWuQ2af5iJdrrqlrdDufDyApwgGjtCFZCzEgYTTFQ4IuEotz0Uy r6xF4TBVtPUAvNpkj0L3NGwKz1LixnBJ33PGN57ZX+hKxaoWC9oqjM6IptIr0xESXF toAfO+K36Pg064pi/zbsPkJ3kilEScoRRHgeU3sF/PbZpkIF9vcod1TAJjeVJwvLwT oDdmp2H2Rt4tVCkcBkEXrXDx+4I4gB36J+nRHGxPcmUZprfpIcFmWBGtIXV5zOELdB kqsgev4LUC99w== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/7] btrfs: avoid create and commit empty transaction when committing super Date: Wed, 22 May 2024 15:36:30 +0100 Message-Id: <89d1791f11c327236ff63ae24327b5e58522ce3d.1716386100.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana At btrfs_commit_super(), called in a few contextes such as when unmounting a filesystem, we use btrfs_join_transaction() to catch any running transaction and then commit it. This will however create a new and empty transaction in case there's no running transaction or there's a running transaction with a state >= TRANS_STATE_UNBLOCKED. As we just want to be sure that any existing transaction is fully committed, we can use btrfs_attach_transaction_barrier() instead of btrfs_join_transaction(), therefore avoiding the creation and commit of empty transactions, which only waste IO and causes rotation of the precious backup roots. Example where we create and commit a pointless empty transaction: $ mkfs.btrfs -f /dev/sdj $ btrfs inspect-internal dump-super /dev/sdj | grep -e '^generation' generation 6 $ mount /dev/sdj /mnt/sdj $ touch /mnt/sdj/foo # Commit the currently open transaction. Just 'sync' or wait ~30 # seconds for the transaction kthread to commit it. $ sync $ btrfs inspect-internal dump-super /dev/sdj | grep -e '^generation' generation 7 $ umount /mnt/sdj $ btrfs inspect-internal dump-super /dev/sdj | grep -e '^generation' generation 8 The transaction with id 8 was pointless, an empty transaction that did not achieve anything. Signed-off-by: Filipe Manana --- fs/btrfs/disk-io.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index eec5bb392b8e..2f56f967beb8 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4156,9 +4156,13 @@ int btrfs_commit_super(struct btrfs_fs_info *fs_info) down_write(&fs_info->cleanup_work_sem); up_write(&fs_info->cleanup_work_sem); - trans = btrfs_join_transaction(root); - if (IS_ERR(trans)) - return PTR_ERR(trans); + trans = btrfs_attach_transaction_barrier(root); + if (IS_ERR(trans)) { + int ret = PTR_ERR(trans); + + return (ret == -ENOENT) ? 0 : ret; + } + return btrfs_commit_transaction(trans); } From patchwork Wed May 22 14:36:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13670902 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 374F522331 for ; Wed, 22 May 2024 14:36:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716388603; cv=none; b=lEJeSAGiEbqXdtnkkxhVAbmK9ZIz1zR+HKac2EI+m2K++U2QCrGvkGsciEya+iIcm8QgS0f30oSCwamcTwvpjdsFnqNA4httD48XlTIUg+QFzWBxYtGaloyM4+a9RfpkzyQe9rZSbL2GQWLxbOVrT67EJVg4T+v5wJTIZXkCaM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716388603; c=relaxed/simple; bh=I+YKT2VcljiROW1ywzaPYu1sfaKwDF3M7uCRXO4vlNU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rP4Y6THkHQgSK3LFNsxKKxiPl/VxTvLSltZVSGTONensg67/Gk2j97Uo0Flgjp7up4Ccs6LcY/2k2V/7SkFQ0e7RTXNctzrI9tkIREWnCxZoH88v5kaTpLIw2iJRiiswpE9+JtjTpbUdAR6Yv1IujUR5l95J8zY6QOcjKVgBfYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ozavy6C4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ozavy6C4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 314C5C32782 for ; Wed, 22 May 2024 14:36:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716388602; bh=I+YKT2VcljiROW1ywzaPYu1sfaKwDF3M7uCRXO4vlNU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ozavy6C41qL3nipg2vCqyNoR5wUhwp4LMV6CGjixIUbygXk4LuZ5sUbUOvjaisvCX zugYWJ3T/9AJM8DmIUm1ck+LcwA3LdBuJLVNfswfsPQTXDOzndfzGrCjx6BRHZ9OZL gCbjEE34m0lMaYnYFG/WV/vCCae98JlJr+JPfTB6yO5qgFbhbWuI1Gt+o5aNnRdSST AwVSyAbmbrFbZcuAcO93RCpS5khAXWb+ww6Hz8k2QS3boVI3hFCKP7wXX6qS+anIU3 DsSy/B6R6wQ4XZvckm0cgyMrR9B3AkJNUGX0S9dLuQxOvF8iNLGXOYUWGt2VbAfqyW 0wZekkgz2EfeQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/7] btrfs: send: make ensure_commit_roots_uptodate() simpler and more efficient Date: Wed, 22 May 2024 15:36:31 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana Before starting a send operation we have to make sure that every root has its commit root matching the regular root, to that send doesn't find stale inodes in the commit root (inodes that were deleted in the regular root) and fails the inode lookups with -ESTALE. Currently we keep looking for roots used by the send operation and as soon as we find one we commit the current transaction (or a new one since btrfs_join_transaction() creates one if there isn't any running or the running one is in a state >= TRANS_STATE_UNBLOCKED). It's pointless to keep looking until we don't find any, because after the first transaction commit all the other roots are updated too, as they were already tagged in the fs_info->fs_roots_radix radix tree when they were modified in order to have a commit root different from the regular root. Currently we are also always passing the main send root into btrfs_join_transaction(), which despite not having any functional issue, it is not optimal because in case the root wasn't modified we end up adding it to fs_info->fs_roots_radix and then update its root item in the root tree when comitting the transaction, causing unnecessary work. So simplify and make this more efficient by removing the looping and by passing the first root we found that is modified as the argument to btrfs_join_transaction(). Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index c69743233be5..2c46bd1c90d3 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -7998,32 +7998,29 @@ static int send_subvol(struct send_ctx *sctx) */ static int ensure_commit_roots_uptodate(struct send_ctx *sctx) { - int i; - struct btrfs_trans_handle *trans = NULL; + struct btrfs_trans_handle *trans; + struct btrfs_root *root = sctx->parent_root; -again: - if (sctx->parent_root && - sctx->parent_root->node != sctx->parent_root->commit_root) + if (root && root->node != root->commit_root) goto commit_trans; - for (i = 0; i < sctx->clone_roots_cnt; i++) - if (sctx->clone_roots[i].root->node != - sctx->clone_roots[i].root->commit_root) + for (int i = 0; i < sctx->clone_roots_cnt; i++) { + root = sctx->clone_roots[i].root; + if (root->node != root->commit_root) goto commit_trans; - - if (trans) - return btrfs_end_transaction(trans); + } return 0; commit_trans: - /* Use any root, all fs roots will get their commit roots updated. */ - if (!trans) { - trans = btrfs_join_transaction(sctx->send_root); - if (IS_ERR(trans)) - return PTR_ERR(trans); - goto again; - } + /* + * Use the first root we found. We could use any but that would cause + * an unnecessary update of the root's item in the root tree when + * committing the transaction if that root wasn't changed before. + */ + trans = btrfs_join_transaction(root); + if (IS_ERR(trans)) + return PTR_ERR(trans); return btrfs_commit_transaction(trans); } From patchwork Wed May 22 14:36:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13670903 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37FC52374C for ; Wed, 22 May 2024 14:36:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716388604; cv=none; b=B1YRb8RPi8Js9yyl0LMreyzOLgs5UbEw+PF6e5Sfd2bFLrVBC9y1d/Pa1ulbPvRSxwOR2bvv7kzmsfoA7OGzssnJnB/x/zrvFpcgJJT5YTEsFfq+FgoInVUt64gUap2Oj/YNqVGzlOPQ8aP5F/GshuoVFLTUDK+/rT0KgFR9LMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716388604; c=relaxed/simple; bh=6IRuYllH1yzVZnG8MNZ9EDWBPfbdUX234D3tFclU5oc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JYfGv/UAdQ8AV7nEg4+wBSdIsHk0IMFsASgpMhXjoO9sDksDPBWnOBxmAOsC7PBQGuUJtJiSquw+vLZZHn8dzjbB3GYNdvP6P7wYAOx632jGdgoyJv0xp/wkL2veyglWt4TJqYr/5i9xY9c85NcojhoFpmc4WZkEa5z/w/piifA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l3qZIQx3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="l3qZIQx3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 356C4C2BBFC for ; Wed, 22 May 2024 14:36:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716388603; bh=6IRuYllH1yzVZnG8MNZ9EDWBPfbdUX234D3tFclU5oc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=l3qZIQx3bcOGwojSrwahf/3mH5rWxTu4Ro9UUoQIN0Rt4qCJyrc96D5MoZq+ZOiqz OtFLaHlOvcpwWkjNMBkxEFU9o6M76VnGliGIyEX8nN+/BxNFDCWaSkd+/HADRfWc9L QoO4fRk1qkmA5KDjrbqGCS7pJdmbRLiIH/e4xsV2S04PApsRyQJm41sOro370Pu1m8 1MpWqZOD45TUkKSvX+26M4cTK4Oc7UM+jUPoJQ70EZZvZzZHhteXJealOJecxYK0Tg 50B4En2vqWGoQFjnwODfpAsPHu+jqiLQVSHPhgcmSlxqoXpAtBvm/nEHDXH64fMcOK BMD1/Hz6Rzogw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 4/7] btrfs: send: avoid create/commit empty transaction at ensure_commit_roots_uptodate() Date: Wed, 22 May 2024 15:36:32 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana At ensure_commit_roots_uptodate() we use btrfs_join_transaction() to catch any running transaction and then commit it. This will however create a new and empty transaction in case there's no running transaction anymore (got committed by the transaction kthread or other task for example) or there's a running transaction finishing its commit and with a state >= TRANS_STATE_UNBLOCKED. In the former case we don't need to do anything while in the second case we just need to wait for the transaction to complete its commit. So improve this by using btrfs_attach_transaction_barrier() instead, which does not create a new transaction if there's none running, and if there's a current transaction that is committing, it will wait for it to fully commit and not create a new transaction. This helps avoiding creating and committing empty transactions, saving IO, time and unnecessary rotation of the backup roots in the super block. Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 2c46bd1c90d3..289e5e6a6c56 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -8018,9 +8018,12 @@ static int ensure_commit_roots_uptodate(struct send_ctx *sctx) * an unnecessary update of the root's item in the root tree when * committing the transaction if that root wasn't changed before. */ - trans = btrfs_join_transaction(root); - if (IS_ERR(trans)) - return PTR_ERR(trans); + trans = btrfs_attach_transaction_barrier(root); + if (IS_ERR(trans)) { + int ret = PTR_ERR(trans); + + return (ret == -ENOENT) ? 0 : ret; + } return btrfs_commit_transaction(trans); } From patchwork Wed May 22 14:36:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13670904 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE7AF25753 for ; Wed, 22 May 2024 14:36:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716388604; cv=none; b=AiRxzqVKvlM8YBfzlBe/z2p2TSXVLeN7DZBPt0r3mxu8vhSBUnbiQzvy6Oej3mkZRAUFw4xqCEJpTAQzDDDWkRHfF2LxrXUI/fr5aN3SpJW3qgnTCiU8sdWLkOpNQGj92KT4STGZ+VsBIANksfW/4halbdCMwDS6Z0pYrG3VJSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716388604; c=relaxed/simple; bh=Jk2pLpQ4kQ62gRmVrx9XMVZ2M/g3S6QHiJjx6Mmh/B0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=i0qOXJ21HXDSjGhhrTcBvVd55E1Etzj657ffqVkL8zRWfn7OkNWF/8UHFol7KcnkPME41dqETNvRa6p8jhGvPXIn7AKA9cQqnxufxqHsyvPGwajvA3ZhTvRFq011Q8juojyvmi27ck2lYIFx3s390S1f9lmc438lGlnWeFO5Xt0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RIcJrzP9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RIcJrzP9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38696C32782 for ; Wed, 22 May 2024 14:36:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716388604; bh=Jk2pLpQ4kQ62gRmVrx9XMVZ2M/g3S6QHiJjx6Mmh/B0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RIcJrzP9tq8UcQbVl+drSybzXYKdP9ZqbcSRBFhRoavR5m5e36FiCYYV+f2rMzOsK GSGNkDHVdEJxvQUIWWd52C6THDsEEt1XJWcUrqpaozX3GORYUnHr/lb93zv8dwsN6T VGgk8y+bXNZ82QCNZFMsXM8kaVRHCu3faAFXEDHMqYeH6BU1a03mTqQCB1lfjkI2Du 67rC8T86AXr0pEveJ8agx52hfLZGm6Bipv0k+qqYMO3nBAkCPaUwFAxX6GjfzKlfK0 v6E82R2ZnJiuQgm4gISml/94UYSVEM01hQesxPUPciPIeIqTsJmmMRMSxkLKvPn3bw cRit327FuAlBg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 5/7] btrfs: scrub: avoid create/commit empty transaction at finish_extent_writes_for_zoned() Date: Wed, 22 May 2024 15:36:33 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana At finish_extent_writes_for_zoned() we use btrfs_join_transaction() to catch any running transaction and then commit it. This will however create a new and empty transaction in case there's no running transaction anymore (got committed by the transaction kthread or other task for example) or there's a running transaction finishing its commit and with a state >= TRANS_STATE_UNBLOCKED. In the former case we don't need to do anything while in the second case we just need to wait for the transaction to complete its commit. So improve this by using btrfs_attach_transaction_barrier() instead, which does not create a new transaction if there's none running, and if there's a current transaction that is committing, it will wait for it to fully commit and not create a new transaction. This helps avoiding creating and committing empty transactions, saving IO, time and unnecessary rotation of the backup roots in the super block. Signed-off-by: Filipe Manana --- fs/btrfs/scrub.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 376c5c2e9aed..6c7b5d52591e 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -2446,9 +2446,13 @@ static int finish_extent_writes_for_zoned(struct btrfs_root *root, btrfs_wait_nocow_writers(cache); btrfs_wait_ordered_roots(fs_info, U64_MAX, cache); - trans = btrfs_join_transaction(root); - if (IS_ERR(trans)) - return PTR_ERR(trans); + trans = btrfs_attach_transaction_barrier(root); + if (IS_ERR(trans)) { + int ret = PTR_ERR(trans); + + return (ret == -ENOENT) ? 0 : ret; + } + return btrfs_commit_transaction(trans); } From patchwork Wed May 22 14:36:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13670906 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CE712B9CD for ; Wed, 22 May 2024 14:36:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716388607; cv=none; b=QoPSbS5sKVbJxupr1ir2LiBSBvqabwdXbIYWG5Fs6j6kXD9l9Bt+0gIt/EoYeXbrOv1GfwrNBNIqdUj1aw/d2ACJKijl/GpO7r0n7lj9E4Q0JWmf4EnLWEPaLaVSitJgMkEe6ELRjNmkmVvKXborUCY4qVBnb1bn/nhfprltaf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716388607; c=relaxed/simple; bh=KK9WWlJhko7qesf7cbOxOzwLJSIkpFPMFqjt1Zmh0iI=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q1Gw2Req64RPk1lDt4Uho/HP4qehFX/FBZaWVqKZhzOXf0qZtlNPi8f9bPeW3V+aFaRaEX4Kc9W1IwxL2V7M90VusBzgAzpoXVY7g0IzuQarKpl0kPgx6J7ZrBGjgguNTWdpYvOYcGKV9jUiuWbFuLv95V83zFytZltefcR8MRc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l8XnczfE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="l8XnczfE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CA12C32782 for ; Wed, 22 May 2024 14:36:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716388605; bh=KK9WWlJhko7qesf7cbOxOzwLJSIkpFPMFqjt1Zmh0iI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=l8XnczfE88lvSvO0SBNd3zvBgSAj2K+1QUAi/dEXE+PP80bxw8tH++59eCECptVY1 eAvoNgNNIrC+skVrzMq84EKx8nTts2L1/0u9V/fubjL5AJthIjr1PPWyamKbTQWZyY 5JkrZyWa8XNzzOjep7UNaPJigAEW0RIrQ2/bgw67d1VHjyqDD01GuCsyFW74y/AyOh F+s0SaU6tJ7YzEtO8ZF4hExNGTqFW68cX0agHikCeUOO/4FziobpXHBG3rOMv9Q+TC Fc1MA1qc6y/a8bfkYUPQ9IFuWqNsKckFsrdv9oTIkpXb27BpjtvS13KwfUIVhMsAVT hIHz1aZBhQ06A== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 6/7] btrfs: add and use helper to commit the current transaction Date: Wed, 22 May 2024 15:36:34 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana We have several places that attach to the current transaction with btrfs_attach_transaction_barrier() and then commit the transaction if there is one. Add a helper and use it to deduplicate this pattern. Signed-off-by: Filipe Manana --- fs/btrfs/disk-io.c | 12 +----------- fs/btrfs/qgroup.c | 33 +++++---------------------------- fs/btrfs/scrub.c | 10 +--------- fs/btrfs/send.c | 10 +--------- fs/btrfs/space-info.c | 9 +-------- fs/btrfs/super.c | 11 +---------- fs/btrfs/transaction.c | 19 +++++++++++++++++++ fs/btrfs/transaction.h | 1 + 8 files changed, 30 insertions(+), 75 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 2f56f967beb8..78d3966232ae 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4144,9 +4144,6 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, int btrfs_commit_super(struct btrfs_fs_info *fs_info) { - struct btrfs_root *root = fs_info->tree_root; - struct btrfs_trans_handle *trans; - mutex_lock(&fs_info->cleaner_mutex); btrfs_run_delayed_iputs(fs_info); mutex_unlock(&fs_info->cleaner_mutex); @@ -4156,14 +4153,7 @@ int btrfs_commit_super(struct btrfs_fs_info *fs_info) down_write(&fs_info->cleanup_work_sem); up_write(&fs_info->cleanup_work_sem); - trans = btrfs_attach_transaction_barrier(root); - if (IS_ERR(trans)) { - int ret = PTR_ERR(trans); - - return (ret == -ENOENT) ? 0 : ret; - } - - return btrfs_commit_transaction(trans); + return btrfs_commit_current_transaction(fs_info->tree_root); } static void warn_about_uncommitted_trans(struct btrfs_fs_info *fs_info) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 391af9e79dd6..6864a8a201df 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -1334,7 +1334,6 @@ int btrfs_quota_enable(struct btrfs_fs_info *fs_info, */ static int flush_reservations(struct btrfs_fs_info *fs_info) { - struct btrfs_trans_handle *trans; int ret; ret = btrfs_start_delalloc_roots(fs_info, LONG_MAX, false); @@ -1342,13 +1341,7 @@ static int flush_reservations(struct btrfs_fs_info *fs_info) return ret; btrfs_wait_ordered_roots(fs_info, U64_MAX, NULL); - trans = btrfs_attach_transaction_barrier(fs_info->tree_root); - if (IS_ERR(trans)) { - ret = PTR_ERR(trans); - return (ret == -ENOENT) ? 0 : ret; - } - - return btrfs_commit_transaction(trans); + return btrfs_commit_current_transaction(fs_info->tree_root); } int btrfs_quota_disable(struct btrfs_fs_info *fs_info) @@ -4028,7 +4021,6 @@ int btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info) { int ret = 0; - struct btrfs_trans_handle *trans; ret = qgroup_rescan_init(fs_info, 0, 1); if (ret) @@ -4045,16 +4037,10 @@ btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info) * going to clear all tracking information for a clean start. */ - trans = btrfs_attach_transaction_barrier(fs_info->fs_root); - if (IS_ERR(trans) && trans != ERR_PTR(-ENOENT)) { + ret = btrfs_commit_current_transaction(fs_info->fs_root); + if (ret) { fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN; - return PTR_ERR(trans); - } else if (trans != ERR_PTR(-ENOENT)) { - ret = btrfs_commit_transaction(trans); - if (ret) { - fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN; - return ret; - } + return ret; } qgroup_rescan_zero_tracking(fs_info); @@ -4190,7 +4176,6 @@ static int qgroup_unreserve_range(struct btrfs_inode *inode, */ static int try_flush_qgroup(struct btrfs_root *root) { - struct btrfs_trans_handle *trans; int ret; /* Can't hold an open transaction or we run the risk of deadlocking. */ @@ -4213,15 +4198,7 @@ static int try_flush_qgroup(struct btrfs_root *root) goto out; btrfs_wait_ordered_extents(root, U64_MAX, NULL); - trans = btrfs_attach_transaction_barrier(root); - if (IS_ERR(trans)) { - ret = PTR_ERR(trans); - if (ret == -ENOENT) - ret = 0; - goto out; - } - - ret = btrfs_commit_transaction(trans); + ret = btrfs_commit_current_transaction(root); out: clear_bit(BTRFS_ROOT_QGROUP_FLUSHING, &root->state); wake_up(&root->qgroup_flush_wait); diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 6c7b5d52591e..188a9c42c9eb 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -2437,7 +2437,6 @@ static int finish_extent_writes_for_zoned(struct btrfs_root *root, struct btrfs_block_group *cache) { struct btrfs_fs_info *fs_info = cache->fs_info; - struct btrfs_trans_handle *trans; if (!btrfs_is_zoned(fs_info)) return 0; @@ -2446,14 +2445,7 @@ static int finish_extent_writes_for_zoned(struct btrfs_root *root, btrfs_wait_nocow_writers(cache); btrfs_wait_ordered_roots(fs_info, U64_MAX, cache); - trans = btrfs_attach_transaction_barrier(root); - if (IS_ERR(trans)) { - int ret = PTR_ERR(trans); - - return (ret == -ENOENT) ? 0 : ret; - } - - return btrfs_commit_transaction(trans); + return btrfs_commit_current_transaction(root); } static noinline_for_stack diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 289e5e6a6c56..7a82132500a8 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -7998,7 +7998,6 @@ static int send_subvol(struct send_ctx *sctx) */ static int ensure_commit_roots_uptodate(struct send_ctx *sctx) { - struct btrfs_trans_handle *trans; struct btrfs_root *root = sctx->parent_root; if (root && root->node != root->commit_root) @@ -8018,14 +8017,7 @@ static int ensure_commit_roots_uptodate(struct send_ctx *sctx) * an unnecessary update of the root's item in the root tree when * committing the transaction if that root wasn't changed before. */ - trans = btrfs_attach_transaction_barrier(root); - if (IS_ERR(trans)) { - int ret = PTR_ERR(trans); - - return (ret == -ENOENT) ? 0 : ret; - } - - return btrfs_commit_transaction(trans); + return btrfs_commit_current_transaction(root); } /* diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 69760e1e726f..0283ee9bf813 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -805,14 +805,7 @@ static void flush_space(struct btrfs_fs_info *fs_info, * because that does not wait for a transaction to fully commit * (only for it to be unblocked, state TRANS_STATE_UNBLOCKED). */ - trans = btrfs_attach_transaction_barrier(root); - if (IS_ERR(trans)) { - ret = PTR_ERR(trans); - if (ret == -ENOENT) - ret = 0; - break; - } - ret = btrfs_commit_transaction(trans); + ret = btrfs_commit_current_transaction(root); break; default: ret = -ENOSPC; diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 117a355dbd7a..21d986e07500 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2257,9 +2257,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, static int btrfs_freeze(struct super_block *sb) { - struct btrfs_trans_handle *trans; struct btrfs_fs_info *fs_info = btrfs_sb(sb); - struct btrfs_root *root = fs_info->tree_root; set_bit(BTRFS_FS_FROZEN, &fs_info->flags); /* @@ -2268,14 +2266,7 @@ static int btrfs_freeze(struct super_block *sb) * we want to avoid on a frozen filesystem), or do the commit * ourselves. */ - trans = btrfs_attach_transaction_barrier(root); - if (IS_ERR(trans)) { - /* no transaction, don't bother */ - if (PTR_ERR(trans) == -ENOENT) - return 0; - return PTR_ERR(trans); - } - return btrfs_commit_transaction(trans); + return btrfs_commit_current_transaction(fs_info->tree_root); } static int check_dev_super(struct btrfs_device *dev) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 639755f025b4..9590a1899b9d 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1989,6 +1989,25 @@ void btrfs_commit_transaction_async(struct btrfs_trans_handle *trans) btrfs_put_transaction(cur_trans); } +/* + * If there is a running transaction commit it or if it's already committing, + * wait for its commit to complete. Does not start and commit a new transaction + * if there isn't any running. + */ +int btrfs_commit_current_transaction(struct btrfs_root *root) +{ + struct btrfs_trans_handle *trans; + + trans = btrfs_attach_transaction_barrier(root); + if (IS_ERR(trans)) { + int ret = PTR_ERR(trans); + + return (ret == -ENOENT) ? 0 : ret; + } + + return btrfs_commit_transaction(trans); +} + static void cleanup_transaction(struct btrfs_trans_handle *trans, int err) { struct btrfs_fs_info *fs_info = trans->fs_info; diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h index 90b987941dd1..81da655b5ee7 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h @@ -268,6 +268,7 @@ void btrfs_maybe_wake_unfinished_drop(struct btrfs_fs_info *fs_info); int btrfs_clean_one_deleted_snapshot(struct btrfs_fs_info *fs_info); int btrfs_commit_transaction(struct btrfs_trans_handle *trans); void btrfs_commit_transaction_async(struct btrfs_trans_handle *trans); +int btrfs_commit_current_transaction(struct btrfs_root *root); int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans); bool btrfs_should_end_transaction(struct btrfs_trans_handle *trans); void btrfs_throttle(struct btrfs_fs_info *fs_info); From patchwork Wed May 22 14:36:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13670905 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3D4F2B9B7 for ; Wed, 22 May 2024 14:36:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716388607; cv=none; b=hz42c+GP7My8QgA573ZsQXJfnVbLZ1xD9re1fbrPLO8Di6hahgDeGy7u/jtSs2oFpqYV0Rahg/IxW9/A6WnZ7yoD6xyiQ0q6geNT7rirhrRIigkRNYxv8iOgZeYhmYfLrlD4SQU6vjQs3a9CgZHFAugIxM1lpCJgCYtjByszLyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716388607; c=relaxed/simple; bh=jSUaWv3D26Gc994bf/+m3KCGYKcbSM+Rx1fog0KmeIY=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n6ZJdWwWjqRxJFV6VJKq6DLFajMFt+yrM68Gv0qcEieyjVJBboc+CgM6FvTuj/wrHahZSWNX/sAB6yKKaf8T89u6ni45Z0G5OTwrdJF9D4hVWYx8R9SnccLw7pedsz8c17hKz0g09xKFnRP2Pszf4cSoVB4PkLXJeOMrFANQSYE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h0/Amg1p; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="h0/Amg1p" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 401E7C2BBFC for ; Wed, 22 May 2024 14:36:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716388606; bh=jSUaWv3D26Gc994bf/+m3KCGYKcbSM+Rx1fog0KmeIY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=h0/Amg1pyy7Z+Makil1hg/z3D68e3+tWzpz4HUtiuJNXjY8lsIT8jmOZihCpjFEYz 1VtkiFZIQR0QvXGMIJlHL8O7huLf5J0PP+iOMXjJYTBm8jZ0FEsETx+q+Mh0BOsLjd l5fYoIbsEjoM3pINaKwMTZOY9sIC9nZuw5uOP4t2l7i9QhQRuV32cFwrBef7h9m8iX 8bdvaCfaOPnoUl/+h23jPLWPqgZcTUswSsRT9F5WuEuC81SdtSC5UJW/jdh8h1ZkJA Sy8zwDtrGnh4eecC29NdT0LreN6K94ZPDD7BBPHPGPwe0mzh0PH/0WMJOgTatZ8ZXe zYInhANq6tUIg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 7/7] btrfs: send: get rid of the label and gotos at ensure_commit_roots_uptodate() Date: Wed, 22 May 2024 15:36:35 +0100 Message-Id: <11d9f5813524b2b2d1164fe921464f8427c18620.1716386100.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana Now that there is a helper to commit the current transaction and we are using it, there's no need for the label and goto statements at ensure_commit_roots_uptodate(). So replace them with direct return statements that call btrfs_commit_current_transaction(). Signed-off-by: Filipe Manana --- fs/btrfs/send.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 7a82132500a8..2099b5f8c022 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -8001,23 +8001,15 @@ static int ensure_commit_roots_uptodate(struct send_ctx *sctx) struct btrfs_root *root = sctx->parent_root; if (root && root->node != root->commit_root) - goto commit_trans; + return btrfs_commit_current_transaction(root); for (int i = 0; i < sctx->clone_roots_cnt; i++) { root = sctx->clone_roots[i].root; if (root->node != root->commit_root) - goto commit_trans; + return btrfs_commit_current_transaction(root); } return 0; - -commit_trans: - /* - * Use the first root we found. We could use any but that would cause - * an unnecessary update of the root's item in the root tree when - * committing the transaction if that root wasn't changed before. - */ - return btrfs_commit_current_transaction(root); } /*