Source-Changes-HG archive

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

[src/trunk]: src Add a new libquota library, which contains some blocks to bu...



details:   https://anonhg.NetBSD.org/src/rev/65436032f6df
branches:  trunk
changeset: 763552:65436032f6df
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Thu Mar 24 17:05:39 2011 +0000

description:
Add a new libquota library, which contains some blocks to build and/or
parse quota plists; as well as a getfsquota() function to retrieve quotas
for a single id from a single filesystem (whatever filesystem this is:
a local quota-enabled fs or NFS). This is build on functions getufsquota()
(for local filesystems with UFS-like quotas) and getnfsquota();
which are also available to userland programs.
move functions from quota2_subr.c to libquota or libprop as appropriate,
and ajust in-tree quota tools.
move some declarations from kernel headers to either sys/quota.h or
quota/quota.h as appropriate. ufs/ufs/quota.h still installed because
it's needed by other installed ufs headers.
ufs/ufs/quota1.h still installed as a quick&dirty way to get a code
using the old quotactl() to compile (just include ufs/ufs/quota1.h instead of
ufs/ufs/quota.h - old code won't compile without this change and this is
on purpose).
Discussed on tech-kern@ and tech-net@ (long thread, but not much about
libquota itself ...)

diffstat:

 common/include/prop/prop_array.h          |    4 +-
 common/include/prop/prop_dictionary.h     |    8 +-
 common/include/quota/Makefile             |    6 +
 common/include/quota/quota.h              |   61 ++++++
 common/include/quota/quotaprop.h          |   83 ++++++++
 common/lib/libprop/prop_array_util.3      |   15 +-
 common/lib/libprop/prop_array_util.c      |   13 +-
 common/lib/libprop/prop_dictionary_util.3 |   19 +-
 common/lib/libprop/prop_dictionary_util.c |   26 ++-
 common/lib/libquota/Makefile.inc          |    4 +
 common/lib/libquota/quotaprop.c           |  216 ++++++++++++++++++++++
 common/lib/libquota/quotasubr.c           |   54 +++++
 distrib/sets/lists/base/ad.mips64eb       |    6 +-
 distrib/sets/lists/base/ad.mips64el       |    6 +-
 distrib/sets/lists/base/md.amd64          |    4 +-
 distrib/sets/lists/base/md.sparc64        |    4 +-
 distrib/sets/lists/base/mi                |    3 +-
 distrib/sets/lists/base/shl.mi            |    5 +-
 distrib/sets/lists/comp/ad.mips64eb       |   12 +-
 distrib/sets/lists/comp/ad.mips64el       |   12 +-
 distrib/sets/lists/comp/md.amd64          |    8 +-
 distrib/sets/lists/comp/md.sparc64        |    7 +-
 distrib/sets/lists/comp/mi                |    8 +-
 distrib/sets/lists/comp/shl.mi            |    4 +-
 etc/mtree/NetBSD.dist.base                |    3 +-
 include/Makefile                          |    3 +-
 lib/Makefile                              |    3 +-
 lib/libquota/Makefile                     |   17 +
 lib/libquota/getfsquota.c                 |   67 +++++++
 lib/libquota/getnfsquota.c                |  209 ++++++++++++++++++++++
 lib/libquota/getufsquota.c                |  180 +++++++++++++++++++
 lib/libquota/shlib_version                |    5 +
 libexec/rpc.rquotad/Makefile              |   13 +-
 libexec/rpc.rquotad/rquotad.c             |   51 ++--
 share/mk/bsd.README                       |    3 +-
 share/mk/bsd.hostprog.mk                  |    3 +-
 sys/compat/common/vfs_syscalls_50.c       |   61 +++--
 sys/lib/libkern/Makefile.libkern          |    3 +-
 sys/rump/librump/rumpvfs/Makefile.rumpvfs |    4 +-
 sys/sys/quota.h                           |   20 +-
 sys/ufs/files.ufs                         |    3 +-
 sys/ufs/ufs/quota.h                       |   41 ++-
 sys/ufs/ufs/quota1.h                      |   16 +-
 sys/ufs/ufs/quota1_subr.c                 |   43 ++--
 sys/ufs/ufs/quota2.h                      |   42 +++-
 sys/ufs/ufs/quota2_prop.c                 |  275 -----------------------------
 sys/ufs/ufs/quota2_prop.h                 |   47 ----
 sys/ufs/ufs/quota2_subr.c                 |   22 +--
 sys/ufs/ufs/ufs_quota.c                   |   12 +-
 sys/ufs/ufs/ufs_quota1.c                  |   90 ++++++--
 sys/ufs/ufs/ufs_quota2.c                  |   75 +++++++-
 sys/ufs/ufs/ufs_vfsops.c                  |    8 +-
 usr.bin/quota/Makefile                    |   12 +-
 usr.bin/quota/getvfsquota.c               |   38 ++-
 usr.bin/quota/getvfsquota.h               |    6 +-
 usr.bin/quota/printquota.c                |   17 +-
 usr.bin/quota/printquota.h                |    3 +-
 usr.bin/quota/quota.c                     |  225 +++++------------------
 usr.bin/quota/quotautil.c                 |   23 +-
 usr.bin/quota/quotautil.h                 |    3 +-
 usr.sbin/edquota/Makefile                 |    8 +-
 usr.sbin/edquota/edquota.c                |  283 +++++++++++++++--------------
 usr.sbin/quotactl/quotactl.c              |    8 +-
 usr.sbin/quotaon/Makefile                 |   11 +-
 usr.sbin/quotaon/quotaon.c                |   16 +-
 usr.sbin/repquota/Makefile                |    8 +-
 usr.sbin/repquota/repquota.c              |  250 ++++++++++++++-----------
 67 files changed, 1790 insertions(+), 1028 deletions(-)

