btrfs: move transaction aborts to the error site in remove_block_group_free_space()
authorDavid Sterba <dsterba@suse.com>
Sat, 17 May 2025 19:04:10 +0000 (21:04 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Jul 2025 21:50:34 +0000 (23:50 +0200)
Transaction aborts should be done next to the place the error happens,
which was not done in remove_block_group_free_space().

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/free-space-tree.c

index a83c268f7f87cab1ded0eb7c47cf85a3f2358acd..0755656a270eecf5dd0ba8522363b76fea354ea3 100644 (file)
@@ -1491,6 +1491,7 @@ int remove_block_group_free_space(struct btrfs_trans_handle *trans,
        path = btrfs_alloc_path();
        if (!path) {
                ret = -ENOMEM;
+               btrfs_abort_transaction(trans, ret);
                goto out;
        }
 
@@ -1503,8 +1504,10 @@ int remove_block_group_free_space(struct btrfs_trans_handle *trans,
 
        while (!done) {
                ret = btrfs_search_prev_slot(trans, root, &key, path, -1, 1);
-               if (ret)
+               if (ret) {
+                       btrfs_abort_transaction(trans, ret);
                        goto out;
+               }
 
                leaf = path->nodes[0];
                nr = 0;
@@ -1532,16 +1535,16 @@ int remove_block_group_free_space(struct btrfs_trans_handle *trans,
                }
 
                ret = btrfs_del_items(trans, root, path, path->slots[0], nr);
-               if (ret)
+               if (ret) {
+                       btrfs_abort_transaction(trans, ret);
                        goto out;
+               }
                btrfs_release_path(path);
        }
 
        ret = 0;
 out:
        btrfs_free_path(path);
-       if (ret)
-               btrfs_abort_transaction(trans, ret);
        return ret;
 }