mirror of https://gitee.com/openkylin/linux.git
btrfs: hold a ref on the root in btrfs_ioctl_get_subvol_info
We look up whatever root userspace has given us, we need to hold a ref throughout this operation. Use 'root' only for the on fs root and not as a temporary variable elsewhere. Signed-off-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
b8a49ae191
commit
04734e8448
|
@ -2681,6 +2681,10 @@ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp)
|
||||||
root = btrfs_get_fs_root(fs_info, &key, true);
|
root = btrfs_get_fs_root(fs_info, &key, true);
|
||||||
if (IS_ERR(root)) {
|
if (IS_ERR(root)) {
|
||||||
ret = PTR_ERR(root);
|
ret = PTR_ERR(root);
|
||||||
|
goto out_free;
|
||||||
|
}
|
||||||
|
if (!btrfs_grab_fs_root(root)) {
|
||||||
|
ret = -ENOENT;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
root_item = &root->root_item;
|
root_item = &root->root_item;
|
||||||
|
@ -2714,16 +2718,14 @@ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp)
|
||||||
|
|
||||||
if (key.objectid != BTRFS_FS_TREE_OBJECTID) {
|
if (key.objectid != BTRFS_FS_TREE_OBJECTID) {
|
||||||
/* Search root tree for ROOT_BACKREF of this subvolume */
|
/* Search root tree for ROOT_BACKREF of this subvolume */
|
||||||
root = fs_info->tree_root;
|
|
||||||
|
|
||||||
key.type = BTRFS_ROOT_BACKREF_KEY;
|
key.type = BTRFS_ROOT_BACKREF_KEY;
|
||||||
key.offset = 0;
|
key.offset = 0;
|
||||||
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
|
ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto out;
|
goto out;
|
||||||
} else if (path->slots[0] >=
|
} else if (path->slots[0] >=
|
||||||
btrfs_header_nritems(path->nodes[0])) {
|
btrfs_header_nritems(path->nodes[0])) {
|
||||||
ret = btrfs_next_leaf(root, path);
|
ret = btrfs_next_leaf(fs_info->tree_root, path);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto out;
|
goto out;
|
||||||
} else if (ret > 0) {
|
} else if (ret > 0) {
|
||||||
|
@ -2758,6 +2760,8 @@ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp)
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
btrfs_put_fs_root(root);
|
||||||
|
out_free:
|
||||||
btrfs_free_path(path);
|
btrfs_free_path(path);
|
||||||
kzfree(subvol_info);
|
kzfree(subvol_info);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in New Issue