Module Name:    src
Committed By:   dholland
Date:           Sun Jan 29 07:08:58 UTC 2012

Modified Files:
        src/sys/kern: vfs_quotactl.c
        src/sys/sys: quotactl.h
        src/sys/ufs/ufs: ufs_quota.c ufs_quota.h ufs_quota2.c

Log Message:
Don't pass the idtype to QUOTACTL_GETALL. Instead, iterate both users
and groups.

This change requires a kernel version bump.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/kern/vfs_quotactl.c
cvs rdiff -u -r1.24 -r1.25 src/sys/sys/quotactl.h
cvs rdiff -u -r1.96 -r1.97 src/sys/ufs/ufs/ufs_quota.c
cvs rdiff -u -r1.18 -r1.19 src/sys/ufs/ufs/ufs_quota.h
cvs rdiff -u -r1.24 -r1.25 src/sys/ufs/ufs/ufs_quota2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_quotactl.c
diff -u src/sys/kern/vfs_quotactl.c:1.27 src/sys/kern/vfs_quotactl.c:1.28
--- src/sys/kern/vfs_quotactl.c:1.27	Sun Jan 29 07:07:22 2012
+++ src/sys/kern/vfs_quotactl.c	Sun Jan 29 07:08:58 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_quotactl.c,v 1.27 2012/01/29 07:07:22 dholland Exp $	*/
+/*	$NetBSD: vfs_quotactl.c,v 1.28 2012/01/29 07:08:58 dholland Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.27 2012/01/29 07:07:22 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.28 2012/01/29 07:08:58 dholland Exp $");
 
 #include <sys/malloc.h> /* XXX: temporary */
 #include <sys/mount.h>
