Source-Changes-HG archive

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

[src/trunk]: src/sys Improve the quota2 QUOTACTL_CLEAR code to allow clearing...



details:   https://anonhg.NetBSD.org/src/rev/c829253d3d6d
branches:  trunk
changeset: 773186:c829253d3d6d
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sun Jan 29 06:53:35 2012 +0000

description:
Improve the quota2 QUOTACTL_CLEAR code to allow clearing blocks and
files independently.

Note: this change requires a kernel version bump.

diffstat:

 sys/kern/vfs_quotactl.c  |  15 +++++++++++++--
 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 |  48 +++++++++++++++++++++++++++++++++---------------
 5 files changed, 55 insertions(+), 23 deletions(-)

diffs (191 lines):

diff -r 0635ae8fb846 -r c829253d3d6d sys/kern/vfs_quotactl.c
--- a/sys/kern/vfs_quotactl.c   Sun Jan 29 06:52:38 2012 +0000
+++ b/sys/kern/vfs_quotactl.c   Sun Jan 29 06:53:35 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_quotactl.c,v 1.17 2012/01/29 06:52:38 dholland Exp $       */
+/*     $NetBSD: vfs_quotactl.c,v 1.18 2012/01/29 06:53:35 dholland Exp $       */
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.17 2012/01/29 06:52:38 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.18 2012/01/29 06:53:35 dholland Exp $");
 
 #include <sys/mount.h>
 #include <sys/quota.h>
@@ -495,6 +495,17 @@
                args.u.clear.qc_idtype = q2type;
                args.u.clear.qc_id = id;
                args.u.clear.qc_defaultq = defaultq;
+               args.u.clear.qc_objtype = QUOTA_OBJTYPE_BLOCKS;
+               error = VFS_QUOTACTL(mp, QUOTACTL_CLEAR, &args);
+               if (error) {
+                       goto err;
+               }
+
+               args.qc_type = QCT_CLEAR;
+               args.u.clear.qc_idtype = q2type;
+               args.u.clear.qc_id = id;
+               args.u.clear.qc_defaultq = defaultq;
+               args.u.clear.qc_objtype = QUOTA_OBJTYPE_FILES;
                error = VFS_QUOTACTL(mp, QUOTACTL_CLEAR, &args);
                if (error) {
                        goto err;
diff -r 0635ae8fb846 -r c829253d3d6d sys/sys/quotactl.h
--- a/sys/sys/quotactl.h        Sun Jan 29 06:52:38 2012 +0000
+++ b/sys/sys/quotactl.h        Sun Jan 29 06:53:35 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: quotactl.h,v 1.15 2012/01/29 06:52:39 dholland Exp $   */
+/*     $NetBSD: quotactl.h,v 1.16 2012/01/29 06:53:35 dholland Exp $   */
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -77,6 +77,7 @@
                        int qc_idtype;
                        id_t qc_id;
                        int qc_defaultq;
+                       int qc_objtype;
                } clear;
        } u;
 };
diff -r 0635ae8fb846 -r c829253d3d6d sys/ufs/ufs/ufs_quota.c
--- a/sys/ufs/ufs/ufs_quota.c   Sun Jan 29 06:52:38 2012 +0000
+++ b/sys/ufs/ufs/ufs_quota.c   Sun Jan 29 06:53:35 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_quota.c,v 1.89 2012/01/29 06:52:39 dholland Exp $  */
+/*     $NetBSD: ufs_quota.c,v 1.90 2012/01/29 06:53:35 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.89 2012/01/29 06:52:39 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.90 2012/01/29 06:53:35 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -319,12 +319,14 @@
        int idtype;
        id_t id;
        int defaultq;
+       int objtype;
        int error;
 
        KASSERT(args->qc_type == QCT_CLEAR);
        idtype = args->u.clear.qc_idtype;
        id = args->u.clear.qc_id;
        defaultq = args->u.clear.qc_defaultq;
+       objtype = args->u.clear.qc_objtype;
 
        if ((ump->um_flags & UFS_QUOTA2) == 0)
                return EOPNOTSUPP;
@@ -338,7 +340,7 @@
 #ifdef QUOTA2
                if (ump->um_flags & UFS_QUOTA2) {
                        error = quota2_handle_cmd_clear(ump, idtype, id,
-                           defaultq);
+                           defaultq, objtype);
                } else
 #endif
                        panic("quota_handle_cmd_get: no support ?");
diff -r 0635ae8fb846 -r c829253d3d6d sys/ufs/ufs/ufs_quota.h
--- a/sys/ufs/ufs/ufs_quota.h   Sun Jan 29 06:52:38 2012 +0000
+++ b/sys/ufs/ufs/ufs_quota.h   Sun Jan 29 06:53:35 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_quota.h,v 1.11 2012/01/29 06:52:39 dholland Exp $  */
+/*     $NetBSD: ufs_quota.h,v 1.12 2012/01/29 06:53:35 dholland Exp $  */
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -127,7 +127,7 @@
     struct quotaval *);
 int quota2_handle_cmd_put(struct ufsmount *, const struct quotakey *,
     const struct quotaval *);
