Sun Jan 29 07:06:02 2012 UTC ()
Stop treating the default values specially in QUOTACTL_GETALL.

Note: this change requires a kernel version bump.


(dholland)
diff -r1.24 -r1.25 src/sys/kern/vfs_quotactl.c
diff -r1.22 -r1.23 src/sys/sys/quotactl.h
diff -r1.21 -r1.22 src/sys/ufs/ufs/ufs_quota2.c

cvs diff -r1.24 -r1.25 src/sys/kern/vfs_quotactl.c (expand / switch to context diff)
--- src/sys/kern/vfs_quotactl.c 2012/01/29 07:05:12 1.24
+++ src/sys/kern/vfs_quotactl.c 2012/01/29 07:06:01 1.25
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_quotactl.c,v 1.24 2012/01/29 07:05:12 dholland Exp $	*/
+/*	$NetBSD: vfs_quotactl.c,v 1.25 2012/01/29 07:06:01 dholland Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.24 2012/01/29 07:05:12 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.25 2012/01/29 07:06:01 dholland Exp $");
 
 #include <sys/malloc.h> /* XXX: temporary */
 #include <sys/mount.h>
@@ -512,6 +512,8 @@
 	prop_array_t replies;
 	prop_dictionary_t dict;
 	unsigned i;
+	id_t id;
+	int defaultq;
 	int error, error2;
 	int skip = 0;
 
@@ -559,15 +561,15 @@
 		goto skip;
 	}
 
