Skip to content

Commit 89cbf5f

Browse files
lorddoskiaskdave
authored andcommitted
btrfs: Don't opencode btrfs_find_name_in_backref in backref_in_log
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>
1 parent 3296bf5 commit 89cbf5f

1 file changed

Lines changed: 12 additions & 36 deletions

File tree

‎fs/btrfs/tree-log.c‎

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -945,54 +945,30 @@ static noinline int backref_in_log(struct btrfs_root *log,
945945
const char *name, int namelen)
946946
{
947947
struct btrfs_path *path;
948-
struct btrfs_inode_ref *ref;
949-
unsigned long ptr;
950-
unsigned long ptr_end;
951-
unsigned long name_ptr;
952-
int found_name_len;
953-
int item_size;
954948
int ret;
955-
int match = 0;
956949

957950
path = btrfs_alloc_path();
958951
if (!path)
959952
return -ENOMEM;
960953

961954
ret = btrfs_search_slot(NULL, log, key, path, 0, 0);
962-
if (ret != 0)
963-
goto out;
964-
965-
ptr = btrfs_item_ptr_offset(path->nodes[0], path->slots[0]);
966-
967-
if (key->type == BTRFS_INODE_EXTREF_KEY) {
968-
if (btrfs_find_name_in_ext_backref(path->nodes[0],
969-
path->slots[0],
970-
ref_objectid,
971-
name, namelen))
972-
match = 1;
973-
955+
if (ret != 0) {
956+
ret = 0;
974957
goto out;
975958
}
976959

977-
item_size = btrfs_item_size_nr(path->nodes[0], path->slots[0]);
978-
ptr_end = ptr + item_size;
979-
while (ptr < ptr_end) {
980-
ref = (struct btrfs_inode_ref *)ptr;
981-
found_name_len = btrfs_inode_ref_name_len(path->nodes[0], ref);
982-
if (found_name_len == namelen) {
983-
name_ptr = (unsigned long)(ref + 1);
984-
ret = memcmp_extent_buffer(path->nodes[0], name,
985-
name_ptr, namelen);
986-
if (ret == 0) {
987-
match = 1;
988-
goto out;
989-
}
990-
}
991-
ptr = (unsigned long)(ref + 1) + found_name_len;
992-
}
960+
if (key->type == BTRFS_INODE_EXTREF_KEY)
961+
ret = !!btrfs_find_name_in_ext_backref(path->nodes[0],
962+
path->slots[0],
963+
ref_objectid,
964+
name, namelen);
965+
else
966+
ret = !!btrfs_find_name_in_backref(path->nodes[0],
967+
path->slots[0],
968+
name, namelen);
993969
out:
994970
btrfs_free_path(path);
995-
return match;
971+
return ret;
996972
}
997973

998974
static inline int __add_inode_ref(struct btrfs_trans_handle *trans,

0 commit comments

Comments
 (0)