aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ioctl.c
diff options
context:
space:
mode:
authorIlya Dryomov <idryomov@gmail.com>2013-01-20 08:57:57 -0500
committerIlya Dryomov <idryomov@gmail.com>2013-01-20 09:21:22 -0500
commit25122d15e21cf252e91e4cad7cea760f97df29f1 (patch)
tree54b7e644e36135f4a2602b56c20d319cff96e625 /fs/btrfs/ioctl.c
parent4ac20c70b0734b65662ded735e5f6ba0415bdb71 (diff)
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>
Diffstat (limited to 'fs/btrfs/ioctl.c')
-rw-r--r--fs/btrfs/ioctl.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index f5c1c150d9f3..afbf3ac2079d 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2186,19 +2186,20 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
2186 struct btrfs_ioctl_defrag_range_args *range; 2186 struct btrfs_ioctl_defrag_range_args *range;
2187 int ret; 2187 int ret;
2188 2188
2189 if (btrfs_root_readonly(root)) 2189 ret = mnt_want_write_file(file);
2190 return -EROFS; 2190 if (ret)
2191 return ret;
2191 2192
2192 if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running, 2193 if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
2193 1)) { 2194 1)) {
2194 pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n"); 2195 pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n");
2196 mnt_drop_write_file(file);
2195 return -EINVAL; 2197 return -EINVAL;
2196 } 2198 }
2197 ret = mnt_want_write_file(file); 2199
2198 if (ret) { 2200 if (btrfs_root_readonly(root)) {
2199 atomic_set(&root->fs_info->mutually_exclusive_operation_running, 2201 ret = -EROFS;
2200 0); 2202 goto out;
2201 return ret;
2202 } 2203 }
2203 2204
2204 switch (inode->i_mode & S_IFMT) { 2205 switch (inode->i_mode & S_IFMT) {
@@ -2250,8 +2251,8 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
2250 ret = -EINVAL; 2251 ret = -EINVAL;
2251 } 2252 }
2252out: 2253out:
2253 mnt_drop_write_file(file);
2254 atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0); 2254 atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0);
2255 mnt_drop_write_file(file);
2255 return ret; 2256 return ret;
2256} 2257}
2257 2258