Module Name:    src
Committed By:   dholland
Date:           Sun Jan 29 06:34:59 UTC 2012

Modified Files:
        src/sys/kern: vfs_quotactl.c vfs_subr.c
        src/sys/miscfs/genfs: layer_extern.h layer_vfsops.c
        src/sys/sys: mount.h quotactl.h
        src/sys/ufs/ufs: ufs_extern.h ufs_quota.c ufs_vfsops.c

Log Message:
Move the proplib-based quota command dispatching (that is, the code
that knows the magic string names for the allowed actions) out of
UFS-specific code and to fs-independent code.

This introduces QUOTACTL_* operation codes and changes the signature
of VFS_QUOTACTL() again for compile safety.

Note: this change requires a kernel version bump.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/kern/vfs_quotactl.c
cvs rdiff -u -r1.427 -r1.428 src/sys/kern/vfs_subr.c
cvs rdiff -u -r1.30 -r1.31 src/sys/miscfs/genfs/layer_extern.h
cvs rdiff -u -r1.35 -r1.36 src/sys/miscfs/genfs/layer_vfsops.c
cvs rdiff -u -r1.203 -r1.204 src/sys/sys/mount.h
cvs rdiff -u -r1.1 -r1.2 src/sys/sys/quotactl.h
cvs rdiff -u -r1.67 -r1.68 src/sys/ufs/ufs/ufs_extern.h
cvs rdiff -u -r1.70 -r1.71 src/sys/ufs/ufs/ufs_quota.c
cvs rdiff -u -r1.44 -r1.45 src/sys/ufs/ufs/ufs_vfsops.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.3 src/sys/kern/vfs_quotactl.c:1.4
--- src/sys/kern/vfs_quotactl.c:1.3	Sun Jan 29 06:32:43 2012
+++ src/sys/kern/vfs_quotactl.c	Sun Jan 29 06:34:57 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_quotactl.c,v 1.3 2012/01/29 06:32:43 dholland Exp $	*/
+/*	$NetBSD: vfs_quotactl.c,v 1.4 2012/01/29 06:34:57 dholland Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -80,11 +80,72 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.3 2012/01/29 06:32:43 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.4 2012/01/29 06:34:57 dholland Exp $");
 
 #include <sys/mount.h>
+#include <sys/quotactl.h>
 #include <quota/quotaprop.h>
 
+static int
+vfs_quotactl_cmd(struct mount *mp, prop_dictionary_t cmddict)
+{
+	int error;
+	const char *cmd, *type;
+	int op;
+	prop_array_t datas;
+	int q2type;
+
+	if (!prop_dictionary_get_cstring_nocopy(cmddict, "command", &cmd))
+		return EINVAL;
+	if (!prop_dictionary_get_cstring_nocopy(cmddict, "type", &type))
+		return EINVAL;
+
+	if (!strcmp(type, QUOTADICT_CLASS_USER)) {
+		q2type = QUOTA_CLASS_USER;
+	} else if (!strcmp(type, QUOTADICT_CLASS_GROUP)) {
+		q2type = QUOTA_CLASS_GROUP;
+	} else {
+		/* XXX this is a bad errno for this case */
+		return EOPNOTSUPP;
+	}
+
+	datas = prop_dictionary_get(cmddict, "data");
+	if (datas == NULL || prop_object_type(datas) != PROP_TYPE_ARRAY)
+		return EINVAL;
+
+	prop_object_retain(datas);
+	prop_dictionary_remove(cmddict, "data"); /* prepare for return */
+
+	if (strcmp(cmd, "get version") == 0) {
+		op = QUOTACTL_GETVERSION;
+	} else if (strcmp(cmd, "quotaon") == 0) {
+		op = QUOTACTL_QUOTAON;
+	} else if (strcmp(cmd, "quotaoff") == 0) {
+		op = QUOTACTL_QUOTAOFF;
+	} else if (strcmp(cmd, "get") == 0) {
+		op = QUOTACTL_GET;
+	} else if (strcmp(cmd, "set") == 0) {
+		op = QUOTACTL_SET;
+	} else if (strcmp(cmd, "getall") == 0) {
+		op = QUOTACTL_GETALL;
+	} else if (strcmp(cmd, "clear") == 0) {
+		op = QUOTACTL_CLEAR;
+	} else {
+		/* XXX this a bad errno for this case */
+		error = EOPNOTSUPP;
+		goto fail;
+	}
+
+	error = VFS_QUOTACTL(mp, op, cmddict, q2type, datas);
+
+ fail:
+	error = (prop_dictionary_set_int8(cmddict, "return",
+	    error) ? 0 : ENOMEM);
+	prop_object_release(datas);
+
+	return error;
+}
+
 int
 vfs_quotactl(struct mount *mp, prop_dictionary_t dict)
 {
@@ -108,7 +169,7 @@ vfs_quotactl(struct mount *mp, prop_dict
 			/* XXX shouldn't this be an error? */
 			continue;
 		}
-		error = VFS_QUOTACTL(mp, cmddict, 0/*dummy*/);
+		error = vfs_quotactl_cmd(mp, cmddict);
 		if (error) {
 			break;
 		}

Index: src/sys/kern/vfs_subr.c
diff -u src/sys/kern/vfs_subr.c:1.427 src/sys/kern/vfs_subr.c:1.428
--- src/sys/kern/vfs_subr.c:1.427	Sun Jan 29 06:32:43 2012
+++ src/sys/kern/vfs_subr.c	Sun Jan 29 06:34:57 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_subr.c,v 1.427 2012/01/29 06:32:43 dholland Exp $	*/
+/*	$NetBSD: vfs_subr.c,v 1.428 2012/01/29 06:34:57 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.427 2012/01/29 06:32:43 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.428 2012/01/29 06:34:57 dholland Exp $");
 
 #include "opt_ddb.h"
 #include "opt_compat_netbsd.h"
@@ -1006,14 +1006,15 @@ VFS_ROOT(struct mount *mp, struct vnode 
 }
 
 int
-VFS_QUOTACTL(struct mount *mp, prop_dictionary_t dict, int dummy)
+VFS_QUOTACTL(struct mount *mp, int op, prop_dictionary_t cmddict, int objtype,
+	     prop_array_t datas)
 {
 	int error;
 
 	if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) {
 		KERNEL_LOCK(1, NULL);
 	}
-	error = (*(mp->mnt_op->vfs_quotactl))(mp, dict, dummy);
+	error = (*(mp->mnt_op->vfs_quotactl))(mp, op, cmddict, objtype, datas);
 	if ((mp->mnt_iflag & IMNT_MPSAFE) == 0) {
 		KERNEL_UNLOCK_ONE(NULL);
 	}

Index: src/sys/miscfs/genfs/layer_extern.h
diff -u src/sys/miscfs/genfs/layer_extern.h:1.30 src/sys/miscfs/genfs/layer_extern.h:1.31
--- src/sys/miscfs/genfs/layer_extern.h:1.30	Sun Jan 29 06:32:44 2012
+++ src/sys/miscfs/genfs/layer_extern.h	Sun Jan 29 06:34:58 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: layer_extern.h,v 1.30 2012/01/29 06:32:44 dholland Exp $	*/
+/*	$NetBSD: layer_extern.h,v 1.31 2012/01/29 06:34:58 dholland Exp $	*/
 
 /*
  * Copyright (c) 1999 National Aeronautics & Space Administration
@@ -88,7 +88,7 @@ struct vnode *layer_node_find(struct mou
 /* VFS routines */
 int	layerfs_start(struct mount *, int);
 int	layerfs_root(struct mount *, struct vnode **);
-int	layerfs_quotactl(struct mount *, prop_dictionary_t, int);
+int	layerfs_quotactl(struct mount *, int, prop_dictionary_t, int, prop_array_t);
 int	layerfs_statvfs(struct mount *, struct statvfs *);
 int	layerfs_sync(struct mount *, int, struct kauth_cred *);
 int	layerfs_vget(struct mount *, ino_t, struct vnode **);

Index: src/sys/miscfs/genfs/layer_vfsops.c
diff -u src/sys/miscfs/genfs/layer_vfsops.c:1.35 src/sys/miscfs/genfs/layer_vfsops.c:1.36
--- src/sys/miscfs/genfs/layer_vfsops.c:1.35	Sun Jan 29 06:32:44 2012
+++ src/sys/miscfs/genfs/layer_vfsops.c	Sun Jan 29 06:34:58 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: layer_vfsops.c,v 1.35 2012/01/29 06:32:44 dholland Exp $	*/
+/*	$NetBSD: layer_vfsops.c,v 1.36 2012/01/29 06:34:58 dholland Exp $	*/
 
 /*
  * Copyright (c) 1999 National Aeronautics & Space Administration
@@ -74,7 +74,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: layer_vfsops.c,v 1.35 2012/01/29 06:32:44 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: layer_vfsops.c,v 1.36 2012/01/29 06:34:58 dholland Exp $");
 
 #include <sys/param.h>
 #include <sys/sysctl.h>
@@ -141,10 +141,12 @@ layerfs_root(struct mount *mp, struct vn
 }
 
 int
-layerfs_quotactl(struct mount *mp, prop_dictionary_t dict, int dummy)
+layerfs_quotactl(struct mount *mp, int op, prop_dictionary_t dict, int objtype,
+		 prop_array_t datas)
 {
 
-	return VFS_QUOTACTL(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, dict, dummy);
+	return VFS_QUOTACTL(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, op, dict,
+			    objtype, datas);
 }
 
 int

Index: src/sys/sys/mount.h
diff -u src/sys/sys/mount.h:1.203 src/sys/sys/mount.h:1.204
--- src/sys/sys/mount.h:1.203	Sun Jan 29 06:32:43 2012
+++ src/sys/sys/mount.h	Sun Jan 29 06:34:57 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mount.h,v 1.203 2012/01/29 06:32:43 dholland Exp $	*/
+/*	$NetBSD: mount.h,v 1.204 2012/01/29 06:34:57 dholland Exp $	*/
 
 /*
  * Copyright (c) 1989, 1991, 1993
@@ -208,7 +208,8 @@ struct vfsops {
 	int	(*vfs_start)	(struct mount *, int);
 	int	(*vfs_unmount)	(struct mount *, int);
 	int	(*vfs_root)	(struct mount *, struct vnode **);
-	int	(*vfs_quotactl)	(struct mount *, prop_dictionary_t, int);
+	int	(*vfs_quotactl)	(struct mount *, int, prop_dictionary_t, int,
+				    prop_array_t);
 	int	(*vfs_statvfs)	(struct mount *, struct statvfs *);
 	int	(*vfs_sync)	(struct mount *, int, struct kauth_cred *);
 	int	(*vfs_vget)	(struct mount *, ino_t, struct vnode **);
@@ -243,7 +244,7 @@ int	VFS_MOUNT(struct mount *, const char
 int	VFS_START(struct mount *, int);
 int	VFS_UNMOUNT(struct mount *, int);
 int	VFS_ROOT(struct mount *, struct vnode **);
-int	VFS_QUOTACTL(struct mount *, prop_dictionary_t, int);
+int	VFS_QUOTACTL(struct mount *, int, prop_dictionary_t, int, prop_array_t);
 int	VFS_STATVFS(struct mount *, struct statvfs *);
 int	VFS_SYNC(struct mount *, int, struct kauth_cred *);
 int	VFS_FHTOVP(struct mount *, struct fid *, struct vnode **);
@@ -269,7 +270,7 @@ int	fsname##_mount(struct mount *, const
 int	fsname##_start(struct mount *, int);				\
 int	fsname##_unmount(struct mount *, int);				\
 int	fsname##_root(struct mount *, struct vnode **);			\
-int	fsname##_quotactl(struct mount *, prop_dictionary_t);		\
+int	fsname##_quotactl(struct mount *, int, prop_dictionary_t, int, prop_array_t);	\
 int	fsname##_statvfs(struct mount *, struct statvfs *);		\
 int	fsname##_sync(struct mount *, int, struct kauth_cred *);	\
 int	fsname##_vget(struct mount *, ino_t, struct vnode **);		\

Index: src/sys/sys/quotactl.h
diff -u src/sys/sys/quotactl.h:1.1 src/sys/sys/quotactl.h:1.2
--- src/sys/sys/quotactl.h:1.1	Sun Jan 29 06:33:51 2012
+++ src/sys/sys/quotactl.h	Sun Jan 29 06:34:57 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: quotactl.h,v 1.1 2012/01/29 06:33:51 dholland Exp $	*/
+/*	$NetBSD: quotactl.h,v 1.2 2012/01/29 06:34:57 dholland Exp $	*/
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -37,5 +37,13 @@
  * use the <quota.h> API instead.
  */
 
+/* Command codes. */
+#define QUOTACTL_GETVERSION	0
+#define QUOTACTL_QUOTAON	1
+#define QUOTACTL_QUOTAOFF	2
+#define QUOTACTL_GET		3
+#define QUOTACTL_SET		4
+#define QUOTACTL_GETALL		5
+#define QUOTACTL_CLEAR		6
 
 #endif /* _SYS_QUOTACTL_H_ */

Index: src/sys/ufs/ufs/ufs_extern.h
diff -u src/sys/ufs/ufs/ufs_extern.h:1.67 src/sys/ufs/ufs/ufs_extern.h:1.68
--- src/sys/ufs/ufs/ufs_extern.h:1.67	Sun Jan 29 06:32:44 2012
+++ src/sys/ufs/ufs/ufs_extern.h	Sun Jan 29 06:34:58 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_extern.h,v 1.67 2012/01/29 06:32:44 dholland Exp $	*/
+/*	$NetBSD: ufs_extern.h,v 1.68 2012/01/29 06:34:58 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -148,7 +148,9 @@ void	ufsquota_init(struct inode *);
 void	ufsquota_free(struct inode *);
 int	chkdq(struct inode *, int64_t, kauth_cred_t, int);
 int	chkiq(struct inode *, int32_t, kauth_cred_t, int);
-int	quota_handle_cmd(struct mount *, struct lwp *, prop_dictionary_t);
+int	quota_handle_cmd(struct mount *, struct lwp *, int,
+			 prop_dictionary_t, int, prop_array_t);
+
 int	qsync(struct mount *);
 
 /* ufs_quota1.c */
@@ -163,7 +165,7 @@ void	ufs_reinit(void);
 void	ufs_done(void);
 int	ufs_start(struct mount *, int);
 int	ufs_root(struct mount *, struct vnode **);
-int	ufs_quotactl(struct mount *, prop_dictionary_t, int);
+int	ufs_quotactl(struct mount *, int, prop_dictionary_t, int, prop_array_t);
 int	ufs_fhtovp(struct mount *, struct ufid *, struct vnode **);
 
 /* ufs_vnops.c */

Index: src/sys/ufs/ufs/ufs_quota.c
diff -u src/sys/ufs/ufs/ufs_quota.c:1.70 src/sys/ufs/ufs/ufs_quota.c:1.71
--- src/sys/ufs/ufs/ufs_quota.c:1.70	Thu Mar 24 17:05:46 2011
+++ src/sys/ufs/ufs/ufs_quota.c	Sun Jan 29 06:34:58 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.c,v 1.70 2011/03/24 17:05:46 bouyer Exp $	*/
+/*	$NetBSD: ufs_quota.c,v 1.71 2012/01/29 06:34: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.70 2011/03/24 17:05:46 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.71 2012/01/29 06:34:58 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -50,6 +50,7 @@ __KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,
 #include <sys/mount.h>
 #include <sys/kauth.h>
 
+#include <sys/quotactl.h>
 #include <ufs/ufs/quota.h>
 #include <ufs/ufs/inode.h>
 #include <ufs/ufs/ufsmount.h>
@@ -152,65 +153,41 @@ chkiq(struct inode *ip, int32_t change, 
 }
 
 int
-quota_handle_cmd(struct mount *mp, struct lwp *l, prop_dictionary_t cmddict)
+quota_handle_cmd(struct mount *mp, struct lwp *l, int op,
+		 prop_dictionary_t cmddict, int q2type, prop_array_t datas)
 {
 	int error = 0;
-	const char *cmd, *type;
-	prop_array_t datas;
-	int q2type;
 
-	if (!prop_dictionary_get_cstring_nocopy(cmddict, "command", &cmd))
-		return EINVAL;
-	if (!prop_dictionary_get_cstring_nocopy(cmddict, "type", &type))
-		return EINVAL;
-	if (!strcmp(type, QUOTADICT_CLASS_USER)) {
-		q2type = USRQUOTA;
-	} else if (!strcmp(type, QUOTADICT_CLASS_GROUP)) {
-		q2type = GRPQUOTA;
-	} else
-		return EOPNOTSUPP;
-	datas = prop_dictionary_get(cmddict, "data");
-	if (datas == NULL || prop_object_type(datas) != PROP_TYPE_ARRAY)
-		return EINVAL;
-
-	prop_object_retain(datas);
-	prop_dictionary_remove(cmddict, "data"); /* prepare for return */
+	KASSERT(prop_object_type(datas) == PROP_TYPE_ARRAY);
 
-	if (strcmp(cmd, "get version") == 0) {
+	switch (op) {
+	    case QUOTACTL_GETVERSION:
 		error = quota_handle_cmd_get_version(mp, l, cmddict, datas);
-		goto end;
-	}
-	if (strcmp(cmd, "quotaon") == 0) {
+		break;
+	    case QUOTACTL_QUOTAON:
 		error = quota_handle_cmd_quotaon(mp, l, cmddict,
 		    q2type, datas);
-		goto end;
-	}
-	if (strcmp(cmd, "quotaoff") == 0) {
+		break;
+	    case QUOTACTL_QUOTAOFF:
 		error = quota_handle_cmd_quotaoff(mp, l, cmddict,
 		    q2type, datas);
-		goto end;
-	}
-	if (strcmp(cmd, "get") == 0) {
+		break;
+	    case QUOTACTL_GET:
 		error = quota_handle_cmd_get(mp, l, cmddict, q2type, datas);
-		goto end;
-	}
-	if (strcmp(cmd, "set") == 0) {
+		break;
+	    case QUOTACTL_SET:
 		error = quota_handle_cmd_set(mp, l, cmddict, q2type, datas);
-		goto end;
-	}
-	if (strcmp(cmd, "getall") == 0) {
+		break;
+	    case QUOTACTL_GETALL:
 		error = quota_handle_cmd_getall(mp, l, cmddict, q2type, datas);
-		goto end;
-	}
-	if (strcmp(cmd, "clear") == 0) {
+		break;
+	    case QUOTACTL_CLEAR:
 		error = quota_handle_cmd_clear(mp, l, cmddict, q2type, datas);
-		goto end;
+		break;
+	    default:
+		panic("Invalid quotactl operation %d\n", op);
 	}
-	error = EOPNOTSUPP;
-end:
-	error = (prop_dictionary_set_int8(cmddict, "return",
-	    error) ? 0 : ENOMEM);
-	prop_object_release(datas);
+
 	return error;
 }
 

Index: src/sys/ufs/ufs/ufs_vfsops.c
diff -u src/sys/ufs/ufs/ufs_vfsops.c:1.44 src/sys/ufs/ufs/ufs_vfsops.c:1.45
--- src/sys/ufs/ufs/ufs_vfsops.c:1.44	Sun Jan 29 06:32:44 2012
+++ src/sys/ufs/ufs/ufs_vfsops.c	Sun Jan 29 06:34:58 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_vfsops.c,v 1.44 2012/01/29 06:32:44 dholland Exp $	*/
+/*	$NetBSD: ufs_vfsops.c,v 1.45 2012/01/29 06:34:58 dholland Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_vfsops.c,v 1.44 2012/01/29 06:32:44 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_vfsops.c,v 1.45 2012/01/29 06:34:58 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -100,7 +100,8 @@ ufs_root(struct mount *mp, struct vnode 
  * Do operations associated with quotas
  */
 int
-ufs_quotactl(struct mount *mp, prop_dictionary_t cmddict, int dummy)
+ufs_quotactl(struct mount *mp, int op, prop_dictionary_t cmddict, int q2type,
+	     prop_array_t datas)
 {
 	struct lwp *l = curlwp;
 
@@ -122,7 +123,7 @@ ufs_quotactl(struct mount *mp, prop_dict
 	}
 	mutex_enter(&mp->mnt_updating);
 
-	error = quota_handle_cmd(mp, l, cmddict);
+	error = quota_handle_cmd(mp, l, op, cmddict, q2type, datas);
 
 	mutex_exit(&mp->mnt_updating);
 	vfs_unbusy(mp, false, NULL);

Reply via email to