-	dict = vfs_quotactl_getall_makereply(0, 1, &result.qr_defblocks,
-					     &result.qr_deffiles);
-	if (!prop_array_add_and_rel(replies, dict)) {
-		error = ENOMEM;
-		goto err;
-	}
-
 	for (i = 0; i < result.qr_num; i += 2) {
-		dict = vfs_quotactl_getall_makereply(result.qr_keys[i].qk_id,0,
+		id = result.qr_keys[i].qk_id;
+		if (id == QUOTA_DEFAULTID) {
+			id = 0;
+			defaultq = 1;
+		} else {
+			defaultq = 0;
+		}
+		dict = vfs_quotactl_getall_makereply(id, defaultq,
 						     &result.qr_vals[i],
 						     &result.qr_vals[i+1]);
 		if (dict == NULL) {

cvs diff -r1.22 -r1.23 src/sys/sys/quotactl.h (expand / switch to context diff)
--- src/sys/sys/quotactl.h 2012/01/29 07:05:12 1.22
+++ src/sys/sys/quotactl.h 2012/01/29 07:06:01 1.23
@@ -1,4 +1,4 @@
-/*	$NetBSD: quotactl.h,v 1.22 2012/01/29 07:05:12 dholland Exp $	*/
+/*	$NetBSD: quotactl.h,v 1.23 2012/01/29 07:06:01 dholland Exp $	*/
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -107,8 +107,6 @@
 			struct quotakcursor *qc_cursor;
 			int qc_idtype;
 			struct quota_getall_result {
-				struct quotaval qr_defblocks;
-				struct quotaval qr_deffiles;
 				struct quotakey *qr_keys;
 				struct quotaval *qr_vals;
 				unsigned qr_num;

cvs diff -r1.21 -r1.22 src/sys/ufs/ufs/ufs_quota2.c (expand / switch to context diff)
--- src/sys/ufs/ufs/ufs_quota2.c 2012/01/29 07:05:12 1.21
+++ src/sys/ufs/ufs/ufs_quota2.c 2012/01/29 07:06:02 1.22
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.21 2012/01/29 07:05:12 dholland Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.22 2012/01/29 07:06:02 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.21 2012/01/29 07:05:12 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.22 2012/01/29 07:06:02 dholland Exp $");
 
 #include <sys/buf.h>
 #include <sys/param.h>
@@ -1055,9 +1055,12 @@
 	const int needswap = UFS_MPNEEDSWAP(ump);
 	struct getuids gu;
 	id_t junkid;
-	struct quotaval qv;
+	struct quotakey bkey, fkey;
+	struct quotaval bval, fval;
+	int dobval = 0, dofval = 0;
 	unsigned num, maxnum;
 	int skipfirst, skiplast;
+	int maxreturn, numreturn;
 
 	cursor = Q2CURSOR(qkc);
 	error = q2cursor_check(cursor);
@@ -1069,6 +1072,9 @@
 		return ENODEV;
 	}
 
+	maxreturn = result->qr_max;
+	numreturn = 0;
+
 	mutex_enter(&dqlock);
 	error = getq2h(ump, idtype, &hbp, &q2h, 0);
 	if (error) {
@@ -1079,13 +1085,19 @@
 	if (cursor->q2c_defaults_done == 0) {
 		quota2_ufs_rwq2e(&q2h->q2h_defentry, &q2e, needswap);
 		if (cursor->q2c_blocks_done == 0) {
-			q2e_to_quotaval(&q2e, 1, &junkid, QL_BLOCK, &qv);
-			result->qr_defblocks = qv;
+			q2e_to_quotaval(&q2e, 1, &junkid, QL_BLOCK, &bval);
+			bkey.qk_idtype = idtype;
+			bkey.qk_id = QUOTA_DEFAULTID;
+			bkey.qk_objtype = QUOTA_OBJTYPE_BLOCKS;
+			dobval = 1;
 			cursor->q2c_blocks_done = 1;
 		}
 		if (cursor->q2c_blocks_done == 1) {
-			q2e_to_quotaval(&q2e, 1, &junkid, QL_FILE, &qv);
-			result->qr_deffiles = qv;
+			q2e_to_quotaval(&q2e, 1, &junkid, QL_FILE, &fval);
+			fkey.qk_idtype = idtype;
+			fkey.qk_id = QUOTA_DEFAULTID;
+			fkey.qk_objtype = QUOTA_OBJTYPE_FILES;
+			dofval = 1;
 			cursor->q2c_blocks_done = 0;
 			cursor->q2c_defaults_done = 1;
 		}
@@ -1110,10 +1122,14 @@
 
 	gu.skip = cursor->q2c_uidpos;
 	gu.seen = 0;
-	gu.limit = result->qr_max / 2;
-	if (gu.limit == 0 && result->qr_max > 0) {
+	gu.limit = (maxreturn - numreturn) / 2;
+	if (gu.limit == 0 && (maxreturn - numreturn) > 0) {
 		gu.limit = 1;
 	}
+	if (dobval && gu.limit > 0)
+		gu.limit--;
+	if (dofval && gu.limit > 0)
+		gu.limit--;
 	for (i = cursor->q2c_hashpos; i < quota2_hash_size ; i++) {
 		offset = q2h->q2h_entries[i];
 		gu.seen = 0;
@@ -1140,11 +1156,29 @@
 		return error;
 
 	maxnum = gu.nuids*2;
+	if (dobval)
+		maxnum++;
+	if (dofval)
+		maxnum++;
 	result->qr_keys = malloc(maxnum * sizeof(result->qr_keys[0]),
 				 M_TEMP, M_WAITOK);
 	result->qr_vals = malloc(maxnum * sizeof(result->qr_vals[0]),
 				 M_TEMP, M_WAITOK);
 
+	if (dobval && numreturn < maxreturn) {
+		result->qr_keys[numreturn] = bkey;
+		result->qr_vals[numreturn] = bval;
+		numreturn++;
+	}
+	if (dofval && numreturn < maxreturn) {
+		result->qr_keys[numreturn] = fkey;
+		result->qr_vals[numreturn] = fval;
+		numreturn++;
+	}
+	if (numreturn == maxreturn) {
+		return 0;
+	}
+
 	/*
 	 * If we've already sent back the blocks value for the first id,
 	 * don't send it again (skipfirst).
@@ -1158,16 +1192,21 @@
 	num = 0;
 	for (j = 0; j < gu.nuids; j++) {
 		error = quota2_result_add_q2e(ump, idtype,
-		    gu.uids[j], result, j*2,
+		    gu.uids[j], result, numreturn + j*2,
 		    j == 0 && skipfirst,
 		    j + 1 == gu.nuids && skiplast);
 		if (error == ENOENT)
 			continue;
 		if (error)
 			break;
-		num += 2;
+		if ((j == 0 && skipfirst) || (j + 1 == gu.nuids && skiplast)) {
+			num += 1;
+		} else {
+			num += 2;
+		}
 	}
-	result->qr_num = num;
+	numreturn += num;
+	result->qr_num = numreturn;
 
 	cursor->q2c_blocks_done = skiplast;