Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Don't pass the idtype to QUOTACTL_GETALL. Instead, itera...



details:   https://anonhg.NetBSD.org/src/rev/1d0d2dbce8e6
branches:  trunk
changeset: 773199:1d0d2dbce8e6
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sun Jan 29 07:08:58 2012 +0000

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

This change requires a kernel version bump.

diffstat:

 sys/kern/vfs_quotactl.c  |  22 +++++------------
 sys/sys/quotactl.h       |   3 +-
 sys/ufs/ufs/ufs_quota.c  |   8 ++----
 sys/ufs/ufs/ufs_quota.h  |   4 +-
 sys/ufs/ufs/ufs_quota2.c |  58 +++++++++++++++++++++++++++++++++++++++++++----
 5 files changed, 65 insertions(+), 30 deletions(-)

diffs (253 lines):

diff -r df43d5d75ae2 -r 1d0d2dbce8e6 sys/kern/vfs_quotactl.c
--- a/sys/kern/vfs_quotactl.c   Sun Jan 29 07:08:00 2012 +0000
+++ b/sys/kern/vfs_quotactl.c   Sun Jan 29 07:08:58 2012 +0000
@@ -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 @@
                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 @@
                        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);
diff -r df43d5d75ae2 -r 1d0d2dbce8e6 sys/sys/quotactl.h
--- a/sys/sys/quotactl.h        Sun Jan 29 07:08:00 2012 +0000
+++ b/sys/sys/quotactl.h        Sun Jan 29 07:08:58 2012 +0000
@@ -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 quotaval *qc_vals;
                        unsigned qc_maxnum;
                        unsigned *qc_ret;
-                       int qc_idtype;
                } getall;
        } u;
 };
diff -r df43d5d75ae2 -r 1d0d2dbce8e6 sys/ufs/ufs/ufs_quota.c
--- a/sys/ufs/ufs/ufs_quota.c   Sun Jan 29 07:08:00 2012 +0000
+++ b/sys/ufs/ufs/ufs_quota.c   Sun Jan 29 07:08:58 2012 +0000
@@ -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 @@
        struct quotaval *vals;
        unsigned maxnum;
        unsigned *ret;
-       int idtype;
        int error;
 
        KASSERT(args->qc_type == QCT_GETALL);
@@ -383,7 +382,6 @@
        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 @@
                
 #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
diff -r df43d5d75ae2 -r 1d0d2dbce8e6 sys/ufs/ufs/ufs_quota.h
--- a/sys/ufs/ufs/ufs_quota.h   Sun Jan 29 07:08:00 2012 +0000
+++ b/sys/ufs/ufs/ufs_quota.h   Sun Jan 29 07:08:58 2012 +0000
@@ -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_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 *);
diff -r df43d5d75ae2 -r 1d0d2dbce8e6 sys/ufs/ufs/ufs_quota2.c
--- a/sys/ufs/ufs/ufs_quota2.c  Sun Jan 29 07:08:00 2012 +0000
+++ b/sys/ufs/ufs/ufs_quota2.c  Sun Jan 29 07:08:58 2012 +0000
@@ -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 @@
        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 @@
                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 @@
 
 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 @@
        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 @@
                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 @@
        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 @@
        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;



Home | Main Index | Thread Index | Old Index