@@ -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);