Module Name: src Committed By: dholland Date: Sun Jan 29 06:38:24 UTC 2012
Modified Files: src/include: quota.h src/sys/sys: quota.h src/sys/ufs/ufs: ufs_quota.c ufs_quota.h ufs_quota1.c ufs_quota2.c Log Message: Move second-layer proplib frobbing within ufs quota code up to the first layer. (Step 2 of several for QUOTACTL_GET.) To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/include/quota.h cvs rdiff -u -r1.7 -r1.8 src/sys/sys/quota.h cvs rdiff -u -r1.74 -r1.75 src/sys/ufs/ufs/ufs_quota.c cvs rdiff -u -r1.2 -r1.3 src/sys/ufs/ufs/ufs_quota.h cvs rdiff -u -r1.7 -r1.8 src/sys/ufs/ufs/ufs_quota1.c cvs rdiff -u -r1.4 -r1.5 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/include/quota.h diff -u src/include/quota.h:1.1 src/include/quota.h:1.2 --- src/include/quota.h:1.1 Mon Jan 9 15:19:45 2012 +++ src/include/quota.h Sun Jan 29 06:38:23 2012 @@ -44,9 +44,6 @@ struct quotacursor; /* Opaque. */ #define QUOTA_OBJTYPE_BLOCKS 0 #define QUOTA_OBJTYPE_FILES 1 -/* id value for "default" */ -#define QUOTA_DEFAULTID ((id_t)-1) - /* limit value for "no limit" */ #define QUOTA_NOLIMIT ((uint64_t)0xffffffffffffffffULL) Index: src/sys/sys/quota.h diff -u src/sys/sys/quota.h:1.7 src/sys/sys/quota.h:1.8 --- src/sys/sys/quota.h:1.7 Sun Jan 1 15:41:16 2012 +++ src/sys/sys/quota.h Sun Jan 29 06:38:23 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: quota.h,v 1.7 2012/01/01 15:41:16 dholland Exp $ */ +/* $NetBSD: quota.h,v 1.8 2012/01/29 06:38:23 dholland Exp $ */ /*- * Copyright (c) 2010 Manuel Bouyer * All rights reserved. @@ -30,6 +30,9 @@ #include <sys/types.h> +/* id value for "default" */ +#define QUOTA_DEFAULTID ((id_t)-1) + /* * Structure used to describe the value part of a quota record. */ Index: src/sys/ufs/ufs/ufs_quota.c diff -u src/sys/ufs/ufs/ufs_quota.c:1.74 src/sys/ufs/ufs/ufs_quota.c:1.75 --- src/sys/ufs/ufs/ufs_quota.c:1.74 Sun Jan 29 06:37:30 2012 +++ src/sys/ufs/ufs/ufs_quota.c Sun Jan 29 06:38:24 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: ufs_quota.c,v 1.74 2012/01/29 06:37:30 dholland Exp $ */ +/* $NetBSD: ufs_quota.c,v 1.75 2012/01/29 06:38:24 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.74 2012/01/29 06:37:30 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.75 2012/01/29 06:38:24 dholland Exp $"); #if defined(_KERNEL_OPT) #include "opt_quota.h" @@ -226,6 +226,33 @@ quota_get_auth(struct mount *mp, struct KAUTH_REQ_SYSTEM_FS_QUOTA_GET, mp, KAUTH_ARG(id), NULL); } +static int +quota_fill_cmd_get_reply(id_t id, + int defaultq, + const struct quotaval *blocks, + const struct quotaval *files, + prop_array_t replies) +{ + prop_dictionary_t dict; + + /* XXX illegal casts */ + uint64_t *valuesp[QUOTA_NLIMITS]; + valuesp[QUOTA_LIMIT_BLOCK] = (void *)(intptr_t)&blocks->qv_hardlimit; + valuesp[QUOTA_LIMIT_FILE] = (void *)(intptr_t)&files->qv_hardlimit; + + dict = quota64toprop(id, defaultq, valuesp, + ufs_quota_entry_names, UFS_QUOTA_NENTRIES, + ufs_quota_limit_names, QUOTA_NLIMITS); + if (dict == NULL) + return ENOMEM; + if (!prop_array_add_and_rel(replies, dict)) { + prop_object_release(dict); + return ENOMEM; + } + + return 0; +} + static int quota_handle_cmd_get(struct mount *mp, struct lwp *l, struct vfs_quotactl_args *args) @@ -236,6 +263,7 @@ quota_handle_cmd_get(struct mount *mp, s int q2type; int defaultq; prop_array_t replies; + struct quotaval blocks, files; KASSERT(args->qc_type == QCT_GET); id = args->u.get.qc_id; @@ -251,21 +279,25 @@ quota_handle_cmd_get(struct mount *mp, s if (error != 0) return error; #ifdef QUOTA - if (ump->um_flags & UFS_QUOTA) + if (ump->um_flags & UFS_QUOTA) { error = quota1_handle_cmd_get(ump, q2type, id, defaultq, - replies); - else + &blocks, &files); + } else #endif #ifdef QUOTA2 if (ump->um_flags & UFS_QUOTA2) { error = quota2_handle_cmd_get(ump, q2type, id, defaultq, - replies); + &blocks, &files); } else #endif panic("quota_handle_cmd_get: no support ?"); if (error != 0) return error; + + error = quota_fill_cmd_get_reply(id, defaultq, + &blocks, &files, + replies); } return error; Index: src/sys/ufs/ufs/ufs_quota.h diff -u src/sys/ufs/ufs/ufs_quota.h:1.2 src/sys/ufs/ufs/ufs_quota.h:1.3 --- src/sys/ufs/ufs/ufs_quota.h:1.2 Sun Mar 6 17:08:39 2011 +++ src/sys/ufs/ufs/ufs_quota.h Sun Jan 29 06:38:24 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: ufs_quota.h,v 1.2 2011/03/06 17:08:39 bouyer Exp $ */ +/* $NetBSD: ufs_quota.h,v 1.3 2012/01/29 06:38:24 dholland Exp $ */ /* * Copyright (c) 1982, 1986, 1990, 1993, 1995 @@ -113,7 +113,8 @@ int chkiq1(struct inode *, int32_t, kaut int q1sync(struct mount *); int dq1get(struct vnode *, u_long, struct ufsmount *, int, struct dquot *); int dq1sync(struct vnode *, struct dquot *); -int quota1_handle_cmd_get(struct ufsmount *, int, int, int, prop_array_t); +int quota1_handle_cmd_get(struct ufsmount *, int, int, int, + struct quotaval *, struct quotaval *); int quota1_handle_cmd_set(struct ufsmount *, int, int, int, prop_dictionary_t); int quota1_handle_cmd_quotaon(struct lwp *, struct ufsmount *, int, const char *); @@ -121,7 +122,8 @@ int quota1_handle_cmd_quotaoff(struct lw int chkdq2(struct inode *, int64_t, kauth_cred_t, int); int chkiq2(struct inode *, int32_t, kauth_cred_t, int); -int quota2_handle_cmd_get(struct ufsmount *, int, int, int, prop_array_t); +int quota2_handle_cmd_get(struct ufsmount *, int, int, int, + struct quotaval *, struct quotaval *); int quota2_handle_cmd_set(struct ufsmount *, int, int, int, prop_dictionary_t); int quota2_handle_cmd_clear(struct ufsmount *, int, int, int, prop_dictionary_t); int quota2_handle_cmd_getall(struct ufsmount *, int, prop_array_t); Index: src/sys/ufs/ufs/ufs_quota1.c diff -u src/sys/ufs/ufs/ufs_quota1.c:1.7 src/sys/ufs/ufs/ufs_quota1.c:1.8 --- src/sys/ufs/ufs/ufs_quota1.c:1.7 Sun Jan 29 06:23:20 2012 +++ src/sys/ufs/ufs/ufs_quota1.c Sun Jan 29 06:38:24 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: ufs_quota1.c,v 1.7 2012/01/29 06:23:20 dholland Exp $ */ +/* $NetBSD: ufs_quota1.c,v 1.8 2012/01/29 06:38:24 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.7 2012/01/29 06:23:20 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ufs_quota1.c,v 1.8 2012/01/29 06:38:24 dholland Exp $"); #include <sys/param.h> #include <sys/kernel.h> @@ -493,51 +493,39 @@ again: } int -quota1_handle_cmd_get(struct ufsmount *ump, int type, int id, - int defaultq, prop_array_t replies) +quota1_handle_cmd_get(struct ufsmount *ump, int idtype, int id, + int defaultq, struct quotaval *blocks, struct quotaval *files) { struct dquot *dq; - struct quotaval qv[QUOTA_NLIMITS]; - prop_dictionary_t dict; int error; uint64_t *valuesp[QUOTA_NLIMITS]; - valuesp[QUOTA_LIMIT_BLOCK] = &qv[QUOTA_LIMIT_BLOCK].qv_hardlimit; - valuesp[QUOTA_LIMIT_FILE] = &qv[QUOTA_LIMIT_FILE].qv_hardlimit; + valuesp[QUOTA_LIMIT_BLOCK] = &blocks->qv_hardlimit; + valuesp[QUOTA_LIMIT_FILE] = &files->qv_hardlimit; - if (ump->um_quotas[type] == NULLVP) + if (ump->um_quotas[idtype] == NULLVP) return ENODEV; if (defaultq) { /* we want the grace period of id 0 */ - if ((error = dqget(NULLVP, 0, ump, type, &dq)) != 0) + if ((error = dqget(NULLVP, 0, ump, idtype, &dq)) != 0) return error; } else { - if ((error = dqget(NULLVP, id, ump, type, &dq)) != 0) + if ((error = dqget(NULLVP, id, ump, idtype, &dq)) != 0) return error; } - dqblk_to_quotavals(&dq->dq_un.dq1_dqb, - &qv[QUOTA_LIMIT_BLOCK], &qv[QUOTA_LIMIT_FILE]); + dqblk_to_quotavals(&dq->dq_un.dq1_dqb, blocks, files); dqrele(NULLVP, dq); if (defaultq) { - if (qv[QUOTA_LIMIT_BLOCK].qv_expiretime > 0) - qv[QUOTA_LIMIT_BLOCK].qv_grace = - qv[QUOTA_LIMIT_BLOCK].qv_expiretime; + if (blocks->qv_expiretime > 0) + blocks->qv_grace = blocks->qv_expiretime; else - qv[QUOTA_LIMIT_BLOCK].qv_grace = MAX_DQ_TIME; - if (qv[QUOTA_LIMIT_FILE].qv_expiretime > 0) - qv[QUOTA_LIMIT_FILE].qv_grace = - qv[QUOTA_LIMIT_FILE].qv_expiretime; + blocks->qv_grace = MAX_DQ_TIME; + if (files->qv_expiretime > 0) + files->qv_grace = files->qv_expiretime; else - qv[QUOTA_LIMIT_FILE].qv_grace = MAX_DQ_TIME; + files->qv_grace = MAX_DQ_TIME; } - dict = quota64toprop(id, defaultq, valuesp, - ufs_quota_entry_names, UFS_QUOTA_NENTRIES, - ufs_quota_limit_names, QUOTA_NLIMITS); - if (dict == NULL) - return ENOMEM; - if (!prop_array_add_and_rel(replies, dict)) - return ENOMEM; return 0; } Index: src/sys/ufs/ufs/ufs_quota2.c diff -u src/sys/ufs/ufs/ufs_quota2.c:1.4 src/sys/ufs/ufs/ufs_quota2.c:1.5 --- src/sys/ufs/ufs/ufs_quota2.c:1.4 Tue Jun 7 14:56:13 2011 +++ src/sys/ufs/ufs/ufs_quota2.c Sun Jan 29 06:38:24 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: ufs_quota2.c,v 1.4 2011/06/07 14:56:13 bouyer Exp $ */ +/* $NetBSD: ufs_quota2.c,v 1.5 2012/01/29 06:38:24 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.4 2011/06/07 14:56:13 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.5 2012/01/29 06:38:24 dholland Exp $"); #include <sys/buf.h> #include <sys/param.h> @@ -41,6 +41,7 @@ __KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c #include <sys/fstrans.h> #include <sys/kauth.h> #include <sys/wapbl.h> +#include <sys/quota.h> #include <ufs/ufs/quota2.h> #include <ufs/ufs/inode.h> @@ -76,6 +77,8 @@ static int quota2_walk_list(struct ufsmo static int quota2_dict_update_q2e_limits(prop_dictionary_t, struct quota2_entry *); static prop_dictionary_t q2etoprop(struct quota2_entry *, int); +static void q2e_to_quotavals(struct quota2_entry *, int, id_t *, + struct quotaval *, struct quotaval *); static const char *limnames[] = INITQLNAMES; @@ -135,6 +138,41 @@ err: return NULL; } +/* + * Convert internal representation to FS-independent representation. + * (Note that while the two types are currently identical, the + * internal representation is an on-disk struct and the FS-independent + * representation is not, and they might diverge in the future.) + */ +static void +q2val_to_quotaval(struct quota2_val *q2v, struct quotaval *qv) +{ + qv->qv_softlimit = q2v->q2v_softlimit; + qv->qv_hardlimit = q2v->q2v_hardlimit; + qv->qv_usage = q2v->q2v_cur; + qv->qv_expiretime = q2v->q2v_time; + qv->qv_grace = q2v->q2v_grace; +} + +/* + * Convert a quota2entry and default-flag to the FS-independent + * representation. + */ +static void +q2e_to_quotavals(struct quota2_entry *q2e, int def, + id_t *id, struct quotaval *blocks, struct quotaval *files) +{ + if (def) { + *id = QUOTA_DEFAULTID; + } else { + *id = q2e->q2e_uid; + } + + CTASSERT(N_QL == 2); + q2val_to_quotaval(&q2e->q2e_val[QL_BLOCK], blocks); + q2val_to_quotaval(&q2e->q2e_val[QL_FILE], files); +} + static int quota2_bwrite(struct mount *mp, struct buf *bp) @@ -808,6 +846,7 @@ quota2_array_add_q2e(struct ufsmount *um brelse(bp, 0); mutex_exit(&dq->dq_interlock); dqrele(NULLVP, dq); + dict = q2etoprop(&q2e, 0); if (dict == NULL) return ENOMEM; @@ -816,16 +855,54 @@ quota2_array_add_q2e(struct ufsmount *um return 0; } +static int +quota2_fetch_q2e(struct ufsmount *ump, int type, + int id, struct quotaval *blocks, struct quotaval *files) +{ + struct dquot *dq; + int error; + struct quota2_entry *q2ep, q2e; + struct buf *bp; + const int needswap = UFS_MPNEEDSWAP(ump); + id_t id2; + + error = dqget(NULLVP, id, ump, type, &dq); + if (error) + return error; + + mutex_enter(&dq->dq_interlock); + if (dq->dq2_lblkno == 0 && dq->dq2_blkoff == 0) { + mutex_exit(&dq->dq_interlock); + dqrele(NULLVP, dq); + return ENOENT; + } + error = getq2e(ump, type, dq->dq2_lblkno, dq->dq2_blkoff, + &bp, &q2ep, 0); + if (error) { + mutex_exit(&dq->dq_interlock); + dqrele(NULLVP, dq); + return error; + } + quota2_ufs_rwq2e(q2ep, &q2e, needswap); + brelse(bp, 0); + mutex_exit(&dq->dq_interlock); + dqrele(NULLVP, dq); + + q2e_to_quotavals(&q2e, 0, &id2, blocks, files); + KASSERT(id2 == id); + return 0; +} + int quota2_handle_cmd_get(struct ufsmount *ump, int type, int id, - int defaultq, prop_array_t replies) + int defaultq, struct quotaval *blocks, struct quotaval *files) { int error; struct quota2_header *q2h; struct quota2_entry q2e; struct buf *bp; - prop_dictionary_t dict; const int needswap = UFS_MPNEEDSWAP(ump); + id_t id2; if (ump->um_quotas[type] == NULLVP) return ENODEV; @@ -839,13 +916,10 @@ quota2_handle_cmd_get(struct ufsmount *u quota2_ufs_rwq2e(&q2h->q2h_defentry, &q2e, needswap); mutex_exit(&dqlock); brelse(bp, 0); - dict = q2etoprop(&q2e, defaultq); - if (dict == NULL) - return ENOMEM; - if (!prop_array_add_and_rel(replies, dict)) - return ENOMEM; + q2e_to_quotavals(&q2e, defaultq, &id2, blocks, files); + (void)id2; } else - error = quota2_array_add_q2e(ump, type, id, replies); + error = quota2_fetch_q2e(ump, type, id, blocks, files); return error; }