ref: 5aa75f97a60f95b53a11caf31044363434227f07
parent: c91beecad10bf077412d7464d98e0618ca1cb9cd
author: gkostka <kostka.grzegorz@gmail.com>
date: Sat Oct 26 12:24:49 EDT 2013
BUGFIX: 1. Delayed cache flush feature when flush is forced UPTATES: 1. Demo app improvements. 2. Ext images update.
--- a/demos/generic/main.c
+++ b/demos/generic/main.c
@@ -354,7 +354,7 @@
for (i = 0; i < rw_count; ++i) {
- memset(wr_buff, i & 0xFF, rw_szie);
+ memset(wr_buff, i % 10 + '0', rw_szie);
r = ext4_fwrite(&f, wr_buff, rw_szie, &size);
@@ -380,7 +380,7 @@
printf("ext4_read: %d * %d ..." , rw_count, rw_szie);
for (i = 0; i < rw_count; ++i) {
- memset(wr_buff, i & 0xFF, rw_szie);
+ memset(wr_buff, i % 10 + '0', rw_szie);
r = ext4_fread(&f, rd_buff, rw_szie, &size);
if((r != EOK) || (size != rw_szie))
@@ -403,11 +403,12 @@
if(sbstat)
mp_stats();
- if(bstat)
- block_stats();
if(cleanup_flag)
cleanup();
+
+ if(bstat)
+ block_stats();
r = ext4_umount("/mp/");
printf("Test finish: OK\n");
binary files a/ext_images.7z b/ext_images.7z differ
--- a/lwext4/ext4_blockdev.c
+++ b/lwext4/ext4_blockdev.c
@@ -96,6 +96,7 @@
uint32_t pb_cnt;
bool is_new;
int r;
+ uint32_t i;
ext4_assert(bdev && b);
if(!(bdev->flags & EXT4_BDEV_INITIALIZED))
@@ -107,6 +108,33 @@
b->dirty = 0;
b->lb_id = lba;
+ /*If cache is full we have to flush it anyway :(*/
+ if(ext4_bcache_is_full(bdev->bc) && bdev->cache_flush_delay){
+ for (i = 0; i < bdev->bc->cnt; ++i) {
+ /*Check if buffer free was delayed.*/
+ if(!bdev->bc->free_delay[i])
+ continue;
+
+ /*Check reference counter.*/
+ if(bdev->bc->refctr[i])
+ continue;
+
+ /*Buffer free was delayed and have no reference. Flush it.*/
+ r = ext4_block_set_direct(bdev,
+ bdev->bc->data + bdev->bc->itemsize * i,
+ bdev->bc->lba[i]);
+ if(r != EOK)
+ return r;
+
+ /*No delayed anymore*/
+ bdev->bc->free_delay[i] = 0;
+
+ /*Reduce refered block count*/
+ bdev->bc->ref_blocks--;
+ }
+ }
+
+
r = ext4_bcache_alloc(bdev->bc, b, &is_new);
if(r != EOK)
return r;
@@ -141,7 +169,6 @@
{
uint64_t pba;
uint32_t pb_cnt;
- uint32_t i;
int r;
ext4_assert(bdev && b);
@@ -159,35 +186,7 @@
if(bdev->cache_flush_delay){
/*Free cahe block and mark as free delayed*/
- ext4_bcache_free(bdev->bc, b, bdev->cache_flush_delay);
-
- /*If cache is full we have to flush it anyway :(*/
- if(ext4_bcache_is_full(bdev->bc)){
- for (i = 0; i < bdev->bc->cnt; ++i) {
- /*Check if buffer free was delayed.*/
- if(!bdev->bc->free_delay[i])
- continue;
-
- /*Check reference counter.*/
- if(bdev->bc->refctr[i])
- continue;
-
- /*Buffer free was delayed and have no reference. Flush it.*/
- r = ext4_block_set_direct(bdev,
- bdev->bc->data + bdev->bc->itemsize * i,
- bdev->bc->lba[i]);
- if(r != EOK)
- return r;
-
- /*No delayed anymore*/
- bdev->bc->free_delay[i] = 0;
-
- /*Reduce refered block count*/
- bdev->bc->ref_blocks--;
- }
- }
-
- return EOK;
+ return ext4_bcache_free(bdev->bc, b, bdev->cache_flush_delay);
}
pba = (b->lb_id * bdev->lg_bsize) / bdev->ph_bsize;