ref: 21375b10667c088455dc123350c977a73cd1bd6b
parent: e21fe5fe454fce1b3a555fc1268e2f77a5d35274
author: ngkaho1234 <[email protected]>
date: Fri Dec 25 18:58:05 EST 2015
ext4_bcache: add ext4_bcache_find_get routines.
--- a/lwext4/ext4_bcache.c
+++ b/lwext4/ext4_bcache.c
@@ -176,11 +176,11 @@
bc->ref_blocks--;
}
-int ext4_bcache_alloc(struct ext4_bcache *bc, struct ext4_block *b,
- bool *is_new)
+struct ext4_buf *
+ext4_bcache_find_get(struct ext4_bcache *bc, struct ext4_block *b,
+ uint64_t lba)
{
- /* Try to search the buffer with exaxt LBA. */
- struct ext4_buf *buf = ext4_buf_lookup(bc, b->lb_id);
+ struct ext4_buf *buf = ext4_buf_lookup(bc, lba);
if (buf) {
/* If buffer is not referenced. */
if (!buf->refctr) {
@@ -197,7 +197,16 @@
b->buf = buf;
b->data = buf->data;
+ }
+ return buf;
+}
+int ext4_bcache_alloc(struct ext4_bcache *bc, struct ext4_block *b,
+ bool *is_new)
+{
+ /* Try to search the buffer with exaxt LBA. */
+ struct ext4_buf *buf = ext4_bcache_find_get(bc, b, b->lb_id);
+ if (buf) {
*is_new = false;
return EOK;
}
--- a/lwext4/ext4_bcache.h
+++ b/lwext4/ext4_bcache.h
@@ -238,6 +238,17 @@
* @param buf buffer*/
void ext4_bcache_drop_buf(struct ext4_bcache *bc, struct ext4_buf *buf);
+/**@brief Find existing buffer from block cache memory.
+ * Unreferenced block allocation is based on LRU
+ * (Last Recently Used) algorithm.
+ * @param bc block cache descriptor
+ * @param b block to alloc
+ * @param lba logical block address
+ * @return block cache buffer */
+struct ext4_buf *
+ext4_bcache_find_get(struct ext4_bcache *bc, struct ext4_block *b,
+ uint64_t lba);
+
/**@brief Allocate block from block cache memory.
* Unreferenced block allocation is based on LRU
* (Last Recently Used) algorithm.