]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: pass struct btrfs_inode to can_nocow_extent()
authorDavid Sterba <dsterba@suse.com>
Mon, 17 Feb 2025 21:15:25 +0000 (22:15 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 18 Mar 2025 19:35:43 +0000 (20:35 +0100)
Pass a struct btrfs_inode to can_nocow_extent() as it's an internal
interface, allowing to remove some use of BTRFS_I.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/btrfs_inode.h
fs/btrfs/direct-io.c
fs/btrfs/file.c
fs/btrfs/inode.c

index 029fba82b81dac069e188f36a6095380b9dbce22..ca1cd600f5d21a399cde6d28257942845c1abb3d 100644 (file)
@@ -532,7 +532,7 @@ int btrfs_check_sector_csum(struct btrfs_fs_info *fs_info, struct page *page,
                            u32 pgoff, u8 *csum, const u8 * const csum_expected);
 bool btrfs_data_csum_ok(struct btrfs_bio *bbio, struct btrfs_device *dev,
                        u32 bio_offset, struct bio_vec *bv);
-noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
+noinline int can_nocow_extent(struct btrfs_inode *inode, u64 offset, u64 *len,
                              struct btrfs_file_extent *file_extent,
                              bool nowait);
 
index eacbb74bf6bc99306fbbdb1cd23fbd6e63688d0b..a374ce7a1813b0a4e49e806beb7c95320dc29ac8 100644 (file)
@@ -248,7 +248,8 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,
                len = min(len, em->len - (start - em->start));
                block_start = extent_map_block_start(em) + (start - em->start);
 
-               if (can_nocow_extent(inode, start, &len, &file_extent, false) == 1) {
+               if (can_nocow_extent(BTRFS_I(inode), start, &len, &file_extent,
+                                    false) == 1) {
                        bg = btrfs_inc_nocow_writers(fs_info, block_start);
                        if (bg)
                                can_nocow = true;
index 59af01d6cc56830c46790941647704bd12f3a6a5..f78cfe5dfa2c97500a601ed7aa9758215586337a 100644 (file)
@@ -1013,8 +1013,7 @@ int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
                btrfs_lock_and_flush_ordered_range(inode, lockstart, lockend,
                                                   &cached_state);
        }
-       ret = can_nocow_extent(&inode->vfs_inode, lockstart, &num_bytes,
-                              NULL, nowait);
+       ret = can_nocow_extent(inode, lockstart, &num_bytes, NULL, nowait);
        if (ret <= 0)
                btrfs_drew_write_unlock(&root->snapshot_lock);
        else
index a7fa63fef85fc0d8fcf2014b43998ace8be097fe..bd54e29c6fffa65455fc476408b0ff8c0f9bf3a4 100644 (file)
@@ -7075,17 +7075,17 @@ static bool btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr)
  * NOTE: This only checks the file extents, caller is responsible to wait for
  *      any ordered extents.
  */
-noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
+noinline int can_nocow_extent(struct btrfs_inode *inode, u64 offset, u64 *len,
                              struct btrfs_file_extent *file_extent,
                              bool nowait)
 {
-       struct btrfs_fs_info *fs_info = inode_to_fs_info(inode);
+       struct btrfs_root *root = inode->root;
+       struct btrfs_fs_info *fs_info = root->fs_info;
        struct can_nocow_file_extent_args nocow_args = { 0 };
        struct btrfs_path *path;
        int ret;
        struct extent_buffer *leaf;
-       struct btrfs_root *root = BTRFS_I(inode)->root;
-       struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
+       struct extent_io_tree *io_tree = &inode->io_tree;
        struct btrfs_file_extent_item *fi;
        struct btrfs_key key;
        int found_type;
@@ -7095,8 +7095,8 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
                return -ENOMEM;
        path->nowait = nowait;
 
-       ret = btrfs_lookup_file_extent(NULL, root, path,
-                       btrfs_ino(BTRFS_I(inode)), offset, 0);
+       ret = btrfs_lookup_file_extent(NULL, root, path, btrfs_ino(inode),
+                                      offset, 0);
        if (ret < 0)
                goto out;
 
@@ -7111,7 +7111,7 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
        ret = 0;
        leaf = path->nodes[0];
        btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
-       if (key.objectid != btrfs_ino(BTRFS_I(inode)) ||
+       if (key.objectid != btrfs_ino(inode) ||
            key.type != BTRFS_EXTENT_DATA_KEY) {
                /* not our file or wrong item type, must cow */
                goto out;
@@ -7132,7 +7132,7 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
        nocow_args.end = offset + *len - 1;
        nocow_args.free_path = true;
 
-       ret = can_nocow_file_extent(path, &key, BTRFS_I(inode), &nocow_args);
+       ret = can_nocow_file_extent(path, &key, inode, &nocow_args);
        /* can_nocow_file_extent() has freed the path. */
        path = NULL;
 
@@ -7148,7 +7148,7 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
                                  nocow_args.file_extent.offset))
                goto out;
 
-       if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW) &&
+       if (!(inode->flags & BTRFS_INODE_NODATACOW) &&
            found_type == BTRFS_FILE_EXTENT_PREALLOC) {
                u64 range_end;