ext4_journal: two changes below.
[lwext4.git] / lwext4 / ext4_bcache.c
index 628735ab659fe38b5aac1e7fda1f660210f6fafb..1a1766ac4ab978339e5e9e95a9d3c14d4bc64e17 100644 (file)
@@ -132,6 +132,7 @@ ext4_buf_alloc(struct ext4_bcache *bc, uint64_t lba)
 
        buf->lba = lba;
        buf->data = data;
+       buf->bc = bc;
        return buf;
 }
 
@@ -190,6 +191,8 @@ void ext4_bcache_invalidate_lba(struct ext4_bcache *bc,
                if (ext4_bcache_test_flag(buf, BC_DIRTY))
                        ext4_bcache_remove_dirty_node(bc, buf);
 
+               buf->end_write = NULL;
+               buf->end_write_arg = NULL;
                ext4_bcache_clear_dirty(buf);
        }
 }
@@ -213,6 +216,7 @@ ext4_bcache_find_get(struct ext4_bcache *bc, struct ext4_block *b,
 
                ext4_bcache_inc_ref(buf);
 
+               b->lb_id = lba;
                b->buf = buf;
                b->data = buf->data;
        }
@@ -238,6 +242,11 @@ int ext4_bcache_alloc(struct ext4_bcache *bc, struct ext4_block *b,
        /* One more buffer in bcache now. :-) */
        bc->ref_blocks++;
 
+       /*Calc ref blocks max depth*/
+       if (bc->max_ref_blocks < bc->ref_blocks)
+               bc->max_ref_blocks = bc->ref_blocks;
+
+
        ext4_bcache_inc_ref(buf);
        /* Assign new value to LRU id and increment LRU counter
         * by 1*/
@@ -275,7 +284,8 @@ int ext4_bcache_free(struct ext4_bcache *bc, struct ext4_block *b)
                if (ext4_bcache_test_flag(buf, BC_DIRTY) &&
                    ext4_bcache_test_flag(buf, BC_UPTODATE)) {
                        if (bc->bdev->cache_write_back &&
-                           !ext4_bcache_test_flag(buf, BC_FLUSH))
+                           !ext4_bcache_test_flag(buf, BC_FLUSH) &&
+                           !ext4_bcache_test_flag(buf, BC_TMP))
                                ext4_bcache_insert_dirty_node(bc, buf);
                        else {
                                ext4_block_flush_buf(bc->bdev, buf);
@@ -284,7 +294,8 @@ int ext4_bcache_free(struct ext4_bcache *bc, struct ext4_block *b)
                }
 
                /* The buffer is invalidated...drop it. */
-               if (!ext4_bcache_test_flag(buf, BC_UPTODATE))
+               if (!ext4_bcache_test_flag(buf, BC_UPTODATE) ||
+                   ext4_bcache_test_flag(buf, BC_TMP))
                        ext4_bcache_drop_buf(bc, buf);
 
        }