Source-Changes-HG archive

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

[src/trunk]: src/lib/libquota Implement fallback direct access to quota1-type...



details:   https://anonhg.NetBSD.org/src/rev/c691c2627ec2
branches:  trunk
changeset: 772611:c691c2627ec2
user:      dholland <dholland%NetBSD.org@localhost>
date:      Mon Jan 09 15:41:58 2012 +0000

description:
Implement fallback direct access to quota1-type quota files.
Uses (mostly) code from repquota. Add some missing pieces that
weren't in repquota.

Use the direct file access code for cursors if proplib reports the
quota version is 1.

diffstat:

 lib/libquota/Makefile         |    3 +-
 lib/libquota/quota_cursor.c   |  109 +++++++-
 lib/libquota/quota_oldfiles.c |  530 ++++++++++++++++++++++++++++++++++++++++++
 lib/libquota/quota_open.c     |   15 +-
 lib/libquota/quota_proplib.c  |    6 +-
 lib/libquota/quotapvt.h       |   34 ++-
 6 files changed, 672 insertions(+), 25 deletions(-)

diffs (truncated from 869 to 300 lines):

diff -r 7d63d8294124 -r c691c2627ec2 lib/libquota/Makefile
--- a/lib/libquota/Makefile     Mon Jan 09 15:41:21 2012 +0000
+++ b/lib/libquota/Makefile     Mon Jan 09 15:41:58 2012 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.4 2012/01/09 15:29:55 dholland Exp $
+#      $NetBSD: Makefile,v 1.5 2012/01/09 15:41:58 dholland Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/4/93
 
 .include <bsd.own.mk>
@@ -20,5 +20,6 @@
 SRCS+= quota_cursor.c
 SRCS+= quota_proplib.c
 SRCS+= quota_nfs.c
+SRCS+= quota_oldfiles.c
 
 .include <bsd.lib.mk>
diff -r 7d63d8294124 -r c691c2627ec2 lib/libquota/quota_cursor.c
--- a/lib/libquota/quota_cursor.c       Mon Jan 09 15:41:21 2012 +0000
+++ b/lib/libquota/quota_cursor.c       Mon Jan 09 15:41:58 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: quota_cursor.c,v 1.2 2012/01/09 15:40:10 dholland Exp $        */
+/*     $NetBSD: quota_cursor.c,v 1.3 2012/01/09 15:41:58 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.2 2012/01/09 15:40:10 dholland Exp $");
+__RCSID("$NetBSD: quota_cursor.c,v 1.3 2012/01/09 15:41:58 dholland Exp $");
 
 #include <stdlib.h>
 #include <errno.h>
@@ -41,6 +41,7 @@
 quota_opencursor(struct quotahandle *qh)
 {
        struct quotacursor *qc;
+       int8_t version;
        int serrno;
 
        if (qh->qh_isnfs) {
@@ -48,19 +49,45 @@
                return NULL;
        }
 
+       if (__quota_proplib_getversion(qh, &version)) {
+               return NULL;
+       }
+
+       /*
+        * For the time being at least the version 1 kernel code
+        * cannot do cursors.
+        */
+       if (version == 1 && !qh->qh_hasoldfiles) {
+               if (__quota_oldfiles_initialize(qh)) {
+                       return NULL;
+               }
+       }
+
        qc = malloc(sizeof(*qc));
        if (qc == NULL) {
                return NULL;
        }
 
        qc->qc_qh = qh;
-       qc->u.qc_proplib = __quota_proplib_cursor_create();
 
-       if (qc->u.qc_proplib == NULL) {
-               serrno = errno;
-               free(qc);
-               errno = serrno;
-               return NULL;
+       if (version == 1) {
+               qc->qc_type = QC_OLDFILES;
+               qc->u.qc_oldfiles = __quota_oldfiles_cursor_create(qh);
+               if (qc->u.qc_oldfiles == NULL) {
+                       serrno = errno;
+                       free(qc);
+                       errno = serrno;
+                       return NULL;
+               }
+       } else {
+               qc->qc_type = QC_PROPLIB;
+               qc->u.qc_proplib = __quota_proplib_cursor_create();
+               if (qc->u.qc_proplib == NULL) {
+                       serrno = errno;
+                       free(qc);
+                       errno = serrno;
+                       return NULL;
+               }
        }
        return qc;
 }
@@ -68,22 +95,47 @@
 void
 quotacursor_close(struct quotacursor *qc)
 {
-       __quota_proplib_cursor_destroy(qc->u.qc_proplib);
+       switch (qc->qc_type) {
+           case QC_PROPLIB:
+               __quota_proplib_cursor_destroy(qc->u.qc_proplib);
+               break;
+           case QC_OLDFILES:
+               __quota_oldfiles_cursor_destroy(qc->u.qc_oldfiles);
+               break;
+       }
        free(qc);
 }
 
 int
 quotacursor_skipidtype(struct quotacursor *qc, unsigned idtype)
 {
-       return __quota_proplib_cursor_skipidtype(qc->u.qc_proplib, idtype);
+       switch (qc->qc_type) {
+           case QC_PROPLIB:
+               return __quota_proplib_cursor_skipidtype(qc->u.qc_proplib,
+                                                        idtype);
+           case QC_OLDFILES:
+               return __quota_oldfiles_cursor_skipidtype(qc->u.qc_oldfiles,
+                                                         idtype);
+       }
+       errno = EINVAL;
+       return -1;
 }
 
 int
 quotacursor_get(struct quotacursor *qc,
                struct quotakey *qk_ret, struct quotaval *qv_ret)
 {
-       return __quota_proplib_cursor_get(qc->qc_qh, qc->u.qc_proplib,
-                                         qk_ret, qv_ret);
+       switch (qc->qc_type) {
+           case QC_PROPLIB:
+               return __quota_proplib_cursor_get(qc->qc_qh, qc->u.qc_proplib,
+                                                 qk_ret, qv_ret);
+           case QC_OLDFILES:
+               return __quota_oldfiles_cursor_get(qc->qc_qh,
+                                                  qc->u.qc_oldfiles,
+                                                  qk_ret, qv_ret);
+       }
+       errno = EINVAL;
+       return -1;
 }
 
 int
