plock/prele here now
[unix-history] / usr / src / sys / ufs / lfs / lfs_inode.c
index e886869..18d152b 100644 (file)
@@ -1,4 +1,4 @@
-/*     lfs_inode.c     4.1     %G%     */
+/*     lfs_inode.c     4.5     81/04/28        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -24,11 +24,12 @@ short       ifreel;
 ihinit()
 {
        register int i;
 ihinit()
 {
        register int i;
+       register struct inode *ip = inode;
 
        ifreel = 0;
 
        ifreel = 0;
-       for (i = 0; i < NINODE - 1; i++)
-               inode[i].i_hlink = i+1;
-       inode[NINODE - 1].i_hlink = -1;
+       for (i = 0; i < ninode-1; i++, ip++)
+               ip->i_hlink = i+1;
+       ip->i_hlink = -1;
        for (i = 0; i < INOHSZ; i++)
                inohash[i] = -1;
 }
        for (i = 0; i < INOHSZ; i++)
                inohash[i] = -1;
 }
@@ -63,8 +64,6 @@ ino_t ino;
  * In all cases, a pointer to a locked
  * inode structure is returned.
  *
  * In all cases, a pointer to a locked
  * inode structure is returned.
  *
- * printf warning: no inodes -- if the inode
- *     structure is full
  * panic: no imt -- if the mounted file
  *     system is not in the mount table.
  *     "cannot happen"
  * panic: no imt -- if the mounted file
  *     system is not in the mount table.
  *     "cannot happen"
@@ -106,7 +105,7 @@ loop:
                ip = &inode[ip->i_hlink];
        }
        if(ifreel < 0) {
                ip = &inode[ip->i_hlink];
        }
        if(ifreel < 0) {
-               printf("Inode table overflow\n");
+               tablefull("inode");
                u.u_error = ENFILE;
                return(NULL);
        }
                u.u_error = ENFILE;
                return(NULL);
        }
@@ -411,3 +410,41 @@ struct inode *ip;
        writei(u.u_pdir);
        iput(u.u_pdir);
 }
        writei(u.u_pdir);
        iput(u.u_pdir);
 }
+
+#ifdef plock
+#undef plock
+#endif
+#ifdef prele
+#undef prele
+#endif
+/*
+ * Lock an inode (should be called ilock).
+ * If its already locked,
+ * set the WANT bit and sleep.
+ */
+plock(ip)
+register struct inode *ip;
+{
+
+       while(ip->i_flag&ILOCK) {
+               ip->i_flag |= IWANT;
+               sleep((caddr_t)ip, PINOD);
+       }
+       ip->i_flag |= ILOCK;
+}
+
+/*
+ * Unlock an inode.
+ * If WANT bit is on,
+ * wakeup.
+ */
+prele(ip)
+register struct inode *ip;
+{
+
+       ip->i_flag &= ~ILOCK;
+       if(ip->i_flag&IWANT) {
+               ip->i_flag &= ~IWANT;
+               wakeup((caddr_t)ip);
+       }
+}