diffs (truncated from 5022 to 300 lines):

diff -r 17380dec7b2e -r 65436032f6df common/include/prop/prop_array.h
--- a/common/include/prop/prop_array.h  Thu Mar 24 17:00:31 2011 +0000
+++ b/common/include/prop/prop_array.h  Thu Mar 24 17:05:39 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_array.h,v 1.11 2011/01/20 11:17:58 bouyer Exp $    */
+/*     $NetBSD: prop_array.h,v 1.12 2011/03/24 17:05:39 bouyer Exp $    */
 
 /*-
  * Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
@@ -154,6 +154,8 @@
                                                   unsigned int,
                                                   const char *);
 
+bool           prop_array_add_and_rel(prop_array_t, prop_object_t);
+
 __END_DECLS
 
 #endif /* _PROPLIB_PROP_ARRAY_H_ */
diff -r 17380dec7b2e -r 65436032f6df common/include/prop/prop_dictionary.h
--- a/common/include/prop/prop_dictionary.h     Thu Mar 24 17:00:31 2011 +0000
+++ b/common/include/prop/prop_dictionary.h     Thu Mar 24 17:05:39 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_dictionary.h,v 1.12 2011/01/20 11:17:58 bouyer Exp $      */
+/*     $NetBSD: prop_dictionary.h,v 1.13 2011/03/24 17:05:39 bouyer Exp $      */
 
 /*-
  * Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
@@ -115,6 +115,8 @@
  * Utility routines to make it more convenient to work with values
  * stored in dictionaries.
  */
+bool           prop_dictionary_get_dict(prop_dictionary_t, const char *,
+                                        prop_dictionary_t *);
 bool           prop_dictionary_get_bool(prop_dictionary_t, const char *,
                                         bool *);
 bool           prop_dictionary_set_bool(prop_dictionary_t, const char *,
@@ -168,6 +170,10 @@
                                                   const char *,
                                                   const char *);
 
+bool           prop_dictionary_set_and_rel(prop_dictionary_t,
+                                                  const char *,
+                                                  prop_object_t);
+
 __END_DECLS
 
 #endif /* _PROPLIB_PROP_DICTIONARY_H_ */
