Source-Changes-HG archive

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

[src/bouyer-quota2]: src Add support for quotactl("getall") command, and conv...



details:   https://anonhg.NetBSD.org/src/rev/69df40ebb73b
branches:  bouyer-quota2
changeset: 761072:69df40ebb73b
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Fri Jan 21 16:58:06 2011 +0000

description:
Add support for quotactl("getall") command, and convert repquota to new
world.

diffstat:

 sys/ufs/ufs/quota2.h         |    3 +-
 sys/ufs/ufs/quota2_prop.c    |   14 +-
 sys/ufs/ufs/quota2_prop.h    |    3 +-
 sys/ufs/ufs/ufs_quota.c      |   85 +++++++--
 sys/ufs/ufs/ufs_quota.h      |    9 +-
 sys/ufs/ufs/ufs_quota2.c     |  218 +++++++++++++++++++++----
 usr.bin/quota/Makefile       |    8 +-
 usr.bin/quota/printquota.c   |  116 ++++++++++++++
 usr.bin/quota/printquota.h   |    4 +
 usr.bin/quota/quota.1        |    3 +-
 usr.bin/quota/quota.c        |  294 ++++++++++++++---------------------
 usr.sbin/repquota/Makefile   |   13 +-
 usr.sbin/repquota/repquota.8 |   31 +-
 usr.sbin/repquota/repquota.c |  353 ++++++++++++++++++++++++++++++------------
 14 files changed, 782 insertions(+), 372 deletions(-)

diffs (truncated from 1705 to 300 lines):

diff -r 61ca6d2ac6ba -r 69df40ebb73b sys/ufs/ufs/quota2.h
--- a/sys/ufs/ufs/quota2.h      Fri Jan 21 16:36:57 2011 +0000
+++ b/sys/ufs/ufs/quota2.h      Fri Jan 21 16:58:06 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2.h,v 1.1.2.1 2011/01/20 14:25:03 bouyer Exp $ */
+/* $NetBSD: quota2.h,v 1.1.2.2 2011/01/21 16:58:06 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -97,5 +97,4 @@
 /* quota2_subr.c */
 void quota2_addfreeq2e(struct quota2_header *, void *, uint64_t, uint64_t, int);
 void quota2_create_blk0(uint64_t, void *bp, int, int, int);
-
 #endif /*  _UFS_UFS_QUOTA2_H_ */
diff -r 61ca6d2ac6ba -r 69df40ebb73b sys/ufs/ufs/quota2_prop.c
--- a/sys/ufs/ufs/quota2_prop.c Fri Jan 21 16:36:57 2011 +0000
+++ b/sys/ufs/ufs/quota2_prop.c Fri Jan 21 16:58:06 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2_prop.c,v 1.1.2.1 2011/01/20 14:25:03 bouyer Exp $ */
+/* $NetBSD: quota2_prop.c,v 1.1.2.2 2011/01/21 16:58:06 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -95,8 +95,6 @@
 {
        int i, error;
        prop_dictionary_t val;
-       if (!prop_dictionary_get_uint32(data, "id", &q2e->q2e_uid))
-               return EINVAL;
        for (i = 0; i < NQ2V; i++) {
                val = prop_dictionary_get_dict(data, quota2_valnames[i]);
                if (val == NULL)
@@ -135,6 +133,16 @@
        return 0;
 }
 
+bool
+prop_array_add_and_rel(prop_array_t array, prop_object_t po)
+{
+       bool ret;
+       if (po == NULL)
+               return false;
+       ret = prop_array_add(array, po);
+       prop_object_release(po);
+       return ret;
+}
 
 bool
 prop_dictionary_set_and_rel(prop_dictionary_t dict, const char *key,
diff -r 61ca6d2ac6ba -r 69df40ebb73b sys/ufs/ufs/quota2_prop.h
--- a/sys/ufs/ufs/quota2_prop.h Fri Jan 21 16:36:57 2011 +0000
+++ b/sys/ufs/ufs/quota2_prop.h Fri Jan 21 16:58:06 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2_prop.h,v 1.1.2.1 2011/01/20 14:25:03 bouyer Exp $ */
+/* $NetBSD: quota2_prop.h,v 1.1.2.2 2011/01/21 16:58:06 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -36,6 +36,7 @@
 int quota2_dict_get_q2e_usage(prop_dictionary_t, struct quota2_entry *);
 int quota2_get_cmds(prop_dictionary_t, prop_array_t *);
 
+bool prop_array_add_and_rel(prop_array_t, prop_object_t);
 bool prop_dictionary_set_and_rel(prop_dictionary_t, const char *,
      prop_object_t);
 prop_dictionary_t quota2_prop_create(void);
diff -r 61ca6d2ac6ba -r 69df40ebb73b sys/ufs/ufs/ufs_quota.c
--- a/sys/ufs/ufs/ufs_quota.c   Fri Jan 21 16:36:57 2011 +0000
+++ b/sys/ufs/ufs/ufs_quota.c   Fri Jan 21 16:58:06 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_quota.c,v 1.68.4.1 2011/01/20 14:25:03 bouyer Exp $        */
+/*     $NetBSD: ufs_quota.c,v 1.68.4.2 2011/01/21 16:58:06 bouyer 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.68.4.1 2011/01/20 14:25:03 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.68.4.2 2011/01/21 16:58:06 bouyer Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -57,9 +57,13 @@
 #include <ufs/ufs/ufs_quota.h>
 #include <ufs/ufs/quota2_prop.h>
 
+kmutex_t dqlock;
+kcondvar_t dqcv;
 
 static int quota_handle_cmd_get(struct mount *, struct lwp *,
-    prop_dictionary_t, const char *, prop_array_t);
+    prop_dictionary_t, int, prop_array_t);
+static int quota_handle_cmd_getall(struct mount *, struct lwp *,
+    prop_dictionary_t, int, prop_array_t);
 /*
  * Initialize the quota fields of an inode.
  */
