diff options
author | Liu Bo <liubo2009@cn.fujitsu.com> | 2012-05-11 06:11:26 -0400 |
---|---|---|
committer | Josef Bacik <josef@redhat.com> | 2012-05-30 10:23:35 -0400 |
commit | 9ba1f6e44ed7a1fa52d3f292508bf921b5054172 (patch) | |
tree | 2c20508be673a9ebce14d27efa6ee05a04695787 /fs/btrfs | |
parent | d1ac6e41d5437385957fd708e285defd0b1a430c (diff) |
Btrfs: do not do balance in readonly mode
In normal cases, we would not be allowed to do balance in RO mode.
However, when we're using a seeding device and adding another device to sprout,
things will change:
$ mkfs.btrfs /dev/sdb7
$ btrfstune -S 1 /dev/sdb7
$ mount /dev/sdb7 /mnt/btrfs -o ro
$ btrfs fi bal /mnt/btrfs -----------------------> fail.
$ btrfs dev add /dev/sdb8 /mnt/btrfs
$ btrfs fi bal /mnt/btrfs -----------------------> works!
It should not be designed as an exception, and we'd better add another check for
mnt flags.
Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
Reviewed-by: Josef Bacik <josef@redhat.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/ioctl.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 3d8ab27622cd..15baf9456300 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -3216,8 +3216,9 @@ void update_ioctl_balance_args(struct btrfs_fs_info *fs_info, int lock, | |||
3216 | } | 3216 | } |
3217 | } | 3217 | } |
3218 | 3218 | ||
3219 | static long btrfs_ioctl_balance(struct btrfs_root *root, void __user *arg) | 3219 | static long btrfs_ioctl_balance(struct file *file, void __user *arg) |
3220 | { | 3220 | { |
3221 | struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root; | ||
3221 | struct btrfs_fs_info *fs_info = root->fs_info; | 3222 | struct btrfs_fs_info *fs_info = root->fs_info; |
3222 | struct btrfs_ioctl_balance_args *bargs; | 3223 | struct btrfs_ioctl_balance_args *bargs; |
3223 | struct btrfs_balance_control *bctl; | 3224 | struct btrfs_balance_control *bctl; |
@@ -3229,6 +3230,10 @@ static long btrfs_ioctl_balance(struct btrfs_root *root, void __user *arg) | |||
3229 | if (fs_info->sb->s_flags & MS_RDONLY) | 3230 | if (fs_info->sb->s_flags & MS_RDONLY) |
3230 | return -EROFS; | 3231 | return -EROFS; |
3231 | 3232 | ||
3233 | ret = mnt_want_write(file->f_path.mnt); | ||
3234 | if (ret) | ||
3235 | return ret; | ||
3236 | |||
3232 | mutex_lock(&fs_info->volume_mutex); | 3237 | mutex_lock(&fs_info->volume_mutex); |
3233 | mutex_lock(&fs_info->balance_mutex); | 3238 | mutex_lock(&fs_info->balance_mutex); |
3234 | 3239 | ||
@@ -3295,6 +3300,7 @@ out_bargs: | |||
3295 | out: | 3300 | out: |
3296 | mutex_unlock(&fs_info->balance_mutex); | 3301 | mutex_unlock(&fs_info->balance_mutex); |
3297 | mutex_unlock(&fs_info->volume_mutex); | 3302 | mutex_unlock(&fs_info->volume_mutex); |
3303 | mnt_drop_write(file->f_path.mnt); | ||
3298 | return ret; | 3304 | return ret; |
3299 | } | 3305 | } |
3300 | 3306 | ||
@@ -3390,7 +3396,7 @@ long btrfs_ioctl(struct file *file, unsigned int | |||
3390 | case BTRFS_IOC_DEV_INFO: | 3396 | case BTRFS_IOC_DEV_INFO: |
3391 | return btrfs_ioctl_dev_info(root, argp); | 3397 | return btrfs_ioctl_dev_info(root, argp); |
3392 | case BTRFS_IOC_BALANCE: | 3398 | case BTRFS_IOC_BALANCE: |
3393 | return btrfs_ioctl_balance(root, NULL); | 3399 | return btrfs_ioctl_balance(file, NULL); |
3394 | case BTRFS_IOC_CLONE: | 3400 | case BTRFS_IOC_CLONE: |
3395 | return btrfs_ioctl_clone(file, arg, 0, 0, 0); | 3401 | return btrfs_ioctl_clone(file, arg, 0, 0, 0); |
3396 | case BTRFS_IOC_CLONE_RANGE: | 3402 | case BTRFS_IOC_CLONE_RANGE: |
@@ -3423,7 +3429,7 @@ long btrfs_ioctl(struct file *file, unsigned int | |||
3423 | case BTRFS_IOC_SCRUB_PROGRESS: | 3429 | case BTRFS_IOC_SCRUB_PROGRESS: |
3424 | return btrfs_ioctl_scrub_progress(root, argp); | 3430 | return btrfs_ioctl_scrub_progress(root, argp); |
3425 | case BTRFS_IOC_BALANCE_V2: | 3431 | case BTRFS_IOC_BALANCE_V2: |
3426 | return btrfs_ioctl_balance(root, argp); | 3432 | return btrfs_ioctl_balance(file, argp); |
3427 | case BTRFS_IOC_BALANCE_CTL: | 3433 | case BTRFS_IOC_BALANCE_CTL: |
3428 | return btrfs_ioctl_balance_ctl(root, arg); | 3434 | return btrfs_ioctl_balance_ctl(root, arg); |
3429 | case BTRFS_IOC_BALANCE_PROGRESS: | 3435 | case BTRFS_IOC_BALANCE_PROGRESS: |