shithub: lwext4

Download patch

ref: d5061ab6135497e2091d94c34ce194c4e83b6b27
parent: 46c3c339d15e69ac633e122b95861151d6af1c62
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Sat Dec 26 06:09:55 EST 2015

ext4_balloc: invalidate buffers which have the blocks freed.

--- a/lwext4/ext4_balloc.c
+++ b/lwext4/ext4_balloc.c
@@ -211,6 +211,7 @@
 
 	bg_ref.dirty = true;
 
+	ext4_bcache_invalidate_lba(fs->bdev->bc, baddr, 1);
 	/* Release block group reference */
 	return ext4_fs_put_block_group_ref(&bg_ref);
 }
@@ -317,6 +318,7 @@
 		bg_first++;
 	}
 
+	ext4_bcache_invalidate_lba(fs->bdev->bc, first, count);
 	/*All blocks should be released*/
 	ext4_assert(count == 0);
 	return rc;
--- a/lwext4/ext4_bcache.c
+++ b/lwext4/ext4_bcache.c
@@ -176,6 +176,21 @@
 	bc->ref_blocks--;
 }
 
+void ext4_bcache_invalidate_lba(struct ext4_bcache *bc,
+				uint64_t from,
+				uint32_t cnt)
+{
+	uint64_t end = from + cnt - 1;
+	struct ext4_buf *tmp = ext4_buf_lookup(bc, from), *buf;
+	RB_FOREACH_FROM(buf, ext4_buf_lba, tmp) {
+		if (buf->lba > end)
+			break;
+
+		/* Clear both dirty and up-to-date flags. */
+		ext4_bcache_clear_dirty(buf);
+	}
+}
+
 struct ext4_buf *
 ext4_bcache_find_get(struct ext4_bcache *bc, struct ext4_block *b,
 		     uint64_t lba)
--- a/lwext4/ext4_bcache.h
+++ b/lwext4/ext4_bcache.h
@@ -238,6 +238,15 @@
  * @param   buf buffer*/
 void ext4_bcache_drop_buf(struct ext4_bcache *bc, struct ext4_buf *buf);
 
+/**@brief   Invalidate a range of buffers.
+ * @param   bc block cache descriptor
+ * @param   from starting lba
+ * @param   cnt block counts
+ * @param   buf buffer*/
+void ext4_bcache_invalidate_lba(struct ext4_bcache *bc,
+				uint64_t from,
+				uint32_t cnt);
+
 /**@brief   Find existing buffer from block cache memory.
  *          Unreferenced block allocation is based on LRU
  *          (Last Recently Used) algorithm.