Skip to contentSkip to conversation

btrfs: some cleanups for btrfs_copy_root()

PATCH In review [email protected] 4 participants 6 messages May 19, 2025 – May 28, 2025 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover btrfs: some cleanups for btrfs_copy_root()

From: Filipe Manana <[email protected]>

A couple simple cleanups, details in the change logs.

Filipe Manana (2):
btrfs: unfold transaction abort at btrfs_copy_root()
btrfs: abort transaction on unexpected eb generation at btrfs_copy_root()

 fs/btrfs/ctree.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
Signature · 1 line
2.47.2
#1 lore raw

PATCH 1/2 btrfs: unfold transaction abort at btrfs_copy_root()

From: Filipe Manana <[email protected]>

Instead of having a common btrfs_abort_transaction() call for when any of the two btrfs_inc_ref() calls fail, move the btrfs_abort_transaction() to happen immediately after each one of the calls, so that when analysing a stack trace with a transaction abort we know which call failed.

---
 fs/btrfs/ctree.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
fs/btrfs/ctree.c +7 -3
index a2e7979372cc..ae6cd77282f5 100644
@@ -284,14 +284,18 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
 	write_extent_buffer_fsid(cow, fs_info->fs_devices->metadata_uuid);
 
 	WARN_ON(btrfs_header_generation(buf) > trans->transid);
-	if (new_root_objectid == BTRFS_TREE_RELOC_OBJECTID)
+	if (new_root_objectid == BTRFS_TREE_RELOC_OBJECTID) {
 		ret = btrfs_inc_ref(trans, root, cow, 1);
-	else
+		if (ret)
+			btrfs_abort_transaction(trans, ret);
+	} else {
 		ret = btrfs_inc_ref(trans, root, cow, 0);
+		if (ret)
+			btrfs_abort_transaction(trans, ret);
+	}
 	if (ret) {
 		btrfs_tree_unlock(cow);
 		free_extent_buffer(cow);
-		btrfs_abort_transaction(trans, ret);
 		return ret;
 	}
 
Signature · 1 line
2.47.2
#2 lore raw

PATCH 2/2 btrfs: abort transaction on unexpected eb generation at btrfs_copy_root()

In reply to [email protected]

From: Filipe Manana <[email protected]>

If we find an unexpected generation for the extent buffer we are cloning at btrfs_copy_root(), we just WARN_ON() and don't error out and abort the transaction, meaning we allow to persist metadata with an unexpected generation. Instead of warning only, abort the transaction and return -EUCLEAN.

---
 fs/btrfs/ctree.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
fs/btrfs/ctree.c +8 -1
index ae6cd77282f5..a5ee6ce312cf 100644
@@ -283,7 +283,14 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
 
 	write_extent_buffer_fsid(cow, fs_info->fs_devices->metadata_uuid);
 
-	WARN_ON(btrfs_header_generation(buf) > trans->transid);
+	if (unlikely(btrfs_header_generation(buf) > trans->transid)) {
+		btrfs_tree_unlock(cow);
+		free_extent_buffer(cow);
+		ret = -EUCLEAN;
+		btrfs_abort_transaction(trans, ret);
+		return ret;
+	}
+
 	if (new_root_objectid == BTRFS_TREE_RELOC_OBJECTID) {
 		ret = btrfs_inc_ref(trans, root, cow, 1);
 		if (ret)
Signature · 1 line
2.47.2
Reviewed-by on the v1 series
#3 lore raw
In reply to [email protected]
Quoted 11 lines · On Mon, 19 May 2025 at 12:42, <[email protected]> wrote:

From: Filipe Manana <[email protected]>

A couple simple cleanups, details in the change logs.

Filipe Manana (2):
btrfs: unfold transaction abort at btrfs_copy_root()
btrfs: abort transaction on unexpected eb generation at btrfs_copy_root()

 fs/btrfs/ctree.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

Looks good to me.

Quoted 4 lines

--
2.47.2

Reviewed-by on the v1 series
#4 lore raw
In reply to [email protected]
Quoted 3 lines · 在 2025/5/19 20:12, [email protected] 写道:

From: Filipe Manana <[email protected]>

A couple simple cleanups, details in the change logs.

Thanks,
Qu

Quoted 8 lines

Filipe Manana (2):
btrfs: unfold transaction abort at btrfs_copy_root()
btrfs: abort transaction on unexpected eb generation at btrfs_copy_root()

  fs/btrfs/ctree.c | 19 +++++++++++++++----
  1 file changed, 15 insertions(+), 4 deletions(-)