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 context 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,4 +1,4 @@
-/*	$NetBSD: vfs_quotactl.c,v 1.17 2012/01/29 06:52:38 dholland Exp $	*/
+/*	$NetBSD: vfs_quotactl.c,v 1.18 2012/01/29 06:53:35 dholland Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.17 2012/01/29 06:52:38 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.18 2012/01/29 06:53:35 dholland Exp $");
 
 #include <sys/mount.h>
 #include <sys/quota.h>
@@ -495,6 +495,17 @@
 		args.u.clear.qc_idtype = q2type;
 		args.u.clear.qc_id = id;
 		args.u.clear.qc_defaultq = defaultq;
+		args.u.clear.qc_objtype = QUOTA_OBJTYPE_BLOCKS;
+		error = VFS_QUOTACTL(mp, QUOTACTL_CLEAR, &args);
+		if (error) {
+			goto err;
+		}
+
+		args.qc_type = QCT_CLEAR;
+		args.u.clear.qc_idtype = q2type;
+		args.u.clear.qc_id = id;
+		args.u.clear.qc_defaultq = defaultq;
+		args.u.clear.qc_objtype = QUOTA_OBJTYPE_FILES;
 		error = VFS_QUOTACTL(mp, QUOTACTL_CLEAR, &args);
 		if (error) {
 			goto err;

cvs diff -r1.15 -r1.16 src/sys/sys/quotactl.h (expand / switch to context 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,4 +1,4 @@
-/*	$NetBSD: quotactl.h,v 1.15 2012/01/29 06:52:39 dholland Exp $	*/
+/*	$NetBSD: quotactl.h,v 1.16 2012/01/29 06:53:35 dholland Exp $	*/
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -77,6 +77,7 @@
 			int qc_idtype;
 			id_t qc_id;
 			int qc_defaultq;
+			int qc_objtype;
 		} clear;
 	} u;
 };

cvs diff -r1.89 -r1.90 src/sys/ufs/ufs/ufs_quota.c (expand / switch to context 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,4 +1,4 @@
-/*	$NetBSD: ufs_quota.c,v 1.89 2012/01/29 06:52:39 dholland Exp $	*/
+/*	$NetBSD: ufs_quota.c,v 1.90 2012/01/29 06:53:35 dholland Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.89 2012/01/29 06:52:39 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.90 2012/01/29 06:53:35 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -319,12 +319,14 @@
 	int idtype;
 	id_t id;
 	int defaultq;
+	int objtype;
 	int error;
 
 	KASSERT(args->qc_type == QCT_CLEAR);
 	idtype = args->u.clear.qc_idtype;
 	id = args->u.clear.qc_id;
 	defaultq = args->u.clear.qc_defaultq;
+	objtype = args->u.clear.qc_objtype;
 
 	if ((ump->um_flags & UFS_QUOTA2) == 0)
 		return EOPNOTSUPP;
@@ -338,7 +340,7 @@
 #ifdef QUOTA2
 		if (ump->um_flags & UFS_QUOTA2) {
 			error = quota2_handle_cmd_clear(ump, idtype, id,
-			    defaultq);
+			    defaultq, objtype);
 		} else
 #endif
 			panic("quota_handle_cmd_get: no support ?");

cvs diff -r1.11 -r1.12 src/sys/ufs/ufs/ufs_quota.h (expand / switch to context 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,4 +1,4 @@
-/*	$NetBSD: ufs_quota.h,v 1.11 2012/01/29 06:52:39 dholland Exp $	*/
+/*	$NetBSD: ufs_quota.h,v 1.12 2012/01/29 06:53:35 dholland Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -127,7 +127,7 @@
     struct quotaval *);
 int quota2_handle_cmd_put(struct ufsmount *, const struct quotakey *,
     const struct quotaval *);
-int quota2_handle_cmd_clear(struct ufsmount *, int, int, int);
+int quota2_handle_cmd_clear(struct ufsmount *, int, int, int, int);
 int quota2_handle_cmd_getall(struct ufsmount *, int, prop_array_t);
 int q2sync(struct mount *);
 int dq2get(struct vnode *, u_long, struct ufsmount *, int, struct dquot *);

cvs diff -r1.12 -r1.13 src/sys/ufs/ufs/ufs_quota2.c (expand / switch to context 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,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.12 2012/01/29 06:52:39 dholland Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.13 2012/01/29 06:53:36 dholland Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -26,7 +26,7 @@
   */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.12 2012/01/29 06:52:39 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.13 2012/01/29 06:53:36 dholland Exp $");
 
 #include <sys/buf.h>
 #include <sys/param.h>
@@ -709,9 +709,9 @@
 }
 int
 quota2_handle_cmd_clear(struct ufsmount *ump, int idtype, int id,
-    int defaultq)
+    int defaultq, int objtype)
 {
-	int error, i;
+	int error, i, canfree;
 	struct dquot *dq;
 	struct quota2_header *q2h;
 	struct quota2_entry q2e, *q2ep;
@@ -755,18 +755,36 @@
 	if (error)
 		goto out_wapbl;
 
-	if (q2ep->q2e_val[QL_BLOCK].q2v_cur != 0 ||
-	    q2ep->q2e_val[QL_FILE].q2v_cur != 0) {
-		/* can't free this entry; revert to default */
-		for (i = 0; i < N_QL; i++) {
-			q2ep->q2e_val[i].q2v_softlimit =
-			    q2e.q2e_val[i].q2v_softlimit;
-			q2ep->q2e_val[i].q2v_hardlimit =
-			    q2e.q2e_val[i].q2v_hardlimit;
-			q2ep->q2e_val[i].q2v_grace =
-			    q2e.q2e_val[i].q2v_grace;
-			q2ep->q2e_val[i].q2v_time = 0;
+	/* make sure we can index by the objtype passed in */
+	CTASSERT(QUOTA_OBJTYPE_BLOCKS == QL_BLOCK);
+	CTASSERT(QUOTA_OBJTYPE_FILES == QL_FILE);
+
+	/* clear the requested objtype by copying from the default entry */
+	q2ep->q2e_val[objtype].q2v_softlimit =
+		q2e.q2e_val[objtype].q2v_softlimit;
+	q2ep->q2e_val[objtype].q2v_hardlimit =
+		q2e.q2e_val[objtype].q2v_hardlimit;
+	q2ep->q2e_val[objtype].q2v_grace =
+		q2e.q2e_val[objtype].q2v_grace;
+	q2ep->q2e_val[objtype].q2v_time = 0;
+
+	/* if this entry now contains no information, we can free it */
+	canfree = 1;
+	for (i = 0; i < N_QL; i++) {
+		if (q2ep->q2e_val[i].q2v_cur != 0 ||
+		    (q2ep->q2e_val[i].q2v_softlimit != 
+		     q2e.q2e_val[i].q2v_softlimit) ||
+		    (q2ep->q2e_val[i].q2v_hardlimit != 
+		     q2e.q2e_val[i].q2v_hardlimit) ||
+		    (q2ep->q2e_val[i].q2v_grace != 
+		     q2e.q2e_val[i].q2v_grace)) {
+			canfree = 0;
+			break;
 		}
+		/* note: do not need to check q2v_time */
+	}
+
+	if (canfree == 0) {
 		quota2_bwrite(ump->um_mountp, bp);
 		goto out_wapbl;
 	}