Don't pass the idtype to QUOTACTL_GETALL. Instead, iterate both users

and groups.

This change requires a kernel version bump.
This commit is contained in:
dholland 2012-01-29 07:08:58 +00:00
parent 876e5535b9
commit 32d1d988da
5 changed files with 65 additions and 30 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_quotactl.c,v 1.27 2012/01/29 07:07:22 dholland Exp $ */
/* $NetBSD: vfs_quotactl.c,v 1.28 2012/01/29 07:08:58 dholland Exp $ */
/*
* Copyright (c) 1991, 1993, 1994
@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.27 2012/01/29 07:07:22 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.28 2012/01/29 07:08:58 dholland Exp $");
#include <sys/malloc.h> /* XXX: temporary */
#include <sys/mount.h>
@ -566,21 +566,8 @@ vfs_quotactl_getall(struct mount *mp,
args.u.getall.qc_vals = vals;
args.u.getall.qc_maxnum = loopmax;
args.u.getall.qc_ret = &loopnum;
args.u.getall.qc_idtype = q2type; /* XXX */
error = VFS_QUOTACTL(mp, QUOTACTL_GETALL, &args);
/*
* XXX this is bogus but up until now *all* errors
* from inside quotactl_getall were suppressed by the
* dispatching code in ufs_quota.c. Fixing that causes
* repquota to break in an undesirable way; this is a
* workaround.
*/
if (error == ENODEV || error == ENXIO) {
error = 0;
break;
}
if (error) {
goto err;
}
@ -594,6 +581,11 @@ vfs_quotactl_getall(struct mount *mp,
key = &keys[i];
val = &vals[i];
if (key->qk_idtype != q2type) {
/* don't want this result */
continue;
}
if (thisreply == NULL || key->qk_id != lastid) {
lastid = key->qk_id;
thisreply = vfs_quotactl_getall_makereply(key);

View File

@ -1,4 +1,4 @@
/* $NetBSD: quotactl.h,v 1.24 2012/01/29 07:07:22 dholland Exp $ */
/* $NetBSD: quotactl.h,v 1.25 2012/01/29 07:08:58 dholland Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
* All rights reserved.
@ -107,7 +107,6 @@ struct vfs_quotactl_args {
struct quotaval *qc_vals;
unsigned qc_maxnum;
unsigned *qc_ret;
int qc_idtype;
} getall;
} u;
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufs_quota.c,v 1.96 2012/01/29 07:07:22 dholland Exp $ */
/* $NetBSD: ufs_quota.c,v 1.97 2012/01/29 07:08:58 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.96 2012/01/29 07:07:22 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.97 2012/01/29 07:08:58 dholland Exp $");
#if defined(_KERNEL_OPT)
#include "opt_quota.h"
@ -374,7 +374,6 @@ quota_handle_cmd_getall(struct mount *mp, struct lwp *l,
struct quotaval *vals;
unsigned maxnum;
unsigned *ret;
int idtype;
int error;
KASSERT(args->qc_type == QCT_GETALL);
@ -383,7 +382,6 @@ quota_handle_cmd_getall(struct mount *mp, struct lwp *l,
vals = args->u.getall.qc_vals;
maxnum = args->u.getall.qc_maxnum;
ret = args->u.getall.qc_ret;
idtype = args->u.getall.qc_idtype;
if ((ump->um_flags & UFS_QUOTA2) == 0)
return EOPNOTSUPP;
@ -395,7 +393,7 @@ quota_handle_cmd_getall(struct mount *mp, struct lwp *l,
#ifdef QUOTA2
if (ump->um_flags & UFS_QUOTA2) {
error = quota2_handle_cmd_getall(ump, cursor, idtype,
error = quota2_handle_cmd_getall(ump, cursor,
keys, vals, maxnum, ret);
} else
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufs_quota.h,v 1.18 2012/01/29 07:07:22 dholland Exp $ */
/* $NetBSD: ufs_quota.h,v 1.19 2012/01/29 07:08:58 dholland Exp $ */
/*
* Copyright (c) 1982, 1986, 1990, 1993, 1995
@ -131,7 +131,7 @@ int quota2_handle_cmd_get(struct ufsmount *, const struct quotakey *,
int quota2_handle_cmd_put(struct ufsmount *, const struct quotakey *,
const struct quotaval *);
int quota2_handle_cmd_delete(struct ufsmount *, const struct quotakey *);
int quota2_handle_cmd_getall(struct ufsmount *, struct quotakcursor *, int,
int quota2_handle_cmd_getall(struct ufsmount *, struct quotakcursor *,
struct quotakey *, struct quotaval *, unsigned, unsigned *);
int quota2_handle_cmd_cursoropen(struct ufsmount *, struct quotakcursor *);
int quota2_handle_cmd_cursorclose(struct ufsmount *, struct quotakcursor *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufs_quota2.c,v 1.24 2012/01/29 07:08:00 dholland Exp $ */
/* $NetBSD: ufs_quota2.c,v 1.25 2012/01/29 07:08:58 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.24 2012/01/29 07:08:00 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.25 2012/01/29 07:08:58 dholland Exp $");
#include <sys/buf.h>
#include <sys/param.h>
@ -966,6 +966,8 @@ struct ufsq2_cursor {
uint32_t q2c_magic; /* magic number */
int q2c_hashsize; /* size of hash table at last go */
int q2c_users_done; /* true if we've returned all user data */
int q2c_groups_done; /* true if we've returned all group data */
int q2c_defaults_done; /* true if we've returned the default values */
int q2c_hashpos; /* slot to start at in hash table */
int q2c_uidpos; /* number of ids we've handled */
@ -986,6 +988,12 @@ q2cursor_check(struct ufsq2_cursor *cursor)
return EINVAL;
}
if (cursor->q2c_users_done != 0 && cursor->q2c_users_done != 1) {
return EINVAL;
}
if (cursor->q2c_groups_done != 0 && cursor->q2c_groups_done != 1) {
return EINVAL;
}
if (cursor->q2c_defaults_done != 0 && cursor->q2c_defaults_done != 1) {
return EINVAL;
}
@ -1043,8 +1051,8 @@ quota2_getuids_callback(struct ufsmount *ump, uint64_t *offp,
int
quota2_handle_cmd_getall(struct ufsmount *ump, struct quotakcursor *qkc,
int idtype, struct quotakey *keys, struct quotaval *vals,
unsigned maxreturn, unsigned *ret)
struct quotakey *keys, struct quotaval *vals, unsigned maxreturn,
unsigned *ret)
{
int error;
struct ufsq2_cursor *cursor;
@ -1052,6 +1060,8 @@ quota2_handle_cmd_getall(struct ufsmount *ump, struct quotakcursor *qkc,
struct quota2_entry q2e;
struct buf *hbp;
uint64_t offset;
int idtype;
int can_switch_idtype;
int i, j;
int quota2_hash_size;
const int needswap = UFS_MPNEEDSWAP(ump);
@ -1069,9 +1079,33 @@ quota2_handle_cmd_getall(struct ufsmount *ump, struct quotakcursor *qkc,
return error;
}
if (ump->um_quotas[idtype] == NULLVP) {
return ENODEV;
CTASSERT(USRQUOTA == QUOTA_IDTYPE_USER);
CTASSERT(GRPQUOTA == QUOTA_IDTYPE_GROUP);
if (cursor->q2c_users_done == 0 &&
ump->um_quotas[USRQUOTA] == NULLVP) {
cursor->q2c_users_done = 1;
}
if (cursor->q2c_groups_done == 0 &&
ump->um_quotas[GRPQUOTA] == NULLVP) {
cursor->q2c_groups_done = 1;
}
restart:
if (cursor->q2c_users_done == 0) {
idtype = QUOTA_IDTYPE_USER;
can_switch_idtype = 1;
} else if (cursor->q2c_groups_done == 0) {
idtype = QUOTA_IDTYPE_GROUP;
can_switch_idtype = 0;
} else {
/* nothing more to do, return 0 */
*ret = 0;
return 0;
}
KASSERT(ump->um_quotas[idtype] != NULLVP);
numreturn = 0;
@ -1160,6 +1194,16 @@ fail:
if (error)
return error;
if (gu.nuids == 0) {
if (idtype == QUOTA_IDTYPE_USER)
cursor->q2c_users_done = 1;
else
cursor->q2c_groups_done = 1;
if (can_switch_idtype) {
goto restart;
}
}
maxnum = gu.nuids*2;
/*
@ -1209,6 +1253,8 @@ quota2_handle_cmd_cursoropen(struct ufsmount *ump, struct quotakcursor *qkc)
cursor->q2c_magic = Q2C_MAGIC;
cursor->q2c_hashsize = 0;
cursor->q2c_users_done = 0;
cursor->q2c_groups_done = 0;
cursor->q2c_defaults_done = 0;
cursor->q2c_hashpos = 0;
cursor->q2c_uidpos = 0;