Current-Users archive

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

Re: lfs heads up



Hello,


After LFS split, ufs_readwrite.c is no longer shared by FFS and LFS.
So I think:

(1) Simplify them (see attached file)

And (2a) merge into {ffs,lfs}_vnops.c
    or (2b) make them standalone like ext2fs_readwrite.c (and rename
            ufs_readwrite.c to ffs_readwrite.c).


Regards,
-- 
nakayosh
diff -u ufs/ufs_readwrite.c.ORIG ufs/ufs_readwrite.c
--- ufs/ufs_readwrite.c.ORIG    2013-06-23 16:28:37.000000000 +0900
+++ ufs/ufs_readwrite.c 2013-06-30 00:55:26.000000000 +0900
@@ -34,43 +34,12 @@
 #include <sys/cdefs.h>
 __KERNEL_RCSID(1, "$NetBSD: ufs_readwrite.c,v 1.107 2013/06/23 07:28:37 
dholland Exp $");
 
-#ifdef LFS_READWRITE
-#define        FS                      struct lfs
-#define        I_FS                    i_lfs
-#define        READ                    lfs_read
-#define        READ_S                  "lfs_read"
-#define        WRITE                   lfs_write
-#define        WRITE_S                 "lfs_write"
-#define        fs_bsize                lfs_bsize
-#define        fs_bmask                lfs_bmask
-#define        UFS_WAPBL_BEGIN(mp)     0
-#define        UFS_WAPBL_END(mp)       do { } while (0)
-#define        UFS_WAPBL_UPDATE(vp, access, modify, flags)     do { } while (0)
-#define ufs_blkoff             lfs_blkoff
-#define ufs_blksize            lfs_blksize
-#define ufs_lblkno             lfs_lblkno
-#define ufs_lblktosize         lfs_lblktosize
-#define ufs_blkroundup         lfs_blkroundup
-#else
-#define        FS                      struct fs
-#define        I_FS                    i_fs
-#define        READ                    ffs_read
-#define        READ_S                  "ffs_read"
-#define        WRITE                   ffs_write
-#define        WRITE_S                 "ffs_write"
-#define ufs_blkoff             ffs_blkoff
-#define ufs_blksize            ffs_blksize
-#define ufs_lblkno             ffs_lblkno
-#define ufs_lblktosize         ffs_lblktosize
-#define ufs_blkroundup         ffs_blkroundup
-#endif
-
 /*
  * Vnode op for reading.
  */
 /* ARGSUSED */
 int
-READ(void *v)
+ffs_read(void *v)
 {
        struct vop_read_args /* {
                struct vnode *a_vp;
@@ -83,7 +52,7 @@
        struct uio *uio;
        struct ufsmount *ump;
        struct buf *bp;
-       FS *fs;
+       struct fs *fs;
        vsize_t bytelen;
        daddr_t lbn, nextlbn;
        off_t bytesinfile;
@@ -100,36 +69,30 @@
 
 #ifdef DIAGNOSTIC
        if (uio->uio_rw != UIO_READ)
-               panic("%s: mode", READ_S);
+               panic("ffs_read: mode");
 
        if (vp->v_type == VLNK) {
                if (ip->i_size < ump->um_maxsymlinklen ||
                    (ump->um_maxsymlinklen == 0 && DIP(ip, blocks) == 0))
-                       panic("%s: short symlink", READ_S);
+                       panic("ffs_read: short symlink");
        } else if (vp->v_type != VREG && vp->v_type != VDIR)
-               panic("%s: type %d", READ_S, vp->v_type);
+               panic("ffs_read: type %d", vp->v_type);
 #endif
-       fs = ip->I_FS;
+       fs = ip->i_fs;
        if ((u_int64_t)uio->uio_offset > ump->um_maxfilesize)
                return (EFBIG);
        if (uio->uio_resid == 0)
                return (0);
 
-#ifndef LFS_READWRITE
        if ((ip->i_flags & (SF_SNAPSHOT | SF_SNAPINVAL)) == SF_SNAPSHOT)
                return ffs_snapshot_read(vp, uio, ioflag);
-#endif /* !LFS_READWRITE */
 
        fstrans_start(vp->v_mount, FSTRANS_SHARED);
 
        if (uio->uio_offset >= ip->i_size)
                goto out;
 
-#ifdef LFS_READWRITE
-       usepc = (vp->v_type == VREG && ip->i_number != LFS_IFILE_INUM);
-#else /* !LFS_READWRITE */
        usepc = vp->v_type == VREG;
-#endif /* !LFS_READWRITE */
        if (usepc) {
                const int advice = IO_ADV_DECODE(ap->a_ioflag);
 
@@ -153,17 +116,17 @@
                bytesinfile = ip->i_size - uio->uio_offset;
                if (bytesinfile <= 0)
                        break;
-               lbn = ufs_lblkno(fs, uio->uio_offset);
+               lbn = ffs_lblkno(fs, uio->uio_offset);
                nextlbn = lbn + 1;
-               size = ufs_blksize(fs, ip, lbn);
-               blkoffset = ufs_blkoff(fs, uio->uio_offset);
+               size = ffs_blksize(fs, ip, lbn);
+               blkoffset = ffs_blkoff(fs, uio->uio_offset);
                xfersize = MIN(MIN(fs->fs_bsize - blkoffset, uio->uio_resid),
                    bytesinfile);
 
-               if (ufs_lblktosize(fs, nextlbn) >= ip->i_size)
+               if (ffs_lblktosize(fs, nextlbn) >= ip->i_size)
                        error = bread(vp, lbn, size, NOCRED, 0, &bp);
                else {
-                       int nextsize = ufs_blksize(fs, ip, nextlbn);
+                       int nextsize = ffs_blksize(fs, ip, nextlbn);
                        error = breadn(vp, lbn,
                            size, &nextlbn, &nextsize, 1, NOCRED, 0, &bp);
                }
@@ -213,7 +176,7 @@
  * Vnode op for writing.
  */
 int
-WRITE(void *v)
+ffs_write(void *v)
 {
        struct vop_write_args /* {
                struct vnode *a_vp;
@@ -224,7 +187,7 @@
        struct vnode *vp;
        struct uio *uio;
        struct inode *ip;
-       FS *fs;
+       struct fs *fs;
        struct buf *bp;
        kauth_cred_t cred;
        daddr_t lbn;
@@ -235,9 +198,6 @@
        vsize_t bytelen;
        bool async;
        bool usepc = false;
-#ifdef LFS_READWRITE
-       bool need_unreserve = false;
-#endif
        struct ufsmount *ump;
 
        cred = ap->a_cred;
@@ -250,7 +210,7 @@
        KASSERT(vp->v_size == ip->i_size);
 #ifdef DIAGNOSTIC
        if (uio->uio_rw != UIO_WRITE)
-               panic("%s: mode", WRITE_S);
+               panic("ffs_write: mode");
 #endif
 
        switch (vp->v_type) {
@@ -264,22 +224,16 @@
                break;
        case VDIR:
                if ((ioflag & IO_SYNC) == 0)
-                       panic("%s: nonsync dir write", WRITE_S);
+                       panic("ffs_write: nonsync dir write");
                break;
        default:
-               panic("%s: type", WRITE_S);
+               panic("ffs_write: type");
        }
 
-       fs = ip->I_FS;
+       fs = ip->i_fs;
        if (uio->uio_offset < 0 ||
            (u_int64_t)uio->uio_offset + uio->uio_resid > ump->um_maxfilesize)
                return (EFBIG);
-#ifdef LFS_READWRITE
-       /* Disallow writes to the Ifile, even if noschg flag is removed */
-       /* XXX can this go away when the Ifile is no longer in the namespace? */
-       if (vp == fs->lfs_ivnode)
-               return (EPERM);
-#endif
        if (uio->uio_resid == 0)
                return (0);
 
@@ -302,30 +256,25 @@
                }
        }
 
-#ifdef LFS_READWRITE
-       async = true;
-       lfs_availwait(fs, btofsb(fs, uio->uio_resid));
-       lfs_check(vp, LFS_UNUSED_LBN, 0);
-#endif /* !LFS_READWRITE */
        if (!usepc)
                goto bcache;
 
-       preallocoff = round_page(ufs_blkroundup(fs, MAX(osize, 
uio->uio_offset)));
+       preallocoff = round_page(ffs_blkroundup(fs, MAX(osize, 
uio->uio_offset)));
        aflag = ioflag & IO_SYNC ? B_SYNC : 0;
        nsize = MAX(osize, uio->uio_offset + uio->uio_resid);
-       endallocoff = nsize - ufs_blkoff(fs, nsize);
+       endallocoff = nsize - ffs_blkoff(fs, nsize);
 
        /*
         * if we're increasing the file size, deal with expanding
         * the fragment if there is one.
         */
 
-       if (nsize > osize && ufs_lblkno(fs, osize) < UFS_NDADDR &&
-           ufs_lblkno(fs, osize) != ufs_lblkno(fs, nsize) &&
-           ufs_blkroundup(fs, osize) != osize) {
+       if (nsize > osize && ffs_lblkno(fs, osize) < UFS_NDADDR &&
+           ffs_lblkno(fs, osize) != ffs_lblkno(fs, nsize) &&
+           ffs_blkroundup(fs, osize) != osize) {
                off_t eob;
 
-               eob = ufs_blkroundup(fs, osize);
+               eob = ffs_blkroundup(fs, osize);
                uvm_vnp_setwritesize(vp, eob);
                error = ufs_balloc_range(vp, osize, eob - osize, cred, aflag);
                if (error)
@@ -348,7 +297,7 @@
                }
 
                oldoff = uio->uio_offset;
-               blkoffset = ufs_blkoff(fs, uio->uio_offset);
+               blkoffset = ffs_blkoff(fs, uio->uio_offset);
                bytelen = MIN(fs->fs_bsize - blkoffset, uio->uio_resid);
                if (bytelen == 0) {
                        break;
@@ -364,12 +313,12 @@
                overwrite = uio->uio_offset >= preallocoff &&
                    uio->uio_offset < endallocoff;
                if (!overwrite && (vp->v_vflag & VV_MAPPED) == 0 &&
-                   ufs_blkoff(fs, uio->uio_offset) == 0 &&
+                   ffs_blkoff(fs, uio->uio_offset) == 0 &&
                    (uio->uio_offset & PAGE_MASK) == 0) {
                        vsize_t len;
 
                        len = trunc_page(bytelen);
-                       len -= ufs_blkoff(fs, len);
+                       len -= ffs_blkoff(fs, len);
                        if (len > 0) {
                                overwrite = true;
                                bytelen = len;
@@ -423,7 +372,6 @@
                 * XXXUBC simplistic async flushing.
                 */
 
-#ifndef LFS_READWRITE
                if (!async && oldoff >> 16 != uio->uio_offset >> 16) {
                        mutex_enter(vp->v_interlock);
                        error = VOP_PUTPAGES(vp, (oldoff >> 16) << 16,
@@ -432,12 +380,11 @@
                        if (error)
                                break;
                }
-#endif
        }
        if (error == 0 && ioflag & IO_SYNC) {
                mutex_enter(vp->v_interlock);
                error = VOP_PUTPAGES(vp, trunc_page(origoff & fs->fs_bmask),
-                   round_page(ufs_blkroundup(fs, uio->uio_offset)),
+                   round_page(ffs_blkroundup(fs, uio->uio_offset)),
                    PGO_CLEANIT | PGO_SYNCIO | PGO_JOURNALLOCKED);
        }
        goto out;
@@ -447,21 +394,14 @@
        VOP_PUTPAGES(vp, trunc_page(origoff), round_page(origoff + resid),
            PGO_CLEANIT | PGO_FREE | PGO_SYNCIO | PGO_JOURNALLOCKED);
        while (uio->uio_resid > 0) {
-               lbn = ufs_lblkno(fs, uio->uio_offset);
-               blkoffset = ufs_blkoff(fs, uio->uio_offset);
+               lbn = ffs_lblkno(fs, uio->uio_offset);
+               blkoffset = ffs_blkoff(fs, uio->uio_offset);
                xfersize = MIN(fs->fs_bsize - blkoffset, uio->uio_resid);
                if (fs->fs_bsize > xfersize)
                        flags |= B_CLRBUF;
                else
                        flags &= ~B_CLRBUF;
 
-#ifdef LFS_READWRITE
-               error = lfs_reserve(fs, vp, NULL,
-                   btofsb(fs, (UFS_NIADDR + 1) << fs->lfs_bshift));
-               if (error)
-                       break;
-               need_unreserve = true;
-#endif
                error = UFS_BALLOC(vp, uio->uio_offset, xfersize,
                    ap->a_cred, flags, &bp);
 
@@ -473,7 +413,7 @@
                        uvm_vnp_setsize(vp, ip->i_size);
                        extended = 1;
                }
-               size = ufs_blksize(fs, ip, lbn) - bp->b_resid;
+               size = ffs_blksize(fs, ip, lbn) - bp->b_resid;
                if (xfersize > size)
                        xfersize = size;
 
@@ -488,28 +428,15 @@
                        brelse(bp, BC_INVAL);
                        break;
                }
-#ifdef LFS_READWRITE
-               (void)VOP_BWRITE(bp->b_vp, bp);
-               lfs_reserve(fs, vp, NULL,
-                   -btofsb(fs, (UFS_NIADDR + 1) << fs->lfs_bshift));
-               need_unreserve = false;
-#else
                if (ioflag & IO_SYNC)
                        (void)bwrite(bp);
                else if (xfersize + blkoffset == fs->fs_bsize)
                        bawrite(bp);
                else
                        bdwrite(bp);
-#endif
                if (error || xfersize == 0)
                        break;
        }
-#ifdef LFS_READWRITE
-       if (need_unreserve) {
-               lfs_reserve(fs, vp, NULL,
-                   -btofsb(fs, (UFS_NIADDR + 1) << fs->lfs_bshift));
-       }
-#endif
 
        /*
         * If we successfully wrote any data, and we are not the superuser
diff -u lfs/ulfs_readwrite.c.ORIG lfs/ulfs_readwrite.c
--- lfs/ulfs_readwrite.c.ORIG   2013-06-19 03:18:58.000000000 +0900
+++ lfs/ulfs_readwrite.c        2013-06-30 00:50:12.000000000 +0900
@@ -35,30 +35,12 @@
 #include <sys/cdefs.h>
 __KERNEL_RCSID(1, "$NetBSD: ulfs_readwrite.c,v 1.4 2013/06/18 18:18:58 
christos Exp $");
 
-#ifdef LFS_READWRITE
-#define        FS                      struct lfs
-#define        I_FS                    i_lfs
-#define        READ                    lfs_read
-#define        READ_S                  "lfs_read"
-#define        WRITE                   lfs_write
-#define        WRITE_S                 "lfs_write"
-#define        fs_bsize                lfs_bsize
-#define        fs_bmask                lfs_bmask
-#else
-#define        FS                      struct fs
-#define        I_FS                    i_fs
-#define        READ                    ffs_read
-#define        READ_S                  "ffs_read"
-#define        WRITE                   ffs_write
-#define        WRITE_S                 "ffs_write"
-#endif
-
 /*
  * Vnode op for reading.
  */
 /* ARGSUSED */
 int
-READ(void *v)
+lfs_read(void *v)
 {
        struct vop_read_args /* {
                struct vnode *a_vp;
@@ -71,7 +53,7 @@
        struct uio *uio;
        struct ulfsmount *ump;
        struct buf *bp;
-       FS *fs;
+       struct lfs *fs;
        vsize_t bytelen;
        daddr_t lbn, nextlbn;
        off_t bytesinfile;
@@ -88,36 +70,28 @@
 
 #ifdef DIAGNOSTIC
        if (uio->uio_rw != UIO_READ)
-               panic("%s: mode", READ_S);
+               panic("lfs_read: mode");
 
        if (vp->v_type == VLNK) {
                if (ip->i_size < ump->um_maxsymlinklen ||
                    (ump->um_maxsymlinklen == 0 && DIP(ip, blocks) == 0))
-                       panic("%s: short symlink", READ_S);
+                       panic("lfs_read: short symlink");
        } else if (vp->v_type != VREG && vp->v_type != VDIR)
-               panic("%s: type %d", READ_S, vp->v_type);
+               panic("lfs_read: type %d", vp->v_type);
 #endif
-       fs = ip->I_FS;
+       fs = ip->i_lfs;
        if ((u_int64_t)uio->uio_offset > ump->um_maxfilesize)
                return (EFBIG);
        if (uio->uio_resid == 0)
                return (0);
 
-#ifndef LFS_READWRITE
-       if ((ip->i_flags & (SF_SNAPSHOT | SF_SNAPINVAL)) == SF_SNAPSHOT)
-               return ffs_snapshot_read(vp, uio, ioflag);
-#endif /* !LFS_READWRITE */
 
        fstrans_start(vp->v_mount, FSTRANS_SHARED);
 
        if (uio->uio_offset >= ip->i_size)
                goto out;
 
-#ifdef LFS_READWRITE
        usepc = (vp->v_type == VREG && ip->i_number != LFS_IFILE_INUM);
-#else /* !LFS_READWRITE */
-       usepc = vp->v_type == VREG;
-#endif /* !LFS_READWRITE */
        if (usepc) {
                const int advice = IO_ADV_DECODE(ap->a_ioflag);
 
@@ -145,7 +119,7 @@
                nextlbn = lbn + 1;
                size = lfs_blksize(fs, ip, lbn);
                blkoffset = lfs_blkoff(fs, uio->uio_offset);
-               xfersize = MIN(MIN(fs->fs_bsize - blkoffset, uio->uio_resid),
+               xfersize = MIN(MIN(fs->lfs_bsize - blkoffset, uio->uio_resid),
                    bytesinfile);
 
                if (lfs_lblktosize(fs, nextlbn) >= ip->i_size)
@@ -195,7 +169,7 @@
  * Vnode op for writing.
  */
 int
-WRITE(void *v)
+lfs_write(void *v)
 {
        struct vop_write_args /* {
                struct vnode *a_vp;
@@ -206,7 +180,7 @@
        struct vnode *vp;
        struct uio *uio;
        struct inode *ip;
-       FS *fs;
+       struct lfs *fs;
        struct buf *bp;
        kauth_cred_t cred;
        daddr_t lbn;
@@ -217,9 +191,7 @@
        vsize_t bytelen;
        bool async;
        bool usepc = false;
-#ifdef LFS_READWRITE
        bool need_unreserve = false;
-#endif
        struct ulfsmount *ump;
 
        cred = ap->a_cred;
@@ -232,7 +204,7 @@
        KASSERT(vp->v_size == ip->i_size);
 #ifdef DIAGNOSTIC
        if (uio->uio_rw != UIO_WRITE)
-               panic("%s: mode", WRITE_S);
+               panic("lfs_write: mode");
 #endif
 
        switch (vp->v_type) {
@@ -246,22 +218,20 @@
                break;
        case VDIR:
                if ((ioflag & IO_SYNC) == 0)
-                       panic("%s: nonsync dir write", WRITE_S);
+                       panic("lfs_write: nonsync dir write");
                break;
        default:
-               panic("%s: type", WRITE_S);
+               panic("lfs_write: type");
        }
 
-       fs = ip->I_FS;
+       fs = ip->i_lfs;
        if (uio->uio_offset < 0 ||
            (u_int64_t)uio->uio_offset + uio->uio_resid > ump->um_maxfilesize)
                return (EFBIG);
-#ifdef LFS_READWRITE
        /* Disallow writes to the Ifile, even if noschg flag is removed */
        /* XXX can this go away when the Ifile is no longer in the namespace? */
        if (vp == fs->lfs_ivnode)
                return (EPERM);
-#endif
        if (uio->uio_resid == 0)
                return (0);
 
@@ -276,11 +246,9 @@
 
        usepc = vp->v_type == VREG;
 
-#ifdef LFS_READWRITE
        async = true;
        lfs_availwait(fs, lfs_btofsb(fs, uio->uio_resid));
        lfs_check(vp, LFS_UNUSED_LBN, 0);
-#endif /* !LFS_READWRITE */
        if (!usepc)
                goto bcache;
 
@@ -306,7 +274,7 @@
                        goto out;
                if (flags & B_SYNC) {
                        mutex_enter(vp->v_interlock);
-                       VOP_PUTPAGES(vp, trunc_page(osize & fs->fs_bmask),
+                       VOP_PUTPAGES(vp, trunc_page(osize & fs->lfs_bmask),
                            round_page(eob),
                            PGO_CLEANIT | PGO_SYNCIO | PGO_JOURNALLOCKED);
                }
@@ -323,7 +291,7 @@
 
                oldoff = uio->uio_offset;
                blkoffset = lfs_blkoff(fs, uio->uio_offset);
-               bytelen = MIN(fs->fs_bsize - blkoffset, uio->uio_resid);
+               bytelen = MIN(fs->lfs_bsize - blkoffset, uio->uio_resid);
                if (bytelen == 0) {
                        break;
                }
@@ -397,20 +365,10 @@
                 * XXXUBC simplistic async flushing.
                 */
 
-#ifndef LFS_READWRITE
-               if (!async && oldoff >> 16 != uio->uio_offset >> 16) {
-                       mutex_enter(vp->v_interlock);
-                       error = VOP_PUTPAGES(vp, (oldoff >> 16) << 16,
-                           (uio->uio_offset >> 16) << 16,
-                           PGO_CLEANIT | PGO_JOURNALLOCKED | PGO_LAZY);
-                       if (error)
-                               break;
-               }
-#endif
        }
        if (error == 0 && ioflag & IO_SYNC) {
                mutex_enter(vp->v_interlock);
-               error = VOP_PUTPAGES(vp, trunc_page(origoff & fs->fs_bmask),
+               error = VOP_PUTPAGES(vp, trunc_page(origoff & fs->lfs_bmask),
                    round_page(lfs_blkroundup(fs, uio->uio_offset)),
                    PGO_CLEANIT | PGO_SYNCIO | PGO_JOURNALLOCKED);
        }
@@ -423,19 +381,17 @@
        while (uio->uio_resid > 0) {
                lbn = lfs_lblkno(fs, uio->uio_offset);
                blkoffset = lfs_blkoff(fs, uio->uio_offset);
-               xfersize = MIN(fs->fs_bsize - blkoffset, uio->uio_resid);
-               if (fs->fs_bsize > xfersize)
+               xfersize = MIN(fs->lfs_bsize - blkoffset, uio->uio_resid);
+               if (fs->lfs_bsize > xfersize)
                        flags |= B_CLRBUF;
                else
                        flags &= ~B_CLRBUF;
 
-#ifdef LFS_READWRITE
                error = lfs_reserve(fs, vp, NULL,
                    lfs_btofsb(fs, (ULFS_NIADDR + 1) << fs->lfs_bshift));
                if (error)
                        break;
                need_unreserve = true;
-#endif
                error = ULFS_BALLOC(vp, uio->uio_offset, xfersize,
                    ap->a_cred, flags, &bp);
 
@@ -462,28 +418,17 @@
                        brelse(bp, BC_INVAL);
                        break;
                }
-#ifdef LFS_READWRITE
                (void)VOP_BWRITE(bp->b_vp, bp);
                lfs_reserve(fs, vp, NULL,
                    -lfs_btofsb(fs, (ULFS_NIADDR + 1) << fs->lfs_bshift));
                need_unreserve = false;
-#else
-               if (ioflag & IO_SYNC)
-                       (void)bwrite(bp);
-               else if (xfersize + blkoffset == fs->fs_bsize)
-                       bawrite(bp);
-               else
-                       bdwrite(bp);
-#endif
                if (error || xfersize == 0)
                        break;
        }
-#ifdef LFS_READWRITE
        if (need_unreserve) {
                lfs_reserve(fs, vp, NULL,
                    -lfs_btofsb(fs, (ULFS_NIADDR + 1) << fs->lfs_bshift));
        }
-#endif
 
        /*
         * If we successfully wrote any data, and we are not the superuser


Home | Main Index | Thread Index | Old Index