Sun Jan 29 06:48:51 2012 UTC ()
Combine the miscellaneous QUOTACTL_SET args into a struct quotakey.
Note: this change requires a kernel version bump.
(dholland)
diff -r1.13 -r1.14 src/sys/kern/vfs_quotactl.c
diff -r1.11 -r1.12 src/sys/sys/quotactl.h
diff -r1.83 -r1.84 src/sys/ufs/ufs/ufs_quota.c
diff -r1.8 -r1.9 src/sys/ufs/ufs/ufs_quota.h
diff -r1.13 -r1.14 src/sys/ufs/ufs/ufs_quota1.c
diff -r1.9 -r1.10 src/sys/ufs/ufs/ufs_quota2.c
--- src/sys/kern/vfs_quotactl.c 2012/01/29 06:47:38 1.13
+++ src/sys/kern/vfs_quotactl.c 2012/01/29 06:48:50 1.14
@@ -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) {
--- src/sys/sys/quotactl.h 2012/01/29 06:47:38 1.11
+++ src/sys/sys/quotactl.h 2012/01/29 06:48:50 1.12
@@ -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;
--- src/sys/ufs/ufs/ufs_quota.c 2012/01/29 06:47:38 1.83
+++ src/sys/ufs/ufs/ufs_quota.c 2012/01/29 06:48:50 1.84
@@ -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 ?");
--- src/sys/ufs/ufs/ufs_quota.h 2012/01/29 06:47:38 1.8
+++ src/sys/ufs/ufs/ufs_quota.h 2012/01/29 06:48:50 1.9
@@ -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);
--- src/sys/ufs/ufs/ufs_quota1.c 2012/01/29 06:47:38 1.13
+++ src/sys/ufs/ufs/ufs_quota1.c 2012/01/29 06:48:51 1.14
@@ -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;
- mutex_exit(&dq->dq_interlock);
+ 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);
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))
- dqb.dqb_itime = time_second + ump->umq1_itime[idtype];
+ dqb.dqb_itime = time_second + ump->umq1_itime[key->qk_idtype];
dq->dq_un.dq1_dqb = dqb;
if (dq->dq_curblocks < dq->dq_bsoftlimit)
dq->dq_flags &= ~DQ_WARN(QL_BLOCK);
--- src/sys/ufs/ufs/ufs_quota2.c 2012/01/29 06:47:38 1.9
+++ src/sys/ufs/ufs/ufs_quota2.c 2012/01/29 06:48:51 1.10
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.9 2012/01/29 06:47:38 dholland Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.10 2012/01/29 06:48:51 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.9 2012/01/29 06:47:38 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.10 2012/01/29 06:48:51 dholland Exp $");
#include <sys/buf.h>
#include <sys/param.h>
@@ -611,8 +611,8 @@
}
int
-quota2_handle_cmd_set(struct ufsmount *ump, int type, int id,
- int defaultq, int objtype, const struct quotaval *val)
+quota2_handle_cmd_set(struct ufsmount *ump, const struct quotakey *key,
+ const struct quotaval *val)
{
int error;
struct dquot *dq;
@@ -621,28 +621,32 @@
struct buf *bp;
const int needswap = UFS_MPNEEDSWAP(ump);
- if (ump->um_quotas[type] == NULLVP)
+ /* make sure we can index by the fs-independent idtype */
+ CTASSERT(QUOTA_IDTYPE_USER == USRQUOTA);
+ CTASSERT(QUOTA_IDTYPE_GROUP == GRPQUOTA);
+
+ if (ump->um_quotas[key->qk_idtype] == NULLVP)
return ENODEV;
error = UFS_WAPBL_BEGIN(ump->um_mountp);
if (error)
return error;
- if (defaultq) {
+ if (key->qk_id == QUOTA_DEFAULTID) {
mutex_enter(&dqlock);
- error = getq2h(ump, type, &bp, &q2h, B_MODIFY);
+ error = getq2h(ump, key->qk_idtype, &bp, &q2h, B_MODIFY);
if (error) {
mutex_exit(&dqlock);
goto out_wapbl;
}
quota2_ufs_rwq2e(&q2h->q2h_defentry, &q2e, needswap);
- quota2_dict_update_q2e_limits(objtype, val, &q2e);
+ quota2_dict_update_q2e_limits(key->qk_objtype, val, &q2e);
quota2_ufs_rwq2e(&q2e, &q2h->q2h_defentry, needswap);
mutex_exit(&dqlock);
quota2_bwrite(ump->um_mountp, bp);
goto out_wapbl;
}
- error = dqget(NULLVP, id, ump, type, &dq);
+ error = dqget(NULLVP, key->qk_id, ump, key->qk_idtype, &dq);
if (error)
goto out_wapbl;
@@ -650,17 +654,18 @@
if (dq->dq2_lblkno == 0 && dq->dq2_blkoff == 0) {
/* need to alloc a new on-disk quot */
mutex_enter(&dqlock);
- error = quota2_q2ealloc(ump, type, id, dq, &bp, &q2ep);
+ error = quota2_q2ealloc(ump, key->qk_idtype, key->qk_id, dq,
+ &bp, &q2ep);
mutex_exit(&dqlock);
} else {
- error = getq2e(ump, type, dq->dq2_lblkno, dq->dq2_blkoff,
- &bp, &q2ep, B_MODIFY);
+ error = getq2e(ump, key->qk_idtype, dq->dq2_lblkno,
+ dq->dq2_blkoff, &bp, &q2ep, B_MODIFY);
}
if (error)
goto out_il;
quota2_ufs_rwq2e(q2ep, &q2e, needswap);
- quota2_dict_update_q2e_limits(objtype, val, &q2e);
+ quota2_dict_update_q2e_limits(key->qk_objtype, val, &q2e);
quota2_ufs_rwq2e(&q2e, q2ep, needswap);
quota2_bwrite(ump->um_mountp, bp);