Module Name:    src
Committed By:   dholland
Date:           Sun Jan 29 06:37:30 UTC 2012

Modified Files:
        src/sys/kern: vfs_quotactl.c
        src/sys/sys: quotactl.h
        src/sys/ufs/ufs: ufs_quota.c

Log Message:
Move first-layer proplib frobbing for QUOTACTL_GET to FS-independent code.
(step 1 of several)

Note: this change requires a kernel version bump.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/kern/vfs_quotactl.c
cvs rdiff -u -r1.4 -r1.5 src/sys/sys/quotactl.h
cvs rdiff -u -r1.73 -r1.74 src/sys/ufs/ufs/ufs_quota.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.6 src/sys/kern/vfs_quotactl.c:1.7
--- src/sys/kern/vfs_quotactl.c:1.6	Sun Jan 29 06:36:50 2012
+++ src/sys/kern/vfs_quotactl.c	Sun Jan 29 06:37:30 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_quotactl.c,v 1.6 2012/01/29 06:36:50 dholland Exp $	*/
+/*	$NetBSD: vfs_quotactl.c,v 1.7 2012/01/29 06:37:30 dholland Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.6 2012/01/29 06:36:50 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.7 2012/01/29 06:37:30 dholland Exp $");
 
 #include <sys/mount.h>
 #include <sys/quotactl.h>
@@ -170,13 +170,74 @@ vfs_quotactl_get(struct mount *mp,
 			prop_dictionary_t cmddict, int q2type,
 			prop_array_t datas)
 {
+	prop_object_iterator_t iter;
+	prop_dictionary_t data;
+	uint32_t id;
+	int defaultq;
+	const char *idstr;
+	prop_array_t replies;
 	struct vfs_quotactl_args args;
+	int error;
 
-	args.qc_type = QCT_PROPLIB;
-	args.u.proplib.qc_cmddict = cmddict;
-	args.u.proplib.qc_q2type = q2type;
-	args.u.proplib.qc_datas = datas;
-	return VFS_QUOTACTL(mp, QUOTACTL_GET, &args);
+	KASSERT(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY);
+	KASSERT(prop_object_type(datas) == PROP_TYPE_ARRAY);
+
+	replies = prop_array_create();
+	if (replies == NULL) {
+		return ENOMEM;
+	}
+
+	iter = prop_array_iterator(datas);
+	if (iter == NULL) {
+		prop_object_release(replies);
+		return ENOMEM;
+	}
+
+	while ((data = prop_object_iterator_next(iter)) != NULL) {
+		if (!prop_dictionary_get_uint32(data, "id", &id)) {
+			if (!prop_dictionary_get_cstring_nocopy(data, "id",
+			    &idstr))
+				continue;
+			if (strcmp(idstr, "default")) {
+				error = EINVAL;
+				goto fail;
+			}
+			id = 0;
+			defaultq = 1;
+		} else {
+			defaultq = 0;
+		}
+
+		args.qc_type = QCT_GET;
+		args.u.get.qc_q2type = q2type;
+		args.u.get.qc_id = id;
+		args.u.get.qc_defaultq = defaultq;
+		args.u.get.qc_replies = replies;
+		error = VFS_QUOTACTL(mp, QUOTACTL_GET, &args);
+		if (error == EPERM) {
+			/* XXX does this make sense? */
+			continue;
+		} else if (error == ENOENT) {
+			/* XXX does *this* make sense? */
+			continue;
+		} else if (error) {
+			goto fail;
+		}
+	}
+
+	prop_object_iterator_release(iter);
+	if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) {
+		error = ENOMEM;
+	} else {
+		error = 0;
+	}
+
+	return error;
+
+ fail:
+	prop_object_iterator_release(iter);
+	prop_object_release(replies);
+	return error;
 }
 
 static int