@@ -126,11 +130,18 @@
        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, "user")) {
+               q2type = USRQUOTA;
+       } else if (!strcmp(type, "group")) {
+               q2type = GRPQUOTA;
+       } else
+               return EOPNOTSUPP;
        datas = prop_dictionary_get(cmddict, "data");
        if (datas == NULL || prop_object_type(datas) != PROP_TYPE_ARRAY)
                return EINVAL;
@@ -139,12 +150,17 @@
        prop_dictionary_remove(cmddict, "data"); /* prepare for return */
 
        if (strcmp(cmd, "get") == 0) {
-               error = quota_handle_cmd_get(mp, l, cmddict, type, datas);
+               error = quota_handle_cmd_get(mp, l, cmddict, q2type, datas);
                goto end;
        }
-       if (!prop_dictionary_set_int8(cmddict, "return", EOPNOTSUPP))
-               error = ENOMEM;
+       if (strcmp(cmd, "getall") == 0) {
+               error = quota_handle_cmd_getall(mp, l, cmddict, q2type, datas);
+               goto end;
+       }
+       error = EOPNOTSUPP;
 end:
+       error = (prop_dictionary_set_int8(cmddict, "return",
+           error) ? 0 : ENOMEM);
        prop_object_release(datas);
        return error;
 }
