fix bufunhash race condition
authorBill Joy <bill@ucbvax.Berkeley.EDU>
Wed, 17 Sep 1980 08:31:47 +0000 (00:31 -0800)
committerBill Joy <bill@ucbvax.Berkeley.EDU>
Wed, 17 Sep 1980 08:31:47 +0000 (00:31 -0800)
SCCS-vsn: sys/kern/kern_physio.c 3.12
SCCS-vsn: sys/kern/vfs_bio.c 3.12
SCCS-vsn: sys/kern/vfs_cluster.c 3.12

usr/src/sys/kern/kern_physio.c
usr/src/sys/kern/vfs_bio.c
usr/src/sys/kern/vfs_cluster.c

index 7e28a11..478323c 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_physio.c   3.11    %G%     */
+/*     kern_physio.c   3.12    %G%     */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -350,6 +350,7 @@ daddr_t blkno;
        if (bp->b_dev == NODEV)
                goto done;
        /* INLINE EXPANSION OF bunhash(bp) */
        if (bp->b_dev == NODEV)
                goto done;
        /* INLINE EXPANSION OF bunhash(bp) */
+       (void) spl6();
        i = BUFHASH(dbtofsb(bp->b_blkno));
        x = bp - buf;
        if (bufhash[i] == x) {
        i = BUFHASH(dbtofsb(bp->b_blkno));
        x = bp - buf;
        if (bufhash[i] == x) {
@@ -364,6 +365,7 @@ daddr_t blkno;
                panic("getblk");
        }
 done:
                panic("getblk");
        }
 done:
+       (void) spl0();
        /* END INLINE EXPANSION */
        bp->b_flags = B_BUSY;
        bp->b_back->b_forw = bp->b_forw;
        /* END INLINE EXPANSION */
        bp->b_flags = B_BUSY;
        bp->b_back->b_forw = bp->b_forw;
