btrfs: use btrfs_for_each_slot in is_ancestor
This function can be simplified by refactoring to use the new iterator macro. No functional changes. Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com> Signed-off-by: Gabriel Niebler <gniebler@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
18f80f1fa4
commit
35a68080ff
|
@ -3550,7 +3550,7 @@ static int check_ino_in_path(struct btrfs_root *root,
|
|||
}
|
||||
|
||||
/*
|
||||
* Check if ino ino1 is an ancestor of inode ino2 in the given root for any
|
||||
* Check if inode ino1 is an ancestor of inode ino2 in the given root for any
|
||||
* possible path (in case ino2 is not a directory and has multiple hard links).
|
||||
* Return 1 if true, 0 if false and < 0 on error.
|
||||
*/
|
||||
|
@ -3562,6 +3562,7 @@ static int is_ancestor(struct btrfs_root *root,
|
|||
{
|
||||
bool free_fs_path = false;
|
||||
int ret = 0;
|
||||
int iter_ret = 0;
|
||||
struct btrfs_path *path = NULL;
|
||||
struct btrfs_key key;
|
||||
|
||||
|
@ -3582,26 +3583,12 @@ static int is_ancestor(struct btrfs_root *root,
|
|||
key.type = BTRFS_INODE_REF_KEY;
|
||||
key.offset = 0;
|
||||
|
||||
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
while (true) {
|
||||
btrfs_for_each_slot(root, &key, &key, path, iter_ret) {
|
||||
struct extent_buffer *leaf = path->nodes[0];
|
||||
int slot = path->slots[0];
|
||||
u32 cur_offset = 0;
|
||||
u32 item_size;
|
||||
|
||||
if (slot >= btrfs_header_nritems(leaf)) {
|
||||
ret = btrfs_next_leaf(root, path);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
if (ret > 0)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
btrfs_item_key_to_cpu(leaf, &key, slot);
|
||||
if (key.objectid != ino2)
|
||||
break;
|
||||
if (key.type != BTRFS_INODE_REF_KEY &&
|
||||
|
@ -3639,10 +3626,12 @@ static int is_ancestor(struct btrfs_root *root,
|
|||
if (ret)
|
||||
goto out;
|
||||
}
|
||||
path->slots[0]++;
|
||||
}
|
||||
ret = 0;
|
||||
out:
|
||||
if (iter_ret < 0)
|
||||
ret = iter_ret;
|
||||
|
||||
out:
|
||||
btrfs_free_path(path);
|
||||
if (free_fs_path)
|
||||
fs_path_free(fs_path);
|
||||
|
|
Loading…
Reference in New Issue