Source-Changes-HG archive

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

[src/trunk]: src/sys Combine the miscellaneous QUOTACTL_SET args into a struc...



details:   https://anonhg.NetBSD.org/src/rev/5540f8ad9009
branches:  trunk
changeset: 773180:5540f8ad9009
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sun Jan 29 06:48:50 2012 +0000

description:
Combine the miscellaneous QUOTACTL_SET args into a struct quotakey.

Note: this change requires a kernel version bump.

diffstat:

 sys/kern/vfs_quotactl.c  |  23 ++++++++++-------
 sys/sys/quotactl.h       |   7 +---
 sys/ufs/ufs/ufs_quota.c  |  29 ++++++++++-----------
 sys/ufs/ufs/ufs_quota.h  |   6 ++--
 sys/ufs/ufs/ufs_quota1.c |  62 ++++++++++++++++++++++++++++-------------------
 sys/ufs/ufs/ufs_quota2.c |  31 +++++++++++++----------
 6 files changed, 87 insertions(+), 71 deletions(-)

diffs (truncated from 395 to 300 lines):

diff -r aba58fd65544 -r 5540f8ad9009 sys/kern/vfs_quotactl.c
--- a/sys/kern/vfs_quotactl.c   Sun Jan 29 06:47:38 2012 +0000
+++ b/sys/kern/vfs_quotactl.c   Sun Jan 29 06:48:50 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_quotactl.c,v 1.13 2012/01/29 06:47:38 dholland Exp $       */
+/*     $NetBSD: vfs_quotactl.c,v 1.14 2012/01/29 06:48:50 dholland Exp $       */
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.13 2012/01/29 06:47:38 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.14 2012/01/29 06:48:50 dholland Exp $");
 
 #include <sys/mount.h>
 #include <sys/quota.h>
@@ -361,6 +361,7 @@
        int defaultq;
        uint32_t id;
        const char *idstr;
+       struct quotakey qk;
        struct quotaval blocks, files;
        struct vfs_quotactl_args args;
        int error;
@@ -399,22 +400,24 @@
                        goto err;
                }
 
+               qk.qk_idtype = q2type;
+               qk.qk_id = defaultq ? QUOTA_DEFAULTID : id;
+               qk.qk_objtype = QUOTA_OBJTYPE_BLOCKS;
+
                args.qc_type = QCT_SET;
-               args.u.set.qc_idtype = q2type;
-               args.u.set.qc_id = id;
-               args.u.set.qc_defaultq = defaultq;
-               args.u.set.qc_objtype = QUOTA_OBJTYPE_BLOCKS;
+               args.u.set.qc_key = &qk;
                args.u.set.qc_val = &blocks;
                error = VFS_QUOTACTL(mp, QUOTACTL_SET, &args);
                if (error) {
                        goto err;
                }
 
+               qk.qk_idtype = q2type;
+               qk.qk_id = defaultq ? QUOTA_DEFAULTID : id;
+               qk.qk_objtype = QUOTA_OBJTYPE_FILES;
+
                args.qc_type = QCT_SET;
-               args.u.set.qc_idtype = q2type;
-               args.u.set.qc_id = id;
-               args.u.set.qc_defaultq = defaultq;
-               args.u.set.qc_objtype = QUOTA_OBJTYPE_FILES;
+               args.u.set.qc_key = &qk;
                args.u.set.qc_val = &files;
                error = VFS_QUOTACTL(mp, QUOTACTL_SET, &args);
                if (error) {
diff -r aba58fd65544 -r 5540f8ad9009 sys/sys/quotactl.h
--- a/sys/sys/quotactl.h        Sun Jan 29 06:47:38 2012 +0000
+++ b/sys/sys/quotactl.h        Sun Jan 29 06:48:50 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: quotactl.h,v 1.11 2012/01/29 06:47:38 dholland Exp $   */
+/*     $NetBSD: quotactl.h,v 1.12 2012/01/29 06:48:50 dholland Exp $   */
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -69,10 +69,7 @@
                        struct quotaval *qc_ret;
                } get;
                struct {
-                       int qc_idtype;
-                       id_t qc_id;
-                       int qc_defaultq;
-                       int qc_objtype;
+                       const struct quotakey *qc_key;
                        const struct quotaval *qc_val;
                } set;
        } u;
