@@ -3837,6 +3837,33 @@ drop_write:
return ret;
}
+static int may_qgroup_limit(struct btrfs_root *root, u64 qgroupid)
+{
+ 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 = qgroupid;
+
+ ret = btrfs_search_slot(NULL, root->fs_info->quota_root,
+ &key, path, 0, 0);
+ if (ret > 0)
+ ret = -ENOENT;
+ btrfs_free_path(path);
+ return ret;
+}
+
static long btrfs_ioctl_qgroup_limit(struct file *file, void __user *arg)
{
struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
@@ -3859,19 +3886,21 @@ static long btrfs_ioctl_qgroup_limit(struct file *file, void __user *arg)
goto drop_write;
}
mutex_lock(&root->fs_info->quota_lock);
- trans = btrfs_join_transaction(root);
- if (IS_ERR(trans)) {
- ret = PTR_ERR(trans);
- goto out;
- }
-
qgroupid = sa->qgroupid;
if (!qgroupid) {
/* take the current subvol as qgroup */
qgroupid = root->root_key.objectid;
}
+ ret = may_qgroup_limit(root, qgroupid);
+ if (ret)
+ goto out;
+
+ trans = btrfs_join_transaction(root);
+ if (IS_ERR(trans)) {
+ ret = PTR_ERR(trans);
+ goto out;
+ }
- /* FIXME: check if the IDs really exist */
ret = btrfs_limit_qgroup(trans, root->fs_info, qgroupid, &sa->lim);
err = btrfs_end_transaction(trans, root);