diff options
author | Christoph Hellwig <hch@infradead.org> | 2010-02-16 03:44:48 -0500 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2010-03-04 18:20:21 -0500 |
commit | f450d4fee42c52e8045131a355b2de03094aa066 (patch) | |
tree | 07fadb1b4c868ad9eb571f68e32a44a6bbd2599c /fs/quota/quota.c | |
parent | c411e5f66a5dd36827a5f9d1392a1afdf69ff075 (diff) |
quota: clean up checks for supported quota methods
Move the checks for sb->s_qcop->foo next to the actual calls for them, same
for sb_has_quota_active checks where applicable.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/quota/quota.c')
-rw-r--r-- | fs/quota/quota.c | 121 |
1 files changed, 37 insertions, 84 deletions
diff --git a/fs/quota/quota.c b/fs/quota/quota.c index 4d7fdc4443b9..dcf7db91fc95 100644 --- a/fs/quota/quota.c +++ b/fs/quota/quota.c | |||
@@ -33,54 +33,6 @@ static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, | |||
33 | if (sb && !sb->s_qcop) | 33 | if (sb && !sb->s_qcop) |
34 | return -ENOSYS; | 34 | return -ENOSYS; |
35 | 35 | ||
36 | switch (cmd) { | ||
37 | case Q_GETFMT: | ||
38 | break; | ||
39 | case Q_QUOTAON: | ||
40 | if (!sb->s_qcop->quota_on) | ||
41 | return -ENOSYS; | ||
42 | break; | ||
43 | case Q_QUOTAOFF: | ||
44 | if (!sb->s_qcop->quota_off) | ||
45 | return -ENOSYS; | ||
46 | break; | ||
47 | case Q_SETINFO: | ||
48 | if (!sb->s_qcop->set_info) | ||
49 | return -ENOSYS; | ||
50 | break; | ||
51 | case Q_GETINFO: | ||
52 | if (!sb->s_qcop->get_info) | ||
53 | return -ENOSYS; | ||
54 | break; | ||
55 | case Q_SETQUOTA: | ||
56 | if (!sb->s_qcop->set_dqblk) | ||
57 | return -ENOSYS; | ||
58 | break; | ||
59 | case Q_GETQUOTA: | ||
60 | if (!sb->s_qcop->get_dqblk) | ||
61 | return -ENOSYS; | ||
62 | break; | ||
63 | case Q_SYNC: | ||
64 | if (sb && !sb->s_qcop->quota_sync) | ||
65 | return -ENOSYS; | ||
66 | break; | ||
67 | default: | ||
68 | return -EINVAL; | ||
69 | } | ||
70 | |||
71 | /* Is quota turned on for commands which need it? */ | ||
72 | switch (cmd) { | ||
73 | case Q_GETFMT: | ||
74 | case Q_GETINFO: | ||
75 | case Q_SETINFO: | ||
76 | case Q_SETQUOTA: | ||
77 | case Q_GETQUOTA: | ||
78 | /* This is just an informative test so we are satisfied | ||
79 | * without the lock */ | ||
80 | if (!sb_has_quota_active(sb, type)) | ||
81 | return -ESRCH; | ||
82 | } | ||
83 | |||
84 | /* Check privileges */ | 36 | /* Check privileges */ |
85 | if (cmd == Q_GETQUOTA) { | 37 | if (cmd == Q_GETQUOTA) { |
86 | if (((type == USRQUOTA && current_euid() != id) || | 38 | if (((type == USRQUOTA && current_euid() != id) || |
@@ -106,33 +58,6 @@ static int xqm_quotactl_valid(struct super_block *sb, int type, int cmd, | |||
106 | if (!sb->s_qcop) | 58 | if (!sb->s_qcop) |
107 | return -ENOSYS; | 59 | return -ENOSYS; |
108 | 60 | ||
109 | switch (cmd) { | ||
110 | case Q_XQUOTAON: | ||
111 | case Q_XQUOTAOFF: | ||
112 | case Q_XQUOTARM: | ||
113 | if (!sb->s_qcop->set_xstate) | ||
114 | return -ENOSYS; | ||
115 | break; | ||
116 | case Q_XGETQSTAT: | ||
117 | if (!sb->s_qcop->get_xstate) | ||
118 | return -ENOSYS; | ||
119 | break; | ||
120 | case Q_XSETQLIM: | ||
121 | if (!sb->s_qcop->set_xquota) | ||
122 | return -ENOSYS; | ||
123 | break; | ||
124 | case Q_XGETQUOTA: | ||
125 | if (!sb->s_qcop->get_xquota) | ||
126 | return -ENOSYS; | ||
127 | break; | ||
128 | case Q_XQUOTASYNC: | ||
129 | if (!sb->s_qcop->quota_sync) | ||
130 | return -ENOSYS; | ||
131 | break; | ||
132 | default: | ||
133 | return -EINVAL; | ||
134 | } | ||
135 | |||
136 | /* Check privileges */ | 61 | /* Check privileges */ |
137 | if (cmd == Q_XGETQUOTA) { | 62 | if (cmd == Q_XGETQUOTA) { |
138 | if (((type == XQM_USRQUOTA && current_euid() != id) || | 63 | if (((type == XQM_USRQUOTA && current_euid() != id) || |
@@ -238,12 +163,13 @@ static int quota_quotaon(struct super_block *sb, int type, int cmd, qid_t id, | |||
238 | void __user *addr) | 163 | void __user *addr) |
239 | { | 164 | { |
240 | char *pathname; | 165 | char *pathname; |
241 | int ret; | 166 | int ret = -ENOSYS; |
242 | 167 | ||
243 | pathname = getname(addr); | 168 | pathname = getname(addr); |
244 | if (IS_ERR(pathname)) | 169 | if (IS_ERR(pathname)) |
245 | return PTR_ERR(pathname); | 170 | return PTR_ERR(pathname); |
246 | ret = sb->s_qcop->quota_on(sb, type, id, pathname, 0); | 171 | if (sb->s_qcop->quota_on) |
172 | ret = sb->s_qcop->quota_on(sb, type, id, pathname, 0); | ||
247 | putname(pathname); | 173 | putname(pathname); |
248 | return ret; | 174 | return ret; |
249 | } | 175 | } |
@@ -269,6 +195,10 @@ static int quota_getinfo(struct super_block *sb, int type, void __user *addr) | |||
269 | struct if_dqinfo info; | 195 | struct if_dqinfo info; |
270 | int ret; | 196 | int ret; |
271 | 197 | ||
198 | if (!sb_has_quota_active(sb, type)) | ||
199 | return -ESRCH; | ||
200 | if (!sb->s_qcop->get_info) | ||
201 | return -ENOSYS; | ||
272 | ret = sb->s_qcop->get_info(sb, type, &info); | 202 | ret = sb->s_qcop->get_info(sb, type, &info); |
273 | if (!ret && copy_to_user(addr, &info, sizeof(info))) | 203 | if (!ret && copy_to_user(addr, &info, sizeof(info))) |
274 | return -EFAULT; | 204 | return -EFAULT; |
@@ -281,6 +211,10 @@ static int quota_setinfo(struct super_block *sb, int type, void __user *addr) | |||
281 | 211 | ||
282 | if (copy_from_user(&info, addr, sizeof(info))) | 212 | if (copy_from_user(&info, addr, sizeof(info))) |
283 | return -EFAULT; | 213 | return -EFAULT; |
214 | if (!sb_has_quota_active(sb, type)) | ||
215 | return -ESRCH; | ||
216 | if (!sb->s_qcop->set_info) | ||
217 | return -ENOSYS; | ||
284 | return sb->s_qcop->set_info(sb, type, &info); | 218 | return sb->s_qcop->set_info(sb, type, &info); |
285 | } | 219 | } |
286 | 220 | ||
@@ -290,6 +224,10 @@ static int quota_getquota(struct super_block *sb, int type, qid_t id, | |||
290 | struct if_dqblk idq; | 224 | struct if_dqblk idq; |
291 | int ret; | 225 | int ret; |
292 | 226 | ||
227 | if (!sb_has_quota_active(sb, type)) | ||
228 | return -ESRCH; | ||
229 | if (!sb->s_qcop->get_dqblk) | ||
230 | return -ENOSYS; | ||
293 | ret = sb->s_qcop->get_dqblk(sb, type, id, &idq); | 231 | ret = sb->s_qcop->get_dqblk(sb, type, id, &idq); |
294 | if (ret) | 232 | if (ret) |
295 | return ret; | 233 | return ret; |
@@ -305,6 +243,10 @@ static int quota_setquota(struct super_block *sb, int type, qid_t id, | |||
305 | 243 | ||
306 | if (copy_from_user(&idq, addr, sizeof(idq))) | 244 | if (copy_from_user(&idq, addr, sizeof(idq))) |
307 | return -EFAULT; | 245 | return -EFAULT; |
246 | if (!sb_has_quota_active(sb, type)) | ||
247 | return -ESRCH; | ||
248 | if (!sb->s_qcop->set_dqblk) | ||
249 | return -ENOSYS; | ||
308 | return sb->s_qcop->set_dqblk(sb, type, id, &idq); | 250 | return sb->s_qcop->set_dqblk(sb, type, id, &idq); |
309 | } | 251 | } |
310 | 252 | ||
@@ -314,6 +256,8 @@ static int quota_setxstate(struct super_block *sb, int cmd, void __user *addr) | |||
314 | 256 | ||
315 | if (copy_from_user(&flags, addr, sizeof(flags))) | 257 | if (copy_from_user(&flags, addr, sizeof(flags))) |
316 | return -EFAULT; | 258 | return -EFAULT; |
259 | if (!sb->s_qcop->set_xstate) | ||
260 | return -ENOSYS; | ||
317 | return sb->s_qcop->set_xstate(sb, flags, cmd); | 261 | return sb->s_qcop->set_xstate(sb, flags, cmd); |
318 | } | 262 | } |
319 | 263 | ||
@@ -321,7 +265,9 @@ static int quota_getxstate(struct super_block *sb, void __user *addr) | |||
321 | { | 265 | { |
322 | struct fs_quota_stat fqs; | 266 | struct fs_quota_stat fqs; |
323 | int ret; | 267 | int ret; |
324 | 268 | ||
269 | if (!sb->s_qcop->get_xstate) | ||
270 | return -ENOSYS; | ||
325 | ret = sb->s_qcop->get_xstate(sb, &fqs); | 271 | ret = sb->s_qcop->get_xstate(sb, &fqs); |
326 | if (!ret && copy_to_user(addr, &fqs, sizeof(fqs))) | 272 | if (!ret && copy_to_user(addr, &fqs, sizeof(fqs))) |
327 | return -EFAULT; | 273 | return -EFAULT; |
@@ -335,6 +281,8 @@ static int quota_setxquota(struct super_block *sb, int type, qid_t id, | |||
335 | 281 | ||
336 | if (copy_from_user(&fdq, addr, sizeof(fdq))) | 282 | if (copy_from_user(&fdq, addr, sizeof(fdq))) |
337 | return -EFAULT; | 283 | return -EFAULT; |
284 | if (!sb->s_qcop->set_xquota) | ||
285 | return -ENOSYS; | ||
338 | return sb->s_qcop->set_xquota(sb, type, id, &fdq); | 286 | return sb->s_qcop->set_xquota(sb, type, id, &fdq); |
339 | } | 287 | } |
340 | 288 | ||
@@ -344,6 +292,8 @@ static int quota_getxquota(struct super_block *sb, int type, qid_t id, | |||
344 | struct fs_disk_quota fdq; | 292 | struct fs_disk_quota fdq; |
345 | int ret; | 293 | int ret; |
346 | 294 | ||
295 | if (!sb->s_qcop->get_xquota) | ||
296 | return -ENOSYS; | ||
347 | ret = sb->s_qcop->get_xquota(sb, type, id, &fdq); | 297 | ret = sb->s_qcop->get_xquota(sb, type, id, &fdq); |
348 | if (!ret && copy_to_user(addr, &fdq, sizeof(fdq))) | 298 | if (!ret && copy_to_user(addr, &fdq, sizeof(fdq))) |
349 | return -EFAULT; | 299 | return -EFAULT; |
@@ -358,6 +308,8 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id, | |||
358 | case Q_QUOTAON: | 308 | case Q_QUOTAON: |
359 | return quota_quotaon(sb, type, cmd, id, addr); | 309 | return quota_quotaon(sb, type, cmd, id, addr); |
360 | case Q_QUOTAOFF: | 310 | case Q_QUOTAOFF: |
311 | if (!sb->s_qcop->quota_off) | ||
312 | return -ENOSYS; | ||
361 | return sb->s_qcop->quota_off(sb, type, 0); | 313 | return sb->s_qcop->quota_off(sb, type, 0); |
362 | case Q_GETFMT: | 314 | case Q_GETFMT: |
363 | return quota_getfmt(sb, type, addr); | 315 | return quota_getfmt(sb, type, addr); |
@@ -370,9 +322,11 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id, | |||
370 | case Q_SETQUOTA: | 322 | case Q_SETQUOTA: |
371 | return quota_setquota(sb, type, id, addr); | 323 | return quota_setquota(sb, type, id, addr); |
372 | case Q_SYNC: | 324 | case Q_SYNC: |
373 | if (sb) | 325 | if (sb) { |
326 | if (!sb->s_qcop->quota_sync) | ||
327 | return -ENOSYS; | ||
374 | sync_quota_sb(sb, type); | 328 | sync_quota_sb(sb, type); |
375 | else | 329 | } else |
376 | sync_dquots(type); | 330 | sync_dquots(type); |
377 | return 0; | 331 | return 0; |
378 | case Q_XQUOTAON: | 332 | case Q_XQUOTAON: |
@@ -386,13 +340,12 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id, | |||
386 | case Q_XGETQUOTA: | 340 | case Q_XGETQUOTA: |
387 | return quota_getxquota(sb, type, id, addr); | 341 | return quota_getxquota(sb, type, id, addr); |
388 | case Q_XQUOTASYNC: | 342 | case Q_XQUOTASYNC: |
343 | if (!sb->s_qcop->quota_sync) | ||
344 | return -ENOSYS; | ||
389 | return sb->s_qcop->quota_sync(sb, type); | 345 | return sb->s_qcop->quota_sync(sb, type); |
390 | /* We never reach here unless validity check is broken */ | ||
391 | default: | 346 | default: |
392 | BUG(); | 347 | return -EINVAL; |
393 | } | 348 | } |
394 | |||
395 | return 0; | ||
396 | } | 349 | } |
397 | 350 | ||
398 | /* | 351 | /* |