Btrfs: reorder locks and sanity checks in btrfs_ioctl_defrag
Operation-specific check (whether subvol is readonly or not) should go after the mutual exclusiveness check. Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
This commit is contained in:
parent
4ac20c70b0
commit
25122d15e2
|
@ -2186,19 +2186,20 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
|
||||||
struct btrfs_ioctl_defrag_range_args *range;
|
struct btrfs_ioctl_defrag_range_args *range;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (btrfs_root_readonly(root))
|
ret = mnt_want_write_file(file);
|
||||||
return -EROFS;
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
|
if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
|
||||||
1)) {
|
1)) {
|
||||||
pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
|
pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
|
||||||
|
mnt_drop_write_file(file);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
ret = mnt_want_write_file(file);
|
|
||||||
if (ret) {
|
if (btrfs_root_readonly(root)) {
|
||||||
atomic_set(&root->fs_info->mutually_exclusive_operation_running,
|
ret = -EROFS;
|
||||||
0);
|
goto out;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (inode->i_mode & S_IFMT) {
|
switch (inode->i_mode & S_IFMT) {
|
||||||
|
@ -2250,8 +2251,8 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
mnt_drop_write_file(file);
|
|
||||||
atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0);
|
atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0);
|
||||||
|
mnt_drop_write_file(file);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue