Sun Jan 29 06:53:36 2012 UTC ()
Improve the quota2 QUOTACTL_CLEAR code to allow clearing blocks and
files independently.

Note: this change requires a kernel version bump.


(dholland)
diff -r1.17 -r1.18 src/sys/kern/vfs_quotactl.c
diff -r1.15 -r1.16 src/sys/sys/quotactl.h
diff -r1.89 -r1.90 src/sys/ufs/ufs/ufs_quota.c
diff -r1.11 -r1.12 src/sys/ufs/ufs/ufs_quota.h
diff -r1.12 -r1.13 src/sys/ufs/ufs/ufs_quota2.c

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

--- src/sys/kern/vfs_quotactl.c 2012/01/29 06:52:38 1.17
+++ src/sys/kern/vfs_quotactl.c 2012/01/29 06:53:35 1.18
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vfs_quotactl.c,v 1.17 2012/01/29 06:52:38 dholland Exp $ */ 1/* $NetBSD: vfs_quotactl.c,v 1.18 2012/01/29 06:53:35 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.17 2012/01/29 06:52:38 dholland Exp $"); 83__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.18 2012/01/29 06:53:35 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;
@@ -485,26 +485,37 @@ vfs_quotactl_clear(struct mount *mp, @@ -485,26 +485,37 @@ vfs_quotactl_clear(struct mount *mp,
485 continue; 485 continue;
486 if (strcmp(idstr, "default")) 486 if (strcmp(idstr, "default"))
487 continue; 487 continue;
488 id = 0; 488 id = 0;
489 defaultq = 1; 489 defaultq = 1;
490 } else { 490 } else {
491 defaultq = 0; 491 defaultq = 0;
492 } 492 }
493 493
494 args.qc_type = QCT_CLEAR; 494 args.qc_type = QCT_CLEAR;
495 args.u.clear.qc_idtype = q2type; 495 args.u.clear.qc_idtype = q2type;
496 args.u.clear.qc_id = id; 496 args.u.clear.qc_id = id;
497 args.u.clear.qc_defaultq = defaultq; 497 args.u.clear.qc_defaultq = defaultq;
 498 args.u.clear.qc_objtype = QUOTA_OBJTYPE_BLOCKS;
 499 error = VFS_QUOTACTL(mp, QUOTACTL_CLEAR, &args);
 500 if (error) {
 501 goto err;
 502 }
 503
 504 args.qc_type = QCT_CLEAR;
 505 args.u.clear.qc_idtype = q2type;
 506 args.u.clear.qc_id = id;
 507 args.u.clear.qc_defaultq = defaultq;
 508 args.u.clear.qc_objtype = QUOTA_OBJTYPE_FILES;
498 error = VFS_QUOTACTL(mp, QUOTACTL_CLEAR, &args); 509 error = VFS_QUOTACTL(mp, QUOTACTL_CLEAR, &args);
499 if (error) { 510 if (error) {
500 goto err; 511 goto err;
501 } 512 }
502 } 513 }
503 514
504 prop_object_iterator_release(iter); 515 prop_object_iterator_release(iter);
505 if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) { 516 if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) {
506 error = ENOMEM; 517 error = ENOMEM;
507 } else { 518 } else {
508 error = 0; 519 error = 0;
509 } 520 }
510 return error; 521 return error;

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

--- src/sys/sys/quotactl.h 2012/01/29 06:52:39 1.15
+++ src/sys/sys/quotactl.h 2012/01/29 06:53:35 1.16
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: quotactl.h,v 1.15 2012/01/29 06:52:39 dholland Exp $ */ 1/* $NetBSD: quotactl.h,v 1.16 2012/01/29 06:53:35 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
@@ -67,18 +67,19 @@ struct vfs_quotactl_args { @@ -67,18 +67,19 @@ struct vfs_quotactl_args {
67 } getversion; 67 } getversion;
68 struct { 68 struct {
69 const struct quotakey *qc_key; 69 const struct quotakey *qc_key;
70 struct quotaval *qc_ret; 70 struct quotaval *qc_ret;
71 } get; 71 } get;
72 struct { 72 struct {
73 const struct quotakey *qc_key; 73 const struct quotakey *qc_key;
74 const struct quotaval *qc_val; 74 const struct quotaval *qc_val;
75 } put; 75 } put;
76 struct { 76 struct {
77 int qc_idtype; 77 int qc_idtype;
78 id_t qc_id; 78 id_t qc_id;
79 int qc_defaultq; 79 int qc_defaultq;
 80 int qc_objtype;
80 } clear; 81 } clear;
81 } u; 82 } u;
82}; 83};
83 84
84#endif /* _SYS_QUOTACTL_H_ */ 85#endif /* _SYS_QUOTACTL_H_ */

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

--- src/sys/ufs/ufs/ufs_quota.c 2012/01/29 06:52:39 1.89
+++ src/sys/ufs/ufs/ufs_quota.c 2012/01/29 06:53:35 1.90
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ufs_quota.c,v 1.89 2012/01/29 06:52:39 dholland Exp $ */ 1/* $NetBSD: ufs_quota.c,v 1.90 2012/01/29 06:53:35 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.89 2012/01/29 06:52:39 dholland Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.90 2012/01/29 06:53:35 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>
@@ -309,46 +309,48 @@ quota_handle_cmd_put(struct mount *mp, s @@ -309,46 +309,48 @@ quota_handle_cmd_put(struct mount *mp, s
309 } 309 }
310 310
311 return error; 311 return error;
312} 312}
313 313
314static int  314static int
315quota_handle_cmd_clear(struct mount *mp, struct lwp *l,  315quota_handle_cmd_clear(struct mount *mp, struct lwp *l,
316 struct vfs_quotactl_args *args) 316 struct vfs_quotactl_args *args)
317{ 317{
318 struct ufsmount *ump = VFSTOUFS(mp); 318 struct ufsmount *ump = VFSTOUFS(mp);
319 int idtype; 319 int idtype;
320 id_t id; 320 id_t id;
321 int defaultq; 321 int defaultq;
 322 int objtype;
322 int error; 323 int error;
323 324
324 KASSERT(args->qc_type == QCT_CLEAR); 325 KASSERT(args->qc_type == QCT_CLEAR);
325 idtype = args->u.clear.qc_idtype; 326 idtype = args->u.clear.qc_idtype;
326 id = args->u.clear.qc_id; 327 id = args->u.clear.qc_id;
327 defaultq = args->u.clear.qc_defaultq; 328 defaultq = args->u.clear.qc_defaultq;
 329 objtype = args->u.clear.qc_objtype;
328 330
329 if ((ump->um_flags & UFS_QUOTA2) == 0) 331 if ((ump->um_flags & UFS_QUOTA2) == 0)
330 return EOPNOTSUPP; 332 return EOPNOTSUPP;
331 333
332 /* avoid whitespace changes */ 334 /* avoid whitespace changes */
333 { 335 {
334 error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA, 336 error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
335 KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(id), NULL); 337 KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(id), NULL);
336 if (error != 0) 338 if (error != 0)
337 goto err; 339 goto err;
338#ifdef QUOTA2 340#ifdef QUOTA2
339 if (ump->um_flags & UFS_QUOTA2) { 341 if (ump->um_flags & UFS_QUOTA2) {
340 error = quota2_handle_cmd_clear(ump, idtype, id, 342 error = quota2_handle_cmd_clear(ump, idtype, id,
341 defaultq); 343 defaultq, objtype);
342 } else 344 } else
343#endif 345#endif
344 panic("quota_handle_cmd_get: no support ?"); 346 panic("quota_handle_cmd_get: no support ?");
345  347
346 if (error && error != ENOENT) 348 if (error && error != ENOENT)
347 goto err; 349 goto err;
348 } 350 }
349 351
350 return 0; 352 return 0;
351 err: 353 err:
352 return error; 354 return error;
353} 355}
354 356

cvs diff -r1.11 -r1.12 src/sys/ufs/ufs/ufs_quota.h (expand / switch to unified diff)

--- src/sys/ufs/ufs/ufs_quota.h 2012/01/29 06:52:39 1.11
+++ src/sys/ufs/ufs/ufs_quota.h 2012/01/29 06:53:35 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ufs_quota.h,v 1.11 2012/01/29 06:52:39 dholland Exp $ */ 1/* $NetBSD: ufs_quota.h,v 1.12 2012/01/29 06:53:35 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.
@@ -117,18 +117,18 @@ int quota1_handle_cmd_get(struct ufsmoun @@ -117,18 +117,18 @@ int quota1_handle_cmd_get(struct ufsmoun
117 struct quotaval *); 117 struct quotaval *);
118int quota1_handle_cmd_put(struct ufsmount *, const struct quotakey *, 118int quota1_handle_cmd_put(struct ufsmount *, const struct quotakey *,
119 const struct quotaval *); 119 const struct quotaval *);
120int quota1_handle_cmd_quotaon(struct lwp *, struct ufsmount *, int, 120int quota1_handle_cmd_quotaon(struct lwp *, struct ufsmount *, int,
121 const char *); 121 const char *);
122int quota1_handle_cmd_quotaoff(struct lwp *, struct ufsmount *, int); 122int quota1_handle_cmd_quotaoff(struct lwp *, struct ufsmount *, int);
123 123
124int chkdq2(struct inode *, int64_t, kauth_cred_t, int); 124int chkdq2(struct inode *, int64_t, kauth_cred_t, int);
125int chkiq2(struct inode *, int32_t, kauth_cred_t, int); 125int chkiq2(struct inode *, int32_t, kauth_cred_t, int);
126int quota2_handle_cmd_get(struct ufsmount *, const struct quotakey *, 126int quota2_handle_cmd_get(struct ufsmount *, const struct quotakey *,
127 struct quotaval *); 127 struct quotaval *);
128int quota2_handle_cmd_put(struct ufsmount *, const struct quotakey *, 128int quota2_handle_cmd_put(struct ufsmount *, const struct quotakey *,
129 const struct quotaval *); 129 const struct quotaval *);
130int quota2_handle_cmd_clear(struct ufsmount *, int, int, int); 130int quota2_handle_cmd_clear(struct ufsmount *, int, int, int, int);
131int quota2_handle_cmd_getall(struct ufsmount *, int, prop_array_t); 131int quota2_handle_cmd_getall(struct ufsmount *, int, prop_array_t);
132int q2sync(struct mount *); 132int q2sync(struct mount *);
133int dq2get(struct vnode *, u_long, struct ufsmount *, int, struct dquot *); 133int dq2get(struct vnode *, u_long, struct ufsmount *, int, struct dquot *);
134int dq2sync(struct vnode *, struct dquot *); 134int dq2sync(struct vnode *, struct dquot *);

cvs diff -r1.12 -r1.13 src/sys/ufs/ufs/ufs_quota2.c (expand / switch to unified diff)

--- src/sys/ufs/ufs/ufs_quota2.c 2012/01/29 06:52:39 1.12
+++ src/sys/ufs/ufs/ufs_quota2.c 2012/01/29 06:53:36 1.13
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ufs_quota2.c,v 1.12 2012/01/29 06:52:39 dholland Exp $ */ 1/* $NetBSD: ufs_quota2.c,v 1.13 2012/01/29 06:53:36 dholland Exp $ */
2/*- 2/*-
3 * Copyright (c) 2010 Manuel Bouyer 3 * Copyright (c) 2010 Manuel Bouyer
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -16,27 +16,27 @@ @@ -16,27 +16,27 @@
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE. 25 * POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28#include <sys/cdefs.h> 28#include <sys/cdefs.h>
29__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.12 2012/01/29 06:52:39 dholland Exp $"); 29__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.13 2012/01/29 06:53:36 dholland Exp $");
30 30
31#include <sys/buf.h> 31#include <sys/buf.h>
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/kernel.h> 33#include <sys/kernel.h>
34#include <sys/systm.h> 34#include <sys/systm.h>
35#include <sys/malloc.h> 35#include <sys/malloc.h>
36#include <sys/namei.h> 36#include <sys/namei.h>
37#include <sys/file.h> 37#include <sys/file.h>
38#include <sys/proc.h> 38#include <sys/proc.h>
39#include <sys/vnode.h> 39#include <sys/vnode.h>
40#include <sys/mount.h> 40#include <sys/mount.h>
41#include <sys/fstrans.h> 41#include <sys/fstrans.h>
42#include <sys/kauth.h> 42#include <sys/kauth.h>
@@ -699,29 +699,29 @@ dq2clear_callback(struct ufsmount *ump,  @@ -699,29 +699,29 @@ dq2clear_callback(struct ufsmount *ump,
699 c->dq->dq2_blkoff = 0; 699 c->dq->dq2_blkoff = 0;
700 myoff = *offp; 700 myoff = *offp;
701 /* remove from hash list */ 701 /* remove from hash list */
702 *offp = q2e->q2e_next; 702 *offp = q2e->q2e_next;
703 /* add to free list */ 703 /* add to free list */
704 q2e->q2e_next = c->q2h->q2h_free; 704 q2e->q2e_next = c->q2h->q2h_free;
705 c->q2h->q2h_free = myoff; 705 c->q2h->q2h_free = myoff;
706 return Q2WL_ABORT; 706 return Q2WL_ABORT;
707 } 707 }
708 return 0; 708 return 0;
709} 709}
710int 710int
711quota2_handle_cmd_clear(struct ufsmount *ump, int idtype, int id, 711quota2_handle_cmd_clear(struct ufsmount *ump, int idtype, int id,
712 int defaultq) 712 int defaultq, int objtype)
713{ 713{
714 int error, i; 714 int error, i, canfree;
715 struct dquot *dq; 715 struct dquot *dq;
716 struct quota2_header *q2h; 716 struct quota2_header *q2h;
717 struct quota2_entry q2e, *q2ep; 717 struct quota2_entry q2e, *q2ep;
718 struct buf *hbp, *bp; 718 struct buf *hbp, *bp;
719 u_long hash_mask; 719 u_long hash_mask;
720 struct dq2clear_callback c; 720 struct dq2clear_callback c;
721 721
722 if (ump->um_quotas[idtype] == NULLVP) 722 if (ump->um_quotas[idtype] == NULLVP)
723 return ENODEV; 723 return ENODEV;
724 if (defaultq) 724 if (defaultq)
725 return EOPNOTSUPP; 725 return EOPNOTSUPP;
726 726
727 /* get the default entry before locking the entry's buffer */ 727 /* get the default entry before locking the entry's buffer */
@@ -745,38 +745,56 @@ quota2_handle_cmd_clear(struct ufsmount  @@ -745,38 +745,56 @@ quota2_handle_cmd_clear(struct ufsmount
745 /* already clear, nothing to do */ 745 /* already clear, nothing to do */
746 error = ENOENT; 746 error = ENOENT;
747 goto out_il; 747 goto out_il;
748 } 748 }
749 error = UFS_WAPBL_BEGIN(ump->um_mountp); 749 error = UFS_WAPBL_BEGIN(ump->um_mountp);
750 if (error) 750 if (error)
751 goto out_dq; 751 goto out_dq;
752  752
753 error = getq2e(ump, idtype, dq->dq2_lblkno, dq->dq2_blkoff, 753 error = getq2e(ump, idtype, dq->dq2_lblkno, dq->dq2_blkoff,
754 &bp, &q2ep, B_MODIFY); 754 &bp, &q2ep, B_MODIFY);
755 if (error) 755 if (error)
756 goto out_wapbl; 756 goto out_wapbl;
757 757
758 if (q2ep->q2e_val[QL_BLOCK].q2v_cur != 0 || 758 /* make sure we can index by the objtype passed in */
759 q2ep->q2e_val[QL_FILE].q2v_cur != 0) { 759 CTASSERT(QUOTA_OBJTYPE_BLOCKS == QL_BLOCK);
760 /* can't free this entry; revert to default */ 760 CTASSERT(QUOTA_OBJTYPE_FILES == QL_FILE);
761 for (i = 0; i < N_QL; i++) { 761
762 q2ep->q2e_val[i].q2v_softlimit = 762 /* clear the requested objtype by copying from the default entry */
763 q2e.q2e_val[i].q2v_softlimit; 763 q2ep->q2e_val[objtype].q2v_softlimit =
764 q2ep->q2e_val[i].q2v_hardlimit = 764 q2e.q2e_val[objtype].q2v_softlimit;
765 q2e.q2e_val[i].q2v_hardlimit; 765 q2ep->q2e_val[objtype].q2v_hardlimit =
766 q2ep->q2e_val[i].q2v_grace = 766 q2e.q2e_val[objtype].q2v_hardlimit;
767 q2e.q2e_val[i].q2v_grace; 767 q2ep->q2e_val[objtype].q2v_grace =
768 q2ep->q2e_val[i].q2v_time = 0; 768 q2e.q2e_val[objtype].q2v_grace;
 769 q2ep->q2e_val[objtype].q2v_time = 0;
 770
 771 /* if this entry now contains no information, we can free it */
 772 canfree = 1;
 773 for (i = 0; i < N_QL; i++) {
 774 if (q2ep->q2e_val[i].q2v_cur != 0 ||
 775 (q2ep->q2e_val[i].q2v_softlimit !=
 776 q2e.q2e_val[i].q2v_softlimit) ||
 777 (q2ep->q2e_val[i].q2v_hardlimit !=
 778 q2e.q2e_val[i].q2v_hardlimit) ||
 779 (q2ep->q2e_val[i].q2v_grace !=
 780 q2e.q2e_val[i].q2v_grace)) {
 781 canfree = 0;
 782 break;
769 } 783 }
 784 /* note: do not need to check q2v_time */
 785 }
 786
 787 if (canfree == 0) {
770 quota2_bwrite(ump->um_mountp, bp); 788 quota2_bwrite(ump->um_mountp, bp);
771 goto out_wapbl; 789 goto out_wapbl;
772 } 790 }
773 /* we can free it. release bp so we can walk the list */ 791 /* we can free it. release bp so we can walk the list */
774 brelse(bp, 0); 792 brelse(bp, 0);
775 mutex_enter(&dqlock); 793 mutex_enter(&dqlock);
776 error = getq2h(ump, idtype, &hbp, &q2h, 0); 794 error = getq2h(ump, idtype, &hbp, &q2h, 0);
777 if (error) 795 if (error)
778 goto out_dqlock; 796 goto out_dqlock;
779 797
780 hash_mask = ((1 << q2h->q2h_hash_shift) - 1); 798 hash_mask = ((1 << q2h->q2h_hash_shift) - 1);
781 c.dq = dq; 799 c.dq = dq;
782 c.id = id; 800 c.id = id;