add ufs_check_export
[unix-history] / usr / src / sys / ufs / lfs / lfs_vfsops.c
index 170f50a..68916b8 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)lfs_vfsops.c        7.78 (Berkeley) %G%
+ *     @(#)lfs_vfsops.c        7.84 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -217,8 +217,8 @@ lfs_mountfs(devvp, mp, p)
 
        /* Allocate the mount structure, copy the superblock into it. */
        ump = (struct ufsmount *)malloc(sizeof *ump, M_UFSMNT, M_WAITOK);
 
        /* Allocate the mount structure, copy the superblock into it. */
        ump = (struct ufsmount *)malloc(sizeof *ump, M_UFSMNT, M_WAITOK);
-       ump->um_lfs = malloc(sizeof(struct lfs), M_UFSMNT, M_WAITOK);
-       bcopy(bp->b_un.b_addr, ump->um_lfs, sizeof(struct lfs));
+       fs = ump->um_lfs = malloc(sizeof(struct lfs), M_UFSMNT, M_WAITOK);
+       bcopy(bp->b_un.b_addr, fs, sizeof(struct lfs));
        if (sizeof(struct lfs) < LFS_SBPAD)                     /* XXX why? */
                bp->b_flags |= B_INVAL;
        brelse(bp);
        if (sizeof(struct lfs) < LFS_SBPAD)                     /* XXX why? */
                bp->b_flags |= B_INVAL;
        brelse(bp);
@@ -227,13 +227,13 @@ lfs_mountfs(devvp, mp, p)
        /* Set up the I/O information */
        fs->lfs_iocount = 0;
 
        /* Set up the I/O information */
        fs->lfs_iocount = 0;
 
-       /* Set up the ifile flags */
+       /* Set up the ifile and lock aflags */
        fs->lfs_doifile = 0;
        fs->lfs_writer = 0;
        fs->lfs_dirops = 0;
        fs->lfs_doifile = 0;
        fs->lfs_writer = 0;
        fs->lfs_dirops = 0;
+       fs->lfs_seglock = 0;
 
        /* Set the file system readonly/modify bits. */
 
        /* Set the file system readonly/modify bits. */
-       fs = ump->um_lfs;
        fs->lfs_ronly = ronly;
        if (ronly == 0)
                fs->lfs_fmod = 1;
        fs->lfs_ronly = ronly;
        if (ronly == 0)
                fs->lfs_fmod = 1;
@@ -287,12 +287,9 @@ lfs_unmount(mp, mntflags, p)
 {
        extern int doforce;
        register struct ufsmount *ump;
 {
        extern int doforce;
        register struct ufsmount *ump;
-       register struct lfs *fs;                                /* LFS */
+       register struct lfs *fs;
        int i, error, flags, ronly;
 
        int i, error, flags, ronly;
 
-#ifdef VERBOSE
-       printf("lfs_unmount\n");
-#endif
        flags = 0;
        if (mntflags & MNT_FORCE) {
                if (!doforce || mp == rootfs)
        flags = 0;
        if (mntflags & MNT_FORCE) {
                if (!doforce || mp == rootfs)
@@ -318,13 +315,14 @@ lfs_unmount(mp, mntflags, p)
                 */
        }
 #endif
                 */
        }
 #endif
-       vrele(fs->lfs_ivnode);
        if (error = vflush(mp, fs->lfs_ivnode, flags))
                return (error);
        if (error = vflush(mp, fs->lfs_ivnode, flags))
                return (error);
+       fs->lfs_clean = 1;
        if (error = VFS_SYNC(mp, 1, p->p_ucred, p))
                return (error);
        if (fs->lfs_ivnode->v_dirtyblkhd)
                panic("lfs_unmount: still dirty blocks on ifile vnode\n");
        if (error = VFS_SYNC(mp, 1, p->p_ucred, p))
                return (error);
        if (fs->lfs_ivnode->v_dirtyblkhd)
                panic("lfs_unmount: still dirty blocks on ifile vnode\n");
+       vrele(fs->lfs_ivnode);
        vgone(fs->lfs_ivnode);
 
        ronly = !fs->lfs_ronly;
        vgone(fs->lfs_ivnode);
 
        ronly = !fs->lfs_ronly;
@@ -345,12 +343,13 @@ lfs_statfs(mp, sbp, p)
        sbp->f_type = MOUNT_LFS;
        sbp->f_bsize = fs->lfs_bsize;
        sbp->f_iosize = fs->lfs_bsize;
        sbp->f_type = MOUNT_LFS;
        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_blocks = dbtofsb(fs,fs->lfs_dsize);
+       sbp->f_bfree = dbtofsb(fs, fs->lfs_bfree);
        sbp->f_bavail = (fs->lfs_dsize * (100 - fs->lfs_minfree) / 100) -
                (fs->lfs_dsize - sbp->f_bfree);
        sbp->f_bavail = (fs->lfs_dsize * (100 - fs->lfs_minfree) / 100) -
                (fs->lfs_dsize - sbp->f_bfree);
+       sbp->f_bavail = dbtofsb(fs, sbp->f_bavail);
        sbp->f_files = fs->lfs_nfiles;
        sbp->f_files = fs->lfs_nfiles;
-       sbp->f_ffree = fs->lfs_bfree * INOPB(fs);
+       sbp->f_ffree = sbp->f_bfree * INOPB(fs);
        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);
@@ -373,18 +372,9 @@ lfs_sync(mp, waitfor, cred, p)
        struct ucred *cred;
        struct proc *p;
 {
        struct ucred *cred;
        struct proc *p;
 {
-       extern int crashandburn, syncprt;
+       extern int syncprt;
        int error;
 
        int error;
 
-#ifdef VERBOSE
-       printf("lfs_sync\n");
-#endif
-
-#ifdef DIAGNOSTIC
-       if (crashandburn)
-               return (0);
-#endif
-
        /* All syncs must be checkpoints until roll-forward is implemented. */
        error = lfs_segwrite(mp, 1);
 #ifdef QUOTA
        /* All syncs must be checkpoints until roll-forward is implemented. */
        error = lfs_segwrite(mp, 1);
 #ifdef QUOTA
@@ -414,9 +404,6 @@ lfs_vget(mp, ino, vpp)
        dev_t dev;
        int error;
 
        dev_t dev;
        int error;
 
-#ifdef VERBOSE
-       printf("lfs_vget\n");
-#endif
        ump = VFSTOUFS(mp);
        dev = ump->um_dev;
        if ((*vpp = ufs_ihashget(dev, ino)) != NULL)
        ump = VFSTOUFS(mp);
        dev = ump->um_dev;
        if ((*vpp = ufs_ihashget(dev, ino)) != NULL)
@@ -465,9 +452,7 @@ lfs_vget(mp, ino, vpp)
                 * would be misleading to leave it on its hash chain.
                 * Iput() will return it to the free list.
                 */
                 * would be misleading to leave it on its hash chain.
                 * Iput() will return it to the free list.
                 */
-               remque(ip);
-               ip->i_forw = ip;
-               ip->i_back = ip;
+               ufs_ihashrem(ip);
 
                /* Unlock and discard unneeded inode. */
                ufs_iput(ip);
 
                /* Unlock and discard unneeded inode. */
                ufs_iput(ip);
@@ -503,7 +488,8 @@ lfs_vget(mp, ino, vpp)
  * - 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 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 that the given client host has export rights and return
+ *   those rights via. exflagsp and credanonp
  *
  * XXX
  * use ifile to see if inode is allocated instead of reading off disk
  *
  * XXX
  * use ifile to see if inode is allocated instead of reading off disk
@@ -519,73 +505,12 @@ lfs_fhtovp(mp, fhp, nam, vpp, exflagsp, credanonp)
        int *exflagsp;
        struct ucred **credanonp;
 {
        int *exflagsp;
        struct ucred **credanonp;
 {
-       register struct inode *ip;
        register struct ufid *ufhp;
        register struct ufid *ufhp;
-       register struct netaddrhash *np;
-       register struct ufsmount *ump = VFSTOUFS(mp);
-       struct vnode *nvp;
-       struct sockaddr *saddr;
-       int error;
 
        ufhp = (struct ufid *)fhp;
        if (ufhp->ufid_ino < ROOTINO)
                return (ESTALE);
 
        ufhp = (struct ufid *)fhp;
        if (ufhp->ufid_ino < ROOTINO)
                return (ESTALE);
-       /*
-        * Get the export permission structure for this <mp, client> tuple.
-        */
-       if ((mp->mnt_flag & MNT_EXPORTED) == 0)
-               return (EACCES);
-       if (nam == NULL) {
-               np = (struct netaddrhash *)0;
-       } else {
-               /*
-                * First search for a network match.
-                */
-               np = ump->um_netaddr[NETMASK_HASH];
-               while (np) {
-                       if (netaddr_match(np->neth_family, &np->neth_haddr,
-                           &np->neth_hmask, nam))
-                               break;
-                       np = np->neth_next;
-               }
-
-               /*
-                * If not found, try for an address match.
-                */
-               if (np == (struct netaddrhash *)0) {
-                       saddr = mtod(nam, struct sockaddr *);
-                       np = ump->um_netaddr[NETADDRHASH(saddr)];
-                       while (np) {
-                               if (netaddr_match(np->neth_family,
-                                   &np->neth_haddr, (struct netaddrhash *)0,
-                                   nam))
-                                       break;
-                               np = np->neth_next;
-                       }
-               }
-       }
-       if (np == (struct netaddrhash *)0) {
-               /*
-                * If no address match, use the default if it exists.
-                */
-               if ((mp->mnt_flag & MNT_DEFEXPORTED) == 0)
-                       return (EACCES);
-               np = &ump->um_defexported;
-       }
-       if (error = VFS_VGET(mp, ufhp->ufid_ino, &nvp)) {
-               *vpp = NULLVP;
-               return (error);
-       }
-       ip = VTOI(nvp);
-       if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen) {
-               ufs_iput(ip);
-               *vpp = NULLVP;
-               return (ESTALE);
-       }
-       *vpp = nvp;
-       *exflagsp = np->neth_exflags;
-       *credanonp = &np->neth_anon;
-       return (0);
+       return (ufs_check_export(mp, fhp, nam, vpp, exflagsp, credanonp));
 }
 
 /*
 }
 
 /*