We lookup a arbitrary fs root, we need to hold a ref on that root. If
we're using our own inodes root then grab a ref on that as well to make
the cleanup easier.
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
if (sk->tree_id == 0) {
/* search the root of the inode that was passed */
- root = BTRFS_I(inode)->root;
+ root = btrfs_grab_fs_root(BTRFS_I(inode)->root);
} else {
key.objectid = sk->tree_id;
key.type = BTRFS_ROOT_ITEM_KEY;
btrfs_free_path(path);
return PTR_ERR(root);
}
+ if (!btrfs_grab_fs_root(root)) {
+ btrfs_free_path(path);
+ return -ENOENT;
+ }
}
key.objectid = sk->min_objectid;
ret = 0;
err:
sk->nr_items = num_found;
+ btrfs_put_fs_root(root);
btrfs_free_path(path);
return ret;
}