Source-Changes-HG archive

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

[src/trunk]: src/lib/libquota Improve how quota_open() works and generally im...



details:   https://anonhg.NetBSD.org/src/rev/bf7d3a82517c
branches:  trunk
changeset: 773044:bf7d3a82517c
user:      dholland <dholland%NetBSD.org@localhost>
date:      Wed Jan 25 17:43:37 2012 +0000

description:
Improve how quota_open() works and generally improve function
dispatching. Allow access to the quota files via the oldfiles code if
quotaon hasn't run yet. Change the latter so it calls getfsent() up
front (and only once) to make it easier to avoid whacking caller
state.

diffstat:

 lib/libquota/quota_cursor.c   |   25 ++-
 lib/libquota/quota_delete.c   |   18 ++-
 lib/libquota/quota_get.c      |   20 ++-
 lib/libquota/quota_oldfiles.c |  259 ++++++++++++++++++++++++++++++++---------
 lib/libquota/quota_open.c     |   50 ++++---
 lib/libquota/quota_put.c      |   18 ++-
 lib/libquota/quota_schema.c   |  105 +++++++++++++++-
 lib/libquota/quotapvt.h       |   12 +-
 8 files changed, 399 insertions(+), 108 deletions(-)

diffs (truncated from 814 to 300 lines):

diff -r 0789ba8e6124 -r bf7d3a82517c lib/libquota/quota_cursor.c
--- a/lib/libquota/quota_cursor.c       Wed Jan 25 17:38:09 2012 +0000
+++ b/lib/libquota/quota_cursor.c       Wed Jan 25 17:43:37 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: quota_cursor.c,v 1.3 2012/01/09 15:41:58 dholland Exp $        */
+/*     $NetBSD: quota_cursor.c,v 1.4 2012/01/25 17:43:37 dholland Exp $        */
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: quota_cursor.c,v 1.3 2012/01/09 15:41:58 dholland Exp $");
+__RCSID("$NetBSD: quota_cursor.c,v 1.4 2012/01/25 17:43:37 dholland Exp $");
 
 #include <stdlib.h>
 #include <errno.h>
@@ -44,20 +44,31 @@
        int8_t version;
        int serrno;
 
