Source-Changes-HG archive

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

[src/trunk]: src/sys Pass only one objtype and its quotaval to QUOTACTL_SET a...



details:   https://anonhg.NetBSD.org/src/rev/aba58fd65544
branches:  trunk
changeset: 773179:aba58fd65544
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sun Jan 29 06:47:38 2012 +0000

description:
Pass only one objtype and its quotaval to QUOTACTL_SET at one time.

(The backend code to handle this is a lot tidier than I expected given
that the proplib code doesn't allow setting blocks and files
independently; I was afraid there would turn out to be a reason for
that...)

Note: this change requires a kernel version bump.

diffstat:

 sys/kern/vfs_quotactl.c  |  25 +++++++++++++----
 sys/sys/quotactl.h       |   9 ++---
 sys/ufs/ufs/ufs_quota.c  |  28 ++++++++-----------
 sys/ufs/ufs/ufs_quota.h  |  10 +++---
 sys/ufs/ufs/ufs_quota1.c |  69 +++++++++++++++++++++++++++++------------------
 sys/ufs/ufs/ufs_quota2.c |  25 ++++++++---------
 6 files changed, 95 insertions(+), 71 deletions(-)

diffs (truncated from 373 to 300 lines):

diff -r 9fab141eaaf8 -r aba58fd65544 sys/kern/vfs_quotactl.c
--- a/sys/kern/vfs_quotactl.c   Sun Jan 29 06:46:49 2012 +0000
+++ b/sys/kern/vfs_quotactl.c   Sun Jan 29 06:47:38 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_quotactl.c,v 1.12 2012/01/29 06:45:25 dholland Exp $       */
+/*     $NetBSD: vfs_quotactl.c,v 1.13 2012/01/29 06:47:38 dholland Exp $       */
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.12 2012/01/29 06:45:25 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.13 2012/01/29 06:47:38 dholland Exp $");
 
 #include <sys/mount.h>
 #include <sys/quota.h>
@@ -379,6 +379,9 @@
        }
 
        while ((data = prop_object_iterator_next(iter)) != NULL) {
+
+               KASSERT(prop_object_type(data) == PROP_TYPE_DICTIONARY);
+
                if (!prop_dictionary_get_uint32(data, "id", &id)) {
                        if (!prop_dictionary_get_cstring_nocopy(data, "id",
                            &idstr))
@@ -397,12 +400,22 @@
                }
 
                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_q2type = q2type;
-               args.u.set.qc_blocks = &blocks;
-               args.u.set.qc_files = &files;
-               args.u.set.qc_data = data;
+               args.u.set.qc_objtype = QUOTA_OBJTYPE_BLOCKS;
+               args.u.set.qc_val = &blocks;
+               error = VFS_QUOTACTL(mp, QUOTACTL_SET, &args);
+               if (error) {
+                       goto err;
+               }
+
+               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_val = &files;
                error = VFS_QUOTACTL(mp, QUOTACTL_SET, &args);
                if (error) {
                        goto err;
diff -r 9fab141eaaf8 -r aba58fd65544 sys/sys/quotactl.h
--- a/sys/sys/quotactl.h        Sun Jan 29 06:46:49 2012 +0000
+++ b/sys/sys/quotactl.h        Sun Jan 29 06:47:38 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: quotactl.h,v 1.10 2012/01/29 06:45:26 dholland Exp $   */
+/*     $NetBSD: quotactl.h,v 1.11 2012/01/29 06:47:38 dholland Exp $   */
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -69,12 +69,11 @@
                        struct quotaval *qc_ret;
                } get;
                struct {
+                       int qc_idtype;
                        id_t qc_id;
                        int qc_defaultq;
-                       int qc_q2type;
-                       const struct quotaval *qc_blocks;
-                       const struct quotaval *qc_files;
-                       prop_dictionary_t qc_data;
+                       int qc_objtype;
+                       const struct quotaval *qc_val;
                } set;
        } u;
 };
