Commit 3ca35e83 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: hold a ref on the root in search_ioctl

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: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent fc92f798
...@@ -2180,7 +2180,7 @@ static noinline int search_ioctl(struct inode *inode, ...@@ -2180,7 +2180,7 @@ static noinline int search_ioctl(struct inode *inode,
if (sk->tree_id == 0) { if (sk->tree_id == 0) {
/* search the root of the inode that was passed */ /* search the root of the inode that was passed */
root = BTRFS_I(inode)->root; root = btrfs_grab_fs_root(BTRFS_I(inode)->root);
} else { } else {
key.objectid = sk->tree_id; key.objectid = sk->tree_id;
key.type = BTRFS_ROOT_ITEM_KEY; key.type = BTRFS_ROOT_ITEM_KEY;
...@@ -2190,6 +2190,10 @@ static noinline int search_ioctl(struct inode *inode, ...@@ -2190,6 +2190,10 @@ static noinline int search_ioctl(struct inode *inode,
btrfs_free_path(path); btrfs_free_path(path);
return PTR_ERR(root); return PTR_ERR(root);
} }
if (!btrfs_grab_fs_root(root)) {
btrfs_free_path(path);
return -ENOENT;
}
} }
key.objectid = sk->min_objectid; key.objectid = sk->min_objectid;
...@@ -2214,6 +2218,7 @@ static noinline int search_ioctl(struct inode *inode, ...@@ -2214,6 +2218,7 @@ static noinline int search_ioctl(struct inode *inode,
ret = 0; ret = 0;
err: err:
sk->nr_items = num_found; sk->nr_items = num_found;
btrfs_put_fs_root(root);
btrfs_free_path(path); btrfs_free_path(path);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment