checkpoint, but not because it's working
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 26 Sep 1991 05:30:13 +0000 (21:30 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 26 Sep 1991 05:30:13 +0000 (21:30 -0800)
SCCS-vsn: sys/ufs/lfs/lfs.h 5.4
SCCS-vsn: sys/ufs/lfs/lfs_alloc.c 7.29
SCCS-vsn: sys/ufs/lfs/lfs_balloc.c 7.15
SCCS-vsn: sys/ufs/lfs/lfs_inode.c 7.42
SCCS-vsn: sys/ufs/lfs/lfs_vfsops.c 7.58
SCCS-vsn: sys/ufs/lfs/lfs_vnops.c 7.67

usr/src/sys/ufs/lfs/lfs.h
usr/src/sys/ufs/lfs/lfs_alloc.c
usr/src/sys/ufs/lfs/lfs_balloc.c
usr/src/sys/ufs/lfs/lfs_inode.c
usr/src/sys/ufs/lfs/lfs_vfsops.c
usr/src/sys/ufs/lfs/lfs_vnops.c

index ce3d1c8..c0e8306 100644 (file)
@@ -4,23 +4,59 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)lfs.h       5.3 (Berkeley) %G%
+ *     @(#)lfs.h       5.4 (Berkeley) %G%
  */
 
  */
 
+typedef struct buf     BUF;
+typedef struct dinode  DINODE;
+typedef struct inode   INODE;
+typedef struct mount   MOUNT;
+typedef struct ucred   UCRED;
+typedef struct ufsmount        UFSMOUNT;
+typedef struct vnode   VNODE;
+
 #define        LFS_LABELPAD    8192            /* LFS label size */
 #define        LFS_SBPAD       8192            /* LFS superblock size */
 #define MAXMNTLEN      512             /* XXX move from fs.h to mount.h */
 
 /* On-disk and in-memory checkpoint segment usage structure. */
 #define        LFS_LABELPAD    8192            /* LFS label size */
 #define        LFS_SBPAD       8192            /* LFS superblock size */
 #define MAXMNTLEN      512             /* XXX move from fs.h to mount.h */
 
 /* On-disk and in-memory checkpoint segment usage structure. */
-typedef struct segusage {
+typedef struct segusage SEGUSE;
+struct segusage {
        u_long  su_nbytes;              /* number of live bytes */
        u_long  su_lastmod;             /* last modified timestamp */
        u_long  su_nbytes;              /* number of live bytes */
        u_long  su_lastmod;             /* last modified timestamp */
-#define        SEGUSE_DIRTY                    0x1
+#define        SEGUSE_DIRTY    0x1             /* XXX fill in comment */
        u_long  su_flags;
        u_long  su_flags;
-} SEGUSE;
+};
+
+/* On-disk file information.  One per file with data blocks in the segment. */
+typedef struct finfo FINFO;
+struct finfo {
+       u_long  fi_nblocks;             /* number of blocks */
+       u_long  fi_version;             /* version number */
+       ino_t   fi_ino;                 /* inode number */
+       long    fi_blocks[1];           /* array of logical block numbers */
+};
+
+/* In-memory description of a segment about to be written */
+typedef struct segment SEGMENT;
+struct segment {
+       SEGMENT *nextp;                 /* Links segments together */
+       BUF     **bpp;                  /* Pointer to buffer array */
+       BUF     **cbpp;                 /* Pointer to next available bp */
+       void    *segsum;                /* Segment Summary info */
+       u_long  sum_bytes_left;         /* Bytes left in summary */
+       u_long  seg_bytes_left;         /* Bytes left in segment */
+       daddr_t saddr;                  /* Current disk address */
+       daddr_t sum_addr;               /* Address of current summary */
+       u_long  ninodes;                /* Number of inodes in this segment */
+       u_long  sum_num;                /* Number of current summary block */
+       u_long  seg_number;             /* Number of this segment */
+       FINFO   *fip;                   /* Current fileinfo pointer */
+};
 
 /* On-disk and in-memory super block. */
 
 /* On-disk and in-memory super block. */
-typedef struct lfs {
+typedef struct lfs LFS;
+struct lfs {
 #define        LFS_MAGIC       0xbedead
        u_long  lfs_magic;              /* magic number */
 #define        LFS_VERSION     1
 #define        LFS_MAGIC       0xbedead
        u_long  lfs_magic;              /* magic number */
 #define        LFS_VERSION     1
@@ -69,8 +105,10 @@ typedef struct lfs {
        daddr_t lfs_sboffs[LFS_MAXNUMSB];
 
 /* These fields are set at mount time and are meaningless on disk. */
        daddr_t lfs_sboffs[LFS_MAXNUMSB];
 
 /* These fields are set at mount time and are meaningless on disk. */
-       struct vnode *lfs_ivnode;       /* vnode for the ifile */
+       VNODE   *lfs_ivnode;            /* vnode for the ifile */
        SEGUSE  *lfs_segtab;            /* in-memory segment usage table */
        SEGUSE  *lfs_segtab;            /* in-memory segment usage table */
+       SEGMENT *lfs_seglist;           /* list of segments being written */
+       u_long  lfs_iocount;            /* Number of ios pending */
        u_char  lfs_fmod;               /* super block modified flag */
        u_char  lfs_clean;              /* file system is clean flag */
        u_char  lfs_ronly;              /* mounted read-only flag */
        u_char  lfs_fmod;               /* super block modified flag */
        u_char  lfs_clean;              /* file system is clean flag */
        u_char  lfs_ronly;              /* mounted read-only flag */
@@ -80,7 +118,7 @@ typedef struct lfs {
 
 /* Checksum; valid on disk. */
        u_long  lfs_cksum;              /* checksum for superblock checking */
 
 /* Checksum; valid on disk. */
        u_long  lfs_cksum;              /* checksum for superblock checking */
-} LFS;
+};
 
 /*
  * The root inode is the root of the file system.  Inode 0 is the out-of-band
 
 /*
  * The root inode is the root of the file system.  Inode 0 is the out-of-band
@@ -102,7 +140,15 @@ typedef struct lfs {
  */
 #define        di_inum di_spare[0]
 
  */
 #define        di_inum di_spare[0]
 
-typedef struct ifile {
+/*
+ * Logical block numbers of indirect blocks.
+ */
+#define S_INDIR        -1
+#define D_INDIR -2
+#define T_INDIR -3
+
+typedef struct ifile IFILE;
+struct ifile {
        u_long  if_version;             /* inode version number */
 #define        LFS_UNUSED_DADDR        0       /* out-of-band daddr */
        daddr_t if_daddr;               /* inode disk address */
        u_long  if_version;             /* inode version number */
 #define        LFS_UNUSED_DADDR        0       /* out-of-band daddr */
        daddr_t if_daddr;               /* inode disk address */
@@ -112,7 +158,7 @@ typedef struct ifile {
        } __ifile_u;
 #define        if_st_atime     __ifile_u.st_atime
 #define        if_nextfree     __ifile_u.nextfree
        } __ifile_u;
 #define        if_st_atime     __ifile_u.st_atime
 #define        if_nextfree     __ifile_u.nextfree
-} IFILE;
+};
 
 /* Segment table size, in blocks. */
 #define        SEGTABSIZE(fs) \
 
 /* Segment table size, in blocks. */
 #define        SEGTABSIZE(fs) \
@@ -130,7 +176,8 @@ typedef struct ifile {
 #define        LFS_SUMMARY_SIZE        512
 
 /* On-disk segment summary information */
 #define        LFS_SUMMARY_SIZE        512
 
 /* On-disk segment summary information */
-typedef struct segsum {
+typedef struct segsum SEGSUM;
+struct segsum {
        u_long  ss_cksum;               /* check sum */
        daddr_t ss_next;                /* next segment */
        daddr_t ss_prev;                /* next segment */
        u_long  ss_cksum;               /* check sum */
        daddr_t ss_next;                /* next segment */
        daddr_t ss_prev;                /* next segment */
@@ -139,15 +186,7 @@ typedef struct segsum {
        u_long  ss_nfinfo;              /* number of file info structures */
        u_long  ss_ninos;               /* number of inode blocks */
        /* FINFO's... */
        u_long  ss_nfinfo;              /* number of file info structures */
        u_long  ss_ninos;               /* number of inode blocks */
        /* FINFO's... */
-} SEGSUM;
-
-/* On-disk file information.  One per file with data blocks in the segment. */
-typedef struct finfo {
-       u_long  fi_nblocks;             /* number of blocks */
-       u_long  fi_version;             /* version number */
-       ino_t   fi_ino;                 /* inode number */
-       u_long  fi_blocks[1];           /* array of logical block numbers */
-} FINFO;
+};
 
 /* NINDIR is the number of indirects in a file system block. */
 #define        NINDIR(fs)      ((fs)->lfs_nindir)
 
 /* NINDIR is the number of indirects in a file system block. */
 #define        NINDIR(fs)      ((fs)->lfs_nindir)
@@ -163,3 +202,9 @@ typedef struct finfo {
 #define        fsbtodb(fs, b)          ((b) << (fs)->lfs_fsbtodb)
 #define        lblkno(fs, loc)         ((loc) >> (fs)->lfs_bshift)
 #define        lblktosize(fs, blk)     ((blk) << (fs)->lfs_bshift)
 #define        fsbtodb(fs, b)          ((b) << (fs)->lfs_fsbtodb)
 #define        lblkno(fs, loc)         ((loc) >> (fs)->lfs_bshift)
 #define        lblktosize(fs, blk)     ((blk) << (fs)->lfs_bshift)
+#define numfrags(fs, loc)      /* calculates (loc / fs->fs_fsize) */ \
+       ((loc) >> (fs)->lfs_bshift)
+#define satosn(fs, saddr) \
+       ((int)((saddr - fs->lfs_sboffs[0]) / fsbtodb(fs, fs->lfs_ssize)))
+#define sntosa(fs, sn) \
+       ((daddr_t)(sn * (fs->lfs_ssize << fs->lfs_fsbtodb) + fs->lfs_sboffs[0]))
index 9a1bc58..465c9bd 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)lfs_alloc.c 7.28 (Berkeley) %G%
+ *     @(#)lfs_alloc.c 7.29 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
 ino_t
 lfs_ialloc(fs, pip, ipp, cred)
        LFS *fs;
 ino_t
 lfs_ialloc(fs, pip, ipp, cred)
        LFS *fs;
-       struct inode *pip, **ipp;
-       struct ucred *cred;
+       INODE *pip, **ipp;
+       UCRED *cred;
 {
 {
+       BUF *bp;
        IFILE *ifp;
        IFILE *ifp;
-       struct buf *bp;
-       struct inode *ip;
-       struct vnode *vp;
+       INODE *ip;
+       VNODE *vp;
        ino_t new_ino;
        int error;
 
        ino_t new_ino;
        int error;
 
@@ -55,8 +55,8 @@ printf("lfs_ialloc: next free %d\n", new_ino);
                panic("lfs_ialloc: corrupt free list");
 
        /* Remove from free list, set the access time. */
                panic("lfs_ialloc: corrupt free list");
 
        /* Remove from free list, set the access time. */
-       ifp->if_st_atime = time.tv_sec;
        fs->lfs_free = ifp->if_nextfree;
        fs->lfs_free = ifp->if_nextfree;
+       ifp->if_st_atime = time.tv_sec;
        brelse(bp);
 
        error = lfs_vcreate(ITOV(pip)->v_mount, new_ino, &vp);
        brelse(bp);
 
        error = lfs_vcreate(ITOV(pip)->v_mount, new_ino, &vp);
@@ -81,11 +81,11 @@ printf("lfs_ialloc: next free %d\n", new_ino);
 
 void
 lfs_ifree(ip)
 
 void
 lfs_ifree(ip)
-       struct inode *ip;
+       INODE *ip;
 {
 {
+       BUF *bp;
        IFILE *ifp;
        LFS *fs;
        IFILE *ifp;
        LFS *fs;
-       struct buf *bp;
        ino_t ino;
 
 printf("lfs_ifree: free %d\n", ip->i_number);
        ino_t ino;
 
 printf("lfs_ifree: free %d\n", ip->i_number);
@@ -106,7 +106,7 @@ itod(fs, ino)
        LFS *fs;
        ino_t ino;
 {
        LFS *fs;
        ino_t ino;
 {
-       struct buf *bp;
+       BUF *bp;
        IFILE *ifp;
        daddr_t iaddr;
 
        IFILE *ifp;
        daddr_t iaddr;
 
@@ -115,17 +115,18 @@ printf("itod: ino %d\n", ino);
 
        if (ifp->if_daddr == LFS_UNUSED_DADDR)
                panic("itod: unused daddr");
 
        if (ifp->if_daddr == LFS_UNUSED_DADDR)
                panic("itod: unused daddr");
-printf("itod: about to return %lx\n", ifp->if_daddr);
-       return (ifp->if_daddr);
+       iaddr = ifp->if_daddr;
+       brelse(bp);
+       return (iaddr);
 }
 
 }
 
-struct dinode *
+DINODE *
 lfs_ifind(fs, ino, page)
        LFS *fs;
        ino_t ino;
        void *page;
 {
 lfs_ifind(fs, ino, page)
        LFS *fs;
        ino_t ino;
        void *page;
 {
-       register struct dinode *dip;
+       register DINODE *dip;
        register int cnt;
 
 printf("lfs_ifind: inode %d\n", ino);
        register int cnt;
 
 printf("lfs_ifind: inode %d\n", ino);
@@ -143,12 +144,12 @@ printf("lfs_ifind: inode %d\n", ino);
  * Create a new vnode/inode and initialize the fields we can.
  */
 lfs_vcreate(mp, ino, vpp)
  * Create a new vnode/inode and initialize the fields we can.
  */
 lfs_vcreate(mp, ino, vpp)
-       struct mount *mp;
+       MOUNT *mp;
        ino_t ino;
        ino_t ino;
-       struct vnode **vpp;
+       VNODE **vpp;
 {
 {
-       struct inode *ip;
-       struct ufsmount *ump;
+       INODE *ip;
+       UFSMOUNT *ump;
        int error, i;
 
 printf("lfs_vcreate: ino %d\n", ino);
        int error, i;
 
 printf("lfs_vcreate: ino %d\n", ino);
@@ -167,7 +168,7 @@ printf("lfs_vcreate: ino %d\n", ino);
        ip->i_lfs = ump->um_lfs;
        ip->i_lockf = 0;
        ip->i_mode = 0;
        ip->i_lfs = ump->um_lfs;
        ip->i_lockf = 0;
        ip->i_mode = 0;
-       ip->i_number = ino;
+       ip->i_number = ip->i_din.di_inum = ino;
        ip->i_vnode = *vpp;
 #ifdef QUOTA
        for (i = 0; i < MAXQUOTAS; i++)
        ip->i_vnode = *vpp;
 #ifdef QUOTA
        for (i = 0; i < MAXQUOTAS; i++)
@@ -175,3 +176,22 @@ printf("lfs_vcreate: ino %d\n", ino);
 #endif
        return (0);
 }
 #endif
        return (0);
 }
+
+/* 
+ * Return the current version number for a specific inode.
+ */
+u_long
+lfs_getversion(fs, ino)
+       LFS *fs;
+       ino_t ino;
+{
+       IFILE *ifp;
+       BUF *bp;
+       int version;
+
+printf("lfs_getversion: %d\n", ino);
+       LFS_IENTRY(ifp, fs, ino, bp);
+       version = ifp->if_version;
+       brelse(bp);
+       return(version);
+}
index dd28afb..b086a46 100644 (file)
@@ -4,18 +4,25 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)lfs_balloc.c        7.14 (Berkeley) %G%
+ *     @(#)lfs_balloc.c        7.15 (Berkeley) %G%
  */
 
 #include "param.h"
 #include "systm.h"
 #include "buf.h"
  */
 
 #include "param.h"
 #include "systm.h"
 #include "buf.h"
+#include "time.h"
+#include "resource.h"
+#include "resourcevar.h"
 #include "proc.h"
 #include "file.h"
 #include "vnode.h"
 #include "proc.h"
 #include "file.h"
 #include "vnode.h"
+#include "mount.h"
+#include "specdev.h"
 
 #include "../ufs/quota.h"
 #include "../ufs/inode.h"
 
 #include "../ufs/quota.h"
 #include "../ufs/inode.h"
+#include "../ufs/ufsmount.h"
+#include "trace.h"
 #include "lfs.h"
 #include "lfs_extern.h"
 
 #include "lfs.h"
 #include "lfs_extern.h"
 
@@ -32,16 +39,31 @@ lfs_bmap(ip, bn, bnp)
 {
        register LFS *fs;                                       /* LFS */
        register daddr_t nb;
 {
        register LFS *fs;                                       /* LFS */
        register daddr_t nb;
+       struct vnode *devvp, *vp;
        struct buf *bp;
        struct buf *bp;
-       daddr_t *bap;
-       int i, j, sh;
+       daddr_t *bap, daddr;
+       daddr_t lbn_ind;
+       int i, j, off, sh;
        int error;
 
 printf("lfs_bmap: block number %d, inode %d\n", bn, ip->i_number);
        int error;
 
 printf("lfs_bmap: block number %d, inode %d\n", bn, ip->i_number);
-       if (bn < 0)
-               return (EFBIG);
        fs = ip->i_lfs;                                         /* LFS */
 
        fs = ip->i_lfs;                                         /* LFS */
 
+       /*
+        * We access all blocks in the cache, even indirect blocks by means of
+        * a logical address. Indirect blocks (single, double, triple) all have
+        * negative block numbers. The first NDADDR blocks are direct blocks,
+        * the first NIADDR negative blocks are the indirect block pointers.
+        * The single, double and triple indirect blocks in the inode
+        * are addressed: -1, -2 and -3 respectively.  
+        * XXX we don't handle triple indirect at all.
+        */
+       if (bn < 0) {
+               /* Shouldn't be here -- we don't think */
+               printf("lfs_bmap: NEGATIVE indirect block number %d\n", bn);
+               panic("negative indirect block number");
+       }
+
        /*
         * The first NDADDR blocks are direct blocks
         */
        /*
         * The first NDADDR blocks are direct blocks
         */
@@ -59,7 +81,9 @@ printf("lfs_bmap: block number %d, inode %d\n", bn, ip->i_number);
         */
        sh = 1;
        bn -= NDADDR;
         */
        sh = 1;
        bn -= NDADDR;
+       lbn_ind = 0;
        for (j = NIADDR; j > 0; j--) {
        for (j = NIADDR; j > 0; j--) {
+               lbn_ind--;
                sh *= NINDIR(fs);
                if (bn < sh)
                        break;
                sh *= NINDIR(fs);
                if (bn < sh)
                        break;
@@ -70,28 +94,39 @@ printf("lfs_bmap: block number %d, inode %d\n", bn, ip->i_number);
        /*
         * Fetch through the indirect blocks.
         */
        /*
         * Fetch through the indirect blocks.
         */
-       nb = ip->i_ib[NIADDR - j];
-       if (nb == 0) {
-               *bnp = (daddr_t)-1;
-               return (0);
-       }
-       for (; j <= NIADDR; j++) {
-               if (error = bread(ip->i_devvp, nb, (int)fs->lfs_bsize,
-                   NOCRED, &bp)) {             /* LFS */
+
+       vp = ITOV(ip);
+       devvp = VFSTOUFS(vp->v_mount)->um_devvp;
+       for (off = NIADDR - j, bap = ip->i_ib; j <= NIADDR; j++) {
+               if((daddr = bap[off]) == 0) {
+                       daddr = (daddr_t)-1;
+                       break;
+               }
+               if (bp)
                        brelse(bp);
                        brelse(bp);
-                       return (error);
+               bp = getblk(vp, lbn_ind, fs->lfs_bsize);
+               if (bp->b_flags & (B_DONE | B_DELWRI)) {
+                       trace(TR_BREADHIT, pack(vp, size), lbn_ind);
+               } else {
+                       trace(TR_BREADMISS, pack(vp, size), lbn_ind);
+                       bp->b_blkno = daddr;
+                       bp->b_flags |= B_READ;
+                       bp->b_dev = devvp->v_rdev;
+                       (*(devvp->v_op->vop_strategy))(bp);
+                       curproc->p_stats->p_ru.ru_inblock++;    /* XXX */
+                       if (error = biowait(bp)) {
+                               brelse(bp);
+                               return (error);
+                       }
                }
                bap = bp->b_un.b_daddr;
                sh /= NINDIR(fs);
                }
                bap = bp->b_un.b_daddr;
                sh /= NINDIR(fs);
-               i = (bn / sh) % NINDIR(fs);
-               nb = bap[i];
-               if (nb == 0) {
-                       *bnp = (daddr_t)-1;
-                       brelse(bp);
-                       return (0);
-               }
-               brelse(bp);
+               off = (bn / sh) % NINDIR(fs);
+               lbn_ind  = -(NIADDR + 1 + off);
        }
        }
-       *bnp = nb;
+       if (bp)
+               brelse(bp);
+
+       *bnp = daddr;
        return (0);
 }
        return (0);
 }
index 6701648..30bf84d 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)lfs_inode.c 7.41 (Berkeley) %G%
+ *     @(#)lfs_inode.c 7.42 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -88,7 +88,7 @@ lfs_iget(xp, ino, ipp)
 {
        dev_t dev = xp->i_dev;
        struct mount *mntp = ITOV(xp)->v_mount;
 {
        dev_t dev = xp->i_dev;
        struct mount *mntp = ITOV(xp)->v_mount;
-       register struct lfs *fs = VFSTOUFS(mntp)->um_lfs;       /* LFS */
+       register LFS *fs = VFSTOUFS(mntp)->um_lfs;              /* LFS */
        extern struct vnodeops ufs_vnodeops, spec_inodeops;
        register struct inode *ip, *iq;
        register struct vnode *vp;
        extern struct vnodeops ufs_vnodeops, spec_inodeops;
        register struct inode *ip, *iq;
        register struct vnode *vp;
@@ -253,52 +253,6 @@ ip->i_number, ip->i_mode, ip->i_nlink);
        return (error);
 }
 
        return (error);
 }
 
-/*
- * Update the access, modified, and inode change times as specified
- * by the IACC, IMOD, and ICHG flags respectively. The IUPD flag
- * is used to specify that the inode needs to be updated but that
- * the times have already been set. The access and modified times
- * are taken from the second and third parameters; the inode change
- * time is always taken from the current time. If waitfor is set,
- * then wait for the disk write of the inode to complete.
- */
-lfs_iupdat(ip, ta, tm, waitfor)
-       register struct inode *ip;
-       struct timeval *ta, *tm;
-       int waitfor;
-{
-       struct buf *bp;
-       struct vnode *vp = ITOV(ip);
-       struct dinode *dp;
-       register struct fs *fs;
-
-       fs = ip->i_fs;
-       if ((ip->i_flag & (IUPD|IACC|ICHG|IMOD)) == 0)
-               return (0);
-       if (vp->v_mount->mnt_flag & MNT_RDONLY)
-               return (0);
-       error = bread(ip->i_devvp, fsbtodb(fs, itod(fs, ip->i_number)),
-               (int)fs->lfs_bsize, NOCRED, &bp);
-       if (error) {
-               brelse(bp);
-               return (error);
-       }
-       if (ip->i_flag&IACC)
-               ip->i_atime = ta->tv_sec;
-       if (ip->i_flag&IUPD)
-               ip->i_mtime = tm->tv_sec;
-       if (ip->i_flag&ICHG)
-               ip->i_ctime = time.tv_sec;
-       ip->i_flag &= ~(IUPD|IACC|ICHG|IMOD);                   /* LFS */
-       *lfs_ifind(fs, ip->i_number, bp->b_un.b_dino) = ip->i_din;
-       if (waitfor) {
-               return (bwrite(bp));
-       } else {
-               bdwrite(bp);
-               return (0);
-       }
-}
-
 #define        SINGLE  0       /* index of single indirect block */
 #define        DOUBLE  1       /* index of double indirect block */
 #define        TRIPLE  2       /* index of triple indirect block */
 #define        SINGLE  0       /* index of single indirect block */
 #define        DOUBLE  1       /* index of double indirect block */
 #define        TRIPLE  2       /* index of triple indirect block */
@@ -313,10 +267,9 @@ lfs_itrunc(oip, length, flags)
        u_long length;
        int flags;
 {
        u_long length;
        int flags;
 {
-#ifdef NOTLFS                                          /* LFS */
        register daddr_t lastblock;
        daddr_t bn, lbn, lastiblock[NIADDR];
        register daddr_t lastblock;
        daddr_t bn, lbn, lastiblock[NIADDR];
-       register struct fs *fs;
+       register LFS *fs;                                       /* LFS */
        register struct inode *ip;
        struct buf *bp;
        int offset, osize, size, level;
        register struct inode *ip;
        struct buf *bp;
        int offset, osize, size, level;
@@ -328,8 +281,8 @@ lfs_itrunc(oip, length, flags)
        vnode_pager_setsize(ITOV(oip), length);
        if (oip->i_size <= length) {
                oip->i_flag |= ICHG|IUPD;
        vnode_pager_setsize(ITOV(oip), length);
        if (oip->i_size <= length) {
                oip->i_flag |= ICHG|IUPD;
-               error = lfs_iupdat(oip, &time, &time, 1);
-               return (error);
+               ITIMES(oip, &time, &time);
+               return (0);
        }
        /*
         * Calculate index into inode's block list of
        }
        /*
         * Calculate index into inode's block list of
@@ -337,12 +290,12 @@ lfs_itrunc(oip, length, flags)
         * which we want to keep.  Lastblock is -1 when
         * the file is truncated to 0.
         */
         * which we want to keep.  Lastblock is -1 when
         * the file is truncated to 0.
         */
-       fs = oip->i_fs;
-       lastblock = lblkno(fs, length + fs->fs_bsize - 1) - 1;
+       fs = oip->i_lfs;                                        /* LFS */
+       lastblock = lblkno(fs, length + fs->lfs_bsize - 1) - 1; /* LFS */
        lastiblock[SINGLE] = lastblock - NDADDR;
        lastiblock[DOUBLE] = lastiblock[SINGLE] - NINDIR(fs);
        lastiblock[TRIPLE] = lastiblock[DOUBLE] - NINDIR(fs) * NINDIR(fs);
        lastiblock[SINGLE] = lastblock - NDADDR;
        lastiblock[DOUBLE] = lastiblock[SINGLE] - NINDIR(fs);
        lastiblock[TRIPLE] = lastiblock[DOUBLE] - NINDIR(fs) * NINDIR(fs);
-       nblocks = btodb(fs->fs_bsize);
+       nblocks = btodb(fs->lfs_bsize);                         /* LFS */
        /*
         * Update the size of the file. If the file is not being
         * truncated to a block boundry, the contents of the
        /*
         * Update the size of the file. If the file is not being
         * truncated to a block boundry, the contents of the
@@ -362,18 +315,22 @@ lfs_itrunc(oip, length, flags)
 #ifdef QUOTA
                if (error = getinoquota(oip))
                        return (error);
 #ifdef QUOTA
                if (error = getinoquota(oip))
                        return (error);
-#endif
-               if (error = balloc(oip, lbn, offset, &bp, aflags))
+#endif 
+               if (error = bread(ITOV(oip), lbn, fs->lfs_bsize, NOCRED, &bp))
                        return (error);
                oip->i_size = length;
                size = blksize(fs);                             /* LFS */
                (void) vnode_pager_uncache(ITOV(oip));
                bzero(bp->b_un.b_addr + offset, (unsigned)(size - offset));
                allocbuf(bp, size);
                        return (error);
                oip->i_size = length;
                size = blksize(fs);                             /* LFS */
                (void) vnode_pager_uncache(ITOV(oip));
                bzero(bp->b_un.b_addr + offset, (unsigned)(size - offset));
                allocbuf(bp, size);
-               if (flags & IO_SYNC)
+#ifdef NOTLFS
+               if (flags & IO_SYNC)                            /* LFS */
                        bwrite(bp);
                else
                        bdwrite(bp);
                        bwrite(bp);
                else
                        bdwrite(bp);
+#else
+               lfs_bwrite(bp);
+#endif
        }
        /*
         * Update file and block pointers
        }
        /*
         * Update file and block pointers
@@ -383,6 +340,7 @@ lfs_itrunc(oip, length, flags)
         * lastiblock values are also normalized to -1
         * for calls to indirtrunc below.
         */
         * lastiblock values are also normalized to -1
         * for calls to indirtrunc below.
         */
+       /* Will need to modify the segment usage information */ /* LFS */
        tip = *oip;
        tip.i_size = osize;
        for (level = TRIPLE; level >= SINGLE; level--)
        tip = *oip;
        tip.i_size = osize;
        for (level = TRIPLE; level >= SINGLE; level--)
@@ -393,9 +351,16 @@ lfs_itrunc(oip, length, flags)
        for (i = NDADDR - 1; i > lastblock; i--)
                oip->i_db[i] = 0;
        oip->i_flag |= ICHG|IUPD;
        for (i = NDADDR - 1; i > lastblock; i--)
                oip->i_db[i] = 0;
        oip->i_flag |= ICHG|IUPD;
+#ifdef NOTLFS
        vinvalbuf(ITOV(oip), (length > 0));
        vinvalbuf(ITOV(oip), (length > 0));
-       allerror = lfs_iupdat(oip, &time, &time, MNT_WAIT);
+       allerror = ITIMES(oip, &time, &time);
+#else
+       /* Need lfs_vinvalbuf to get rid of invalid buffers in the cache */
+       ITIMES(oip, &time, &time);
+       allerror = 0;
+#endif
 
 
+#ifdef NOTLFS
        /*
         * Indirect blocks first.
         */
        /*
         * Indirect blocks first.
         */
@@ -417,6 +382,10 @@ lfs_itrunc(oip, length, flags)
                if (lastiblock[level] >= 0)
                        goto done;
        }
                if (lastiblock[level] >= 0)
                        goto done;
        }
+#else
+       /* LFS -- not yet implemented.  Need to rewrite indirect blocks */
+       panic("lfs_itrunc: not yet implemented");
+#endif
 
        /*
         * All whole direct blocks or frags.
 
        /*
         * All whole direct blocks or frags.
@@ -429,7 +398,11 @@ lfs_itrunc(oip, length, flags)
                        continue;
                ip->i_db[i] = 0;
                bsize = (off_t)blksize(fs);                     /* LFS */
                        continue;
                ip->i_db[i] = 0;
                bsize = (off_t)blksize(fs);                     /* LFS */
+#ifdef NOTLFS
                blkfree(ip, bn, bsize);
                blkfree(ip, bn, bsize);
+#else
+               /* LFS Update segment usage information */
+#endif
                blocksreleased += btodb(bsize);
        }
        if (lastblock < 0)
                blocksreleased += btodb(bsize);
        }
        if (lastblock < 0)
@@ -481,10 +454,6 @@ done:
                (void) chkdq(oip, -blocksreleased, NOCRED, 0);
 #endif
        return (allerror);
                (void) chkdq(oip, -blocksreleased, NOCRED, 0);
 #endif
        return (allerror);
-#else
-       /* LFS IMPLEMENT -- lfs_itrunc */
-       panic("lfs_itrunc not implemented");
-#endif
 }
 
 /*
 }
 
 /*
index cea5010..87a41ae 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)lfs_vfsops.c        7.57 (Berkeley) %G%
+ *     @(#)lfs_vfsops.c        7.58 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -226,6 +226,10 @@ lfs_mountfs(devvp, mp, p)
        brelse(bp);
        bp = NULL;
 
        brelse(bp);
        bp = NULL;
 
+       /* Set up the I/O information */
+       fs->lfs_iocount = 0;
+       fs->lfs_seglist = NULL;
+
        /* Set the file system readonly/modify bits. */
        fs = ump->um_lfs;
        fs->lfs_ronly = ronly;
        /* Set the file system readonly/modify bits. */
        fs = ump->um_lfs;
        fs->lfs_ronly = ronly;
@@ -304,7 +308,7 @@ lfs_unmount(mp, mntflags, p)
        struct proc *p;
 {
        register struct ufsmount *ump;
        struct proc *p;
 {
        register struct ufsmount *ump;
-       register struct lfs *fs;                                /* LFS */
+       register LFS *fs;                                       /* LFS */
        int i, error, ronly, flags = 0;
 
 printf("lfs_unmount\n");
        int i, error, ronly, flags = 0;
 
 printf("lfs_unmount\n");
@@ -454,43 +458,8 @@ printf("lfs_sync\n");
                allerror = sbupdate(ump, waitfor);
        }
 #else
                allerror = sbupdate(ump, waitfor);
        }
 #else
-#ifdef DEBUG
-       return (0);
-#else
-       /* LFS IMPLEMENT -- read only access, super-block update */
-       panic("lfs_sync not implemented"); */
-#endif
+       allerror = lfs_segwrite(mp);
 #endif
 #endif
-       /*
-        * Write back each (modified) inode.
-        */
-loop:
-       for (vp = mp->mnt_mounth; vp; vp = vp->v_mountf) {
-               /*
-                * If the vnode that we are about to sync is no longer
-                * associated with this mount point, start over.
-                */
-               if (vp->v_mount != mp)
-                       goto loop;
-               if (VOP_ISLOCKED(vp))
-                       continue;
-               ip = VTOI(vp);
-               if ((ip->i_flag & (IMOD|IACC|IUPD|ICHG)) == 0 &&
-                   vp->v_dirtyblkhd == NULL)
-                       continue;
-               if (vget(vp))
-                       goto loop;
-               if (vp->v_dirtyblkhd)
-                       vflushbuf(vp, 0);
-               if ((ip->i_flag & (IMOD|IACC|IUPD|ICHG)) &&
-                   (error = lfs_iupdat(ip, &time, &time, 0)))  /* LFS */
-                       allerror = error;
-               vput(vp);
-       }
-       /*
-        * Force stale file system control information to be flushed.
-        */
-       vflushbuf(ump->um_devvp, waitfor == MNT_WAIT ? B_SYNC : 0);
 #ifdef QUOTA
        qsync(mp);
 #endif
 #ifdef QUOTA
        qsync(mp);
 #endif
@@ -521,7 +490,7 @@ lfs_fhtovp(mp, fhp, vpp)
        struct vnode **vpp;
 {
        register struct ufid *ufhp;
        struct vnode **vpp;
 {
        register struct ufid *ufhp;
-       register struct lfs *fs;                                /* LFS */
+       register LFS *fs;                                       /* LFS */
        register struct inode *ip;
        IFILE *ifp;
        struct buf *bp;
        register struct inode *ip;
        IFILE *ifp;
        struct buf *bp;
index 62ad38f..3f3b1ba 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)lfs_vnops.c 7.66 (Berkeley) %G%
+ *     @(#)lfs_vnops.c 7.67 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -99,7 +99,7 @@ lfs_getattr(vp, vap, cred, p)
        register struct inode *ip = VTOI(vp);
 
 printf("lfs_getattr\n");
        register struct inode *ip = VTOI(vp);
 
 printf("lfs_getattr\n");
-       ITIMES(ip, &time, &time);
+       ITIMES(ip, &time, &time);                               /* LFS */
        /*
         * Copy from inode table
         */
        /*
         * Copy from inode table
         */
@@ -180,8 +180,7 @@ printf("lfs_setattr\n");
                if (vap->va_mtime.tv_sec != VNOVAL)
                        ip->i_flag |= IUPD;
                ip->i_flag |= ICHG;                             /* LFS */
                if (vap->va_mtime.tv_sec != VNOVAL)
                        ip->i_flag |= IUPD;
                ip->i_flag |= ICHG;                             /* LFS */
-               if (error = lfs_iupdat(ip, &vap->va_atime, &vap->va_mtime, 1))
-                       return (error);
+               ITIMES(ip, &vap->va_atime, &vap->va_mtime);     /* LFS */
        }
        if (vap->va_mode != (u_short)VNOVAL)
                error = chmod1(vp, (int)vap->va_mode, p);
        }
        if (vap->va_mode != (u_short)VNOVAL)
                error = chmod1(vp, (int)vap->va_mode, p);
@@ -274,7 +273,7 @@ lfs_write(vp, uio, ioflag, cred)
 {
        struct proc *p = uio->uio_procp;
        register struct inode *ip = VTOI(vp);
 {
        struct proc *p = uio->uio_procp;
        register struct inode *ip = VTOI(vp);
-       register struct fs *fs;
+       register LFS *fs;                                       /* LFS */
        struct buf *bp;
        daddr_t lbn, bn;
        u_long osize;
        struct buf *bp;
        daddr_t lbn, bn;
        u_long osize;
@@ -318,30 +317,32 @@ printf("lfs_write ino %d\n", ip->i_number);
        }
        resid = uio->uio_resid;
        osize = ip->i_size;
        }
        resid = uio->uio_resid;
        osize = ip->i_size;
-#ifdef NOTLFS                                                  /* LFS */
-       fs = ip->i_fs;
+       fs = ip->i_lfs;                                         /* LFS */
        flags = 0;
        flags = 0;
+#ifdef NOTLFS
        if (ioflag & IO_SYNC)
                flags = B_SYNC;
        if (ioflag & IO_SYNC)
                flags = B_SYNC;
+#endif
        do {
                lbn = lblkno(fs, uio->uio_offset);
        do {
                lbn = lblkno(fs, uio->uio_offset);
-               on = blkoff(fs, uio->uio_offset);
-               n = MIN((unsigned)(fs->fs_bsize - on), uio->uio_resid);
-               if (n < fs->fs_bsize)
+               on = blkoff(fs, uio->uio_offset);               /* LFS */
+               n = MIN((unsigned)(fs->lfs_bsize - on), uio->uio_resid);
+               if (n < fs->lfs_bsize)                          /* LFS */
                        flags |= B_CLRBUF;
                else
                        flags |= B_CLRBUF;
                else
-                       flags &= ~B_CLRBUF;
-               if (error = balloc(ip, lbn, (int)(on + n), &bp, flags))
+                       flags &= ~B_CLRBUF;                     /* LFS */
+               if (error = bread(vp, lbn, fs->lfs_bsize, NOCRED, &bp))
                        break;
                bn = bp->b_blkno;
                if (uio->uio_offset + n > ip->i_size) {
                        ip->i_size = uio->uio_offset + n;
                        vnode_pager_setsize(vp, ip->i_size);
                }
                        break;
                bn = bp->b_blkno;
                if (uio->uio_offset + n > ip->i_size) {
                        ip->i_size = uio->uio_offset + n;
                        vnode_pager_setsize(vp, ip->i_size);
                }
-               size = blksize(fs, ip, lbn);
+               size = blksize(fs);
                (void) vnode_pager_uncache(vp);
                n = MIN(n, size - bp->b_resid);
                error = uiomove(bp->b_un.b_addr + on, n, uio);
                (void) vnode_pager_uncache(vp);
                n = MIN(n, size - bp->b_resid);
                error = uiomove(bp->b_un.b_addr + on, n, uio);
+#ifdef NOTLFS                                                  /* LFS */
                if (ioflag & IO_SYNC)
                        (void) bwrite(bp);
                else if (n + on == fs->fs_bsize) {
                if (ioflag & IO_SYNC)
                        (void) bwrite(bp);
                else if (n + on == fs->fs_bsize) {
@@ -349,21 +350,27 @@ printf("lfs_write ino %d\n", ip->i_number);
                        bawrite(bp);
                } else
                        bdwrite(bp);
                        bawrite(bp);
                } else
                        bdwrite(bp);
+#else
+               /*
+                * Update segment usage information; call segment
+                * writer if necessary.
+                */
+               lfs_bwrite(bp);
+#endif
                ip->i_flag |= IUPD|ICHG;
                if (cred->cr_uid != 0)
                        ip->i_mode &= ~(ISUID|ISGID);
        } while (error == 0 && uio->uio_resid > 0 && n != 0);
                ip->i_flag |= IUPD|ICHG;
                if (cred->cr_uid != 0)
                        ip->i_mode &= ~(ISUID|ISGID);
        } while (error == 0 && uio->uio_resid > 0 && n != 0);
-#else
-       /* LFS IMPLEMENT -- write call */
-       panic("lfs_write not implemented");
-#endif
        if (error && (ioflag & IO_UNIT)) {
        if (error && (ioflag & IO_UNIT)) {
+#ifdef NOTLFS
+       /* This just doesn't work... */
                (void) lfs_itrunc(ip, osize, ioflag & IO_SYNC);
                (void) lfs_itrunc(ip, osize, ioflag & IO_SYNC);
+#endif
                uio->uio_offset -= resid - uio->uio_resid;
                uio->uio_resid = resid;
        }
        if (!error && (ioflag & IO_SYNC))
                uio->uio_offset -= resid - uio->uio_resid;
                uio->uio_resid = resid;
        }
        if (!error && (ioflag & IO_SYNC))
-               error = lfs_iupdat(ip, &time, &time, 1);
+               ITIMES(ip, &time, &time);                       /* LFS */
        return (error);
 }
 
        return (error);
 }
 
@@ -383,8 +390,9 @@ lfs_fsync(vp, fflags, cred, waitfor, p)
 printf("lfs_sync: ino %d\n", ip->i_number);
        if (fflags & FWRITE)
                ip->i_flag |= ICHG;
 printf("lfs_sync: ino %d\n", ip->i_number);
        if (fflags & FWRITE)
                ip->i_flag |= ICHG;
+       ITIMES(ip, &time, &time);                               /* LFS */
        vflushbuf(vp, waitfor == MNT_WAIT ? B_SYNC : 0);        /* LFS */
        vflushbuf(vp, waitfor == MNT_WAIT ? B_SYNC : 0);        /* LFS */
-       return (lfs_iupdat(ip, &time, &time, waitfor == MNT_WAIT));
+       return (0);
 }
 
 /*
 }
 
 /*
@@ -438,9 +446,8 @@ printf("lfs_link\n");
                ILOCK(ip);
        ip->i_nlink++;
        ip->i_flag |= ICHG;
                ILOCK(ip);
        ip->i_nlink++;
        ip->i_flag |= ICHG;
-       error = lfs_iupdat(ip, &time, &time, 1);                /* LFS */
-       if (!error)
-               error = lfs_direnter(ip, ndp);                  /* LFS */
+       ITIMES(ip, &time, &time);                               /* LFS */
+       error = lfs_direnter(ip, ndp);                          /* LFS */
        if (ndp->ni_dvp != vp)
                IUNLOCK(ip);
        FREE(ndp->ni_pnbuf, M_NAMEI);
        if (ndp->ni_dvp != vp)
                IUNLOCK(ip);
        FREE(ndp->ni_pnbuf, M_NAMEI);
@@ -539,7 +546,7 @@ printf("lfs_rename\n");
         */
        ip->i_nlink++;
        ip->i_flag |= ICHG;
         */
        ip->i_nlink++;
        ip->i_flag |= ICHG;
-       error = lfs_iupdat(ip, &time, &time, 1);                /* LFS */
+       ITIMES(ip, &time, &time);                               /* LFS */
        IUNLOCK(ip);
 
        /*
        IUNLOCK(ip);
 
        /*
@@ -604,14 +611,13 @@ printf("lfs_rename\n");
                        }
                        dp->i_nlink++;
                        dp->i_flag |= ICHG;                     /* LFS */
                        }
                        dp->i_nlink++;
                        dp->i_flag |= ICHG;                     /* LFS */
-                       if (error = lfs_iupdat(dp, &time, &time, 1))
-                               goto bad;
+                       ITIMES(dp, &time, &time);               /* LFS */
                }
                if (error = lfs_direnter(ip, tndp)) {
                        if (doingdirectory && newparent) {
                                dp->i_nlink--;
                                dp->i_flag |= ICHG;             /* LFS */
                }
                if (error = lfs_direnter(ip, tndp)) {
                        if (doingdirectory && newparent) {
                                dp->i_nlink--;
                                dp->i_flag |= ICHG;             /* LFS */
-                               (void) lfs_iupdat(dp, &time, &time, 1);
+                               ITIMES(dp, &time, &time);       /* LFS */
                        }
                        goto bad;
                }
                        }
                        goto bad;
                }
@@ -855,7 +861,7 @@ printf("lfs_mkdir\n");
        ip->i_mode = dmode;
        ITOV(ip)->v_type = VDIR;        /* Rest init'd in iget() */
        ip->i_nlink = 2;
        ip->i_mode = dmode;
        ITOV(ip)->v_type = VDIR;        /* Rest init'd in iget() */
        ip->i_nlink = 2;
-       error = lfs_iupdat(ip, &time, &time, 1);                /* LFS */
+       ITIMES(ip, &time, &time);                               /* LFS */
 
        /*
         * Bump link count in parent directory
 
        /*
         * Bump link count in parent directory
@@ -865,8 +871,7 @@ printf("lfs_mkdir\n");
         */
        dp->i_nlink++;
        dp->i_flag |= ICHG;
         */
        dp->i_nlink++;
        dp->i_flag |= ICHG;
-       if (error = lfs_iupdat(dp, &time, &time, 1))            /* LFS */
-               goto bad;
+       ITIMES(dp, &time, &time);                               /* LFS */
 
        /*
         * Initialize directory with "."
 
        /*
         * Initialize directory with "."
@@ -1155,13 +1160,7 @@ printf("maknode\n");
            suser(ndp->ni_cred, NULL))
                ip->i_mode &= ~ISGID;
 
            suser(ndp->ni_cred, NULL))
                ip->i_mode &= ~ISGID;
 
-       /*
-        * Make sure inode goes to disk before directory entry.
-        *
-        * XXX Wrong...
-        */
-       if (error = lfs_iupdat(ip, &time, &time, 1))            /* LFS */
-               goto bad;
+       ITIMES(ip, &time, &time);                               /* LFS */
        if (error = lfs_direnter(ip, ndp))                      /* LFS */
                goto bad;
        if ((ndp->ni_nameiop & SAVESTART) == 0)
        if (error = lfs_direnter(ip, ndp))                      /* LFS */
                goto bad;
        if ((ndp->ni_nameiop & SAVESTART) == 0)