Sun Jan 29 06:44:33 2012 UTC ()
Move the top level iteration for QUOTACTL_SET from ufs to vfs_quotactl.

Note: this change requires a kernel version bump.


(dholland)
diff -r1.10 -r1.11 src/sys/kern/vfs_quotactl.c
diff -r1.8 -r1.9 src/sys/sys/quotactl.h
diff -r1.79 -r1.80 src/sys/ufs/ufs/ufs_quota.c

cvs diff -r1.10 -r1.11 src/sys/kern/vfs_quotactl.c (expand / switch to unified diff)

--- src/sys/kern/vfs_quotactl.c 2012/01/29 06:41:41 1.10
+++ src/sys/kern/vfs_quotactl.c 2012/01/29 06:44:33 1.11
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vfs_quotactl.c,v 1.10 2012/01/29 06:41:41 dholland Exp $ */ 1/* $NetBSD: vfs_quotactl.c,v 1.11 2012/01/29 06:44:33 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1991, 1993, 1994 4 * Copyright (c) 1991, 1993, 1994
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc. 6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed 7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph 8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc. 10 * the permission of UNIX System Laboratories, Inc.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -70,27 +70,27 @@ @@ -70,27 +70,27 @@
70 * 70 *
71 * @(#)ufs_quota.c 8.5 (Berkeley) 5/20/95 71 * @(#)ufs_quota.c 8.5 (Berkeley) 5/20/95
72 * From NetBSD: ufs_quota.c,v 1.70 2011/03/24 17:05:46 bouyer Exp 72 * From NetBSD: ufs_quota.c,v 1.70 2011/03/24 17:05:46 bouyer Exp
73 */ 73 */
74 74
75/* 75/*
76 * Note that both of the copyrights above are moderately spurious; 76 * Note that both of the copyrights above are moderately spurious;
77 * this code should almost certainly have the Copyright 2010 Manuel 77 * this code should almost certainly have the Copyright 2010 Manuel
78 * Bouyer notice and license found in e.g. sys/ufs/ufs/quota2_subr.c. 78 * Bouyer notice and license found in e.g. sys/ufs/ufs/quota2_subr.c.
79 * However, they're what was on the files this code was sliced out of. 79 * However, they're what was on the files this code was sliced out of.
80 */ 80 */
81 81
82#include <sys/cdefs.h> 82#include <sys/cdefs.h>
83__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.10 2012/01/29 06:41:41 dholland Exp $"); 83__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.11 2012/01/29 06:44:33 dholland Exp $");
84 84
85#include <sys/mount.h> 85#include <sys/mount.h>
86#include <sys/quota.h> 86#include <sys/quota.h>
87#include <sys/quotactl.h> 87#include <sys/quotactl.h>
88#include <quota/quotaprop.h> 88#include <quota/quotaprop.h>
89 89
90static int 90static int
91vfs_quotactl_getversion(struct mount *mp, 91vfs_quotactl_getversion(struct mount *mp,
92 prop_dictionary_t cmddict, int q2type, 92 prop_dictionary_t cmddict, int q2type,
93 prop_array_t datas) 93 prop_array_t datas)
94{ 94{
95 prop_array_t replies; 95 prop_array_t replies;
96 prop_dictionary_t data; 96 prop_dictionary_t data;
@@ -293,33 +293,82 @@ vfs_quotactl_get(struct mount *mp, @@ -293,33 +293,82 @@ vfs_quotactl_get(struct mount *mp,
293 return error; 293 return error;
294 294
295 fail: 295 fail:
296 prop_object_iterator_release(iter); 296 prop_object_iterator_release(iter);
297 prop_object_release(replies); 297 prop_object_release(replies);
298 return error; 298 return error;
299} 299}
300 300
301static int 301static int
302vfs_quotactl_set(struct mount *mp, 302vfs_quotactl_set(struct mount *mp,
303 prop_dictionary_t cmddict, int q2type, 303 prop_dictionary_t cmddict, int q2type,
304 prop_array_t datas) 304 prop_array_t datas)
305{ 305{
 306 prop_array_t replies;
 307 prop_object_iterator_t iter;
 308 prop_dictionary_t data;
 309 int defaultq;
 310 uint32_t id;
 311 const char *idstr;
306 struct vfs_quotactl_args args; 312 struct vfs_quotactl_args args;
 313 int error;
307 314
308 args.qc_type = QCT_PROPLIB; 315 KASSERT(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY);
309 args.u.proplib.qc_cmddict = cmddict; 316 KASSERT(prop_object_type(datas) == PROP_TYPE_ARRAY);
310 args.u.proplib.qc_q2type = q2type; 317
311 args.u.proplib.qc_datas = datas; 318 replies = prop_array_create();
312 return VFS_QUOTACTL(mp, QUOTACTL_SET, &args); 319 if (replies == NULL)
 320 return ENOMEM;
 321
 322 iter = prop_array_iterator(datas);
 323 if (iter == NULL) {
 324 prop_object_release(replies);
 325 return ENOMEM;
 326 }
 327
 328 while ((data = prop_object_iterator_next(iter)) != NULL) {
 329 if (!prop_dictionary_get_uint32(data, "id", &id)) {
 330 if (!prop_dictionary_get_cstring_nocopy(data, "id",
 331 &idstr))
 332 continue;
 333 if (strcmp(idstr, "default"))
 334 continue;
 335 id = 0;
 336 defaultq = 1;
 337 } else {
 338 defaultq = 0;
 339 }
 340
 341 args.qc_type = QCT_SET;
 342 args.u.set.qc_id = id;
 343 args.u.set.qc_defaultq = defaultq;
 344 args.u.set.qc_q2type = q2type;
 345 args.u.set.qc_data = data;
 346 error = VFS_QUOTACTL(mp, QUOTACTL_SET, &args);
 347 if (error) {
 348 goto err;
 349 }
 350 }
 351 prop_object_iterator_release(iter);
 352 if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) {
 353 error = ENOMEM;
 354 } else {
 355 error = 0;
 356 }
 357 return error;
 358err:
 359 prop_object_iterator_release(iter);
 360 prop_object_release(replies);
 361 return error;
313} 362}
314 363
315static int 364static int
316vfs_quotactl_getall(struct mount *mp, 365vfs_quotactl_getall(struct mount *mp,
317 prop_dictionary_t cmddict, int q2type, 366 prop_dictionary_t cmddict, int q2type,
318 prop_array_t datas) 367 prop_array_t datas)
319{ 368{
320 struct vfs_quotactl_args args; 369 struct vfs_quotactl_args args;
321 370
322 args.qc_type = QCT_PROPLIB; 371 args.qc_type = QCT_PROPLIB;
323 args.u.proplib.qc_cmddict = cmddict; 372 args.u.proplib.qc_cmddict = cmddict;
324 args.u.proplib.qc_q2type = q2type; 373 args.u.proplib.qc_q2type = q2type;
325 args.u.proplib.qc_datas = datas; 374 args.u.proplib.qc_datas = datas;

cvs diff -r1.8 -r1.9 src/sys/sys/quotactl.h (expand / switch to unified diff)

--- src/sys/sys/quotactl.h 2012/01/29 06:41:41 1.8
+++ src/sys/sys/quotactl.h 2012/01/29 06:44:33 1.9
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: quotactl.h,v 1.8 2012/01/29 06:41:41 dholland Exp $ */ 1/* $NetBSD: quotactl.h,v 1.9 2012/01/29 06:44:33 dholland Exp $ */
2/*- 2/*-
3 * Copyright (c) 2011 The NetBSD Foundation, Inc. 3 * Copyright (c) 2011 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This code is derived from software contributed to The NetBSD Foundation 6 * This code is derived from software contributed to The NetBSD Foundation
7 * by David A. Holland. 7 * by David A. Holland.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -41,33 +41,40 @@ @@ -41,33 +41,40 @@
41#define QUOTACTL_GETVERSION 0 41#define QUOTACTL_GETVERSION 0
42#define QUOTACTL_QUOTAON 1 42#define QUOTACTL_QUOTAON 1
43#define QUOTACTL_QUOTAOFF 2 43#define QUOTACTL_QUOTAOFF 2
44#define QUOTACTL_GET 3 44#define QUOTACTL_GET 3
45#define QUOTACTL_SET 4 45#define QUOTACTL_SET 4
46#define QUOTACTL_GETALL 5 46#define QUOTACTL_GETALL 5
47#define QUOTACTL_CLEAR 6 47#define QUOTACTL_CLEAR 6
48 48
49/* Argument encoding. */ 49/* Argument encoding. */
50enum vfs_quotactl_argtypes { 50enum vfs_quotactl_argtypes {
51 QCT_PROPLIB, /* quotaon/off, get, set, getall, clear */ 51 QCT_PROPLIB, /* quotaon/off, get, set, getall, clear */
52 QCT_GETVERSION, /* getversion */ 52 QCT_GETVERSION, /* getversion */
53 QCT_GET, /* get */ 53 QCT_GET, /* get */
 54 QCT_SET, /* set */
54}; 55};
55struct vfs_quotactl_args { 56struct vfs_quotactl_args {
56 enum vfs_quotactl_argtypes qc_type; 57 enum vfs_quotactl_argtypes qc_type;
57 union { 58 union {
58 struct { 59 struct {
59 prop_dictionary_t qc_cmddict; 60 prop_dictionary_t qc_cmddict;
60 int qc_q2type; 61 int qc_q2type;
61 prop_array_t qc_datas; 62 prop_array_t qc_datas;
62 } proplib; 63 } proplib;
63 struct { 64 struct {
64 int *qc_version_ret; 65 int *qc_version_ret;
65 } getversion; 66 } getversion;
66 struct { 67 struct {
67 const struct quotakey *qc_key; 68 const struct quotakey *qc_key;
68 struct quotaval *qc_ret; 69 struct quotaval *qc_ret;
69 } get; 70 } get;
 71 struct {
 72 id_t qc_id;
 73 int qc_defaultq;
 74 int qc_q2type;
 75 prop_dictionary_t qc_data;
 76 } set;
70 } u; 77 } u;
71}; 78};
72 79
73#endif /* _SYS_QUOTACTL_H_ */ 80#endif /* _SYS_QUOTACTL_H_ */

cvs diff -r1.79 -r1.80 src/sys/ufs/ufs/ufs_quota.c (expand / switch to unified diff)

--- src/sys/ufs/ufs/ufs_quota.c 2012/01/29 06:42:14 1.79
+++ src/sys/ufs/ufs/ufs_quota.c 2012/01/29 06:44:33 1.80
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ufs_quota.c,v 1.79 2012/01/29 06:42:14 dholland Exp $ */ 1/* $NetBSD: ufs_quota.c,v 1.80 2012/01/29 06:44:33 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1982, 1986, 1990, 1993, 1995 4 * Copyright (c) 1982, 1986, 1990, 1993, 1995
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Robert Elz at The University of Melbourne. 8 * Robert Elz at The University of Melbourne.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 * 33 *
34 * @(#)ufs_quota.c 8.5 (Berkeley) 5/20/95 34 * @(#)ufs_quota.c 8.5 (Berkeley) 5/20/95
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.79 2012/01/29 06:42:14 dholland Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.80 2012/01/29 06:44:33 dholland Exp $");
39 39
40#if defined(_KERNEL_OPT) 40#if defined(_KERNEL_OPT)
41#include "opt_quota.h" 41#include "opt_quota.h"
42#endif  42#endif
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/kernel.h> 44#include <sys/kernel.h>
45#include <sys/systm.h> 45#include <sys/systm.h>
46#include <sys/namei.h> 46#include <sys/namei.h>
47#include <sys/file.h> 47#include <sys/file.h>
48#include <sys/proc.h> 48#include <sys/proc.h>
49#include <sys/vnode.h> 49#include <sys/vnode.h>
50#include <sys/mount.h> 50#include <sys/mount.h>
51#include <sys/kauth.h> 51#include <sys/kauth.h>
@@ -257,100 +257,70 @@ quota_handle_cmd_get(struct mount *mp, s @@ -257,100 +257,70 @@ quota_handle_cmd_get(struct mount *mp, s
257#endif 257#endif
258 panic("quota_handle_cmd_get: no support ?"); 258 panic("quota_handle_cmd_get: no support ?");
259  259
260 if (error != 0) 260 if (error != 0)
261 return error; 261 return error;
262 262
263 return error; 263 return error;
264} 264}
265 265
266static int  266static int
267quota_handle_cmd_set(struct mount *mp, struct lwp *l,  267quota_handle_cmd_set(struct mount *mp, struct lwp *l,
268 struct vfs_quotactl_args *args) 268 struct vfs_quotactl_args *args)
269{ 269{
270 prop_array_t replies; 
271 prop_object_iterator_t iter; 
272 prop_dictionary_t data; 
273 uint32_t id; 
274 struct ufsmount *ump = VFSTOUFS(mp); 270 struct ufsmount *ump = VFSTOUFS(mp);
275 int error, defaultq = 0; 271 id_t id;
276 const char *idstr; 272 int defaultq;
277 prop_dictionary_t cmddict; 
278 int q2type; 273 int q2type;
279 prop_array_t datas; 274 prop_dictionary_t data;
 275 int error;
280 276
281 KASSERT(args->qc_type == QCT_PROPLIB); 277 KASSERT(args->qc_type == QCT_SET);
282 cmddict = args->u.proplib.qc_cmddict; 278 id = args->u.set.qc_id;
283 q2type = args->u.proplib.qc_q2type; 279 defaultq = args->u.set.qc_defaultq;
284 datas = args->u.proplib.qc_datas; 280 q2type = args->u.set.qc_q2type;
 281 data = args->u.set.qc_data;
285 282
286 KASSERT(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY); 283 KASSERT(prop_object_type(data) == PROP_TYPE_DICTIONARY);
287 KASSERT(prop_object_type(datas) == PROP_TYPE_ARRAY); 
288 284
289 if ((ump->um_flags & (UFS_QUOTA|UFS_QUOTA2)) == 0) 285 if ((ump->um_flags & (UFS_QUOTA|UFS_QUOTA2)) == 0)
290 return EOPNOTSUPP; 286 return EOPNOTSUPP;
291  
292 replies = prop_array_create(); 
293 if (replies == NULL) 
294 return ENOMEM; 
295 287
296 iter = prop_array_iterator(datas); 288 /* avoid whitespace changes */
297 if (iter == NULL) { 289 {
298 prop_object_release(replies); 
299 return ENOMEM; 
300 } 
301 while ((data = prop_object_iterator_next(iter)) != NULL) { 
302 if (!prop_dictionary_get_uint32(data, "id", &id)) { 
303 if (!prop_dictionary_get_cstring_nocopy(data, "id", 
304 &idstr)) 
305 continue; 
306 if (strcmp(idstr, "default")) 
307 continue; 
308 id = 0; 
309 defaultq = 1; 
310 } else { 
311 defaultq = 0; 
312 } 
313 error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA, 290 error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
314 KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(id), NULL); 291 KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(id), NULL);
315 if (error != 0) 292 if (error != 0)
316 goto err; 293 goto err;
317#ifdef QUOTA 294#ifdef QUOTA
318 if (ump->um_flags & UFS_QUOTA) 295 if (ump->um_flags & UFS_QUOTA)
319 error = quota1_handle_cmd_set(ump, q2type, id, defaultq, 296 error = quota1_handle_cmd_set(ump, q2type, id, defaultq,
320 data); 297 data);
321 else 298 else
322#endif 299#endif
323#ifdef QUOTA2 300#ifdef QUOTA2
324 if (ump->um_flags & UFS_QUOTA2) { 301 if (ump->um_flags & UFS_QUOTA2) {
325 error = quota2_handle_cmd_set(ump, q2type, id, defaultq, 302 error = quota2_handle_cmd_set(ump, q2type, id, defaultq,
326 data); 303 data);
327 } else 304 } else
328#endif 305#endif
329 panic("quota_handle_cmd_get: no support ?"); 306 panic("quota_handle_cmd_get: no support ?");
330  307
331 if (error && error != ENOENT) 308 if (error && error != ENOENT)
332 goto err; 309 goto err;
333 } 310 }
334 prop_object_iterator_release(iter); 311
335 if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) { 312 return 0;
336 error = ENOMEM; 313 err:
337 } else { 
338 error = 0; 
339 } 
340 return error; 
341err: 
342 prop_object_iterator_release(iter); 
343 prop_object_release(replies); 
344 return error; 314 return error;
345} 315}
346 316
347static int  317static int
348quota_handle_cmd_clear(struct mount *mp, struct lwp *l,  318quota_handle_cmd_clear(struct mount *mp, struct lwp *l,
349 struct vfs_quotactl_args *args) 319 struct vfs_quotactl_args *args)
350{ 320{
351 prop_array_t replies; 321 prop_array_t replies;
352 prop_object_iterator_t iter; 322 prop_object_iterator_t iter;
353 prop_dictionary_t data; 323 prop_dictionary_t data;
354 uint32_t id; 324 uint32_t id;
355 struct ufsmount *ump = VFSTOUFS(mp); 325 struct ufsmount *ump = VFSTOUFS(mp);
356 int error, defaultq = 0; 326 int error, defaultq = 0;