ext4_bcache: add new flag BC_FLUSH.
authorngkaho1234 <ngkaho1234@gmail.com>
Wed, 16 Dec 2015 10:45:24 +0000 (10:45 +0000)
committerngkaho1234 <ngkaho1234@gmail.com>
Wed, 16 Dec 2015 10:54:24 +0000 (10:54 +0000)
lwext4/ext4_bcache.c
lwext4/ext4_bcache.h

index ab19c177c619a66dc45c48e4da572a8d5eb866ac..fb37f4434fde98bd2f48b157db4a574480db79cf 100644 (file)
@@ -233,10 +233,13 @@ int ext4_bcache_free(struct ext4_bcache *bc, struct ext4_block *b)
                RB_INSERT(ext4_buf_lru, &bc->lru_root, buf);
                /* This buffer is ready to be flushed. */
                if (ext4_bcache_test_flag(buf, BC_DIRTY)) {
-                       if (bc->bdev->cache_write_back)
+                       if (bc->bdev->cache_write_back &&
+                           !ext4_bcache_test_flag(buf, BC_FLUSH))
                                ext4_bcache_insert_dirty_node(bc, buf);
-                       else
+                       else {
                                ext4_block_flush_buf(bc->bdev, buf);
+                               ext4_bcache_clear_flag(buf, BC_FLUSH);
+                       }
                }
 
                /* The buffer is invalidated...drop it. */
index 40431d2d9f0e486cb44babbf1765ef174fb45fec..938f13bb3f0191bb5fc922e196c458fe63d06035 100644 (file)
@@ -142,9 +142,17 @@ struct ext4_bcache {
        SLIST_HEAD(ext4_buf_dirty, ext4_buf) dirty_list;
 };
 
+/**@brief buffer state bits
+ *
+ *  - BC♡UPTODATE: Buffer contains valid data.
+ *  - BC_DIRTY: Buffer is dirty.
+ *  - BC_FLUSH: Buffer will be immediately flushed,
+ *              when no one references it.
+ */
 enum bcache_state_bits {
        BC_UPTODATE,
-       BC_DIRTY
+       BC_DIRTY,
+       BC_FLUSH
 };
 
 #define ext4_bcache_set_flag(buf, b)    \