From: Wang Shilong <wangsl-fnst@xxxxxxxxxxxxxx>
This patch try to add a check before creating/destroying a qgroup.
Signed-off-by: Wang Shilong <wangsl-fnst@xxxxxxxxxxxxxx>
Reviewed-by: Miao Xie <miaox@xxxxxxxxxxxxxx>
---
fs/btrfs/ioctl.c | 41 ++++++++++++++++++++++++++++++++++++++++-
1 files changed, 40 insertions(+), 1 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 3c4fde0..8a01326 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -3784,6 +3784,42 @@ drop_write:
return ret;
}
+static int may_qgroup_create(struct btrfs_root *root,
+ struct btrfs_ioctl_qgroup_create_args *sa)
+{
+ int ret = 0;
+ struct btrfs_key key;
+ struct btrfs_path *path;
+
+ if (!root->fs_info->quota_root)
+ return -EINVAL;
+
+ path = btrfs_alloc_path();
+ if (!path) {
+ ret = -ENOMEM;
+ return ret;
+ }
+
+ key.objectid = 0;
+ key.type = BTRFS_QGROUP_INFO_KEY;
+ key.offset = sa->qgroupid;
+
+ ret = btrfs_search_slot(NULL, root->fs_info->quota_root,
+ &key, path, 0, 0);
+ if (sa->create) {
+ if (!ret)
+ ret = -EEXIST;
+ if (ret > 0)
+ ret = 0;
+ goto out;
+ }
+ if (ret > 0)
+ ret = -ENOENT;
+out:
+ btrfs_free_path(path);
+ return ret;
+}
+
static long btrfs_ioctl_qgroup_create(struct file *file, void __user *arg)
{
struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
@@ -3810,13 +3846,16 @@ static long btrfs_ioctl_qgroup_create(struct file *file, void __user *arg)
goto out;
}
mutex_lock(&root->fs_info->quota_lock);
+ ret = may_qgroup_create(root, sa);
+ if (ret)
+ goto out_unlock;
+
trans = btrfs_join_transaction(root);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
goto out_unlock;
}
- /* FIXME: check if the IDs really exist */
if (sa->create) {
ret = btrfs_create_qgroup(trans, root->fs_info, sa->qgroupid,
NULL);
--
1.7.7.6
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html