diff -r 9fab141eaaf8 -r aba58fd65544 sys/ufs/ufs/ufs_quota.c
--- a/sys/ufs/ufs/ufs_quota.c   Sun Jan 29 06:46:49 2012 +0000
+++ b/sys/ufs/ufs/ufs_quota.c   Sun Jan 29 06:47:38 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_quota.c,v 1.82 2012/01/29 06:46:49 dholland Exp $  */
+/*     $NetBSD: ufs_quota.c,v 1.83 2012/01/29 06:47:38 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.82 2012/01/29 06:46:49 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.83 2012/01/29 06:47:38 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -268,23 +268,19 @@
     struct vfs_quotactl_args *args)
 {
        struct ufsmount *ump = VFSTOUFS(mp);
+       int idtype;
        id_t id;
        int defaultq;
-       int q2type;
-       const struct quotaval *blocks;
-       const struct quotaval *files;
-       prop_dictionary_t data;
+       int objtype;
+       const struct quotaval *qv;
        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;
-       q2type = args->u.set.qc_q2type;
-       blocks = args->u.set.qc_blocks;
-       files = args->u.set.qc_files;
-       data = args->u.set.qc_data;
-
-       KASSERT(prop_object_type(data) == PROP_TYPE_DICTIONARY);
+       objtype = args->u.set.qc_objtype;
+       qv = args->u.set.qc_val;
 
        if ((ump->um_flags & (UFS_QUOTA|UFS_QUOTA2)) == 0)
                return EOPNOTSUPP;
@@ -297,14 +293,14 @@
                        goto err;
 #ifdef QUOTA
                if (ump->um_flags & UFS_QUOTA)
-                       error = quota1_handle_cmd_set(ump, q2type, id, defaultq,
-                           blocks, files);
+                       error = quota1_handle_cmd_set(ump, idtype, id, defaultq,
+                           objtype, qv);
                else
 #endif
 #ifdef QUOTA2
                if (ump->um_flags & UFS_QUOTA2) {
-                       error = quota2_handle_cmd_set(ump, q2type, id, defaultq,
-                           blocks, files);
+                       error = quota2_handle_cmd_set(ump, idtype, id, defaultq,
+                           objtype, qv);
                } else
 #endif
                        panic("quota_handle_cmd_get: no support ?");
diff -r 9fab141eaaf8 -r aba58fd65544 sys/ufs/ufs/ufs_quota.h
--- a/sys/ufs/ufs/ufs_quota.h   Sun Jan 29 06:46:49 2012 +0000
+++ b/sys/ufs/ufs/ufs_quota.h   Sun Jan 29 06:47:38 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_quota.h,v 1.7 2012/01/29 06:46:50 dholland Exp $   */
+/*     $NetBSD: ufs_quota.h,v 1.8 2012/01/29 06:47:38 dholland Exp $   */
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -115,8 +115,8 @@
 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,
-    const struct quotaval *, const struct quotaval *);
+int quota1_handle_cmd_set(struct ufsmount *, int, int, int, int,
+    const struct quotaval *);
 int quota1_handle_cmd_quotaon(struct lwp *, struct ufsmount *, int,
     const char *);
 int quota1_handle_cmd_quotaoff(struct lwp *, struct ufsmount *, int);
@@ -125,8 +125,8 @@
 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,
-    const struct quotaval *, const struct quotaval *);
+int quota2_handle_cmd_set(struct ufsmount *, int, int, int, int,
+    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);
 int q2sync(struct mount *);
diff -r 9fab141eaaf8 -r aba58fd65544 sys/ufs/ufs/ufs_quota1.c
--- a/sys/ufs/ufs/ufs_quota1.c  Sun Jan 29 06:46:49 2012 +0000
+++ b/sys/ufs/ufs/ufs_quota1.c  Sun Jan 29 06:47:38 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_quota1.c,v 1.12 2012/01/29 06:46:16 dholland Exp $ */
+/*     $NetBSD: ufs_quota1.c,v 1.13 2012/01/29 06:47:38 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.12 2012/01/29 06:46:16 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota1.c,v 1.13 2012/01/29 06:47:38 dholland Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -553,35 +553,43 @@
 }
 
 int
-quota1_handle_cmd_set(struct ufsmount *ump, int type, int id,
-    int defaultq, const struct quotaval *blocks, const struct quotaval *files)
+quota1_handle_cmd_set(struct ufsmount *ump, int idtype, int id,
+    int defaultq, int objtype, const struct quotaval *val)
 {
        struct dquot *dq;
        struct dqblk dqb;
        int error;
 
-       if (ump->um_quotas[type] == NULLVP)
+       switch (objtype) {
+           case QUOTA_OBJTYPE_BLOCKS:
+           case QUOTA_OBJTYPE_FILES:
+               break;
+           default:
+               return EINVAL;
+       }
+
+       if (ump->um_quotas[idtype] == NULLVP)
                return ENODEV;
 
        if (defaultq) {
                /* just update grace times */
                KASSERT(id == 0);
