generalize the buffer pool so that NFS can become a client
[unix-history] / usr / src / sys / ufs / ffs / ffs_inode.c
index bae874a..14c5f75 100644 (file)
@@ -14,7 +14,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)ffs_inode.c 7.6 (Berkeley) %G%
+ *     @(#)ffs_inode.c 7.12 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -144,8 +144,8 @@ loop:
                                ip->i_freef = NULL;
                                ip->i_freeb = NULL;
                        }
                                ip->i_freef = NULL;
                                ip->i_freeb = NULL;
                        }
-                       ip->i_flag |= ILOCKED;
-                       vp->v_count++;
+                       ILOCK(ip);
+                       VREF(vp);
                        *ipp = ip;
                        return(0);
                }
                        *ipp = ip;
                        return(0);
                }
@@ -158,7 +158,7 @@ loop:
         * Read in the disk contents for the inode.
         */
        if (error = bread(VFSTOUFS(mntp)->um_devvp, fsbtodb(fs, itod(fs, ino)),
         * Read in the disk contents for the inode.
         */
        if (error = bread(VFSTOUFS(mntp)->um_devvp, fsbtodb(fs, itod(fs, ino)),
-           (int)fs->fs_bsize, &bp)) {
+           (int)fs->fs_bsize, NOCRED, &bp)) {
                /*
                 * The inode doesn't contain anything useful, so it would
                 * be misleading to leave it on its hash chain. Iput() will
                /*
                 * The inode doesn't contain anything useful, so it would
                 * be misleading to leave it on its hash chain. Iput() will
@@ -169,7 +169,9 @@ loop:
                ip->i_forw = ip;
                ip->i_back = ip;
                ip->i_number = 0;
                ip->i_forw = ip;
                ip->i_back = ip;
                ip->i_number = 0;
+               ITOV(ip)->v_type = VNON;
                INSFREE(ip);
                INSFREE(ip);
+               iunlock(ip);
                ip->i_flag = 0;
                brelse(bp);
                *ipp = 0;
                ip->i_flag = 0;
                brelse(bp);
                *ipp = 0;
@@ -192,10 +194,11 @@ loop:
        } else {
 again:
                for (iq = bdevlisth; iq; iq = iq->i_devlst) {
        } else {
 again:
                for (iq = bdevlisth; iq; iq = iq->i_devlst) {
-                       if (dp->di_rdev != ITOV(iq)->v_rdev)
+                       vp = ITOV(iq);
+                       if (dp->di_rdev != vp->v_rdev)
                                continue;
                        igrab(iq);
                                continue;
                        igrab(iq);
-                       if (dp->di_rdev != ITOV(iq)->v_rdev) {
+                       if (dp->di_rdev != vp->v_rdev) {
                                iput(iq);
                                goto again;
                        }
                                iput(iq);
                                goto again;
                        }
@@ -206,7 +209,9 @@ again:
                        ip->i_forw = ip;
                        ip->i_back = ip;
                        ip->i_number = 0;
                        ip->i_forw = ip;
                        ip->i_back = ip;
                        ip->i_number = 0;
+                       ITOV(ip)->v_type = VNON;
                        INSFREE(ip);
                        INSFREE(ip);
+                       iunlock(ip);
                        ip->i_flag = 0;
                        /*
                         * Reinitialize aliased inode.
                        ip->i_flag = 0;
                        /*
                         * Reinitialize aliased inode.
@@ -216,7 +221,6 @@ again:
                         * disk block.
                         */
                        ip = iq;
                         * disk block.
                         */
                        ip = iq;
-                       vp = ITOV(iq);
                        tdip.di_ic = dp->di_ic;
                        brelse(bp);
                        error = iupdat(ip, &time, &time, 1);
                        tdip.di_ic = dp->di_ic;
                        brelse(bp);
                        error = iupdat(ip, &time, &time, 1);
@@ -244,7 +248,7 @@ again:
         */
        ip->i_fs = fs;
        ip->i_devvp = VFSTOUFS(mntp)->um_devvp;
         */
        ip->i_fs = fs;
        ip->i_devvp = VFSTOUFS(mntp)->um_devvp;
-       ip->i_devvp->v_count++;
+       VREF(ip->i_devvp);
        /*
         * Initialize the associated vnode
         */
        /*
         * Initialize the associated vnode
         */
@@ -260,6 +264,17 @@ again:
        if (ip->i_mode != 0)
                ip->i_dquot = inoquota(ip);
 #endif
        if (ip->i_mode != 0)
                ip->i_dquot = inoquota(ip);
 #endif
+       /*
+        * Set up a generation number for this inode if it does not
+        * already have one. This should only happen on old filesystems.
+        */
+       if (ip->i_gen == 0) {
+               if (++nextgennumber < (u_long)time.tv_sec)
+                       nextgennumber = time.tv_sec;
+               ip->i_gen = nextgennumber;
+               if ((vp->v_mount->m_flag & M_RDONLY) == 0)
+                       ip->i_flag |= IMOD;
+       }
        *ipp = ip;
        return (0);
 }
        *ipp = ip;
        return (0);
 }