diff -r aba58fd65544 -r 5540f8ad9009 sys/ufs/ufs/ufs_quota.c
--- a/sys/ufs/ufs/ufs_quota.c   Sun Jan 29 06:47:38 2012 +0000
+++ b/sys/ufs/ufs/ufs_quota.c   Sun Jan 29 06:48:50 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_quota.c,v 1.83 2012/01/29 06:47:38 dholland Exp $  */
+/*     $NetBSD: ufs_quota.c,v 1.84 2012/01/29 06:48:50 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.83 2012/01/29 06:47:38 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.84 2012/01/29 06:48:50 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -268,39 +268,38 @@
     struct vfs_quotactl_args *args)
 {
        struct ufsmount *ump = VFSTOUFS(mp);
-       int idtype;
-       id_t id;
-       int defaultq;
-       int objtype;
+       const struct quotakey *qk;
        const struct quotaval *qv;
+       id_t kauth_id;
        int error;
 
        KASSERT(args->qc_type == QCT_SET);
-       idtype = args->u.set.qc_idtype;
-       id = args->u.set.qc_id;
-       defaultq = args->u.set.qc_defaultq;
-       objtype = args->u.set.qc_objtype;
+       qk = args->u.set.qc_key;
        qv = args->u.set.qc_val;
 
        if ((ump->um_flags & (UFS_QUOTA|UFS_QUOTA2)) == 0)
                return EOPNOTSUPP;
 
+       kauth_id = qk->qk_id;
+       if (kauth_id == QUOTA_DEFAULTID) {
+               kauth_id = 0;
+       }
+
        /* avoid whitespace changes */
        {
                error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
-                   KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(id), NULL);
+                   KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(kauth_id),
+                   NULL);
                if (error != 0)
                        goto err;
 #ifdef QUOTA
                if (ump->um_flags & UFS_QUOTA)
-                       error = quota1_handle_cmd_set(ump, idtype, id, defaultq,
-                           objtype, qv);
+                       error = quota1_handle_cmd_set(ump, qk, qv);
                else
 #endif
 #ifdef QUOTA2
                if (ump->um_flags & UFS_QUOTA2) {
-                       error = quota2_handle_cmd_set(ump, idtype, id, defaultq,
-                           objtype, qv);
+                       error = quota2_handle_cmd_set(ump, qk, qv);
                } else
 #endif
                        panic("quota_handle_cmd_get: no support ?");
diff -r aba58fd65544 -r 5540f8ad9009 sys/ufs/ufs/ufs_quota.h
--- a/sys/ufs/ufs/ufs_quota.h   Sun Jan 29 06:47:38 2012 +0000
+++ b/sys/ufs/ufs/ufs_quota.h   Sun Jan 29 06:48:50 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_quota.h,v 1.8 2012/01/29 06:47:38 dholland Exp $   */
+/*     $NetBSD: ufs_quota.h,v 1.9 2012/01/29 06:48:50 dholland Exp $   */
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -115,7 +115,7 @@
 int dq1sync(struct vnode *, struct dquot *);
 int quota1_handle_cmd_get(struct ufsmount *, const struct quotakey *,
     struct quotaval *);