-               if ((error = dqget(NULLVP, id, ump, type, &dq)) != 0)
+               if ((error = dqget(NULLVP, id, ump, idtype, &dq)) != 0)
                        return error;
                mutex_enter(&dq->dq_interlock);
-               if (blocks->qv_grace > 0)
-                       ump->umq1_btime[type] = dq->dq_btime =
-                           blocks->qv_grace;
-               if (files->qv_grace > 0)
-                       ump->umq1_itime[type] = dq->dq_itime =
-                           files->qv_grace;
+               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;
                mutex_exit(&dq->dq_interlock);
                dq->dq_flags |= DQ_MOD;
                dqrele(NULLVP, dq);
                return 0;
        }
 
-       if ((error = dqget(NULLVP, id, ump, type, &dq)) != 0)
+       if ((error = dqget(NULLVP, id, ump, idtype, &dq)) != 0)
                return (error);
        mutex_enter(&dq->dq_interlock);
        /*
@@ -593,29 +601,38 @@
        dqb.dqb_curinodes = dq->dq_curinodes;
        dqb.dqb_btime = dq->dq_btime;
        dqb.dqb_itime = dq->dq_itime;
-       dqb.dqb_bsoftlimit = quota1_encode_limit(blocks->qv_softlimit);
-       dqb.dqb_bhardlimit = quota1_encode_limit(blocks->qv_hardlimit);
-       dqb.dqb_isoftlimit = quota1_encode_limit(files->qv_softlimit);
-       dqb.dqb_ihardlimit = quota1_encode_limit(files->qv_hardlimit);
-       if (dq->dq_id == 0) {
+       switch (objtype) {
+           case QUOTA_OBJTYPE_BLOCKS:
+               dqb.dqb_bsoftlimit = quota1_encode_limit(val->qv_softlimit);
+               dqb.dqb_bhardlimit = quota1_encode_limit(val->qv_hardlimit);
+               dqb.dqb_isoftlimit = dq->dq_isoftlimit;
+               dqb.dqb_ihardlimit = dq->dq_ihardlimit;
+               break;
+           case QUOTA_OBJTYPE_FILES:
+               dqb.dqb_bsoftlimit = dq->dq_bsoftlimit;
+               dqb.dqb_bhardlimit = dq->dq_bhardlimit;
+               dqb.dqb_isoftlimit = quota1_encode_limit(val->qv_softlimit);
+               dqb.dqb_ihardlimit = quota1_encode_limit(val->qv_hardlimit);
+               break;
+       }
+       if (dq->dq_id == 0 && val->qv_grace != QUOTA_NOTIME) {
                /* also update grace time if available */
-               if (blocks->qv_grace != QUOTA_NOTIME) {
-                       ump->umq1_btime[type] = dqb.dqb_btime =
-                               blocks->qv_grace;
+               if (objtype == QUOTA_OBJTYPE_BLOCKS) {
+                       ump->umq1_btime[idtype] = dqb.dqb_btime = val->qv_grace;
+                               
                }
-               if (files->qv_grace != QUOTA_NOTIME) {
-                       ump->umq1_itime[type] = dqb.dqb_itime =
-                               files->qv_grace;
+               if (objtype == QUOTA_OBJTYPE_FILES) {
+                       ump->umq1_itime[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[type];
+               dqb.dqb_btime = time_second + ump->umq1_btime[idtype];
        if (dqb.dqb_isoftlimit &&
            dq->dq_curinodes >= dqb.dqb_isoftlimit &&
            (dq->dq_isoftlimit == 0 || dq->dq_curinodes < dq->dq_isoftlimit))
-               dqb.dqb_itime = time_second + ump->umq1_itime[type];
+               dqb.dqb_itime = time_second + ump->umq1_itime[idtype];



Home | Main Index | Thread Index | Old Index