]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: unfold transaction abort at btrfs_copy_root()
authorFilipe Manana <fdmanana@suse.com>
Mon, 19 May 2025 09:59:18 +0000 (10:59 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Jul 2025 21:50:35 +0000 (23:50 +0200)
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 analyzing a
stack trace with a transaction abort we know which call failed.

Reviewed-by: Daniel Vacek <neelx@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.c

index a2e7979372ccd8fb56e53f438803ff36d6c11265..ae6cd77282f522e156809bc20872b53354b9b9e1 100644 (file)
@@ -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;
        }