-int quota2_handle_cmd_clear(struct ufsmount *, int, int, int);
+int quota2_handle_cmd_clear(struct ufsmount *, int, int, int, int);
 int quota2_handle_cmd_getall(struct ufsmount *, int, prop_array_t);
 int q2sync(struct mount *);
 int dq2get(struct vnode *, u_long, struct ufsmount *, int, struct dquot *);
diff -r 0635ae8fb846 -r c829253d3d6d sys/ufs/ufs/ufs_quota2.c
--- a/sys/ufs/ufs/ufs_quota2.c  Sun Jan 29 06:52:38 2012 +0000
+++ b/sys/ufs/ufs/ufs_quota2.c  Sun Jan 29 06:53:35 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.12 2012/01/29 06:52:39 dholland Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.13 2012/01/29 06:53:36 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.12 2012/01/29 06:52:39 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.13 2012/01/29 06:53:36 dholland Exp $");
 
 #include <sys/buf.h>
 #include <sys/param.h>
@@ -709,9 +709,9 @@
 }
 int
 quota2_handle_cmd_clear(struct ufsmount *ump, int idtype, int id,
-    int defaultq)
+    int defaultq, int objtype)
 {
-       int error, i;
+       int error, i, canfree;
        struct dquot *dq;
        struct quota2_header *q2h;
        struct quota2_entry q2e, *q2ep;
@@ -755,18 +755,36 @@
        if (error)
                goto out_wapbl;
 
-       if (q2ep->q2e_val[QL_BLOCK].q2v_cur != 0 ||
-           q2ep->q2e_val[QL_FILE].q2v_cur != 0) {
-               /* can't free this entry; revert to default */
-               for (i = 0; i < N_QL; i++) {
-                       q2ep->q2e_val[i].q2v_softlimit =
-                           q2e.q2e_val[i].q2v_softlimit;
-                       q2ep->q2e_val[i].q2v_hardlimit =
-                           q2e.q2e_val[i].q2v_hardlimit;
-                       q2ep->q2e_val[i].q2v_grace =
-                           q2e.q2e_val[i].q2v_grace;
-                       q2ep->q2e_val[i].q2v_time = 0;
+       /* make sure we can index by the objtype passed in */
+       CTASSERT(QUOTA_OBJTYPE_BLOCKS == QL_BLOCK);
+       CTASSERT(QUOTA_OBJTYPE_FILES == QL_FILE);
+
+       /* clear the requested objtype by copying from the default entry */
+       q2ep->q2e_val[objtype].q2v_softlimit =
+               q2e.q2e_val[objtype].q2v_softlimit;
+       q2ep->q2e_val[objtype].q2v_hardlimit =
+               q2e.q2e_val[objtype].q2v_hardlimit;
+       q2ep->q2e_val[objtype].q2v_grace =
+               q2e.q2e_val[objtype].q2v_grace;
+       q2ep->q2e_val[objtype].q2v_time = 0;
+
+       /* if this entry now contains no information, we can free it */
+       canfree = 1;
+       for (i = 0; i < N_QL; i++) {
+               if (q2ep->q2e_val[i].q2v_cur != 0 ||
+                   (q2ep->q2e_val[i].q2v_softlimit != 
+                    q2e.q2e_val[i].q2v_softlimit) ||
+                   (q2ep->q2e_val[i].q2v_hardlimit != 
+                    q2e.q2e_val[i].q2v_hardlimit) ||
+                   (q2ep->q2e_val[i].q2v_grace != 
+                    q2e.q2e_val[i].q2v_grace)) {
+                       canfree = 0;
+                       break;
                }
+               /* note: do not need to check q2v_time */
+       }
+
+       if (canfree == 0) {
                quota2_bwrite(ump->um_mountp, bp);
                goto out_wapbl;
        }



Home | Main Index | Thread Index | Old Index