diff -r 17380dec7b2e -r 65436032f6df common/include/quota/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/common/include/quota/Makefile     Thu Mar 24 17:05:39 2011 +0000
@@ -0,0 +1,6 @@
+#      $NetBSD: Makefile,v 1.1 2011/03/24 17:05:39 bouyer Exp $
+
+INCS=  quotaprop.h quota.h
+INCSDIR=       /usr/include/quota
+
+.include <bsd.prog.mk>
diff -r 17380dec7b2e -r 65436032f6df common/include/quota/quota.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/common/include/quota/quota.h      Thu Mar 24 17:05:39 2011 +0000
@@ -0,0 +1,61 @@
+/* $NetBSD: quota.h,v 1.1 2011/03/24 17:05:39 bouyer Exp $ */
+/*-
+  * Copyright (c) 2010 Manuel Bouyer
+  * All rights reserved.
+  * This software is distributed under the following condiions
+  * compliant with the NetBSD foundation policy.
+  *
+  * Redistribution and use in source and binary forms, with or without
+  * modification, are permitted provided that the following conditions
+  * are met:
+  * 1. Redistributions of source code must retain the above copyright
+  *    notice, this list of conditions and the following disclaimer.
+  * 2. Redistributions in binary form must reproduce the above copyright
+  *    notice, this list of conditions and the following disclaimer in the
+  *    documentation and/or other materials provided with the distribution.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+  * POSSIBILITY OF SUCH DAMAGE.
+  */
+
+#ifndef _QUOTA_QUOTA_H
+#define _QUOTA_QUOTA_H
+#include <sys/types.h>
+#include <quota/quotaprop.h>
+
+/* check a quota usage against limits (assumes UFS semantic) */
+int quota_check_limit(uint64_t, uint64_t,  uint64_t, uint64_t, time_t, time_t);
+/* return values for above */
+#define QL_S_ALLOW_OK  0x00 /* below soft limit */
+#define QL_S_ALLOW_SOFT        0x01 /* over soft limit */
+#define QL_S_DENY_GRACE        0x02 /* over soft limit, grace time expired */
+#define QL_S_DENY_HARD 0x03 /* over hard limit */
+ 
+#define QL_F_CROSS     0x80 /* crossing soft limit */
+
+#define QL_STATUS(x)   ((x) & 0x0f)
+#define QL_FLAGS(x)    ((x) & 0xf0)
+
+/*
+ * retrieve quotas with ufs semantics from vfs, for the given id and class.
+ * second argument points to a struct ufs_quota_entry array of QUOTA_NLIMITS
+ * elements.
+ */
+int getufsquota(const char *, struct ufs_quota_entry *, uid_t, const char *);
+
+/* same as above, but for NFS */
+int getnfsquota(const char *, struct ufs_quota_entry *, uid_t, const char *);
+
+/* call one of the above, if appropriate, after a statvfs(2) */
+int getfsquota(const char *, struct ufs_quota_entry *, uid_t, const char *);
+
+#endif /* _QUOTA_QUOTA_H */
diff -r 17380dec7b2e -r 65436032f6df common/include/quota/quotaprop.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/common/include/quota/quotaprop.h  Thu Mar 24 17:05:39 2011 +0000
@@ -0,0 +1,83 @@
+/* $NetBSD: quotaprop.h,v 1.1 2011/03/24 17:05:39 bouyer Exp $ */
+/*-
+  * Copyright (c) 2010 Manuel Bouyer
+  * All rights reserved.
+  * This software is distributed under the following condiions
+  * compliant with the NetBSD foundation policy.
+  *
+  * Redistribution and use in source and binary forms, with or without
+  * modification, are permitted provided that the following conditions
+  * are met:
+  * 1. Redistributions of source code must retain the above copyright
+  *    notice, this list of conditions and the following disclaimer.
+  * 2. Redistributions in binary form must reproduce the above copyright
+  *    notice, this list of conditions and the following disclaimer in the
+  *    documentation and/or other materials provided with the distribution.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+  * POSSIBILITY OF SUCH DAMAGE.
+  */
+
+#ifndef _QUOTA_QUOTAPROP_H
+#define _QUOTA_QUOTAPROP_H
+#include <prop/proplib.h>
+#include <sys/quota.h>
+
+int quotaprop_dict_get_uint64(prop_dictionary_t, uint64_t[],
+    const char *[], int, bool);
+int proptoquota64(prop_dictionary_t, uint64_t *[], const char *[], int,
+    const char *[], int);
+
+int quota_get_cmds(prop_dictionary_t, prop_array_t *);
+prop_dictionary_t quota_prop_create(void);
+bool quota_prop_add_command(prop_array_t, const char *, const char *,
+    prop_array_t);
+
+prop_dictionary_t limits64toprop(uint64_t[], const char *[], int);
+prop_dictionary_t quota64toprop(uid_t, int, uint64_t *[], const char *[], int,
+    const char *[], int);
+
+/* structure used to describe a UFS-like quota entry */
+struct ufs_quota_entry {
+        uint64_t ufsqe_hardlimit; /* absolute limit */
+       uint64_t ufsqe_softlimit; /* overflowable limit */
+       uint64_t ufsqe_cur; /* current usage */
+       int64_t ufsqe_time; /* grace expiration date for softlimit overflow */
+       int64_t ufsqe_grace; /* allowed time for softlimit overflow */
+};
+
+/* array of strings for the above */
+#define UFS_QUOTA_ENTRY_NAMES \
+    {QUOTADICT_LIMIT_HARD, \
+     QUOTADICT_LIMIT_SOFT, \
+     QUOTADICT_LIMIT_USAGE, \
+     QUOTADICT_LIMIT_ETIME, \
+     QUOTADICT_LIMIT_GTIME \
+    }
+#define UFS_QUOTA_NENTRIES 5
+extern const char *ufs_quota_entry_names[];
+
+/* array of strings for limit types and associated #define */
+extern const char *ufs_quota_limit_names[];
+#define QUOTA_LIMIT_BLOCK 0
+#define QUOTA_LIMIT_FILE 1
+#define QUOTA_NLIMITS 2
+#define QUOTA_LIMIT_NAMES { QUOTADICT_LTYPE_BLOCK, QUOTADICT_LTYPE_FILE }
+
+/* array of strings for quota class and associated #define */
+extern const char *ufs_quota_class_names[];
+#define QUOTA_CLASS_USER 0
+#define QUOTA_CLASS_GROUP 1
+#define QUOTA_NCLASS 2
+#define QUOTA_CLASS_NAMES { QUOTADICT_CLASS_USER, QUOTADICT_CLASS_GROUP }
+
+#endif /* _QUOTA_QUOTAPROP_H */
diff -r 17380dec7b2e -r 65436032f6df common/lib/libprop/prop_array_util.3
--- a/common/lib/libprop/prop_array_util.3      Thu Mar 24 17:00:31 2011 +0000
+++ b/common/lib/libprop/prop_array_util.3      Thu Mar 24 17:05:39 2011 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: prop_array_util.3,v 1.4 2011/01/20 10:42:19 wiz Exp $
+.\"    $NetBSD: prop_array_util.3,v 1.5 2011/03/24 17:05:39 bouyer Exp $
 .\"
 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd June 2, 2008
