Skip to content

Commit

Permalink
btrfs: hold a ref on the root in search_ioctl
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: David Sterba <[email protected]>
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
josefbacik authored and kdave committed Mar 23, 2020
1 parent fc92f79 commit 3ca35e8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ static noinline int search_ioctl(struct inode *inode,

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;
Expand All @@ -2190,6 +2190,10 @@ static noinline int search_ioctl(struct inode *inode,
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;
Expand All @@ -2214,6 +2218,7 @@ static noinline int search_ioctl(struct inode *inode,
ret = 0;
err:
sk->nr_items = num_found;
btrfs_put_fs_root(root);
btrfs_free_path(path);
return ret;
}
Expand Down

0 comments on commit 3ca35e8

Please sign in to comment.