Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Move the proplib-based quota command dispatching (that i...



details:   https://anonhg.NetBSD.org/src/rev/08de58454a08
branches:  trunk
changeset: 773165:08de58454a08
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sun Jan 29 06:34:57 2012 +0000

description:
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.

diffstat:

 sys/kern/vfs_quotactl.c         |  67 +++++++++++++++++++++++++++++++++++-
 sys/kern/vfs_subr.c             |   9 ++--
 sys/miscfs/genfs/layer_extern.h |   4 +-
 sys/miscfs/genfs/layer_vfsops.c |  10 +++--
 sys/sys/mount.h                 |   9 ++--
 sys/sys/quotactl.h              |  10 +++++-
 sys/ufs/ufs/ufs_extern.h        |   8 ++-
 sys/ufs/ufs/ufs_quota.c         |  73 ++++++++++++++--------------------------
 sys/ufs/ufs/ufs_vfsops.c        |   9 ++--
 9 files changed, 126 insertions(+), 73 deletions(-)

diffs (truncated from 419 to 300 lines):

diff -r a1bdecc4f9b4 -r 08de58454a08 sys/kern/vfs_quotactl.c
--- a/sys/kern/vfs_quotactl.c   Sun Jan 29 06:33:51 2012 +0000
+++ b/sys/kern/vfs_quotactl.c   Sun Jan 29 06:34:57 2012 +0000
@@ -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 @@
                        /* XXX shouldn't this be an error? */
                        continue;
                }
-               error = VFS_QUOTACTL(mp, cmddict, 0/*dummy*/);
+               error = vfs_quotactl_cmd(mp, cmddict);
                if (error) {
                        break;
                }
diff -r a1bdecc4f9b4 -r 08de58454a08 sys/kern/vfs_subr.c
--- a/sys/kern/vfs_subr.c       Sun Jan 29 06:33:51 2012 +0000
+++ b/sys/kern/vfs_subr.c       Sun Jan 29 06:34:57 2012 +0000
@@ -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 @@
 }
 
 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);
        }
diff -r a1bdecc4f9b4 -r 08de58454a08 sys/miscfs/genfs/layer_extern.h
--- a/sys/miscfs/genfs/layer_extern.h   Sun Jan 29 06:33:51 2012 +0000
+++ b/sys/miscfs/genfs/layer_extern.h   Sun Jan 29 06:34:57 2012 +0000
@@ -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 @@
 /* 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 **);
diff -r a1bdecc4f9b4 -r 08de58454a08 sys/miscfs/genfs/layer_vfsops.c
--- a/sys/miscfs/genfs/layer_vfsops.c   Sun Jan 29 06:33:51 2012 +0000
+++ b/sys/miscfs/genfs/layer_vfsops.c   Sun Jan 29 06:34:57 2012 +0000
@@ -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 @@
 }
 
 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
diff -r a1bdecc4f9b4 -r 08de58454a08 sys/sys/mount.h
--- a/sys/sys/mount.h   Sun Jan 29 06:33:51 2012 +0000
+++ b/sys/sys/mount.h   Sun Jan 29 06:34:57 2012 +0000
@@ -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 @@
        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_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##_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 **);          \
diff -r a1bdecc4f9b4 -r 08de58454a08 sys/sys/quotactl.h
--- a/sys/sys/quotactl.h        Sun Jan 29 06:33:51 2012 +0000
+++ b/sys/sys/quotactl.h        Sun Jan 29 06:34:57 2012 +0000
@@ -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_ */
diff -r a1bdecc4f9b4 -r 08de58454a08 sys/ufs/ufs/ufs_extern.h
--- a/sys/ufs/ufs/ufs_extern.h  Sun Jan 29 06:33:51 2012 +0000
+++ b/sys/ufs/ufs/ufs_extern.h  Sun Jan 29 06:34:57 2012 +0000
@@ -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_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_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 */
diff -r a1bdecc4f9b4 -r 08de58454a08 sys/ufs/ufs/ufs_quota.c
--- a/sys/ufs/ufs/ufs_quota.c   Sun Jan 29 06:33:51 2012 +0000
+++ b/sys/ufs/ufs/ufs_quota.c   Sun Jan 29 06:34:57 2012 +0000
@@ -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 @@
 #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 @@
 }
 
 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,



Home | Main Index | Thread Index | Old Index