Skip to contentSkip to conversation

btrfs: move transaction aborts to the error site in add_block_group_free_space()

PATCH In review David Sterba 2 participants 2 messages May 17, 2025 – May 19, 2025 Btrfs file system

lore
Share & tools
lore

David Sterba

author maintainer
#0 lore raw

PATCH 1/1 btrfs: move transaction aborts to the error site in add_block_group_free_space()

Transaction aborts should be done next to the place the error happens, which was not done in add_block_group_free_space().

---
 fs/btrfs/free-space-tree.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/btrfs/free-space-tree.c +3 -2
index 0c573d46639ae9..6cbdb578e66c1f 100644
@@ -1408,16 +1408,17 @@ int add_block_group_free_space(struct btrfs_trans_handle *trans,
 	path = btrfs_alloc_path();
 	if (!path) {
 		ret = -ENOMEM;
+		btrfs_abort_transaction(trans, ret);
 		goto out;
 	}
 
 	ret = __add_block_group_free_space(trans, block_group, path);
+	if (ret)
+		btrfs_abort_transaction(trans, ret);
 
 out:
 	btrfs_free_path(path);
 	mutex_unlock(&block_group->free_space_lock);
-	if (ret)
-		btrfs_abort_transaction(trans, ret);
 	return ret;
 }
 
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · David Sterba

Transaction aborts should be done next to the place the error happens, which was not done in add_block_group_free_space().

Looks good, thanks.

Quoted 32 lines
---
 fs/btrfs/free-space-tree.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/btrfs/free-space-tree.c +3 -3
index 0c573d46639ae9..6cbdb578e66c1f 100644
@@ -1408,16 +1408,17 @@ int add_block_group_free_space(struct btrfs_trans_handle *trans,
        path = btrfs_alloc_path();
        if (!path) {
                ret = -ENOMEM;
+               btrfs_abort_transaction(trans, ret);
                goto out;
        }
 
        ret = __add_block_group_free_space(trans, block_group, path);
+       if (ret)
+               btrfs_abort_transaction(trans, ret);
 
 out:
        btrfs_free_path(path);
        mutex_unlock(&block_group->free_space_lock);
-       if (ret)
-               btrfs_abort_transaction(trans, ret);
        return ret;
 }
 
--

2.49.0