@@ -91,19 +143,42 @@
                 struct quotakey *keys, struct quotaval *vals, 
                 unsigned maxnum)
 {
-       return __quota_proplib_cursor_getn(qc->qc_qh, qc->u.qc_proplib,
-                                          keys, vals, maxnum);
+       switch (qc->qc_type) {
+           case QC_PROPLIB:
+               return __quota_proplib_cursor_getn(qc->qc_qh, qc->u.qc_proplib,
+                                                  keys, vals, maxnum);
+           case QC_OLDFILES:
+               return __quota_oldfiles_cursor_getn(qc->qc_qh,
+                                                   qc->u.qc_oldfiles,
+                                                   keys, vals, maxnum);
+       }
+       errno = EINVAL;
+       return -1;
 }
 
 int
 quotacursor_atend(struct quotacursor *qc)
 {
-       return __quota_proplib_cursor_atend(qc->qc_qh,
-                                           qc->u.qc_proplib);
+       switch (qc->qc_type) {
+           case QC_PROPLIB:
+               return __quota_proplib_cursor_atend(qc->qc_qh,
+                                                   qc->u.qc_proplib);
+           case QC_OLDFILES:
+               return __quota_oldfiles_cursor_atend(qc->u.qc_oldfiles);
+       }
+       errno = EINVAL;
+       return -1;
 }
 
 int
 quotacursor_rewind(struct quotacursor *qc)
 {
-       return __quota_proplib_cursor_rewind(qc->u.qc_proplib);
+       switch (qc->qc_type) {
+           case QC_PROPLIB:
+               return __quota_proplib_cursor_rewind(qc->u.qc_proplib);
+           case QC_OLDFILES:
+               return __quota_oldfiles_cursor_rewind(qc->u.qc_oldfiles);
+       }
+       errno = EINVAL;
+       return -1;
 }
diff -r 7d63d8294124 -r c691c2627ec2 lib/libquota/quota_oldfiles.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libquota/quota_oldfiles.c     Mon Jan 09 15:41:58 2012 +0000
@@ -0,0 +1,530 @@
+/*     $NetBSD: quota_oldfiles.c,v 1.1 2012/01/09 15:41:58 dholland Exp $      */
+
+/*
+ * Copyright (c) 1980, 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Robert Elz at The University of Melbourne.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <fstab.h>
+#include <errno.h>
+#include <err.h>
+
+#include <ufs/ufs/quota1.h>
+
+#include <quota.h>
+#include "quotapvt.h"
+
+struct oldfiles_quotacursor {
+       unsigned oqc_doingusers;
+       unsigned oqc_doinggroups;
+
+       unsigned oqc_numusers;
+       unsigned oqc_numgroups;
+
+       unsigned oqc_didusers;
+       unsigned oqc_didgroups;
+       unsigned oqc_diddefault;
+       unsigned oqc_pos;
+       unsigned oqc_didblocks;
+};
+
+static uint64_t
+dqblk_limit(uint32_t val)
+{
+       if (val == 0) {
+               return QUOTA_NOLIMIT;
+       } else {
+               return val - 1;
+       }
+}
+
+static void
+dqblk_getblocks(const struct dqblk *dq, struct quotaval *qv)
+{
+       qv->qv_hardlimit = dqblk_limit(dq->dqb_bhardlimit);
+       qv->qv_softlimit = dqblk_limit(dq->dqb_bsoftlimit);
+       qv->qv_usage = dq->dqb_curblocks;
+       qv->qv_expiretime = dq->dqb_btime;
+       qv->qv_grace = QUOTA_NOTIME;
+}
+
+static void
+dqblk_getfiles(const struct dqblk *dq, struct quotaval *qv)
+{
+       qv->qv_hardlimit = dqblk_limit(dq->dqb_ihardlimit);
+       qv->qv_softlimit = dqblk_limit(dq->dqb_isoftlimit);
+       qv->qv_usage = dq->dqb_curinodes;
+       qv->qv_expiretime = dq->dqb_itime;
+       qv->qv_grace = QUOTA_NOTIME;
+}
+
+static int
+__quota_oldfiles_open(struct quotahandle *qh, const char *path, int *fd_ret)
+{
+       int fd;
+
+       fd = open(path, O_RDWR);
+       if (fd < 0 && (errno == EACCES || errno == EROFS)) {



Home | Main Index | Thread Index | Old Index