Btrfs: get write access for qgroup operations
We need get write access for qgroup operations, or we will modify the R/O fs. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
This commit is contained in:
@@ -3558,8 +3558,9 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long btrfs_ioctl_quota_ctl(struct btrfs_root *root, void __user *arg)
|
static long btrfs_ioctl_quota_ctl(struct file *file, void __user *arg)
|
||||||
{
|
{
|
||||||
|
struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
|
||||||
struct btrfs_ioctl_quota_ctl_args *sa;
|
struct btrfs_ioctl_quota_ctl_args *sa;
|
||||||
struct btrfs_trans_handle *trans = NULL;
|
struct btrfs_trans_handle *trans = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -3568,12 +3569,15 @@ static long btrfs_ioctl_quota_ctl(struct btrfs_root *root, void __user *arg)
|
|||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
if (root->fs_info->sb->s_flags & MS_RDONLY)
|
ret = mnt_want_write_file(file);
|
||||||
return -EROFS;
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
sa = memdup_user(arg, sizeof(*sa));
|
sa = memdup_user(arg, sizeof(*sa));
|
||||||
if (IS_ERR(sa))
|
if (IS_ERR(sa)) {
|
||||||
return PTR_ERR(sa);
|
ret = PTR_ERR(sa);
|
||||||
|
goto drop_write;
|
||||||
|
}
|
||||||
|
|
||||||
if (sa->cmd != BTRFS_QUOTA_CTL_RESCAN) {
|
if (sa->cmd != BTRFS_QUOTA_CTL_RESCAN) {
|
||||||
trans = btrfs_start_transaction(root, 2);
|
trans = btrfs_start_transaction(root, 2);
|
||||||
@@ -3606,14 +3610,16 @@ static long btrfs_ioctl_quota_ctl(struct btrfs_root *root, void __user *arg)
|
|||||||
if (err && !ret)
|
if (err && !ret)
|
||||||
ret = err;
|
ret = err;
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
kfree(sa);
|
kfree(sa);
|
||||||
|
drop_write:
|
||||||
|
mnt_drop_write_file(file);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long btrfs_ioctl_qgroup_assign(struct btrfs_root *root, void __user *arg)
|
static long btrfs_ioctl_qgroup_assign(struct file *file, void __user *arg)
|
||||||
{
|
{
|
||||||
|
struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
|
||||||
struct btrfs_ioctl_qgroup_assign_args *sa;
|
struct btrfs_ioctl_qgroup_assign_args *sa;
|
||||||
struct btrfs_trans_handle *trans;
|
struct btrfs_trans_handle *trans;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -3622,12 +3628,15 @@ static long btrfs_ioctl_qgroup_assign(struct btrfs_root *root, void __user *arg)
|
|||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
if (root->fs_info->sb->s_flags & MS_RDONLY)
|
ret = mnt_want_write_file(file);
|
||||||
return -EROFS;
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
sa = memdup_user(arg, sizeof(*sa));
|
sa = memdup_user(arg, sizeof(*sa));
|
||||||
if (IS_ERR(sa))
|
if (IS_ERR(sa)) {
|
||||||
return PTR_ERR(sa);
|
ret = PTR_ERR(sa);
|
||||||
|
goto drop_write;
|
||||||
|
}
|
||||||
|
|
||||||
trans = btrfs_join_transaction(root);
|
trans = btrfs_join_transaction(root);
|
||||||
if (IS_ERR(trans)) {
|
if (IS_ERR(trans)) {
|
||||||
@@ -3650,11 +3659,14 @@ static long btrfs_ioctl_qgroup_assign(struct btrfs_root *root, void __user *arg)
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
kfree(sa);
|
kfree(sa);
|
||||||
|
drop_write:
|
||||||
|
mnt_drop_write_file(file);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long btrfs_ioctl_qgroup_create(struct btrfs_root *root, void __user *arg)
|
static long btrfs_ioctl_qgroup_create(struct file *file, void __user *arg)
|
||||||
{
|
{
|
||||||
|
struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
|
||||||
struct btrfs_ioctl_qgroup_create_args *sa;
|
struct btrfs_ioctl_qgroup_create_args *sa;
|
||||||
struct btrfs_trans_handle *trans;
|
struct btrfs_trans_handle *trans;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -3663,12 +3675,15 @@ static long btrfs_ioctl_qgroup_create(struct btrfs_root *root, void __user *arg)
|
|||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
if (root->fs_info->sb->s_flags & MS_RDONLY)
|
ret = mnt_want_write_file(file);
|
||||||
return -EROFS;
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
sa = memdup_user(arg, sizeof(*sa));
|
sa = memdup_user(arg, sizeof(*sa));
|
||||||
if (IS_ERR(sa))
|
if (IS_ERR(sa)) {
|
||||||
return PTR_ERR(sa);
|
ret = PTR_ERR(sa);
|
||||||
|
goto drop_write;
|
||||||
|
}
|
||||||
|
|
||||||
trans = btrfs_join_transaction(root);
|
trans = btrfs_join_transaction(root);
|
||||||
if (IS_ERR(trans)) {
|
if (IS_ERR(trans)) {
|
||||||
@@ -3690,11 +3705,14 @@ static long btrfs_ioctl_qgroup_create(struct btrfs_root *root, void __user *arg)
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
kfree(sa);
|
kfree(sa);
|
||||||
|
drop_write:
|
||||||
|
mnt_drop_write_file(file);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long btrfs_ioctl_qgroup_limit(struct btrfs_root *root, void __user *arg)
|
static long btrfs_ioctl_qgroup_limit(struct file *file, void __user *arg)
|
||||||
{
|
{
|
||||||
|
struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
|
||||||
struct btrfs_ioctl_qgroup_limit_args *sa;
|
struct btrfs_ioctl_qgroup_limit_args *sa;
|
||||||
struct btrfs_trans_handle *trans;
|
struct btrfs_trans_handle *trans;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -3704,12 +3722,15 @@ static long btrfs_ioctl_qgroup_limit(struct btrfs_root *root, void __user *arg)
|
|||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
if (root->fs_info->sb->s_flags & MS_RDONLY)
|
ret = mnt_want_write_file(file);
|
||||||
return -EROFS;
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
sa = memdup_user(arg, sizeof(*sa));
|
sa = memdup_user(arg, sizeof(*sa));
|
||||||
if (IS_ERR(sa))
|
if (IS_ERR(sa)) {
|
||||||
return PTR_ERR(sa);
|
ret = PTR_ERR(sa);
|
||||||
|
goto drop_write;
|
||||||
|
}
|
||||||
|
|
||||||
trans = btrfs_join_transaction(root);
|
trans = btrfs_join_transaction(root);
|
||||||
if (IS_ERR(trans)) {
|
if (IS_ERR(trans)) {
|
||||||
@@ -3732,6 +3753,8 @@ static long btrfs_ioctl_qgroup_limit(struct btrfs_root *root, void __user *arg)
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
kfree(sa);
|
kfree(sa);
|
||||||
|
drop_write:
|
||||||
|
mnt_drop_write_file(file);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3907,13 +3930,13 @@ long btrfs_ioctl(struct file *file, unsigned int
|
|||||||
case BTRFS_IOC_GET_DEV_STATS:
|
case BTRFS_IOC_GET_DEV_STATS:
|
||||||
return btrfs_ioctl_get_dev_stats(root, argp);
|
return btrfs_ioctl_get_dev_stats(root, argp);
|
||||||
case BTRFS_IOC_QUOTA_CTL:
|
case BTRFS_IOC_QUOTA_CTL:
|
||||||
return btrfs_ioctl_quota_ctl(root, argp);
|
return btrfs_ioctl_quota_ctl(file, argp);
|
||||||
case BTRFS_IOC_QGROUP_ASSIGN:
|
case BTRFS_IOC_QGROUP_ASSIGN:
|
||||||
return btrfs_ioctl_qgroup_assign(root, argp);
|
return btrfs_ioctl_qgroup_assign(file, argp);
|
||||||
case BTRFS_IOC_QGROUP_CREATE:
|
case BTRFS_IOC_QGROUP_CREATE:
|
||||||
return btrfs_ioctl_qgroup_create(root, argp);
|
return btrfs_ioctl_qgroup_create(file, argp);
|
||||||
case BTRFS_IOC_QGROUP_LIMIT:
|
case BTRFS_IOC_QGROUP_LIMIT:
|
||||||
return btrfs_ioctl_qgroup_limit(root, argp);
|
return btrfs_ioctl_qgroup_limit(file, argp);
|
||||||
case BTRFS_IOC_DEV_REPLACE:
|
case BTRFS_IOC_DEV_REPLACE:
|
||||||
return btrfs_ioctl_dev_replace(root, argp);
|
return btrfs_ioctl_dev_replace(root, argp);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user