+.Dd March 12, 2011
 .Dt PROP_ARRAY_UTIL 3
 .Os
 .Sh NAME
@@ -61,7 +61,8 @@
 .Nm prop_array_get_cstring ,
 .Nm prop_array_set_cstring ,
 .Nm prop_array_get_cstring_nocopy ,
-.Nm prop_array_set_cstring_nocopy
+.Nm prop_array_set_cstring_nocopy,
+.Nm prop_array_add_and_rel
 .Sh LIBRARY
 .Lb libprop
 .Sh SYNOPSIS
@@ -163,6 +164,9 @@
 .Ft bool
 .Fn prop_array_set_cstring_nocopy "prop_array_t dict" \
     "unsigned int indx" "const char *strp"
+.Ft bool
+.Fn prop_array_add_and_rel "prop_array_t dict" \
+    "prop_object_t obj"
 .Sh DESCRIPTION
 The
 .Nm prop_array_util
@@ -190,6 +194,11 @@
 See
 .Xr prop_string 3
 for more information.
+.Pp
+The
+.Fn prop_array_add_and_rel
+function adds the object to the end of the array and release it.
+The object is also released on failure.
 .Sh RETURN VALUES
 The
 .Nm prop_array_util
diff -r 17380dec7b2e -r 65436032f6df common/lib/libprop/prop_array_util.c
--- a/common/lib/libprop/prop_array_util.c      Thu Mar 24 17:00:31 2011 +0000
+++ b/common/lib/libprop/prop_array_util.c      Thu Mar 24 17:05:39 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_array_util.c,v 1.2 2008/09/11 13:15:13 haad Exp $ */
+/*     $NetBSD: prop_array_util.c,v 1.3 2011/03/24 17:05:39 bouyer Exp $       */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -238,3 +238,14 @@
 TEMPLATE(_nocopy,const)
 
 #undef TEMPLATE
+
+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;
+}
diff -r 17380dec7b2e -r 65436032f6df common/lib/libprop/prop_dictionary_util.3
--- a/common/lib/libprop/prop_dictionary_util.3 Thu Mar 24 17:00:31 2011 +0000
+++ b/common/lib/libprop/prop_dictionary_util.3 Thu Mar 24 17:05:39 2011 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: prop_dictionary_util.3,v 1.4 2008/06/02 09:27:04 haad Exp $
+.\"    $NetBSD: prop_dictionary_util.3,v 1.5 2011/03/24 17:05:39 bouyer Exp $
 .\"
 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,11 +27,12 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 25, 2006
+.Dd March 12, 2011
 .Dt PROP_DICTIONARY_UTIL 3
 .Os



Home | Main Index | Thread Index | Old Index