Module Name: src Committed By: dholland Date: Sun Jul 28 01:25:06 UTC 2013
Modified Files: src/sys/ufs/lfs: lfs_alloc.c lfs_balloc.c lfs_inode.c lfs_vfsops.c Log Message: Add more of the bits for supporting quotas. To generate a diff of this commit: cvs rdiff -u -r1.118 -r1.119 src/sys/ufs/lfs/lfs_alloc.c cvs rdiff -u -r1.79 -r1.80 src/sys/ufs/lfs/lfs_balloc.c cvs rdiff -u -r1.134 -r1.135 src/sys/ufs/lfs/lfs_inode.c cvs rdiff -u -r1.311 -r1.312 src/sys/ufs/lfs/lfs_vfsops.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/ufs/lfs/lfs_alloc.c diff -u src/sys/ufs/lfs/lfs_alloc.c:1.118 src/sys/ufs/lfs/lfs_alloc.c:1.119 --- src/sys/ufs/lfs/lfs_alloc.c:1.118 Sun Jul 28 01:05:52 2013 +++ src/sys/ufs/lfs/lfs_alloc.c Sun Jul 28 01:25:05 2013 @@ -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 @@ lfs_vcreate(struct mount *mp, ino_t ino, 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 } Index: src/sys/ufs/lfs/lfs_balloc.c diff -u src/sys/ufs/lfs/lfs_balloc.c:1.79 src/sys/ufs/lfs/lfs_balloc.c:1.80 --- src/sys/ufs/lfs/lfs_balloc.c:1.79 Sun Jul 28 01:10:49 2013 +++ src/sys/ufs/lfs/lfs_balloc.c Sun Jul 28 01:25:06 2013 @@ -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 @@ lfs_fragextend(struct vnode *vp, int osi 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 @@ lfs_fragextend(struct vnode *vp, int osi 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); Index: src/sys/ufs/lfs/lfs_inode.c diff -u src/sys/ufs/lfs/lfs_inode.c:1.134 src/sys/ufs/lfs/lfs_inode.c:1.135 --- src/sys/ufs/lfs/lfs_inode.c:1.134 Sun Jul 28 01:10:49 2013 +++ src/sys/ufs/lfs/lfs_inode.c Sun Jul 28 01:25:06 2013 @@ -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 @@ done: 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, Index: src/sys/ufs/lfs/lfs_vfsops.c diff -u src/sys/ufs/lfs/lfs_vfsops.c:1.311 src/sys/ufs/lfs/lfs_vfsops.c:1.312 --- src/sys/ufs/lfs/lfs_vfsops.c:1.311 Sun Jul 28 01:22:55 2013 +++ src/sys/ufs/lfs/lfs_vfsops.c Sun Jul 28 01:25:06 2013 @@ -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 @@ lfs_mount(struct mount *mp, const char * 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 @@ lfs_mountfs(struct vnode *devvp, struct 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_unmount(struct mount *mp, int mntfla 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 @@ lfs_unmount(struct mount *mp, int mntfla 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 @@ lfs_vinit(struct mount *mp, struct vnode 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);