btrfs: move transaction aborts to the error site in convert_free_space_to_bitmaps()
authorDavid Sterba <dsterba@suse.com>
Wed, 30 Apr 2025 16:45:18 +0000 (18:45 +0200)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:54 +0000 (14:30 +0200)
Transaction aborts should be done next to the place the error happens,
which was not done in convert_free_space_to_bitmaps(). The DEBUG_WARN()
is removed because we get the abort message.

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

index ef62f3a69267f311e12575e2e3a0e0401a454ceb..b5458a71f0b3e8a5ef2b90dccc64e18d79d773e2 100644 (file)
@@ -223,6 +223,7 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
        bitmap = alloc_bitmap(bitmap_size);
        if (!bitmap) {
                ret = -ENOMEM;
+               btrfs_abort_transaction(trans, ret);
                goto out;
        }
 
@@ -235,8 +236,10 @@ int convert_free_space_to_bitmaps(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;
@@ -271,14 +274,17 @@ int convert_free_space_to_bitmaps(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);
        }
 
        info = search_free_space_info(trans, block_group, path, 1);
        if (IS_ERR(info)) {
                ret = PTR_ERR(info);
+               btrfs_abort_transaction(trans, ret);
                goto out;
        }
        leaf = path->nodes[0];
@@ -293,8 +299,8 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
                          "incorrect extent count for %llu; counted %u, expected %u",
                          block_group->start, extent_count,
                          expected_extent_count);
-               DEBUG_WARN();
                ret = -EIO;
+               btrfs_abort_transaction(trans, ret);
                goto out;
        }
 
@@ -315,8 +321,10 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
 
                ret = btrfs_insert_empty_item(trans, root, path, &key,
                                              data_size);
-               if (ret)
+               if (ret) {
+                       btrfs_abort_transaction(trans, ret);
                        goto out;
+               }
 
                leaf = path->nodes[0];
                ptr = btrfs_item_ptr_offset(leaf, path->slots[0]);
@@ -331,8 +339,6 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
        ret = 0;
 out:
        kvfree(bitmap);
-       if (ret)
-               btrfs_abort_transaction(trans, ret);
        return ret;
 }