-       if (qh->qh_isnfs) {
+       switch (qh->qh_mode) {
+           case QUOTA_MODE_NFS:
                errno = EOPNOTSUPP;
                return NULL;
-       }
+
+           case QUOTA_MODE_PROPLIB:
+               if (__quota_proplib_getversion(qh, &version)) {
+                       return NULL;
+               }
+               break;
 
-       if (__quota_proplib_getversion(qh, &version)) {
-               return NULL;
+           case QUOTA_MODE_OLDFILES:
+               version = 1;
+               break;
+
+           default:
+               errno = EINVAL;
+               break;
        }
 
        /*
         * For the time being at least the version 1 kernel code
         * cannot do cursors.
         */
-       if (version == 1 && !qh->qh_hasoldfiles) {
+       if (version == 1 && !qh->qh_oldfilesopen) {
                if (__quota_oldfiles_initialize(qh)) {
                        return NULL;
                }
diff -r 0789ba8e6124 -r bf7d3a82517c lib/libquota/quota_delete.c
--- a/lib/libquota/quota_delete.c       Wed Jan 25 17:38:09 2012 +0000
+++ b/lib/libquota/quota_delete.c       Wed Jan 25 17:43:37 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: quota_delete.c,v 1.2 2012/01/09 15:43:19 dholland Exp $        */
+/*     $NetBSD: quota_delete.c,v 1.3 2012/01/25 17:43:37 dholland Exp $        */
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: quota_delete.c,v 1.2 2012/01/09 15:43:19 dholland Exp $");
+__RCSID("$NetBSD: quota_delete.c,v 1.3 2012/01/25 17:43:37 dholland Exp $");
 
 #include <errno.h>
 
@@ -39,10 +39,20 @@
 int
 quota_delete(struct quotahandle *qh, const struct quotakey *qk)
 {
-       if (qh->qh_isnfs) {
+       switch (qh->qh_mode) {
+           case QUOTA_MODE_NFS:
                errno = EOPNOTSUPP;
                return -1;
-       } else {
+
+           case QUOTA_MODE_PROPLIB:
                return __quota_proplib_delete(qh, qk);
+
+           case QUOTA_MODE_OLDFILES:
+               return __quota_oldfiles_delete(qh, qk);
+
+           default:
+               break;
        }
+       errno = EINVAL;
+       return -1;
 }
diff -r 0789ba8e6124 -r bf7d3a82517c lib/libquota/quota_get.c
--- a/lib/libquota/quota_get.c  Wed Jan 25 17:38:09 2012 +0000
+++ b/lib/libquota/quota_get.c  Wed Jan 25 17:43:37 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: quota_get.c,v 1.3 2012/01/09 15:29:55 dholland Exp $   */
+/*     $NetBSD: quota_get.c,v 1.4 2012/01/25 17:43:37 dholland Exp $   */
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,9 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: quota_get.c,v 1.3 2012/01/09 15:29:55 dholland Exp $");
+__RCSID("$NetBSD: quota_get.c,v 1.4 2012/01/25 17:43:37 dholland Exp $");
+
+#include <errno.h>
 
 #include <quota.h>
 #include "quotapvt.h"
@@ -47,9 +49,19 @@
 int
 quota_get(struct quotahandle *qh, const struct quotakey *qk, struct quotaval *qv)
 {
-       if (qh->qh_isnfs) {
+       switch (qh->qh_mode) {
+           case QUOTA_MODE_NFS:
                return __quota_nfs_get(qh, qk, qv);
-       } else {
+
+           case QUOTA_MODE_PROPLIB:
                return __quota_proplib_get(qh, qk, qv);
+
+           case QUOTA_MODE_OLDFILES:
+               return __quota_oldfiles_get(qh, qk, qv);
+
+           default:
+               break;
        }
+       errno = EINVAL;
+       return -1;
 }
diff -r 0789ba8e6124 -r bf7d3a82517c lib/libquota/quota_oldfiles.c
--- a/lib/libquota/quota_oldfiles.c     Wed Jan 25 17:38:09 2012 +0000
+++ b/lib/libquota/quota_oldfiles.c     Wed Jan 25 17:43:37 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: quota_oldfiles.c,v 1.2 2012/01/09 15:45:19 dholland Exp $      */
+/*     $NetBSD: quota_oldfiles.c,v 1.3 2012/01/25 17:43:37 dholland Exp $      */
 
 /*
  * Copyright (c) 1980, 1990, 1993
@@ -49,6 +49,14 @@
 #include <quota.h>
 #include "quotapvt.h"
 
+struct oldfiles_fstabentry {
+       char *ofe_mountpoint;
+       int ofe_hasuserquota;
+       int ofe_hasgroupquota;
+       char *ofe_userquotafile;
+       char *ofe_groupquotafile;
+};
+
 struct oldfiles_quotacursor {
        unsigned oqc_doingusers;
        unsigned oqc_doinggroups;
@@ -63,6 +71,172 @@
        unsigned oqc_didblocks;
 };
 
+static struct oldfiles_fstabentry *__quota_oldfiles_fstab;
+static unsigned __quota_oldfiles_numfstab;
+static unsigned __quota_oldfiles_maxfstab;
+static int __quota_oldfiles_fstab_loaded;
+
+static const struct oldfiles_fstabentry *
+__quota_oldfiles_find_fstabentry(const char *mountpoint)
+{
+       unsigned i;
+
+       for (i = 0; i < __quota_oldfiles_numfstab; i++) {
+               if (!strcmp(mountpoint,
+                           __quota_oldfiles_fstab[i].ofe_mountpoint)) {
+                       return &__quota_oldfiles_fstab[i];
+               }
+       }
+       return NULL;
+}
+
+static int
+__quota_oldfiles_add_fstabentry(struct oldfiles_fstabentry *ofe)
+{
+       unsigned newmax;
+       struct oldfiles_fstabentry *newptr;
+
+       if (__quota_oldfiles_numfstab + 1 >= __quota_oldfiles_maxfstab) {
+               if (__quota_oldfiles_maxfstab == 0) {
+                       newmax = 4;
+               } else {
+                       newmax = __quota_oldfiles_maxfstab * 2;
+               }
+               newptr = realloc(__quota_oldfiles_fstab,
+                                newmax * sizeof(__quota_oldfiles_fstab[0]));
+               if (newptr == NULL) {
+                       return -1;
+               }
+               __quota_oldfiles_maxfstab = newmax;
+               __quota_oldfiles_fstab = newptr;
+       }
+
+       __quota_oldfiles_fstab[__quota_oldfiles_numfstab++] = *ofe;
+       return 0;
+}
+
+static int
+__quota_oldfiles_fill_fstabentry(const struct fstab *fs,
+                                struct oldfiles_fstabentry *ofe)
+{
+       char buf[sizeof(fs->fs_mntops)];
+       char *opt, *state, *s;
+       int serrno;
+       int ret = 0;
+
+       /*
+        * Inspect the mount options to find the quota files.
+        * XXX this info should be gotten from the kernel.
+        *
+        * The options are:
+        *    userquota[=path]          enable user quotas
+        *    groupquota[=path]         enable group quotas
+        */
+
+       ofe->ofe_mountpoint = NULL;
+       ofe->ofe_hasuserquota = ofe->ofe_hasgroupquota = 0;
+       ofe->ofe_userquotafile = ofe->ofe_groupquotafile = NULL;
+
+       strlcpy(buf, fs->fs_mntops, sizeof(buf));
+       for (opt = strtok_r(buf, ",", &state);
+            opt != NULL;
+            opt = strtok_r(NULL, ",", &state)) {
+               s = strchr(opt, '=');
+               if (s != NULL) {
+                       *(s++) = '\0';
+               }
+               if (!strcmp(opt, "userquota")) {
+                       ret = 1;
+                       ofe->ofe_hasuserquota = 1;
+                       if (s != NULL) {
+                               ofe->ofe_userquotafile = strdup(s);
+                               if (ofe->ofe_userquotafile == NULL) {
+                                       goto fail;
+                               }
+                       }
+               } else if (!strcmp(opt, "groupquota")) {
+                       ret = 1;
+                       ofe->ofe_hasgroupquota = 1;
+                       if (s != NULL) {
+                               ofe->ofe_groupquotafile = strdup(s);
+                               if (ofe->ofe_groupquotafile == NULL) {
+                                       goto fail;
+                               }
+                       }
+               }
+       }
+
+       if (ret == 1) {
+               ofe->ofe_mountpoint = strdup(fs->fs_file);
+               if (ofe->ofe_mountpoint == NULL) {
+                       goto fail;
+               }
+       }
+
+       return ret;
+
+fail:
+       serrno = errno;
+       if (ofe->ofe_mountpoint != NULL) {
+               free(ofe->ofe_mountpoint);
+       }
+       if (ofe->ofe_groupquotafile != NULL) {
+               free(ofe->ofe_groupquotafile);
+       }
+       if (ofe->ofe_userquotafile != NULL) {
+               free(ofe->ofe_userquotafile);
+       }
+       errno = serrno;
+       return -1;
+}
+
+void
+__quota_oldfiles_load_fstab(void)
+{
+       struct oldfiles_fstabentry ofe;
+       struct fstab *fs;
+       int result;
+
+       if (__quota_oldfiles_fstab_loaded) {
+               return;
+       }
+
+       /*
+        * XXX: should be able to handle ext2fs quota1 files too
+        *
+        * XXX: should use getfsent_r(), but there isn't one.



Home | Main Index | Thread Index | Old Index