]> git.hungrycats.org Git - linux/commitdiff
btrfs: drop the transaction handle from the prealloc helpers
authorTal Zussman <tz2294@columbia.edu>
Thu, 17 Sep 2026 04:00:02 +0000 (00:00 -0400)
committerDavid Sterba <dsterba@suse.com>
Thu, 17 Sep 2026 17:49:47 +0000 (19:49 +0200)
The v1 space cache created its inode during the transaction commit, and
btrfs_prealloc_file_range_trans() existed so that preallocation could
reuse the open handle. It was the only caller passing a transaction, so
__btrfs_prealloc_file_range() and insert_prealloc_file_extent() now
always start their own. Fold the wrapper into
btrfs_prealloc_file_range() and drop the parameter.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c

index 8598792f1ae4255b559a8b97f187165f815fb83e..142ce180e7c9330d5929d52972daeda24ac3e380 100644 (file)
@@ -9156,14 +9156,13 @@ out_inode:
 }
 
 static struct btrfs_trans_handle *insert_prealloc_file_extent(
-                                      struct btrfs_trans_handle *trans_in,
                                       struct btrfs_inode *inode,
                                       struct btrfs_key *ins,
                                       u64 file_offset)
 {
        struct btrfs_file_extent_item stack_fi;
        struct btrfs_replace_extent_info extent_info;
-       struct btrfs_trans_handle *trans = trans_in;
+       struct btrfs_trans_handle *trans;
        struct btrfs_path *path;
        u64 start = ins->objectid;
        u64 len = ins->offset;
@@ -9184,15 +9183,6 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent(
        if (ret < 0)
                return ERR_PTR(ret);
 
-       if (trans) {
-               ret = insert_reserved_file_extent(trans, inode,
-                                                 file_offset, &stack_fi,
-                                                 true, qgroup_released);
-               if (ret)
-                       goto free_qgroup;
-               return trans;
-       }
-
        extent_info.disk_offset = start;
        extent_info.disk_len = len;
        extent_info.data_offset = 0;
@@ -9232,12 +9222,12 @@ free_qgroup:
        return ERR_PTR(ret);
 }
 
-static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
-                                      u64 start, u64 num_bytes, u64 min_size,
-                                      loff_t actual_len, u64 *alloc_hint,
-                                      struct btrfs_trans_handle *trans)
+int btrfs_prealloc_file_range(struct inode *inode, int mode,
+                             u64 start, u64 num_bytes, u64 min_size,
+                             loff_t actual_len, u64 *alloc_hint)
 {
        struct btrfs_fs_info *fs_info = inode_to_fs_info(inode);
+       struct btrfs_trans_handle *trans;
        struct extent_map *em;
        struct btrfs_root *root = BTRFS_I(inode)->root;
        struct btrfs_key ins;
@@ -9247,11 +9237,8 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
        u64 cur_bytes;
        u64 last_alloc = (u64)-1;
        int ret = 0;
-       bool own_trans = true;
        u64 end = start + num_bytes - 1;
 
-       if (trans)
-               own_trans = false;
        while (num_bytes > 0) {
                cur_bytes = min_t(u64, num_bytes, SZ_256M);
                cur_bytes = max(cur_bytes, min_size);
@@ -9277,8 +9264,8 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
                clear_offset += ins.offset;
 
                last_alloc = ins.offset;
-               trans = insert_prealloc_file_extent(trans, BTRFS_I(inode),
-                                                   &ins, cur_offset);
+               trans = insert_prealloc_file_extent(BTRFS_I(inode), &ins,
+                                                   cur_offset);
                /*
                 * Now that we inserted the prealloc extent we can finally
                 * decrement the number of reservations in the block group.
@@ -9350,8 +9337,7 @@ next:
                                        range_start, range_end - range_start);
                        if (ret) {
                                btrfs_abort_transaction(trans, ret);
-                               if (own_trans)
-                                       btrfs_end_transaction(trans);
+                               btrfs_end_transaction(trans);
                                break;
                        }
 
@@ -9363,15 +9349,11 @@ next:
 
                if (unlikely(ret)) {
                        btrfs_abort_transaction(trans, ret);
-                       if (own_trans)
-                               btrfs_end_transaction(trans);
+                       btrfs_end_transaction(trans);
                        break;
                }
 
-               if (own_trans) {
-                       btrfs_end_transaction(trans);
-                       trans = NULL;
-               }
+               btrfs_end_transaction(trans);
        }
        if (clear_offset < end)
                btrfs_free_reserved_data_space(BTRFS_I(inode), NULL, clear_offset,
@@ -9379,15 +9361,6 @@ next:
        return ret;
 }
 
-int btrfs_prealloc_file_range(struct inode *inode, int mode,
-                             u64 start, u64 num_bytes, u64 min_size,
-                             loff_t actual_len, u64 *alloc_hint)
-{
-       return __btrfs_prealloc_file_range(inode, mode, start, num_bytes,
-                                          min_size, actual_len, alloc_hint,
-                                          NULL);
-}
-
 /*
  * NOTE: in case you are adding MAY_EXEC check for directories:
  * we are marking them with IOP_FASTPERM_MAY_EXEC, allowing path lookup to