Source-Changes-HG archive

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

[src/trunk]: src/sys/ufs/lfs Add more of the bits for supporting quotas.



details:   https://anonhg.NetBSD.org/src/rev/5ef2da63876f
branches:  trunk
changeset: 788900:5ef2da63876f
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sun Jul 28 01:25:05 2013 +0000

description:
Add more of the bits for supporting quotas.

diffstat:

 sys/ufs/lfs/lfs_alloc.c  |   6 +-
 sys/ufs/lfs/lfs_balloc.c |   8 ++--
 sys/ufs/lfs/lfs_inode.c  |   6 +-
 sys/ufs/lfs/lfs_vfsops.c |  91 ++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 99 insertions(+), 12 deletions(-)

diffs (235 lines):

diff -r 278ca8d17a43 -r 5ef2da63876f sys/ufs/lfs/lfs_alloc.c
--- a/sys/ufs/lfs/lfs_alloc.c   Sun Jul 28 01:22:55 2013 +0000
+++ b/sys/ufs/lfs/lfs_alloc.c   Sun Jul 28 01:25:05 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_alloc.c,v 1.118 2013/07/28 01:05:52 dholland Exp $ */
+/*     $NetBSD: lfs_alloc.c,v 1.119 2013/07/28 01:25:05 dholland Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.118 2013/07/28 01:05:52 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.119 2013/07/28 01:25:05 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -338,7 +338,7 @@
        SPLAY_INIT(&ip->i_lfs_lbtree);
        ip->i_lfs_nbtree = 0;
        LIST_INIT(&ip->i_lfs_segdhd);
-#ifdef LFS_QUOTA
+#if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
        ulfsquota_init(ip);
 #endif
 }
diff -r 278ca8d17a43 -r 5ef2da63876f sys/ufs/lfs/lfs_balloc.c
--- a/sys/ufs/lfs/lfs_balloc.c  Sun Jul 28 01:22:55 2013 +0000
+++ b/sys/ufs/lfs/lfs_balloc.c  Sun Jul 28 01:25:05 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_balloc.c,v 1.79 2013/07/28 01:10:49 dholland Exp $ */
+/*     $NetBSD: lfs_balloc.c,v 1.80 2013/07/28 01:25:06 dholland Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.79 2013/07/28 01:10:49 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.80 2013/07/28 01:25:06 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -412,7 +412,7 @@
        if (bpp && (error = bread(vp, lbn, osize, NOCRED, 0, bpp))) {
                goto out;
        }
-#ifdef LFS_QUOTA
+#if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
        if ((error = lfs_chkdq(ip, frags, cred, 0))) {
                if (bpp)
                        brelse(*bpp, 0);
@@ -430,7 +430,7 @@
                if (!lfs_fits(fs, frags)) {
                        if (bpp)
                                brelse(*bpp, 0);
-#ifdef LFS_QUOTA
+#if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
                        lfs_chkdq(ip, -frags, cred, 0);
 #endif
                        rw_exit(&fs->lfs_fraglock);
diff -r 278ca8d17a43 -r 5ef2da63876f sys/ufs/lfs/lfs_inode.c
--- a/sys/ufs/lfs/lfs_inode.c   Sun Jul 28 01:22:55 2013 +0000
+++ b/sys/ufs/lfs/lfs_inode.c   Sun Jul 28 01:25:05 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_inode.c,v 1.134 2013/07/28 01:10:49 dholland Exp $ */
+/*     $NetBSD: lfs_inode.c,v 1.135 2013/07/28 01:25:06 dholland Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.134 2013/07/28 01:10:49 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.135 2013/07/28 01:25:06 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -587,7 +587,7 @@
        mutex_exit(&lfs_lock);
 
        oip->i_flag |= IN_CHANGE;
-#ifdef LFS_QUOTA
+#if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
        (void) lfs_chkdq(oip, -blocksreleased, NOCRED, 0);
 #endif
        lfs_reserve(fs, ovp, NULL,
diff -r 278ca8d17a43 -r 5ef2da63876f sys/ufs/lfs/lfs_vfsops.c
--- a/sys/ufs/lfs/lfs_vfsops.c  Sun Jul 28 01:22:55 2013 +0000
+++ b/sys/ufs/lfs/lfs_vfsops.c  Sun Jul 28 01:25:05 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_vfsops.c,v 1.311 2013/07/28 01:22:55 dholland Exp $        */
+/*     $NetBSD: lfs_vfsops.c,v 1.312 2013/07/28 01:25:06 dholland Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.311 2013/07/28 01:22:55 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.312 2013/07/28 01:25:06 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_lfs.h"
@@ -757,11 +757,50 @@
 
                ump = VFSTOULFS(mp);
                fs = ump->um_lfs;
+
+               if (fs->lfs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) {
+                       /*
+                        * Changing from read/write to read-only.
+                        * XXX: shouldn't we sync here? or does vfs do that?
+                        */
+#ifdef LFS_QUOTA2
+                       /* XXX: quotas should remain on when readonly */
+                       if (fs->lfs_use_quota2) {
+                               error = lfsquota2_umount(mp, 0);
+                               if (error) {
+                                       return error;
+                               }
+                       }
+#endif
+               }
+
                if (fs->lfs_ronly && (mp->mnt_iflag & IMNT_WANTRDWR)) {
                        /*
                         * Changing from read-only to read/write.
                         * Note in the superblocks that we're writing.
                         */
+
+                       /* XXX: quotas should have been on even if readonly */
+                       if (fs->lfs_use_quota2) {
+#ifdef LFS_QUOTA2
+                               error = lfs_quota2_mount(mp);
+#else
+                               uprintf("%s: no kernel support for this "
+                                       "filesystem's quotas\n",
+                                       mp->mnt_stat.f_mntonname);
+                               if (mp->mnt_flag & MNT_FORCE) {
+                                       uprintf("%s: mounting anyway; "
+                                               "fsck afterwards\n",
+                                               mp->mnt_stat.f_mntonname);
+                               } else {
+                                       error = EINVAL;
+                               }
+#endif
+                               if (error) {
+                                       return error;
+                               }
+                       }
+
                        fs->lfs_ronly = 0;
                        if (fs->lfs_pflags & LFS_PF_CLEAN) {
                                fs->lfs_pflags &= ~LFS_PF_CLEAN;
@@ -1092,6 +1131,46 @@
                        brelse(bp, 0);
        }
 
+       /*
+        * XXX: if the fs has quotas, quotas should be on even if
+        * readonly. Otherwise you can't query the quota info!
+        * However, that's not how the quota2 code got written and I
+        * don't know if it'll behave itself if enabled while
+        * readonly, so for now use the same enable logic as ffs.
+        *
+        * XXX: also, if you use the -f behavior allowed here (and
+        * equivalently above for remount) it will corrupt the fs. It
+        * ought not to allow that. It should allow mounting readonly
+        * if there are quotas and the kernel doesn't have the quota
+        * code, but only readonly.
+        *
+        * XXX: and if you use the -f behavior allowed here it will
+        * likely crash at unmount time (or remount time) because we
+        * think quotas are active.
+        *
+        * Although none of this applies until there's a way to set
+        * lfs_use_quota2 and have quotas in the fs at all.
+        */
+       if (!ronly && fs->lfs_use_quota2) {
+#ifdef LFS_QUOTA2
+               error = lfs_quota2_mount(mp);
+#else
+               uprintf("%s: no kernel support for this filesystem's quotas\n",
+                       mp->mnt_stat.f_mntonname);
+               if (mp->mnt_flag & MNT_FORCE) {
+                       uprintf("%s: mounting anyway; fsck afterwards\n",
+                               mp->mnt_stat.f_mntonname);
+               } else {
+                       error = EINVAL;
+               }
+#endif
+               if (error) {
+                       /* XXX XXX must clean up the stuff immediately above */
+                       printf("lfs_mountfs: sorry, leaking some memory\n");
+                       goto out;
+               }
+       }
+
 #ifdef LFS_KERNEL_RFW
        lfs_roll_forward(fs, mp, l);
 #endif
@@ -1181,6 +1260,7 @@
        lfs_segwrite(mp, SEGM_CKP | SEGM_SYNC);
 
        /* wake up the cleaner so it can die */
+       /* XXX: shouldn't this be *after* the error cases below? */
        lfs_wakeup_cleaner(fs);
        mutex_enter(&lfs_lock);
        while (fs->lfs_sleepers)
@@ -1192,6 +1272,10 @@
         if ((error = lfsquota1_umount(mp, flags)) != 0)
                return (error);
 #endif
+#ifdef LFS_QUOTA2
+        if ((error = lfsquota2_umount(mp, flags)) != 0)
+               return (error);
+#endif
        if ((error = vflush(mp, fs->lfs_ivnode, flags)) != 0)
                return (error);
        if ((error = VFS_SYNC(mp, 1, l->l_cred)) != 0)
@@ -2010,6 +2094,9 @@
 
        ip->i_devvp = ump->um_devvp;
        vref(ip->i_devvp);
+#if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
+       ulfsquota_init(ip);
+#endif
        genfs_node_init(vp, &lfs_genfsops);
        uvm_vnp_setsize(vp, ip->i_size);
 



Home | Main Index | Thread Index | Old Index