@@ -161,7 +177,7 @@
 
 static int 
 quota_handle_cmd_get(struct mount *mp, struct lwp *l, 
-    prop_dictionary_t cmddict, const char *type, prop_array_t datas)
+    prop_dictionary_t cmddict, int type, prop_array_t datas)
 {
        prop_array_t replies;
        prop_object_iterator_t iter;
@@ -172,19 +188,16 @@
        const char *idstr;
 
        if ((ump->um_flags & (UFS_QUOTA|UFS_QUOTA2)) == 0)
-               return (prop_dictionary_set_int8(cmddict, "return",
-                   EOPNOTSUPP) ? 0 : ENOMEM);
+               return EOPNOTSUPP;
        
        replies = prop_array_create();
        if (replies == NULL)
-               return (prop_dictionary_set_int8(cmddict, "return", ENOMEM) ?
-                   0 : ENOMEM);
+               return ENOMEM;
 
        iter = prop_array_iterator(datas);
        if (iter == NULL) {
                prop_object_release(replies);
-               return (prop_dictionary_set_int8(cmddict, "return", ENOMEM) ?
-                   0 : ENOMEM);
+               return ENOMEM;
        }
        while ((data = prop_object_iterator_next(iter)) != NULL) {
                if (!prop_dictionary_get_uint32(data, "id", &id)) {
@@ -200,8 +213,6 @@
                if (error == EPERM)
                        continue;
                if (error != 0) {
-                       error = (prop_dictionary_set_int8(cmddict, "return",
-                           error) ? 0 : ENOMEM);
                        prop_object_release(replies);
                        return error;
                }
@@ -219,18 +230,50 @@
                        panic("quota_handle_cmd_get: no support ?");
                
                if (error && error != ENOENT) {
-                       error = (prop_dictionary_set_int8(cmddict, "return",
-                           error) ? 0 : ENOMEM);
                        prop_object_release(replies);
                        return error;
                }
        }
        if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) {
-               error = (prop_dictionary_set_int8(cmddict, "return",
-                   ENOMEM) ? 0 : ENOMEM);
+               error = ENOMEM;
        } else {
-               error = (prop_dictionary_set_int8(cmddict, "return", 0) ?
-                   0 : ENOMEM);
+               error = 0;
+       }
+       return error;
+}
+
+static int 
+quota_handle_cmd_getall(struct mount *mp, struct lwp *l, 
+    prop_dictionary_t cmddict, int type, prop_array_t datas)
+{
+       prop_array_t replies;
+       struct ufsmount *ump = VFSTOUFS(mp);
+       int error;
+
+       if ((ump->um_flags & UFS_QUOTA2) == 0)
+               return EOPNOTSUPP;
+       
+       error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
+           KAUTH_REQ_SYSTEM_FS_QUOTA_GET, mp, NULL, NULL);
+       if (error)
+               return error;
+               
+       replies = prop_array_create();
+       if (replies == NULL)
+               return ENOMEM;
+
+#ifdef QUOTA2
+       if (ump->um_flags & UFS_QUOTA2) {
+               mutex_enter(&dqlock);
+               error = quota2_handle_cmd_getall(ump, type, replies);
+               mutex_exit(&dqlock);
+       } else
+#endif
+               panic("quota_handle_cmd_getall: no support ?");
+       if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) {
+               error = ENOMEM;
+       } else {
+               error = 0;
        }
        return error;
 }
diff -r 61ca6d2ac6ba -r 69df40ebb73b sys/ufs/ufs/ufs_quota.h
--- a/sys/ufs/ufs/ufs_quota.h   Fri Jan 21 16:36:57 2011 +0000
+++ b/sys/ufs/ufs/ufs_quota.h   Fri Jan 21 16:58:06 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_quota.h,v 1.1.2.1 2011/01/20 14:25:03 bouyer Exp $ */
+/*     $NetBSD: ufs_quota.h,v 1.1.2.2 2011/01/21 16:58:06 bouyer Exp $ */
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -96,8 +96,8 @@
  */
 #define        NODQUOT         NULL
 
-static kmutex_t dqlock;
-static kcondvar_t dqcv;
+extern kmutex_t dqlock;
+extern kcondvar_t dqcv;
 /*
  * Quota name to error message mapping.
  */
@@ -128,8 +128,9 @@
 
 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 *, const char *, int, int,
+int quota2_handle_cmd_get(struct ufsmount *, int, int, int,
     prop_array_t);
+int quota2_handle_cmd_getall(struct ufsmount *, int, prop_array_t);
 int q2sync(struct mount *);
 int dq2get(struct vnode *, u_long, struct ufsmount *, int, struct dquot *);
 int dq2sync(struct vnode *, struct dquot *);
diff -r 61ca6d2ac6ba -r 69df40ebb73b sys/ufs/ufs/ufs_quota2.c
--- a/sys/ufs/ufs/ufs_quota2.c  Fri Jan 21 16:36:57 2011 +0000
+++ b/sys/ufs/ufs/ufs_quota2.c  Fri Jan 21 16:58:06 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.1.2.1 2011/01/20 14:25:03 bouyer Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.1.2.2 2011/01/21 16:58:06 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -28,7 +28,7 @@
   */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.1 2011/01/20 14:25:03 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.2 2011/01/21 16:58:06 bouyer Exp $");
 
 #include <sys/buf.h>
 #include <sys/param.h>
@@ -58,6 +58,9 @@
     struct quota2_header **, int);
 static int getq2e(struct ufsmount *, int, daddr_t, int, struct buf **,
     struct quota2_entry **, int);
+static int quota2_walk_list(struct ufsmount *, struct buf *, int,
+    uint64_t *, int, void *,
+    int (*func)(struct ufsmount *, uint64_t *, struct quota2_entry *, uint64_t, void *));
 
 static int
 getq2h(struct ufsmount *ump, int type,
@@ -107,6 +110,80 @@
        *bpp = bp;
        return 0;



Home | Main Index | Thread Index | Old Index