btrfs: stop allocating a path when checking if cross reference exists
authorFilipe Manana <fdmanana@suse.com>
Wed, 23 Mar 2022 16:19:26 +0000 (16:19 +0000)
committerDavid Sterba <dsterba@suse.com>
Mon, 16 May 2022 15:03:10 +0000 (17:03 +0200)
At btrfs_cross_ref_exist() we always allocate a path, but we really don't
need to because all its callers (only 2) already have an allocated path
that is not being used when they call btrfs_cross_ref_exist(). So change
btrfs_cross_ref_exist() to take a path as an argument and update both
its callers to pass in the unused path they have when they call
btrfs_cross_ref_exist().

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/ctree.h
fs/btrfs/extent-tree.c
fs/btrfs/inode.c

index 0d0ac09..79399eb 100644 (file)
@@ -2784,7 +2784,8 @@ int btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans,
                                    u64 bytenr, u64 num_bytes);
 int btrfs_exclude_logged_extents(struct extent_buffer *eb);
 int btrfs_cross_ref_exist(struct btrfs_root *root,
-                         u64 objectid, u64 offset, u64 bytenr, bool strict);
+                         u64 objectid, u64 offset, u64 bytenr, bool strict,
+                         struct btrfs_path *path);
 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
                                             struct btrfs_root *root,
                                             u64 parent, u64 root_objectid,
index 6aa92f8..fc5b9be 100644 (file)
@@ -2357,15 +2357,10 @@ out:
 }
 
 int btrfs_cross_ref_exist(struct btrfs_root *root, u64 objectid, u64 offset,
-                         u64 bytenr, bool strict)
+                         u64 bytenr, bool strict, struct btrfs_path *path)
 {
-       struct btrfs_path *path;
        int ret;
 
-       path = btrfs_alloc_path();
-       if (!path)
-               return -ENOMEM;
-
        do {
                ret = check_committed_ref(root, path, objectid,
                                          offset, bytenr, strict);
@@ -2376,7 +2371,7 @@ int btrfs_cross_ref_exist(struct btrfs_root *root, u64 objectid, u64 offset,
        } while (ret == -EAGAIN);
 
 out:
-       btrfs_free_path(path);
+       btrfs_release_path(path);
        if (btrfs_is_data_reloc_root(root))
                WARN_ON(ret > 0);
        return ret;
index 05cb7b1..ca47f7c 100644 (file)
@@ -1788,7 +1788,8 @@ next_slot:
 
                        ret = btrfs_cross_ref_exist(root, ino,
                                                    found_key.offset -
-                                                   extent_offset, disk_bytenr, false);
+                                                   extent_offset, disk_bytenr,
+                                                   false, path);
                        if (ret) {
                                /*
                                 * ret could be -EIO if the above fails to read
@@ -7222,7 +7223,7 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
 
        ret = btrfs_cross_ref_exist(root, btrfs_ino(BTRFS_I(inode)),
                                    key.offset - backref_offset, disk_bytenr,
-                                   strict);
+                                   strict, path);
        if (ret) {
                ret = 0;
                goto out;