@@ -422,23 +424,26 @@ bunhash(bp)
        register struct buf *bp;
 {
        register struct buf *ep;
        register struct buf *bp;
 {
        register struct buf *ep;
-       register int i, x;
+       register int i, x, s;
 
        if (bp->b_dev == NODEV)
                return;
 
        if (bp->b_dev == NODEV)
                return;
+       s = spl6();
        i = BUFHASH(dbtofsb(bp->b_blkno));
        x = bp - buf;
        if (bufhash[i] == x) {
                bufhash[i] = bp->b_hlink;
        i = BUFHASH(dbtofsb(bp->b_blkno));
        x = bp - buf;
        if (bufhash[i] == x) {
                bufhash[i] = bp->b_hlink;
-               return;
+               goto ret;
        }
        for (ep = &buf[bufhash[i]]; ep != &buf[-1];
            ep = &buf[ep->b_hlink])
                if (ep->b_hlink == x) {
                        ep->b_hlink = bp->b_hlink;
        }
        for (ep = &buf[bufhash[i]]; ep != &buf[-1];
            ep = &buf[ep->b_hlink])
                if (ep->b_hlink == x) {
                        ep->b_hlink = bp->b_hlink;
-                       return;
+                       goto ret;
                }
        panic("bunhash");
                }
        panic("bunhash");
+ret:
+       splx(s);
 }
 
 /*
 }
 
 /*
index 0c785ee..9ddf17e 100644 (file)
@@ -1,4 +1,4 @@
-/*     vfs_bio.c       3.11    %G%     */
+/*     vfs_bio.c       3.12    %G%     */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -350,6 +350,7 @@ daddr_t blkno;
        if (bp->b_dev == NODEV)
                goto done;
        /* INLINE EXPANSION OF bunhash(bp) */
        if (bp->b_dev == NODEV)
                goto done;
        /* INLINE EXPANSION OF bunhash(bp) */
+       (void) spl6();
        i = BUFHASH(dbtofsb(bp->b_blkno));
        x = bp - buf;
        if (bufhash[i] == x) {
        i = BUFHASH(dbtofsb(bp->b_blkno));
        x = bp - buf;
        if (bufhash[i] == x) {
@@ -364,6 +365,7 @@ daddr_t blkno;
                panic("getblk");
        }
 done:
                panic("getblk");
        }
 done:
+       (void) spl0();
        /* END INLINE EXPANSION */
        bp->b_flags = B_BUSY;
        bp->b_back->b_forw = bp->b_forw;
        /* END INLINE EXPANSION */
        bp->b_flags = B_BUSY;
        bp->b_back->b_forw = bp->b_forw;
@@ -422,23 +424,26 @@ bunhash(bp)
        register struct buf *bp;
 {
        register struct buf *ep;
        register struct buf *bp;
 {
        register struct buf *ep;
-       register int i, x;
+       register int i, x, s;
 
        if (bp->b_dev == NODEV)
                return;
 
        if (bp->b_dev == NODEV)
                return;
+       s = spl6();
        i = BUFHASH(dbtofsb(bp->b_blkno));
        x = bp - buf;
        if (bufhash[i] == x) {
                bufhash[i] = bp->b_hlink;
        i = BUFHASH(dbtofsb(bp->b_blkno));
        x = bp - buf;
        if (bufhash[i] == x) {
                bufhash[i] = bp->b_hlink;
-               return;
+               goto ret;
        }
        for (ep = &buf[bufhash[i]]; ep != &buf[-1];
            ep = &buf[ep->b_hlink])
                if (ep->b_hlink == x) {
                        ep->b_hlink = bp->b_hlink;
        }
        for (ep = &buf[bufhash[i]]; ep != &buf[-1];
            ep = &buf[ep->b_hlink])
                if (ep->b_hlink == x) {
                        ep->b_hlink = bp->b_hlink;
-                       return;
+                       goto ret;
                }
        panic("bunhash");
                }
        panic("bunhash");
+ret:
+       splx(s);
 }
 
 /*
 }
 
 /*
index 4b8cb8f..d3b6855 100644 (file)
@@ -1,4 +1,4 @@
-/*     vfs_cluster.c   3.11    %G%     */
+/*     vfs_cluster.c   3.12    %G%     */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -350,6 +350,7 @@ daddr_t blkno;
        if (bp->b_dev == NODEV)
                goto done;
        /* INLINE EXPANSION OF bunhash(bp) */
        if (bp->b_dev == NODEV)
                goto done;
        /* INLINE EXPANSION OF bunhash(bp) */
+       (void) spl6();
        i = BUFHASH(dbtofsb(bp->b_blkno));
        x = bp - buf;
        if (bufhash[i] == x) {
        i = BUFHASH(dbtofsb(bp->b_blkno));
        x = bp - buf;
        if (bufhash[i] == x) {
@@ -364,6 +365,7 @@ daddr_t blkno;
                panic("getblk");
        }
 done:
                panic("getblk");
        }
 done:
+       (void) spl0();
        /* END INLINE EXPANSION */
        bp->b_flags = B_BUSY;
        bp->b_back->b_forw = bp->b_forw;
        /* END INLINE EXPANSION */
        bp->b_flags = B_BUSY;
        bp->b_back->b_forw = bp->b_forw;
@@ -422,23 +424,26 @@ bunhash(bp)
        register struct buf *bp;
 {
        register struct buf *ep;
        register struct buf *bp;
 {
        register struct buf *ep;
-       register int i, x;
+       register int i, x, s;
 
        if (bp->b_dev == NODEV)
                return;
 
        if (bp->b_dev == NODEV)
                return;
+       s = spl6();
        i = BUFHASH(dbtofsb(bp->b_blkno));
        x = bp - buf;
        if (bufhash[i] == x) {
                bufhash[i] = bp->b_hlink;
        i = BUFHASH(dbtofsb(bp->b_blkno));
        x = bp - buf;
        if (bufhash[i] == x) {
                bufhash[i] = bp->b_hlink;
-               return;
+               goto ret;
        }
        for (ep = &buf[bufhash[i]]; ep != &buf[-1];
            ep = &buf[ep->b_hlink])
                if (ep->b_hlink == x) {
                        ep->b_hlink = bp->b_hlink;
        }
        for (ep = &buf[bufhash[i]]; ep != &buf[-1];
            ep = &buf[ep->b_hlink])
                if (ep->b_hlink == x) {
                        ep->b_hlink = bp->b_hlink;
-                       return;
+                       goto ret;
                }
        panic("bunhash");
                }
        panic("bunhash");
+ret:
+       splx(s);
 }
 
 /*
 }
 
 /*