]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: simplify arguments for btrfs_cross_ref_exist()
authorFilipe Manana <fdmanana@suse.com>
Mon, 9 Dec 2024 16:59:23 +0000 (16:59 +0000)
committerDavid Sterba <dsterba@suse.com>
Mon, 13 Jan 2025 13:53:16 +0000 (14:53 +0100)
Instead of passing a root and an objectid which matches an inode number,
pass the inode instead, since the root is always the root associated to
the inode and the objectid is the number of that inode.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c
fs/btrfs/extent-tree.h
fs/btrfs/inode.c

index 51c49b2f49911afd0e8ef44405310bb34e226f53..af3893ad784b674dc1ec064b24c65ddeebb5cdaa 100644 (file)
@@ -2206,10 +2206,11 @@ int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans,
        return ret;
 }
 
-static noinline int check_delayed_ref(struct btrfs_root *root,
+static noinline int check_delayed_ref(struct btrfs_inode *inode,
                                      struct btrfs_path *path,
-                                     u64 objectid, u64 offset, u64 bytenr)
+                                     u64 offset, u64 bytenr)
 {
+       struct btrfs_root *root = inode->root;
        struct btrfs_delayed_ref_head *head;
        struct btrfs_delayed_ref_node *ref;
        struct btrfs_delayed_ref_root *delayed_refs;
@@ -2283,7 +2284,7 @@ static noinline int check_delayed_ref(struct btrfs_root *root,
                 * then we have a cross reference.
                 */
                if (ref->ref_root != btrfs_root_id(root) ||
-                   ref_owner != objectid || ref_offset != offset) {
+                   ref_owner != btrfs_ino(inode) || ref_offset != offset) {
                        ret = 1;
                        break;
                }
@@ -2294,10 +2295,11 @@ static noinline int check_delayed_ref(struct btrfs_root *root,
        return ret;
 }
 
-static noinline int check_committed_ref(struct btrfs_root *root,
+static noinline int check_committed_ref(struct btrfs_inode *inode,
                                        struct btrfs_path *path,
-                                       u64 objectid, u64 offset, u64 bytenr)
+                                       u64 offset, u64 bytenr)
 {
+       struct btrfs_root *root = inode->root;
        struct btrfs_fs_info *fs_info = root->fs_info;
        struct btrfs_root *extent_root = btrfs_extent_root(fs_info, bytenr);
        struct extent_buffer *leaf;
@@ -2364,29 +2366,29 @@ static noinline int check_committed_ref(struct btrfs_root *root,
        if (btrfs_extent_refs(leaf, ei) !=
            btrfs_extent_data_ref_count(leaf, ref) ||
            btrfs_extent_data_ref_root(leaf, ref) != btrfs_root_id(root) ||
-           btrfs_extent_data_ref_objectid(leaf, ref) != objectid ||
+           btrfs_extent_data_ref_objectid(leaf, ref) != btrfs_ino(inode) ||
            btrfs_extent_data_ref_offset(leaf, ref) != offset)
                return 1;
 
        return 0;
 }
 
-int btrfs_cross_ref_exist(struct btrfs_root *root, u64 objectid, u64 offset,
+int btrfs_cross_ref_exist(struct btrfs_inode *inode, u64 offset,
                          u64 bytenr, struct btrfs_path *path)
 {
        int ret;
 
        do {
-               ret = check_committed_ref(root, path, objectid, offset, bytenr);
+               ret = check_committed_ref(inode, path, offset, bytenr);
                if (ret && ret != -ENOENT)
                        goto out;
 
-               ret = check_delayed_ref(root, path, objectid, offset, bytenr);
+               ret = check_delayed_ref(inode, path, offset, bytenr);
        } while (ret == -EAGAIN && !path->nowait);
 
 out:
        btrfs_release_path(path);
-       if (btrfs_is_data_reloc_root(root))
+       if (btrfs_is_data_reloc_root(inode->root))
                WARN_ON(ret > 0);
        return ret;
 }
index ee62035c4a7154c23feb258988d126553ea87b80..46b8e19022df80f438820f22847687b72c55e870 100644 (file)
@@ -116,8 +116,7 @@ int btrfs_pin_extent(struct btrfs_trans_handle *trans, u64 bytenr, u64 num,
 int btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans,
                                    const struct extent_buffer *eb);
 int btrfs_exclude_logged_extents(struct extent_buffer *eb);
-int btrfs_cross_ref_exist(struct btrfs_root *root,
-                         u64 objectid, u64 offset, u64 bytenr,
+int btrfs_cross_ref_exist(struct btrfs_inode *inode, u64 offset, u64 bytenr,
                          struct btrfs_path *path);
 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
                                             struct btrfs_root *root,
index 0965a29cf4f71284917f6e03407006c6e93d52f0..8a173a24ac05c64ea2db077520f6d18b741e1f29 100644 (file)
@@ -1920,8 +1920,7 @@ static int can_nocow_file_extent(struct btrfs_path *path,
         */
        btrfs_release_path(path);
 
-       ret = btrfs_cross_ref_exist(root, btrfs_ino(inode),
-                                   key->offset - args->file_extent.offset,
+       ret = btrfs_cross_ref_exist(inode, key->offset - args->file_extent.offset,
                                    args->file_extent.disk_bytenr, path);
        WARN_ON_ONCE(ret > 0 && is_freespace_inode);
        if (ret != 0)