提交 198605a8 编写于 作者: M Miao Xie 提交者: Chris Mason

Btrfs: get write access when doing resize fs

Steps to reproduce:
 # mkfs.btrfs <partition>
 # mount -o ro <partition> <mnt0>
 # mount -o ro <partition> <mnt1>
 # mount -o remount,rw <mnt0>
 # umount <mnt0>
 # btrfs fi resize 10g <mnt1>

We re-sized a R/O filesystem. The reason is that we just check the R/O flag
of the super block object. It is not enough, because the kernel may set the
R/O flag only for the mount point. We need invoke mnt_want_write_file() to
do a full check.
Signed-off-by: NMiao Xie <miaox@cn.fujitsu.com>
Signed-off-by: NChris Mason <chris.mason@fusionio.com>
上级 3c04ce01
...@@ -1298,12 +1298,13 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, ...@@ -1298,12 +1298,13 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
return ret; return ret;
} }
static noinline int btrfs_ioctl_resize(struct btrfs_root *root, static noinline int btrfs_ioctl_resize(struct file *file,
void __user *arg) void __user *arg)
{ {
u64 new_size; u64 new_size;
u64 old_size; u64 old_size;
u64 devid = 1; u64 devid = 1;
struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
struct btrfs_ioctl_vol_args *vol_args; struct btrfs_ioctl_vol_args *vol_args;
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
struct btrfs_device *device = NULL; struct btrfs_device *device = NULL;
...@@ -1318,6 +1319,10 @@ static noinline int btrfs_ioctl_resize(struct btrfs_root *root, ...@@ -1318,6 +1319,10 @@ static noinline int btrfs_ioctl_resize(struct btrfs_root *root,
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
ret = mnt_want_write_file(file);
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");
...@@ -1425,6 +1430,7 @@ static noinline int btrfs_ioctl_resize(struct btrfs_root *root, ...@@ -1425,6 +1430,7 @@ static noinline int btrfs_ioctl_resize(struct btrfs_root *root,
kfree(vol_args); kfree(vol_args);
out: out:
mutex_unlock(&root->fs_info->volume_mutex); mutex_unlock(&root->fs_info->volume_mutex);
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);
return ret; return ret;
} }
...@@ -3832,7 +3838,7 @@ long btrfs_ioctl(struct file *file, unsigned int ...@@ -3832,7 +3838,7 @@ long btrfs_ioctl(struct file *file, unsigned int
case BTRFS_IOC_DEFRAG_RANGE: case BTRFS_IOC_DEFRAG_RANGE:
return btrfs_ioctl_defrag(file, argp); return btrfs_ioctl_defrag(file, argp);
case BTRFS_IOC_RESIZE: case BTRFS_IOC_RESIZE:
return btrfs_ioctl_resize(root, argp); return btrfs_ioctl_resize(file, argp);
case BTRFS_IOC_ADD_DEV: case BTRFS_IOC_ADD_DEV:
return btrfs_ioctl_add_dev(root, argp); return btrfs_ioctl_add_dev(root, argp);
case BTRFS_IOC_RM_DEV: case BTRFS_IOC_RM_DEV:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册