@@ -566,21 +566,8 @@ vfs_quotactl_getall(struct mount *mp,
 		args.u.getall.qc_vals = vals;
 		args.u.getall.qc_maxnum = loopmax;
 		args.u.getall.qc_ret = &loopnum;
-		args.u.getall.qc_idtype = q2type;	/* XXX */
 
 		error = VFS_QUOTACTL(mp, QUOTACTL_GETALL, &args);
-		/*
-		 * XXX this is bogus but up until now *all* errors
-		 * from inside quotactl_getall were suppressed by the
-		 * dispatching code in ufs_quota.c. Fixing that causes
-		 * repquota to break in an undesirable way; this is a
-		 * workaround.
-		 */
-		if (error == ENODEV || error == ENXIO) {
-			error = 0;
-			break;
-		}
-
 		if (error) {
 			goto err;
 		}
@@ -594,6 +581,11 @@ vfs_quotactl_getall(struct mount *mp,
 			key = &keys[i];
 			val = &vals[i];
 
+			if (key->qk_idtype != q2type) {
+				/* don't want this result */
+				continue;
+			}
+
 			if (thisreply == NULL || key->qk_id != lastid) {
 				lastid = key->qk_id;
 				thisreply = vfs_quotactl_getall_makereply(key);

Index: src/sys/sys/quotactl.h
diff -u src/sys/sys/quotactl.h:1.24 src/sys/sys/quotactl.h:1.25
--- src/sys/sys/quotactl.h:1.24	Sun Jan 29 07:07:22 2012
+++ src/sys/sys/quotactl.h	Sun Jan 29 07:08:58 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: quotactl.h,v 1.24 2012/01/29 07:07:22 dholland Exp $	*/
+/*	$NetBSD: quotactl.h,v 1.25 2012/01/29 07:08:58 dholland Exp $	*/
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -107,7 +107,6 @@ struct vfs_quotactl_args {
 			struct quotaval *qc_vals;
 			unsigned qc_maxnum;
 			unsigned *qc_ret;
-			int qc_idtype;
 		} getall;
 	} u;
 };

Index: src/sys/ufs/ufs/ufs_quota.c
diff -u src/sys/ufs/ufs/ufs_quota.c:1.96 src/sys/ufs/ufs/ufs_quota.c:1.97
--- src/sys/ufs/ufs/ufs_quota.c:1.96	Sun Jan 29 07:07:22 2012
+++ src/sys/ufs/ufs/ufs_quota.c	Sun Jan 29 07:08:58 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.c,v 1.96 2012/01/29 07:07:22 dholland Exp $	*/
+/*	$NetBSD: ufs_quota.c,v 1.97 2012/01/29 07:08:58 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.96 2012/01/29 07:07:22 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.97 2012/01/29 07:08:58 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -374,7 +374,6 @@ quota_handle_cmd_getall(struct mount *mp
 	struct quotaval *vals;
 	unsigned maxnum;
 	unsigned *ret;
-	int idtype;
 	int error;
 
 	KASSERT(args->qc_type == QCT_GETALL);
@@ -383,7 +382,6 @@ quota_handle_cmd_getall(struct mount *mp
 	vals = args->u.getall.qc_vals;
 	maxnum = args->u.getall.qc_maxnum;
 	ret = args->u.getall.qc_ret;
-	idtype = args->u.getall.qc_idtype;
 
 	if ((ump->um_flags & UFS_QUOTA2) == 0)
 		return EOPNOTSUPP;
@@ -395,7 +393,7 @@ quota_handle_cmd_getall(struct mount *mp
 		
 #ifdef QUOTA2
 	if (ump->um_flags & UFS_QUOTA2) {
-		error = quota2_handle_cmd_getall(ump, cursor, idtype,
+		error = quota2_handle_cmd_getall(ump, cursor,
 						 keys, vals, maxnum, ret);
 	} else
 #endif

Index: src/sys/ufs/ufs/ufs_quota.h
diff -u src/sys/ufs/ufs/ufs_quota.h:1.18 src/sys/ufs/ufs/ufs_quota.h:1.19
--- src/sys/ufs/ufs/ufs_quota.h:1.18	Sun Jan 29 07:07:22 2012
+++ src/sys/ufs/ufs/ufs_quota.h	Sun Jan 29 07:08:58 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.h,v 1.18 2012/01/29 07:07:22 dholland Exp $	*/
+/*	$NetBSD: ufs_quota.h,v 1.19 2012/01/29 07:08:58 dholland Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -131,7 +131,7 @@ int quota2_handle_cmd_get(struct ufsmoun
 int quota2_handle_cmd_put(struct ufsmount *, const struct quotakey *,
     const struct quotaval *);
 int quota2_handle_cmd_delete(struct ufsmount *, const struct quotakey *);
-int quota2_handle_cmd_getall(struct ufsmount *, struct quotakcursor *, int,
+int quota2_handle_cmd_getall(struct ufsmount *, struct quotakcursor *,
     struct quotakey *, struct quotaval *, unsigned, unsigned *);
 int quota2_handle_cmd_cursoropen(struct ufsmount *, struct quotakcursor *);
 int quota2_handle_cmd_cursorclose(struct ufsmount *, struct quotakcursor *);

Index: src/sys/ufs/ufs/ufs_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.24 src/sys/ufs/ufs/ufs_quota2.c:1.25
--- src/sys/ufs/ufs/ufs_quota2.c:1.24	Sun Jan 29 07:08:00 2012
+++ src/sys/ufs/ufs/ufs_quota2.c	Sun Jan 29 07:08:58 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.24 2012/01/29 07:08:00 dholland Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.25 2012/01/29 07:08:58 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.24 2012/01/29 07:08:00 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.25 2012/01/29 07:08:58 dholland Exp $");
 
 #include <sys/buf.h>
 #include <sys/param.h>
@@ -966,6 +966,8 @@ struct ufsq2_cursor {
 	uint32_t q2c_magic;	/* magic number */
 	int q2c_hashsize;	/* size of hash table at last go */
 
+	int q2c_users_done;	/* true if we've returned all user data */
+	int q2c_groups_done;	/* true if we've returned all group data */
 	int q2c_defaults_done;	/* true if we've returned the default values */
 	int q2c_hashpos;	/* slot to start at in hash table */
 	int q2c_uidpos;		/* number of ids we've handled */
@@ -986,6 +988,12 @@ q2cursor_check(struct ufsq2_cursor *curs
 		return EINVAL;
 	}
 
+	if (cursor->q2c_users_done != 0 && cursor->q2c_users_done != 1) {
+		return EINVAL;
+	}
+	if (cursor->q2c_groups_done != 0 && cursor->q2c_groups_done != 1) {
+		return EINVAL;
+	}
 	if (cursor->q2c_defaults_done != 0 && cursor->q2c_defaults_done != 1) {
 		return EINVAL;
 	}
@@ -1043,8 +1051,8 @@ quota2_getuids_callback(struct ufsmount 
 
 int
 quota2_handle_cmd_getall(struct ufsmount *ump, struct quotakcursor *qkc,
-    int idtype, struct quotakey *keys, struct quotaval *vals,
-    unsigned maxreturn, unsigned *ret)
+    struct quotakey *keys, struct quotaval *vals, unsigned maxreturn,
+    unsigned *ret)
 {
 	int error;
 	struct ufsq2_cursor *cursor;
@@ -1052,6 +1060,8 @@ quota2_handle_cmd_getall(struct ufsmount
 	struct quota2_entry  q2e;
 	struct buf *hbp;
 	uint64_t offset;
+	int idtype;
+	int can_switch_idtype;
 	int i, j;
 	int quota2_hash_size;
 	const int needswap = UFS_MPNEEDSWAP(ump);
@@ -1069,10 +1079,34 @@ quota2_handle_cmd_getall(struct ufsmount
 		return error;
 	}
 
-	if (ump->um_quotas[idtype] == NULLVP) {
-		return ENODEV;
+	CTASSERT(USRQUOTA == QUOTA_IDTYPE_USER);
+	CTASSERT(GRPQUOTA == QUOTA_IDTYPE_GROUP);
+
+	if (cursor->q2c_users_done == 0 &&
+	    ump->um_quotas[USRQUOTA] == NULLVP) {
+		cursor->q2c_users_done = 1;
+	}
+	if (cursor->q2c_groups_done == 0 &&
+	    ump->um_quotas[GRPQUOTA] == NULLVP) {
+		cursor->q2c_groups_done = 1;
+	}
+
+restart:
+
+	if (cursor->q2c_users_done == 0) {
+		idtype = QUOTA_IDTYPE_USER;
+		can_switch_idtype = 1;
+	} else if (cursor->q2c_groups_done == 0) {
+		idtype = QUOTA_IDTYPE_GROUP;
+		can_switch_idtype = 0;
+	} else {
+		/* nothing more to do, return 0 */
+		*ret = 0;
+		return 0;
 	}
 
+	KASSERT(ump->um_quotas[idtype] != NULLVP);
+
 	numreturn = 0;
 
 	mutex_enter(&dqlock);
@@ -1160,6 +1194,16 @@ fail:
 	if (error)
 		return error;
 
+	if (gu.nuids == 0) {
+		if (idtype == QUOTA_IDTYPE_USER)
+			cursor->q2c_users_done = 1;
+		else
+			cursor->q2c_groups_done = 1;
+		if (can_switch_idtype) {
+			goto restart;
+		}
+	}
+
 	maxnum = gu.nuids*2;
 
 	/*
@@ -1209,6 +1253,8 @@ quota2_handle_cmd_cursoropen(struct ufsm
 	cursor->q2c_magic = Q2C_MAGIC;
 	cursor->q2c_hashsize = 0;
 
+	cursor->q2c_users_done = 0;
+	cursor->q2c_groups_done = 0;
 	cursor->q2c_defaults_done = 0;
 	cursor->q2c_hashpos = 0;
 	cursor->q2c_uidpos = 0;

Reply via email to