ref: f7eb061d6c5e916767b66d952993bbb66d0fc8f7
parent: b1083b540d92bad9fecc510d0c0ca4e12abd14a0
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Fri Dec 4 07:56:38 EST 2015
ext4_blockdev: a number of changes below - call buf->end_write() during ext4_block_flush_buf. - For ext4_block_get, call ext4_blocks_get_direct instead of directly calling bdev->bread().
--- a/lwext4/ext4_bcache.h
+++ b/lwext4/ext4_bcache.h
@@ -69,6 +69,8 @@
uint8_t *data;
};
+struct ext4_bcache;
+
/**@brief Single block descriptor*/
struct ext4_buf {
/**@brief Flags*/
@@ -100,6 +102,19 @@
/**@brief Dirty list node*/
SLIST_ENTRY(ext4_buf) dirty_node;
+
+ /**@brief Callback routine after a disk-write operation.
+ * @param bc block cache descriptor
+ * @param buf buffer descriptor
+ * @param standard error code returned by bdev->bwrite()
+ * @param arg argument passed to this routine*/
+ void (*end_write)(struct ext4_bcache *bc,
+ struct ext4_buf *buf,
+ int res,
+ void *arg);
+
+ /**@brief argument passed to end_write() callback.*/
+ void *end_write_arg;
};
/**@brief Block cache descriptor*/
--- a/lwext4/ext4_blockdev.c
+++ b/lwext4/ext4_blockdev.c
@@ -95,11 +95,19 @@
if (ext4_bcache_test_flag(buf, BC_DIRTY)) {
r = ext4_blocks_set_direct(bdev, buf->data, buf->lba, 1);
- if (r)
+
+ if (r) {
+ if (buf->end_write)
+ buf->end_write(bc, buf, r, buf->end_write_arg);
+
return r;
+ }
ext4_bcache_remove_dirty_node(bc, buf);
ext4_bcache_clear_flag(buf, BC_DIRTY);
+ if (buf->end_write)
+ buf->end_write(bc, buf, r, buf->end_write_arg);
+
}
return EOK;
}
@@ -159,8 +167,6 @@
int ext4_block_get(struct ext4_blockdev *bdev, struct ext4_block *b,
uint64_t lba)
{
- uint64_t pba;
- uint32_t pb_cnt;
int r = ext4_block_get_noread(bdev, b, lba);
if (r != EOK)
return r;
@@ -171,11 +177,7 @@
return EOK;
}
- pba = (lba * bdev->lg_bsize) / bdev->ph_bsize;
- pb_cnt = bdev->lg_bsize / bdev->ph_bsize;
-
- r = bdev->bread(bdev, b->data, pba, pb_cnt);
-
+ r = ext4_blocks_get_direct(bdev, b->data, lba, 1);
if (r != EOK) {
ext4_bcache_free(bdev->bc, b);
b->lb_id = 0;
@@ -186,7 +188,6 @@
* fresh data is read from physical device just now. */
ext4_bcache_set_flag(b->buf, BC_UPTODATE);
b->uptodate = true;
- bdev->bread_ctr++;
return EOK;
}