@@ -310,7 +325,8 @@ getnewino(dev, ino, ipp)
                ih = &ihead[INOHASH(dev, ino)];
                insque(ip, ih);
        }
                ih = &ihead[INOHASH(dev, ino)];
                insque(ip, ih);
        }
-       ip->i_flag = ILOCKED;
+       ip->i_flag = 0;
+       ILOCK(ip);
        ip->i_lastr = 0;
 #endif SECSIZE
        /*
        ip->i_lastr = 0;
 #endif SECSIZE
        /*
@@ -371,8 +387,8 @@ igrab(ip)
                ip->i_freef = NULL;
                ip->i_freeb = NULL;
        }
                ip->i_freef = NULL;
                ip->i_freeb = NULL;
        }
-       vp->v_count++;
-       ip->i_flag |= ILOCKED;
+       VREF(vp);
+       ILOCK(ip);
 }
 
 /*
 }
 
 /*
@@ -447,7 +463,12 @@ ufs_inactive(vp)
 
        if (ITOV(ip)->v_count != 0)
                panic("ufs_inactive: not inactive");
 
        if (ITOV(ip)->v_count != 0)
                panic("ufs_inactive: not inactive");
-       ip->i_flag |= ILOCKED;
+       /*
+        * Get rid of inodes related to stale file handles.
+        */
+       if (ip->i_mode == 0)
+               goto freeit;
+       ILOCK(ip);
        if (ip->i_nlink <= 0 && (ITOV(ip)->v_mount->m_flag&M_RDONLY) == 0) {
                error = itrunc(ip, (u_long)0);
                mode = ip->i_mode;
        if (ip->i_nlink <= 0 && (ITOV(ip)->v_mount->m_flag&M_RDONLY) == 0) {
                error = itrunc(ip, (u_long)0);
                mode = ip->i_mode;
@@ -463,6 +484,7 @@ ufs_inactive(vp)
        }
        IUPDAT(ip, &time, &time, 0);
        IUNLOCK(ip);
        }
        IUPDAT(ip, &time, &time, 0);
        IUNLOCK(ip);
+freeit:
        ip->i_flag = 0;
        /*
         * Put the inode on the end of the free list.
        ip->i_flag = 0;
        /*
         * Put the inode on the end of the free list.
@@ -498,7 +520,7 @@ iupdat(ip, ta, tm, waitfor)
        if (vp->v_mount->m_flag & M_RDONLY)
                return (0);
        error = bread(ip->i_devvp, fsbtodb(fs, itod(fs, ip->i_number)),
        if (vp->v_mount->m_flag & M_RDONLY)
                return (0);
        error = bread(ip->i_devvp, fsbtodb(fs, itod(fs, ip->i_number)),
-               (int)fs->fs_bsize, &bp);
+               (int)fs->fs_bsize, NOCRED, &bp);
        if (error) {
                brelse(bp);
                return (error);
        if (error) {
                brelse(bp);
                return (error);
@@ -585,7 +607,7 @@ itrunc(oip, length)
                size = blksize(fs, oip, lbn);
                count = howmany(size, CLBYTES);
                        munhash(oip->i_devvp, bn + i * CLBYTES / DEV_BSIZE);
                size = blksize(fs, oip, lbn);
                count = howmany(size, CLBYTES);
                        munhash(oip->i_devvp, bn + i * CLBYTES / DEV_BSIZE);
-               error = bread(oip->i_devvp, bn, size, &bp);
+               error = bread(oip->i_devvp, bn, size, NOCRED, &bp);
                if (error) {
                        oip->i_size = osize;
                        brelse(bp);
                if (error) {
                        oip->i_size = osize;
                        brelse(bp);
@@ -746,7 +768,8 @@ indirtrunc(ip, bn, lastbn, level, countp)
        bp = bread(ip->i_dev, fsbtodb(fs, bn), (int)fs->fs_bsize,
            fs->fs_dbsize);
 #else SECSIZE
        bp = bread(ip->i_dev, fsbtodb(fs, bn), (int)fs->fs_bsize,
            fs->fs_dbsize);
 #else SECSIZE
-       error = bread(ip->i_devvp, fsbtodb(fs, bn), (int)fs->fs_bsize, &bp);
+       error = bread(ip->i_devvp, fsbtodb(fs, bn), (int)fs->fs_bsize,
+               NOCRED, &bp);
        if (error) {
                brelse(bp);
                *countp = 0;
        if (error) {
                brelse(bp);
                *countp = 0;