Index: src/sys/sys/quotactl.h
diff -u src/sys/sys/quotactl.h:1.4 src/sys/sys/quotactl.h:1.5
--- src/sys/sys/quotactl.h:1.4	Sun Jan 29 06:36:50 2012
+++ src/sys/sys/quotactl.h	Sun Jan 29 06:37:30 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: quotactl.h,v 1.4 2012/01/29 06:36:50 dholland Exp $	*/
+/*	$NetBSD: quotactl.h,v 1.5 2012/01/29 06:37:30 dholland Exp $	*/
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -50,6 +50,7 @@
 enum vfs_quotactl_argtypes {
 	QCT_PROPLIB,	/* quotaon/off, get, set, getall, clear */
 	QCT_GETVERSION,	/* getversion */
+	QCT_GET,	/* get */
 };
 struct vfs_quotactl_args {
 	enum vfs_quotactl_argtypes qc_type;
@@ -62,6 +63,12 @@ struct vfs_quotactl_args {
 		struct {
 			int *qc_version_ret;
 		} getversion;
+		struct {
+			int qc_q2type;
+			id_t qc_id;
+			int qc_defaultq;
+			prop_array_t qc_replies;
+		} get;
 	} u;
 };
 

Index: src/sys/ufs/ufs/ufs_quota.c
diff -u src/sys/ufs/ufs/ufs_quota.c:1.73 src/sys/ufs/ufs/ufs_quota.c:1.74
--- src/sys/ufs/ufs/ufs_quota.c:1.73	Sun Jan 29 06:36:51 2012
+++ src/sys/ufs/ufs/ufs_quota.c	Sun Jan 29 06:37:30 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_quota.c,v 1.73 2012/01/29 06:36:51 dholland Exp $	*/
+/*	$NetBSD: ufs_quota.c,v 1.74 2012/01/29 06:37:30 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.73 2012/01/29 06:36:51 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.74 2012/01/29 06:37:30 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -230,56 +230,26 @@ static int 
 quota_handle_cmd_get(struct mount *mp, struct lwp *l, 
     struct vfs_quotactl_args *args)
 {
-	prop_array_t replies;
-	prop_object_iterator_t iter;
-	prop_dictionary_t data;
-	uint32_t id;
 	struct ufsmount *ump = VFSTOUFS(mp);
-	int error, defaultq = 0;
-	const char *idstr;
-	prop_dictionary_t cmddict;
+	int error;
+	id_t id;
 	int q2type;
-	prop_array_t datas;
-
-	KASSERT(args->qc_type == QCT_PROPLIB);
-	cmddict = args->u.proplib.qc_cmddict;
-	q2type = args->u.proplib.qc_q2type;
-	datas = args->u.proplib.qc_datas;
+	int defaultq;
+	prop_array_t replies;
 
-	KASSERT(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY);
-	KASSERT(prop_object_type(datas) == PROP_TYPE_ARRAY);
+	KASSERT(args->qc_type == QCT_GET);
+	id = args->u.get.qc_id;
+	q2type = args->u.get.qc_q2type;
+	defaultq = args->u.get.qc_defaultq;
+	replies = args->u.get.qc_replies;
 
 	if ((ump->um_flags & (UFS_QUOTA|UFS_QUOTA2)) == 0)
 		return EOPNOTSUPP;
 	
-	replies = prop_array_create();
-	if (replies == NULL)
-		return ENOMEM;
-
-	iter = prop_array_iterator(datas);
-	if (iter == NULL) {
-		prop_object_release(replies);
-		return ENOMEM;
-	}
-	while ((data = prop_object_iterator_next(iter)) != NULL) {
-		if (!prop_dictionary_get_uint32(data, "id", &id)) {
-			if (!prop_dictionary_get_cstring_nocopy(data, "id",
-			    &idstr))
-				continue;
-			if (strcmp(idstr, "default")) {
-				error = EINVAL;
-				goto err;
-			}
-			id = 0;
-			defaultq = 1;
-		} else {
-			defaultq = 0;
-		}
+	/* avoid whitespace diffs */ {
 		error = quota_get_auth(mp, l, id);
-		if (error == EPERM)
-			continue;
 		if (error != 0) 
-			goto err;
+			return error;
 #ifdef QUOTA
 		if (ump->um_flags & UFS_QUOTA)
 			error = quota1_handle_cmd_get(ump, q2type, id, defaultq,
@@ -294,21 +264,10 @@ quota_handle_cmd_get(struct mount *mp, s
 #endif
 			panic("quota_handle_cmd_get: no support ?");
 		
-		if (error == ENOENT)
-			continue;
 		if (error != 0)
-			goto err;
-	}
-	prop_object_iterator_release(iter);
-	if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) {
-		error = ENOMEM;
-	} else {
-		error = 0;
+			return error;
 	}
-	return error;
-err:
-	prop_object_iterator_release(iter);
-	prop_object_release(replies);
+
 	return error;
 }
 

Reply via email to