-int quota1_handle_cmd_set(struct ufsmount *, int, int, int, int,
+int quota1_handle_cmd_set(struct ufsmount *, const struct quotakey *,
     const struct quotaval *);
 int quota1_handle_cmd_quotaon(struct lwp *, struct ufsmount *, int,
     const char *);
@@ -125,7 +125,7 @@
 int chkiq2(struct inode *, int32_t, kauth_cred_t, int);
 int quota2_handle_cmd_get(struct ufsmount *, const struct quotakey *,
     struct quotaval *);
-int quota2_handle_cmd_set(struct ufsmount *, int, int, int, int,
+int quota2_handle_cmd_set(struct ufsmount *, const struct quotakey *,
     const struct quotaval *);
 int quota2_handle_cmd_clear(struct ufsmount *, int, int, int, prop_dictionary_t);
 int quota2_handle_cmd_getall(struct ufsmount *, int, prop_array_t);
diff -r aba58fd65544 -r 5540f8ad9009 sys/ufs/ufs/ufs_quota1.c
--- a/sys/ufs/ufs/ufs_quota1.c  Sun Jan 29 06:47:38 2012 +0000
+++ b/sys/ufs/ufs/ufs_quota1.c  Sun Jan 29 06:48:50 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_quota1.c,v 1.13 2012/01/29 06:47:38 dholland Exp $ */
+/*     $NetBSD: ufs_quota1.c,v 1.14 2012/01/29 06:48:51 dholland Exp $ */
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota1.c,v 1.13 2012/01/29 06:47:38 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota1.c,v 1.14 2012/01/29 06:48:51 dholland Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -553,14 +553,22 @@
 }
 
 int
-quota1_handle_cmd_set(struct ufsmount *ump, int idtype, int id,
-    int defaultq, int objtype, const struct quotaval *val)
+quota1_handle_cmd_set(struct ufsmount *ump, const struct quotakey *key,
+    const struct quotaval *val)
 {
        struct dquot *dq;
        struct dqblk dqb;
        int error;
 
-       switch (objtype) {
+       switch (key->qk_idtype) {
+           case QUOTA_IDTYPE_USER:
+           case QUOTA_IDTYPE_GROUP:
+               break;
+           default:
+               return EINVAL;
+       }
+
+       switch (key->qk_objtype) {
            case QUOTA_OBJTYPE_BLOCKS:
            case QUOTA_OBJTYPE_FILES:
                break;
@@ -568,28 +576,31 @@
                return EINVAL;
        }
 
-       if (ump->um_quotas[idtype] == NULLVP)
+       if (ump->um_quotas[key->qk_idtype] == NULLVP)
                return ENODEV;
 
-       if (defaultq) {
+       if (key->qk_id == QUOTA_DEFAULTID) {
                /* just update grace times */
-               KASSERT(id == 0);
-               if ((error = dqget(NULLVP, id, ump, idtype, &dq)) != 0)
+               id_t id = 0;
+
+               if ((error = dqget(NULLVP, id, ump, key->qk_idtype, &dq)) != 0)
                        return error;
                mutex_enter(&dq->dq_interlock);
-               if (objtype == QUOTA_OBJTYPE_BLOCKS && val->qv_grace > 0)
-                       ump->umq1_btime[idtype] = dq->dq_btime =
-                           val->qv_grace;
-               if (objtype == QUOTA_OBJTYPE_FILES && val->qv_grace > 0)
-                       ump->umq1_itime[idtype] = dq->dq_itime =
-                           val->qv_grace;
+               if (val->qv_grace != QUOTA_NOTIME) {
+                       if (key->qk_objtype == QUOTA_OBJTYPE_BLOCKS)
+                               ump->umq1_btime[key->qk_idtype] = dq->dq_btime =
+                                       val->qv_grace;
+                       if (key->qk_objtype == QUOTA_OBJTYPE_FILES)
+                               ump->umq1_itime[key->qk_idtype] = dq->dq_itime =
+                                       val->qv_grace;
+               }
+               dq->dq_flags |= DQ_MOD;
                mutex_exit(&dq->dq_interlock);
-               dq->dq_flags |= DQ_MOD;
                dqrele(NULLVP, dq);
                return 0;
        }
 
-       if ((error = dqget(NULLVP, id, ump, idtype, &dq)) != 0)
+       if ((error = dqget(NULLVP, key->qk_id, ump, key->qk_idtype, &dq)) != 0)
                return (error);
        mutex_enter(&dq->dq_interlock);
        /*
@@ -601,7 +612,7 @@
        dqb.dqb_curinodes = dq->dq_curinodes;
        dqb.dqb_btime = dq->dq_btime;
        dqb.dqb_itime = dq->dq_itime;
-       switch (objtype) {
+       switch (key->qk_objtype) {
            case QUOTA_OBJTYPE_BLOCKS:
                dqb.dqb_bsoftlimit = quota1_encode_limit(val->qv_softlimit);
                dqb.dqb_bhardlimit = quota1_encode_limit(val->qv_hardlimit);
@@ -617,22 +628,23 @@
        }
        if (dq->dq_id == 0 && val->qv_grace != QUOTA_NOTIME) {
                /* also update grace time if available */
-               if (objtype == QUOTA_OBJTYPE_BLOCKS) {
-                       ump->umq1_btime[idtype] = dqb.dqb_btime = val->qv_grace;
-                               
+               if (key->qk_objtype == QUOTA_OBJTYPE_BLOCKS) {
+                       ump->umq1_btime[key->qk_idtype] = dqb.dqb_btime =
+                               val->qv_grace;
                }
-               if (objtype == QUOTA_OBJTYPE_FILES) {
-                       ump->umq1_itime[idtype] = dqb.dqb_itime = val->qv_grace;
+               if (key->qk_objtype == QUOTA_OBJTYPE_FILES) {
+                       ump->umq1_itime[key->qk_idtype] = dqb.dqb_itime =
+                               val->qv_grace;
                }
        }
        if (dqb.dqb_bsoftlimit &&
            dq->dq_curblocks >= dqb.dqb_bsoftlimit &&
            (dq->dq_bsoftlimit == 0 || dq->dq_curblocks < dq->dq_bsoftlimit))
-               dqb.dqb_btime = time_second + ump->umq1_btime[idtype];
+               dqb.dqb_btime = time_second + ump->umq1_btime[key->qk_idtype];
        if (dqb.dqb_isoftlimit &&
            dq->dq_curinodes >= dqb.dqb_isoftlimit &&
            (dq->dq_isoftlimit == 0 || dq->dq_curinodes < dq->dq_isoftlimit))



Home | Main Index | Thread Index | Old Index