Skip to content

Commit

Permalink
btrfs: Don't opencode btrfs_find_name_in_backref in backref_in_log
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: David Sterba <[email protected]>
[ add changelog ]
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
lorddoskias authored and kdave committed Nov 18, 2019
1 parent 3296bf5 commit 89cbf5f
Showing 1 changed file with 12 additions and 36 deletions.
48 changes: 12 additions & 36 deletions fs/btrfs/tree-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 89cbf5f

Please sign in to comment.