]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
btrfs: Don't opencode btrfs_find_name_in_backref in backref_in_log
authorNikolay Borisov <nborisov@suse.com>
Fri, 30 Aug 2019 14:44:47 +0000 (17:44 +0300)
committerDavid Sterba <dsterba@suse.com>
Mon, 18 Nov 2019 11:46:51 +0000 (12:46 +0100)
Direct replacement, though note that the inside of the loop in
btrfs_find_name_in_backref is organized in a slightly different way but
is equvalent.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
[ add changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/tree-log.c

index 8a6cc600bf183d4a9182915c3440924720e94fad..1d7f22951ef26ac7c7f9312d5a517dbd477cdeb5 100644 (file)
@@ -945,54 +945,30 @@ static noinline int backref_in_log(struct btrfs_root *log,
                                   const char *name, int namelen)
 {
        struct btrfs_path *path;
-       struct btrfs_inode_ref *ref;
-       unsigned long ptr;
-       unsigned long ptr_end;
-       unsigned long name_ptr;
-       int found_name_len;
-       int item_size;
        int ret;
-       int match = 0;
 
        path = btrfs_alloc_path();
        if (!path)
                return -ENOMEM;
 
        ret = btrfs_search_slot(NULL, log, key, path, 0, 0);
-       if (ret != 0)
-               goto out;
-
-       ptr = btrfs_item_ptr_offset(path->nodes[0], path->slots[0]);
-
-       if (key->type == BTRFS_INODE_EXTREF_KEY) {
-               if (btrfs_find_name_in_ext_backref(path->nodes[0],
-                                                  path->slots[0],
-                                                  ref_objectid,
-                                                  name, namelen))
-                       match = 1;
-
+       if (ret != 0) {
+               ret = 0;
                goto out;
        }
 
-       item_size = btrfs_item_size_nr(path->nodes[0], path->slots[0]);
-       ptr_end = ptr + item_size;
-       while (ptr < ptr_end) {
-               ref = (struct btrfs_inode_ref *)ptr;
-               found_name_len = btrfs_inode_ref_name_len(path->nodes[0], ref);
-               if (found_name_len == namelen) {
-                       name_ptr = (unsigned long)(ref + 1);
-                       ret = memcmp_extent_buffer(path->nodes[0], name,
-                                                  name_ptr, namelen);
-                       if (ret == 0) {
-                               match = 1;
-                               goto out;
-                       }
-               }
-               ptr = (unsigned long)(ref + 1) + found_name_len;
-       }
+       if (key->type == BTRFS_INODE_EXTREF_KEY)
+               ret = !!btrfs_find_name_in_ext_backref(path->nodes[0],
+                                                      path->slots[0],
+                                                      ref_objectid,
+                                                      name, namelen);
+       else
+               ret = !!btrfs_find_name_in_backref(path->nodes[0],
+                                                  path->slots[0],
+                                                  name, namelen);
 out:
        btrfs_free_path(path);
-       return match;
+       return ret;
 }
 
 static inline int __add_inode_ref(struct btrfs_trans_handle *trans,