-
Notifications
You must be signed in to change notification settings - Fork 0
/
0004-Btrfs-fix-missing-check-before-creating-removing-a-q.patch
129 lines (120 loc) · 3.95 KB
/
0004-Btrfs-fix-missing-check-before-creating-removing-a-q.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
From 47a85b029c1f8a9d29904d75d8daeb36a89321c7 Mon Sep 17 00:00:00 2001
From: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Date: Fri, 29 Mar 2013 11:56:43 +0800
Subject: [PATCH V2 4/6] Btrfs: fix missing check before creating/destroying a
qgroup
For creating a qgroup, if the qgroup exsits, return -EEXIST.
For destroying a qgroup, if there are qgroup relations, return -EBUSY,
if the qgroup dosen't exist, return -ENOENT.
Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Reviewed-by: Miao Xie <miaox@cn.fujitsu.com>
---
fs/btrfs/ctree.h | 2 ++
fs/btrfs/ioctl.c | 5 ++++-
fs/btrfs/qgroup.c | 45 ++++++++++++++++++++++++++-------------------
3 files changed, 32 insertions(+), 20 deletions(-)
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 3fc393d..9e4ccb3 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3831,6 +3831,8 @@ int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info, u64 src, u64 dst);
int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info, u64 src, u64 dst);
+int btrfs_may_create_qgroup(struct btrfs_root *root,
+ struct btrfs_ioctl_qgroup_create_args *sa);
int btrfs_create_qgroup(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info, u64 qgroupid,
char *name);
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 7c72b12..f66d622 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -3811,13 +3811,16 @@ static long btrfs_ioctl_qgroup_create(struct file *file, void __user *arg)
goto out;
}
mutex_lock(&root->fs_info->quota_lock);
+ ret = btrfs_may_create_qgroup(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);
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index bed0e22..6f57a98 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -1003,15 +1003,13 @@ int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans,
int btrfs_create_qgroup(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info, u64 qgroupid, char *name)
{
- struct btrfs_root *quota_root;
+ struct btrfs_root *quota_root = fs_info->quota_root;
struct btrfs_qgroup *qgroup;
int ret = 0;
- quota_root = fs_info->quota_root;
- if (!quota_root)
- return -EINVAL;
-
ret = add_qgroup_item(trans, quota_root, qgroupid);
+ if (ret)
+ return ret;
spin_lock(&fs_info->qgroup_lock);
qgroup = add_qgroup_rb(fs_info, qgroupid);
@@ -1026,22 +1024,9 @@ int btrfs_create_qgroup(struct btrfs_trans_handle *trans,
int btrfs_remove_qgroup(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info, u64 qgroupid)
{
- struct btrfs_root *quota_root;
- struct btrfs_qgroup *qgroup;
+ struct btrfs_root *quota_root = fs_info->quota_root;
int ret = 0;
- quota_root = fs_info->quota_root;
- if (!quota_root)
- return -EINVAL;
-
- /* check if there are no relations to this qgroup */
- qgroup = find_qgroup_rb(fs_info, qgroupid);
- if (qgroup) {
- if (!list_empty(&qgroup->groups) ||
- !list_empty(&qgroup->members))
- return -EBUSY;
- }
-
ret = del_qgroup_item(trans, quota_root, qgroupid);
spin_lock(&fs_info->qgroup_lock);
@@ -1674,3 +1659,25 @@ int btrfs_may_limit_qgroup(struct btrfs_root *root, u64 qgroupid)
return -ENOENT;
return 0;
}
+
+int btrfs_may_create_qgroup(struct btrfs_root *root,
+ struct btrfs_ioctl_qgroup_create_args *sa)
+{
+ struct btrfs_qgroup *qgroup = NULL;
+
+ if (!root->fs_info->quota_root)
+ return -EINVAL;
+
+ qgroup = find_qgroup_rb(root->fs_info, sa->qgroupid);
+ if (sa->create) {
+ if (qgroup)
+ return -EEXIST;
+ return 0;
+ }
+ if (!qgroup)
+ return -ENOENT;
+ /* check if there are no relations to this qgroup */
+ if (!list_empty(&qgroup->groups) || !list_empty(&qgroup->members))
+ return -EBUSY;
+ return 0;
+}
--
1.7.7.6