Module Name: src Committed By: dholland Date: Sun Jan 29 06:53:36 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: Improve the quota2 QUOTACTL_CLEAR code to allow clearing blocks and files independently. Note: this change requires a kernel version bump. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/sys/kern/vfs_quotactl.c cvs rdiff -u -r1.15 -r1.16 src/sys/sys/quotactl.h cvs rdiff -u -r1.89 -r1.90 src/sys/ufs/ufs/ufs_quota.c cvs rdiff -u -r1.11 -r1.12 src/sys/ufs/ufs/ufs_quota.h cvs rdiff -u -r1.12 -r1.13 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.17 src/sys/kern/vfs_quotactl.c:1.18 --- src/sys/kern/vfs_quotactl.c:1.17 Sun Jan 29 06:52:38 2012 +++ src/sys/kern/vfs_quotactl.c Sun Jan 29 06:53:35 2012 @@ -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 @@ vfs_quotactl_clear(struct mount *mp, 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; Index: src/sys/sys/quotactl.h diff -u src/sys/sys/quotactl.h:1.15 src/sys/sys/quotactl.h:1.16 --- src/sys/sys/quotactl.h:1.15 Sun Jan 29 06:52:39 2012 +++ src/sys/sys/quotactl.h Sun Jan 29 06:53:35 2012 @@ -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 @@ struct vfs_quotactl_args { int qc_idtype; id_t qc_id; int qc_defaultq; + int qc_objtype; } clear; } u; }; Index: src/sys/ufs/ufs/ufs_quota.c diff -u src/sys/ufs/ufs/ufs_quota.c:1.89 src/sys/ufs/ufs/ufs_quota.c:1.90 --- src/sys/ufs/ufs/ufs_quota.c:1.89 Sun Jan 29 06:52:39 2012 +++ src/sys/ufs/ufs/ufs_quota.c Sun Jan 29 06:53:35 2012 @@ -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 @@ quota_handle_cmd_clear(struct mount *mp, 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 @@ quota_handle_cmd_clear(struct mount *mp, #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 ?"); Index: src/sys/ufs/ufs/ufs_quota.h diff -u src/sys/ufs/ufs/ufs_quota.h:1.11 src/sys/ufs/ufs/ufs_quota.h:1.12 --- src/sys/ufs/ufs/ufs_quota.h:1.11 Sun Jan 29 06:52:39 2012 +++ src/sys/ufs/ufs/ufs_quota.h Sun Jan 29 06:53:35 2012 @@ -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 @@ int quota2_handle_cmd_get(struct ufsmoun 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 *); Index: src/sys/ufs/ufs/ufs_quota2.c diff -u src/sys/ufs/ufs/ufs_quota2.c:1.12 src/sys/ufs/ufs/ufs_quota2.c:1.13 --- src/sys/ufs/ufs/ufs_quota2.c:1.12 Sun Jan 29 06:52:39 2012 +++ src/sys/ufs/ufs/ufs_quota2.c Sun Jan 29 06:53:36 2012 @@ -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 @@ dq2clear_callback(struct ufsmount *ump, } 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 @@ quota2_handle_cmd_clear(struct ufsmount 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; }