statfs.f_bsize => statfs.f_iosize; statfs.f_fsize => statfs.f_bsize (for SunOS)
[unix-history] / usr / src / sys / ufs / lfs / lfs_vfsops.c
index e26afbf..7076647 100644 (file)
@@ -4,39 +4,36 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)lfs_vfsops.c        7.60 (Berkeley) %G%
+ *     @(#)lfs_vfsops.c        7.67 (Berkeley) %G%
  */
 
  */
 
-#ifdef LOGFS
-#include "param.h"
-#include "systm.h"
-#include "namei.h"
-#include "proc.h"
-#include "kernel.h"
-#include "vnode.h"
-#include "specdev.h"
-#include "mount.h"
-#include "buf.h"
-#include "file.h"
-#include "disklabel.h"
-#include "ioctl.h"
-#include "errno.h"
-#include "malloc.h"
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/namei.h>
+#include <sys/proc.h>
+#include <sys/kernel.h>
+#include <sys/vnode.h>
+#include <sys/specdev.h>
+#include <sys/mount.h>
+#include <sys/buf.h>
+#include <sys/file.h>
+#include <sys/disklabel.h>
+#include <sys/ioctl.h>
+#include <sys/errno.h>
+#include <sys/malloc.h>
 #include "ioctl.h"
 #include "disklabel.h"
 #include "stat.h"
 
 #include "ioctl.h"
 #include "disklabel.h"
 #include "stat.h"
 
-#include "../ufs/quota.h"
-#include "../ufs/inode.h"
-#include "../ufs/ufsmount.h"
-#include "lfs.h"
-#include "lfs_extern.h"
+#include <ufs/ufs/quota.h>
+#include <ufs/ufs/inode.h>
+#include <ufs/ufs/ufsmount.h>
+#include <ufs/ufs/ufs_extern.h>
 
 
-static int     lfs_mountfs
-                   __P((struct vnode *, struct mount *, struct proc *));
+#include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_extern.h>
 
 
-static int     lfs_umountdebug __P((struct mount *));
-static int     lfs_vinvalbuf __P((register struct vnode *));
+static int lfs_mountfs __P((struct vnode *, struct mount *, struct proc *));
 
 struct vfsops lfs_vfsops = {
        lfs_mount,
 
 struct vfsops lfs_vfsops = {
        lfs_mount,
@@ -47,19 +44,14 @@ struct vfsops lfs_vfsops = {
        lfs_statfs,
        lfs_sync,
        lfs_fhtovp,
        lfs_statfs,
        lfs_sync,
        lfs_fhtovp,
-       ufs_vptofh,
-       lfs_init
+       lfs_vptofh,
+       lfs_init,
 };
 
 };
 
-/*
- * Flag to allow forcible unmounting.
- */
-extern int doforce;                                            /* LFS */
-
+int
 lfs_mountroot()
 {
 lfs_mountroot()
 {
-       /* LFS IMPLEMENT -- lfs_mountroot */
-       panic("lfs_mountroot");
+       panic("lfs_mountroot");         /* XXX -- implement */
 }
 
 /*
 }
 
 /*
@@ -77,12 +69,16 @@ lfs_mount(mp, path, data, ndp, p)
        struct vnode *devvp;
        struct ufs_args args;
        struct ufsmount *ump;
        struct vnode *devvp;
        struct ufs_args args;
        struct ufsmount *ump;
-       register LFS *fs;                                       /* LFS */
+       register struct lfs *fs;                                /* LFS */
        u_int size;
        int error;
 
        if (error = copyin(data, (caddr_t)&args, sizeof (struct ufs_args)))
                return (error);
        u_int size;
        int error;
 
        if (error = copyin(data, (caddr_t)&args, sizeof (struct ufs_args)))
                return (error);
+
+       /* Until LFS can do NFS right.          XXX */
+       if (args.exflags & MNT_EXPORTED)
+               return (EINVAL);
        /*
         * Process export requests.
         */
        /*
         * Process export requests.
         */
@@ -180,7 +176,7 @@ lfs_mountfs(devvp, mp, p)
        struct proc *p;
 {
        extern struct vnode *rootvp;
        struct proc *p;
 {
        extern struct vnode *rootvp;
-       register LFS *fs;
+       register struct lfs *fs;
        register struct ufsmount *ump;
        struct inode *ip;
        struct vnode *vp;
        register struct ufsmount *ump;
        struct inode *ip;
        struct vnode *vp;
@@ -216,21 +212,21 @@ lfs_mountfs(devvp, mp, p)
                goto out;
        }
 #ifdef DEBUG
                goto out;
        }
 #ifdef DEBUG
-       dump_super(fs);
+       lfs_dump_super(fs);
 #endif
 
        /* Allocate the mount structure, copy the superblock into it. */
        ump = (struct ufsmount *)malloc(sizeof *ump, M_UFSMNT, M_WAITOK);
 #endif
 
        /* Allocate the mount structure, copy the superblock into it. */
        ump = (struct ufsmount *)malloc(sizeof *ump, M_UFSMNT, M_WAITOK);
-       ump->um_lfs = malloc(sizeof(LFS), M_SUPERBLK, M_WAITOK);
-       bcopy(bp->b_un.b_addr, ump->um_lfs, sizeof(LFS));
-       if (sizeof(LFS) < LFS_SBPAD)                    /* XXX why? */
+       ump->um_lfs = malloc(sizeof(struct lfs), M_SUPERBLK, M_WAITOK);
+       bcopy(bp->b_un.b_addr, ump->um_lfs, sizeof(struct lfs));
+       if (sizeof(struct lfs) < LFS_SBPAD)                     /* XXX why? */
                bp->b_flags |= B_INVAL;
        brelse(bp);
        bp = NULL;
 
        /* Set up the I/O information */
        fs->lfs_iocount = 0;
                bp->b_flags |= B_INVAL;
        brelse(bp);
        bp = NULL;
 
        /* Set up the I/O information */
        fs->lfs_iocount = 0;
-       fs->lfs_seglist = NULL;
+       /* XXX NOTUSED: fs->lfs_seglist = NULL; */
 
        /* Set the file system readonly/modify bits. */
        fs = ump->um_lfs;
 
        /* Set the file system readonly/modify bits. */
        fs = ump->um_lfs;
@@ -251,13 +247,12 @@ lfs_mountfs(devvp, mp, p)
                ump->um_quotas[i] = NULLVP;
 
        /* Read the ifile disk inode and store it in a vnode. */
                ump->um_quotas[i] = NULLVP;
 
        /* Read the ifile disk inode and store it in a vnode. */
-       error = bread(devvp, fs->lfs_idaddr, fs->lfs_bsize, NOCRED, &bp);
-       if (error)
+       if (error = bread(devvp, fs->lfs_idaddr, fs->lfs_bsize, NOCRED, &bp))
                goto out;
                goto out;
-       error = lfs_vcreate(mp, LFS_IFILE_INUM, &vp);
-       if (error)
+       if (error = lfs_vcreate(mp, LFS_IFILE_INUM, &vp))
                goto out;
        ip = VTOI(vp);
                goto out;
        ip = VTOI(vp);
+       VREF(ip->i_devvp);
 
        /* The ifile inode is stored in the superblock. */
        fs->lfs_ivnode = vp;
 
        /* The ifile inode is stored in the superblock. */
        fs->lfs_ivnode = vp;
@@ -269,22 +264,6 @@ lfs_mountfs(devvp, mp, p)
        /* Initialize the associated vnode */
        vp->v_type = IFTOVT(ip->i_mode);
 
        /* Initialize the associated vnode */
        vp->v_type = IFTOVT(ip->i_mode);
 
-       /*
-        * Read in the segusage table.
-        * 
-        * Since we always explicitly write the segusage table at a checkpoint,
-        * we're assuming that it is continguous on disk.
-        */
-       seg_addr = ip->i_din.di_db[0];
-       size = fs->lfs_segtabsz << fs->lfs_bshift;
-       fs->lfs_segtab = malloc(size, M_SUPERBLK, M_WAITOK);
-       error = bread(devvp, seg_addr, size, NOCRED, &bp);
-       if (error) {
-               free(fs->lfs_segtab, M_SUPERBLK);
-               goto out;
-       }
-       bcopy((caddr_t)bp->b_un.b_addr, fs->lfs_segtab, size);
-       brelse(bp);
        devvp->v_specflags |= SI_MOUNTEDON;
        VREF(ip->i_devvp);
 
        devvp->v_specflags |= SI_MOUNTEDON;
        VREF(ip->i_devvp);
 
@@ -294,8 +273,8 @@ out:
                brelse(bp);
        (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
        if (ump) {
                brelse(bp);
        (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
        if (ump) {
-               free((caddr_t)ump->um_lfs, M_SUPERBLK);
-               free((caddr_t)ump, M_UFSMNT);
+               free(ump->um_lfs, M_SUPERBLK);
+               free(ump, M_UFSMNT);
                mp->mnt_data = (qaddr_t)0;
        }
        return (error);
                mp->mnt_data = (qaddr_t)0;
        }
        return (error);
@@ -309,12 +288,15 @@ lfs_unmount(mp, mntflags, p)
        int mntflags;
        struct proc *p;
 {
        int mntflags;
        struct proc *p;
 {
+       extern int doforce;
        register struct ufsmount *ump;
        register struct ufsmount *ump;
-       register LFS *fs;                                       /* LFS */
+       register struct lfs *fs;                                /* LFS */
        int i, error, ronly, flags = 0;
        int ndirty;                                             /* LFS */
 
        int i, error, ronly, flags = 0;
        int ndirty;                                             /* LFS */
 
-printf("lfs_unmount\n");
+#ifdef VERBOSE
+       printf("lfs_unmount\n");
+#endif
        if (mntflags & MNT_FORCE) {
                if (!doforce || mp == rootfs)
                        return (EINVAL);
        if (mntflags & MNT_FORCE) {
                if (!doforce || mp == rootfs)
                        return (EINVAL);
@@ -354,29 +336,6 @@ return(0);
        fs = ump->um_lfs;
        ronly = !fs->lfs_ronly;
 #endif
        fs = ump->um_lfs;
        ronly = !fs->lfs_ronly;
 #endif
- * Return root of a filesystem
- */
-lfs_root(mp, vpp)
-       struct mount *mp;
-       struct vnode **vpp;
-{
-       register struct inode *ip;
-       struct inode *nip;
-       struct vnode tvp;
-       int error;
-
-       tvp.v_mount = mp;
-       ip = VTOI(&tvp);
-       ip->i_vnode = &tvp;
-       ip->i_dev = VFSTOUFS(mp)->um_dev;
-       error = lfs_iget(ip, (ino_t)ROOTINO, &nip);             /* LFS */
-       if (error)
-               return (error);
-       *vpp = ITOV(nip);
-       return (0);
-}
-
-/*
  * Get file system statistics.
  */
 lfs_statfs(mp, sbp, p)
  * Get file system statistics.
  */
 lfs_statfs(mp, sbp, p)
@@ -384,38 +343,22 @@ lfs_statfs(mp, sbp, p)
        register struct statfs *sbp;
        struct proc *p;
 {
        register struct statfs *sbp;
        struct proc *p;
 {
-       register LFS *fs;
+       register struct lfs *fs;
        register struct ufsmount *ump;
 
        ump = VFSTOUFS(mp);
        register struct ufsmount *ump;
 
        ump = VFSTOUFS(mp);
-#ifdef NOTLFS                                                  /* LFS */
-       fs = ump->um_fs;
-       if (fs->fs_magic != FS_MAGIC)
-               panic("ufs_statfs");
-       sbp->f_type = MOUNT_UFS;
-       sbp->f_fsize = fs->fs_fsize;
-       sbp->f_bsize = fs->fs_bsize;
-       sbp->f_blocks = fs->fs_dsize;
-       sbp->f_bfree = fs->fs_cstotal.cs_nbfree * fs->fs_frag +
-               fs->fs_cstotal.cs_nffree;
-       sbp->f_bavail = (fs->fs_dsize * (100 - fs->fs_minfree) / 100) -
-               (fs->fs_dsize - sbp->f_bfree);
-       sbp->f_files =  fs->fs_ncg * fs->fs_ipg - ROOTINO;
-       sbp->f_ffree = fs->fs_cstotal.cs_nifree;
-#else
        fs = ump->um_lfs;
        if (fs->lfs_magic != LFS_MAGIC)
                panic("lfs_statfs: magic");
        sbp->f_type = MOUNT_LFS;
        fs = ump->um_lfs;
        if (fs->lfs_magic != LFS_MAGIC)
                panic("lfs_statfs: magic");
        sbp->f_type = MOUNT_LFS;
-       sbp->f_fsize = fs->lfs_bsize;
        sbp->f_bsize = fs->lfs_bsize;
        sbp->f_bsize = fs->lfs_bsize;
+       sbp->f_iosize = fs->lfs_bsize;
        sbp->f_blocks = fs->lfs_dsize;
        sbp->f_bfree = fs->lfs_bfree;
        sbp->f_bavail = (fs->lfs_dsize * (100 - fs->lfs_minfree) / 100) -
                (fs->lfs_dsize - sbp->f_bfree);
        sbp->f_files = fs->lfs_nfiles;
        sbp->f_ffree = fs->lfs_bfree * INOPB(fs);
        sbp->f_blocks = fs->lfs_dsize;
        sbp->f_bfree = fs->lfs_bfree;
        sbp->f_bavail = (fs->lfs_dsize * (100 - fs->lfs_minfree) / 100) -
                (fs->lfs_dsize - sbp->f_bfree);
        sbp->f_files = fs->lfs_nfiles;
        sbp->f_ffree = fs->lfs_bfree * INOPB(fs);
-#endif
        if (sbp != &mp->mnt_stat) {
                bcopy((caddr_t)mp->mnt_stat.f_mntonname,
                        (caddr_t)&sbp->f_mntonname[0], MNAMELEN);
        if (sbp != &mp->mnt_stat) {
                bcopy((caddr_t)mp->mnt_stat.f_mntonname,
                        (caddr_t)&sbp->f_mntonname[0], MNAMELEN);
@@ -425,8 +368,6 @@ lfs_statfs(mp, sbp, p)
        return (0);
 }
 
        return (0);
 }
 
-extern int     syncprt;                                        /* LFS */
-
 /*
  * Go through the disk queues to initiate sandbagged IO;
  * go through the inodes to write those that have been modified;
 /*
  * Go through the disk queues to initiate sandbagged IO;
  * go through the inodes to write those that have been modified;
@@ -434,16 +375,22 @@ extern int        syncprt;                                        /* LFS */
  *
  * Note: we are always called with the filesystem marked `MPBUSY'.
  */
  *
  * Note: we are always called with the filesystem marked `MPBUSY'.
  */
-int STOPNOW;
 lfs_sync(mp, waitfor)
        struct mount *mp;
        int waitfor;
 {
 lfs_sync(mp, waitfor)
        struct mount *mp;
        int waitfor;
 {
+       extern int crashandburn, syncprt;
        static int sync_lock, sync_want;
        int error;
 
        static int sync_lock, sync_want;
        int error;
 
-printf("lfs_sync\n");
+#ifdef VERBOSE
+       printf("lfs_sync\n");
+#endif
 
 
+#ifdef DIAGNOSTIC
+       if (crashandburn)
+               return (0);
+#endif
        /*
         * Meta data blocks are only marked dirty, not busy, so LFS syncs
         * must be single threaded.
        /*
         * Meta data blocks are only marked dirty, not busy, so LFS syncs
         * must be single threaded.
@@ -456,10 +403,9 @@ printf("lfs_sync\n");
        sync_lock = 1;
 
        if (syncprt)
        sync_lock = 1;
 
        if (syncprt)
-               bufstats();
+               ufs_bufstats();
 
        /* All syncs must be checkpoints until roll-forward is implemented. */
 
        /* All syncs must be checkpoints until roll-forward is implemented. */
-STOPNOW = 1;
        error = lfs_segwrite(mp, 1);            
 #ifdef QUOTA
        qsync(mp);
        error = lfs_segwrite(mp, 1);            
 #ifdef QUOTA
        qsync(mp);
@@ -476,130 +422,64 @@ STOPNOW = 1;
  * File handle to vnode
  *
  * Have to be really careful about stale file handles:
  * File handle to vnode
  *
  * Have to be really careful about stale file handles:
- * - check that the inode number is in range
- * - call iget() to get the locked inode
+ * - check that the inode number is valid
+ * - call lfs_vget() to get the locked inode
  * - check for an unallocated inode (i_mode == 0)
  * - check that the generation number matches
  * - check for an unallocated inode (i_mode == 0)
  * - check that the generation number matches
+ *
+ * XXX
+ * use ifile to see if inode is allocated instead of reading off disk
+ * what is the relationship between my generational number and the NFS
+ * generational number.
  */
  */
+int
 lfs_fhtovp(mp, fhp, vpp)
        register struct mount *mp;
        struct fid *fhp;
        struct vnode **vpp;
 {
 lfs_fhtovp(mp, fhp, vpp)
        register struct mount *mp;
        struct fid *fhp;
        struct vnode **vpp;
 {
-       register struct ufid *ufhp;
-       register LFS *fs;                                       /* LFS */
        register struct inode *ip;
        register struct inode *ip;
-       IFILE *ifp;
-       struct buf *bp;
-       struct inode *nip;
-       struct vnode tvp;
+       register struct ufid *ufhp;
+       struct vnode *nvp;
        int error;
 
        ufhp = (struct ufid *)fhp;
        int error;
 
        ufhp = (struct ufid *)fhp;
-#ifdef NOTLFS                                                  /* LFS */
-       fs = VFSTOUFS(mp)->um_fs;
-       if (ufhp->ufid_ino < ROOTINO ||
-           ufhp->ufid_ino >= fs->fs_ncg * fs->fs_ipg) {
-               *vpp = NULLVP;
-               return (EINVAL);
-       }
-#else
-       fs = VFSTOUFS(mp)->um_lfs;
-       if (ufhp->ufid_ino < ROOTINO) {
-               *vpp = NULLVP;
+       if (ufhp->ufid_ino < ROOTINO)
                return (EINVAL);
                return (EINVAL);
-       }
-#endif
-       tvp.v_mount = mp;
-       ip = VTOI(&tvp);
-       ip->i_vnode = &tvp;
-       ip->i_dev = VFSTOUFS(mp)->um_dev;
-       if (error = lfs_iget(ip, ufhp->ufid_ino, &nip)) {       /* LFS */
+       if (error = lfs_vget(mp, ufhp->ufid_ino, &nvp)) {
                *vpp = NULLVP;
                return (error);
        }
                *vpp = NULLVP;
                return (error);
        }
-       ip = nip;
+       ip = VTOI(nvp);
        if (ip->i_mode == 0) {
        if (ip->i_mode == 0) {
-               iput(ip);
+               ufs_iput(ip);
                *vpp = NULLVP;
                return (EINVAL);
        }
        if (ip->i_gen != ufhp->ufid_gen) {
                *vpp = NULLVP;
                return (EINVAL);
        }
        if (ip->i_gen != ufhp->ufid_gen) {
-               iput(ip);
+               ufs_iput(ip);
                *vpp = NULLVP;
                return (EINVAL);
        }
                *vpp = NULLVP;
                return (EINVAL);
        }
-       *vpp = ITOV(ip);
+       *vpp = nvp;
        return (0);
 }
 
        return (0);
 }
 
-static int
-lfs_umountdebug(mp)
-       struct mount *mp;
-{
+/*
+ * Vnode pointer to File handle
+ */
+/* ARGSUSED */
+lfs_vptofh(vp, fhp)
        struct vnode *vp;
        struct vnode *vp;
-       int dirty;
-
-       dirty = 0;
-       if ((mp->mnt_flag & MNT_MPBUSY) == 0)
-               panic("umountdebug: not busy");
-loop:
-       for (vp = mp->mnt_mounth; vp; vp = vp->v_mountf) {
-               if (vget(vp))
-                       goto loop;
-               dirty += lfs_vinvalbuf(vp);
-               vput(vp);
-               if (vp->v_mount != mp)
-                       goto loop;
-       }
-       return (dirty);
-}
-static int
-lfs_vinvalbuf(vp)
-       register struct vnode *vp;
+       struct fid *fhp;
 {
 {
-       register struct buf *bp;
-       struct buf *nbp, *blist;
-       int s, dirty = 0;
-
-       for (;;) {
-               if (blist = vp->v_dirtyblkhd)
-                       /* void */;
-               else if (blist = vp->v_cleanblkhd)
-                       /* void */;
-               else
-                       break;
-               for (bp = blist; bp; bp = nbp) {
-printf("lfs_vinvalbuf: ino %d, lblkno %d, blkno %lx flags %xl\n",
-VTOI(vp)->i_number, bp->b_lblkno, bp->b_blkno, bp->b_flags);
-                       nbp = bp->b_blockf;
-                       s = splbio();
-                       if (bp->b_flags & B_BUSY) {
-printf("lfs_vinvalbuf: buffer busy, would normally sleep\n");
-/*
-                               bp->b_flags |= B_WANTED;
-                               sleep((caddr_t)bp, PRIBIO + 1);
-*/
-                               splx(s);
-                               break;
-                       }
-                       bremfree(bp);
-                       bp->b_flags |= B_BUSY;
-                       splx(s);
-                       if (bp->b_flags & B_DELWRI) {
-                               dirty++;                        /* XXX */
-printf("lfs_vinvalbuf: buffer dirty (DELWRI). would normally write\n");
-                               break;
-                       }
-                       if (bp->b_vp != vp)
-                               reassignbuf(bp, bp->b_vp);
-                       else
-                               bp->b_flags |= B_INVAL;
-                       brelse(bp);
-               }
-       }
-       if (vp->v_dirtyblkhd || vp->v_cleanblkhd)
-               panic("lfs_vinvalbuf: flush failed");
-       return (dirty);
+       register struct inode *ip;
+       register struct ufid *ufhp;
+
+       ip = VTOI(vp);
+       ufhp = (struct ufid *)fhp;
+       ufhp->ufid_len = sizeof(struct ufid);
+       ufhp->ufid_ino = ip->i_number;
+       ufhp->ufid_gen = ip->i_gen;
+       return (0);
 }
 }
-#endif /* LOGFS */