Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: fdmanana@kernel.org
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v2 5/6] btrfs: abort transaction on qgroup failures in create_pending_snapshot()
Date: Sat,  3 Oct 2026 18:00:04 +0100	[thread overview]
Message-ID: <e09eefcdd2d6aecf0dc4e2a786b46789f6f66efb.1791046651.git.fdmanana@suse.com> (raw)
In-Reply-To: <cover.1791046651.git.fdmanana@suse.com>

From: Filipe Manana <fdmanana@suse.com>

If we get an error when calling one of the qgroup functions, we jump to
the 'fail' label without aborting the transaction. This is not a bug as up
the call chain (transaction commit path), we will end up aborting the
transaction. However having the explicit transaction abort in
create_pending_snapshot() allows us to get a stack trace and log message
that tells us exactly where we failed, useful for troubleshooting, and
also adds consistency since in that function we abort the transaction in
every other error path.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/transaction.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index da4ffa7bda00..fcbcb4a208be 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1920,14 +1920,21 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 	 * To co-operate with that hack, we do hack again.
 	 * Or snapshot will be greatly slowed down by a subtree qgroup rescan
 	 */
-	if (btrfs_qgroup_mode(fs_info) == BTRFS_QGROUP_MODE_FULL)
+	if (btrfs_qgroup_mode(fs_info) == BTRFS_QGROUP_MODE_FULL) {
 		ret = qgroup_account_snapshot(trans, root, parent_root,
 					      pending->inherit, objectid);
-	else if (btrfs_qgroup_mode(fs_info) == BTRFS_QGROUP_MODE_SIMPLE)
+		if (unlikely(ret < 0)) {
+			btrfs_abort_transaction(trans, ret);
+			goto fail;
+		}
+	} else if (btrfs_qgroup_mode(fs_info) == BTRFS_QGROUP_MODE_SIMPLE) {
 		ret = btrfs_qgroup_inherit(trans, btrfs_root_id(root), objectid,
 					   btrfs_root_id(parent_root), pending->inherit);
-	if (unlikely(ret < 0))
-		goto fail;
+		if (unlikely(ret < 0)) {
+			btrfs_abort_transaction(trans, ret);
+			goto fail;
+		}
+	}
 
 	ret = btrfs_insert_dir_item(trans, &fname.disk_name,
 				    parent_inode, &key, BTRFS_FT_DIR, index, NULL);
-- 
2.47.2


  parent reply	other threads:[~2026-10-03 17:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02 18:55 [PATCH 0/6] btrfs: some qgroup fixes and cleanups fdmanana
2026-10-02 18:55 ` [PATCH] btrfs: qgroup: fix race between subvolume creation and adding/removing relations fdmanana
2026-10-02 18:58   ` Filipe Manana
2026-10-02 18:55 ` [PATCH 1/6] btrfs: qgroup: fix swapped blocks existence check when tracing after COW fdmanana
2026-10-03  0:18   ` Qu Wenruo
2026-10-02 18:55 ` [PATCH 2/6] btrfs: qgroup: abort transaction on failure to add qgroup relation fdmanana
2026-10-03  0:19   ` Qu Wenruo
2026-10-02 18:55 ` [PATCH 3/6] btrfs: qgroup: fix leak of qgroups in rb tree after failure to enable quotas fdmanana
2026-10-02 18:55 ` [PATCH 4/6] btrfs: qgroup: merge error labels in btrfs_quota_enable() fdmanana
2026-10-03  0:22   ` Qu Wenruo
2026-10-02 18:55 ` [PATCH 5/6] btrfs: abort transaction on qgroup failures in create_pending_snapshot() fdmanana
2026-10-03  0:22   ` Qu Wenruo
2026-10-02 18:55 ` [PATCH 6/6] btrfs: qgroup: fix off-by-one max level check in qgroup_trace_new_subtree_blocks() fdmanana
2026-10-03 16:59 ` [PATCH v2 0/6] btrfs: some qgroup fixes and cleanups fdmanana
2026-10-03 17:00   ` [PATCH v2 1/6] btrfs: qgroup: fix swapped blocks existence check when tracing after COW fdmanana
2026-10-03 21:29     ` Qu Wenruo
2026-10-03 17:00   ` [PATCH v2 2/6] btrfs: qgroup: abort transaction on failure to add qgroup relation fdmanana
2026-10-03 17:00   ` [PATCH v2 3/6] btrfs: qgroup: fix leak of qgroups in rb tree after failure to enable quotas fdmanana
2026-10-03 21:35     ` Qu Wenruo
2026-10-03 17:00   ` [PATCH v2 4/6] btrfs: qgroup: merge error labels in btrfs_quota_enable() fdmanana
2026-10-03 17:00   ` fdmanana [this message]
2026-10-03 17:00   ` [PATCH v2 6/6] btrfs: qgroup: fix off-by-one max level check in qgroup_trace_new_subtree_blocks() fdmanana
2026-10-03 21:36     ` Qu Wenruo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e09eefcdd2d6aecf0dc4e2a786b46789f6f66efb.1791046651.git.fdmanana@suse.com \
    --to=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox