ref: d36c74f96ba22f58fb3ed11c19e3d6cb138e3224
parent: ead60f17e6fe9c651e2c954cd2f3eba796fa9ff5
author: gkostka <[email protected]>
date: Thu Nov 7 15:21:26 EST 2013
Update cache mode.
--- a/lwext4/ext4_bcache.c
+++ b/lwext4/ext4_bcache.c
@@ -66,6 +66,11 @@
if(!bc->lba)
goto error;
+ bc->dirty = malloc(cnt * sizeof(bool));
+ if(!bc->dirty)
+ goto error;
+
+
bc->data = malloc(cnt * itemsize);
if(!bc->data)
goto error;
@@ -74,6 +79,7 @@
memset(bc->lru_id, 0, cnt * sizeof(uint32_t));
memset(bc->free_delay, 0, cnt * sizeof(uint8_t));
memset(bc->lba, 0, cnt * sizeof(uint64_t));
+ memset(bc->dirty, 0, cnt * sizeof(bool));
bc->cnt = cnt;
bc->itemsize = itemsize;
@@ -96,6 +102,9 @@
if(bc->lba)
free(bc->lba);
+ if(bc->dirty)
+ free(bc->dirty);
+
if(bc->data)
free(bc->data);
@@ -117,6 +126,9 @@
if(bc->lba)
free(bc->lba);
+
+ if(bc->dirty)
+ free(bc->dirty);
if(bc->data)
free(bc->data);
--- a/lwext4/ext4_bcache.h
+++ b/lwext4/ext4_bcache.h
@@ -82,6 +82,9 @@
/**@brief Logical block table (cnt).*/
uint64_t *lba;
+ /**@brief Dirty mark (cnt).*/
+ bool *dirty;
+
/**@brief Cache data buffers (cnt * itemsize)*/
uint8_t *data;
@@ -99,6 +102,7 @@
static uint32_t __name##_lru_id[(__cnt)]; \
static uint8_t __name##_free_delay[(__cnt)]; \
static uint64_t __name##_lba[(__cnt)]; \
+ static bool __name##_dirty[(__cnt)]; \
static uint8_t __name##_data[(__cnt) * (__itemsize)]; \
static struct ext4_bcache __name = { \
.cnt = __cnt, \
@@ -107,6 +111,7 @@
.refctr = __name##_refctr, \
.lru_id = __name##_lru_id, \
.lba = __name##_lba, \
+ .dirty = __name##_dirty, \
.free_delay= __name##_free_delay, \
.data = __name##_data, \
}
--- a/lwext4/ext4_blockdev.c
+++ b/lwext4/ext4_blockdev.c
@@ -176,7 +176,7 @@
return EIO;
/*Doesn,t need to write.*/
- if(b->dirty == false){
+ if(b->dirty == false && !bdev->bc->dirty[b->cache_id]){
ext4_bcache_free(bdev->bc, b, 0);
return EOK;
}
@@ -191,9 +191,13 @@
pba = (b->lb_id * bdev->lg_bsize) / bdev->ph_bsize;
pb_cnt = bdev->lg_bsize / bdev->ph_bsize;
+ if(bdev->bc->refctr[b->cache_id] > 1){
+ bdev->bc->dirty[b->cache_id] = true;
+ return ext4_bcache_free(bdev->bc, b, 0);
+ }
r = bdev->bwrite(bdev, b->data, pba, pb_cnt);
-
+ bdev->bc->dirty[b->cache_id] = false;
if(r != EOK){
b->dirty = false;
ext4_bcache_free(bdev->bc, b, 0);