Module Name: src Committed By: dholland Date: Sun Jan 29 06:47:38 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_quota1.c ufs_quota2.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/sys/kern/vfs_quotactl.c cvs rdiff -u -r1.10 -r1.11 src/sys/sys/quotactl.h cvs rdiff -u -r1.82 -r1.83 src/sys/ufs/ufs/ufs_quota.c cvs rdiff -u -r1.7 -r1.8 src/sys/ufs/ufs/ufs_quota.h cvs rdiff -u -r1.12 -r1.13 src/sys/ufs/ufs/ufs_quota1.c cvs rdiff -u -r1.8 -r1.9 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.12 src/sys/kern/vfs_quotactl.c:1.13 --- src/sys/kern/vfs_quotactl.c:1.12 Sun Jan 29 06:45:25 2012 +++ src/sys/kern/vfs_quotactl.c Sun Jan 29 06:47:38 2012 @@ -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 @@ vfs_quotactl_set(struct mount *mp, } 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 @@ vfs_quotactl_set(struct mount *mp, } 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_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_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_FILES; + args.u.set.qc_val = &files; error = VFS_QUOTACTL(mp, QUOTACTL_SET, &args); if (error) { goto err; Index: src/sys/sys/quotactl.h diff -u src/sys/sys/quotactl.h:1.10 src/sys/sys/quotactl.h:1.11 --- src/sys/sys/quotactl.h:1.10 Sun Jan 29 06:45:26 2012 +++ src/sys/sys/quotactl.h Sun Jan 29 06:47:38 2012 @@ -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 vfs_quotactl_args { 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; }; Index: src/sys/ufs/ufs/ufs_quota.c diff -u src/sys/ufs/ufs/ufs_quota.c:1.82 src/sys/ufs/ufs/ufs_quota.c:1.83 --- src/sys/ufs/ufs/ufs_quota.c:1.82 Sun Jan 29 06:46:49 2012 +++ src/sys/ufs/ufs/ufs_quota.c Sun Jan 29 06:47:38 2012 @@ -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 @@ quota_handle_cmd_set(struct mount *mp, s 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 @@ quota_handle_cmd_set(struct mount *mp, s 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 ?"); Index: src/sys/ufs/ufs/ufs_quota.h diff -u src/sys/ufs/ufs/ufs_quota.h:1.7 src/sys/ufs/ufs/ufs_quota.h:1.8 --- src/sys/ufs/ufs/ufs_quota.h:1.7 Sun Jan 29 06:46:50 2012 +++ src/sys/ufs/ufs/ufs_quota.h Sun Jan 29 06:47:38 2012 @@ -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 dq1get(struct vnode *, u_long, struc 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 chkdq2(struct inode *, int64_t, kaut 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 *); Index: src/sys/ufs/ufs/ufs_quota1.c diff -u src/sys/ufs/ufs/ufs_quota1.c:1.12 src/sys/ufs/ufs/ufs_quota1.c:1.13 --- src/sys/ufs/ufs/ufs_quota1.c:1.12 Sun Jan 29 06:46:16 2012 +++ src/sys/ufs/ufs/ufs_quota1.c Sun Jan 29 06:47:38 2012 @@ -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 @@ quota1_encode_limit(uint64_t lim) } 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 @@ quota1_handle_cmd_set(struct ufsmount *u 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 (files->qv_grace != QUOTA_NOTIME) { - ump->umq1_itime[type] = dqb.dqb_itime = - files->qv_grace; + if (objtype == QUOTA_OBJTYPE_BLOCKS) { + ump->umq1_btime[idtype] = dqb.dqb_btime = val->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]; dq->dq_un.dq1_dqb = dqb; if (dq->dq_curblocks < dq->dq_bsoftlimit) dq->dq_flags &= ~DQ_WARN(QL_BLOCK); Index: src/sys/ufs/ufs/ufs_quota2.c diff -u src/sys/ufs/ufs/ufs_quota2.c:1.8 src/sys/ufs/ufs/ufs_quota2.c:1.9 --- src/sys/ufs/ufs/ufs_quota2.c:1.8 Sun Jan 29 06:46:50 2012 +++ src/sys/ufs/ufs/ufs_quota2.c Sun Jan 29 06:47:38 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: ufs_quota2.c,v 1.8 2012/01/29 06:46:50 dholland Exp $ */ +/* $NetBSD: ufs_quota2.c,v 1.9 2012/01/29 06:47:38 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.8 2012/01/29 06:46:50 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.9 2012/01/29 06:47:38 dholland Exp $"); #include <sys/buf.h> #include <sys/param.h> @@ -79,17 +79,16 @@ static prop_dictionary_t q2etoprop(struc static const char *limnames[] = INITQLNAMES; static void -quota2_dict_update_q2e_limits(const struct quotaval *blocks, - const struct quotaval *files, +quota2_dict_update_q2e_limits(int objtype, const struct quotaval *val, struct quota2_entry *q2e) { - q2e->q2e_val[QL_BLOCK].q2v_hardlimit = blocks->qv_hardlimit; - q2e->q2e_val[QL_BLOCK].q2v_softlimit = blocks->qv_softlimit; - q2e->q2e_val[QL_BLOCK].q2v_grace = blocks->qv_grace; - - q2e->q2e_val[QL_FILE].q2v_hardlimit = blocks->qv_hardlimit; - q2e->q2e_val[QL_FILE].q2v_softlimit = blocks->qv_softlimit; - q2e->q2e_val[QL_FILE].q2v_grace = blocks->qv_grace; + /* make sure we can index q2e_val[] by the fs-independent objtype */ + CTASSERT(QUOTA_OBJTYPE_BLOCKS == QL_BLOCK); + CTASSERT(QUOTA_OBJTYPE_FILES == QL_FILE); + + q2e->q2e_val[objtype].q2v_hardlimit = val->qv_hardlimit; + q2e->q2e_val[objtype].q2v_softlimit = val->qv_softlimit; + q2e->q2e_val[objtype].q2v_grace = val->qv_grace; } static prop_dictionary_t @@ -613,7 +612,7 @@ chkiq2(struct inode *ip, int32_t change, int quota2_handle_cmd_set(struct ufsmount *ump, int type, int id, - int defaultq, const struct quotaval *blocks, const struct quotaval *files) + int defaultq, int objtype, const struct quotaval *val) { int error; struct dquot *dq; @@ -636,7 +635,7 @@ quota2_handle_cmd_set(struct ufsmount *u goto out_wapbl; } quota2_ufs_rwq2e(&q2h->q2h_defentry, &q2e, needswap); - quota2_dict_update_q2e_limits(blocks, files, &q2e); + quota2_dict_update_q2e_limits(objtype, val, &q2e); quota2_ufs_rwq2e(&q2e, &q2h->q2h_defentry, needswap); mutex_exit(&dqlock); quota2_bwrite(ump->um_mountp, bp); @@ -661,7 +660,7 @@ quota2_handle_cmd_set(struct ufsmount *u goto out_il; quota2_ufs_rwq2e(q2ep, &q2e, needswap); - quota2_dict_update_q2e_limits(blocks, files, &q2e); + quota2_dict_update_q2e_limits(objtype, val, &q2e); quota2_ufs_rwq2e(&q2e, q2ep, needswap); quota2_bwrite(ump->um_mountp, bp);