]> Zhao Yanbai Git Server - minix.git/commitdiff
mfs: mark blocks clean when invalidated
authorBen Gras <ben@minix3.org>
Fri, 13 Jan 2012 15:05:32 +0000 (16:05 +0100)
committerBen Gras <ben@minix3.org>
Wed, 18 Jan 2012 16:51:04 +0000 (17:51 +0100)
. it could happen that newly filled blocks were still marked
  dirty
. causing unnecessary i/o and the new warning of the superblock
  being written

servers/mfs/cache.c
servers/mfs/clean.h

index 89b81b321774d8e143d2230c0919e7abd32dcc36..d64dcc228e23c6f36e64cc9a4ec0455f80ceea80 100644 (file)
@@ -145,11 +145,12 @@ PUBLIC struct buf *get_block(
         */
        yieldid = make64(bp->b_dev, bp->b_blocknr);
        assert(bp->b_bytes == fs_block_size);
-       bp->b_dev = NO_DEV;
+       BP_CLEARDEV(bp);
   }
 
   /* Fill in block's parameters and add it to the hash chain where it goes. */
-  bp->b_dev = dev;             /* fill in device number */
+  if(dev == NO_DEV) BP_CLEARDEV(bp);
+  else BP_SETDEV(bp, dev);
   bp->b_blocknr = block;       /* fill in block number */
   bp->b_count++;               /* record that block is being used */
   b = BUFHASH(bp->b_blocknr);
@@ -183,7 +184,7 @@ PUBLIC struct buf *get_block(
 
   if(only_search == PREFETCH) {
        /* PREFETCH: don't do i/o. */
-       bp->b_dev = NO_DEV;
+       BP_CLEARDEV(bp);
   } else if (only_search == NORMAL) {
        read_block(bp);
   } else if(only_search == NO_READ) {
@@ -350,7 +351,7 @@ register struct buf *bp;    /* buffer pointer */
        }
 
        if (op_failed) {
-               bp->b_dev = NO_DEV;     /* invalidate block */
+               BP_CLEARDEV(bp);        /* invalidate block */
 
                /* Report read errors to interested parties. */
                rdwt_err = r;
@@ -370,7 +371,7 @@ PUBLIC void invalidate(
   register struct buf *bp;
 
   for (bp = &buf[0]; bp < &buf[nr_bufs]; bp++)
-       if (bp->b_dev == device) bp->b_dev = NO_DEV;
+       if (bp->b_dev == device) BP_CLEARDEV(bp);
 
   vm_forgetblocks();
 }
@@ -501,13 +502,13 @@ PUBLIC void rw_scattered(
                if (r < (ssize_t) fs_block_size) {
                        /* Transfer failed. */
                        if (i == 0) {
-                               bp->b_dev = NO_DEV;     /* Invalidate block */
+                               BP_CLEARDEV(bp);        /* Invalidate block */
                                vm_forgetblocks();
                        }
                        break;
                }
                if (rw_flag == READING) {
-                       bp->b_dev = dev;        /* validate block */
+                       BP_SETDEV(bp, dev);     /* validate block */
                        put_block(bp, PARTIAL_DATA_BLOCK);
                } else {
                        MARKCLEAN(bp);
@@ -662,7 +663,7 @@ PUBLIC void buf_pool(int new_nr_bufs)
 
   for (bp = &buf[0]; bp < &buf[nr_bufs]; bp++) {
         bp->b_blocknr = NO_BLOCK;
-        bp->b_dev = NO_DEV;
+       BP_CLEARDEV(bp);
         bp->b_next = bp + 1;
         bp->b_prev = bp - 1;
         bp->bp = NULL;
index 626c7aceca61dba8ce8083c3931eb4fb3abc0653..d6d112985b0aa4d900c85d4cbcbd68aebde1dc6f 100644 (file)
@@ -8,4 +8,7 @@
 #define ISDIRTY(b)     ((b)->b_dirt == BP_DIRTY)
 #define ISCLEAN(b)     ((b)->b_dirt == BP_CLEAN)
 
+#define BP_SETDEV(b, dev) do { assert((dev) != NO_DEV); (b)->b_dev = (dev); } while(0)
+#define BP_CLEARDEV(b) do { (b)->b_dev = NO_DEV; MARKCLEAN(b); } while(0)
+
 #endif