Skip to contentSkip to conversation

btrfs: move transaction aborts to the error site in remove_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 remove_block_group_free_space()

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

---
 fs/btrfs/free-space-tree.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
fs/btrfs/free-space-tree.c +7 -4
index 6cbdb578e66c1f..af51cf784a5bd7 100644
@@ -1444,6 +1444,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;
 	}
 
@@ -1456,8 +1457,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;
@@ -1485,16 +1488,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;
 }
 
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 remove_block_group_free_space().

Looks good, thanks.

Quoted 52 lines
---
 fs/btrfs/free-space-tree.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
fs/btrfs/free-space-tree.c +7 -5
index 6cbdb578e66c1f..af51cf784a5bd7 100644
@@ -1444,6 +1444,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;
        }
 
@@ -1456,8 +1457,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;
@@ -1485,16 +1488,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;
 }
 
--

2.49.0