From: Denis Mukhin <[email protected]> Add minimal test invoking new blk_dflush() API.
Signed-off-by: Denis Mukhin <[email protected]> --- Changes since v2: - new patch --- arch/sandbox/cpu/os.c | 5 +++++ drivers/block/sandbox.c | 9 +++++++++ include/os.h | 8 ++++++++ test/dm/host.c | 2 ++ test/dm/mmc.c | 2 ++ 5 files changed, 26 insertions(+) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index e48eb23cdc01..a39e0fcab795 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -139,6 +139,11 @@ int os_close(int fd) return -1; } +int os_fsync(int fd) +{ + return fsync(fd); +} + int os_unlink(const char *pathname) { return unlink(pathname); diff --git a/drivers/block/sandbox.c b/drivers/block/sandbox.c index 9cb27561a97f..f7e854fbf982 100644 --- a/drivers/block/sandbox.c +++ b/drivers/block/sandbox.c @@ -55,9 +55,18 @@ static unsigned long host_block_write(struct udevice *dev, return -EIO; } +unsigned long host_block_flush(struct udevice *dev) +{ + struct udevice *host_dev = dev_get_parent(dev); + struct host_sb_plat *plat = dev_get_plat(host_dev); + + return os_fsync(plat->fd); +} + static const struct blk_ops sandbox_host_blk_ops = { .read = host_block_read, .write = host_block_write, + .flush = host_block_flush, }; U_BOOT_DRIVER(sandbox_host_blk) = { diff --git a/include/os.h b/include/os.h index ae3ca6d42a2a..13c7651bf537 100644 --- a/include/os.h +++ b/include/os.h @@ -90,6 +90,14 @@ int os_open(const char *pathname, int flags); */ int os_close(int fd); +/** + * os_fsync() - synchronize a file's in-core state with storage device + * + * @fd: File descriptor to synchronize + * Return: 0 on success, negative error code - otherwise + */ +int os_fsync(int fd); + /** * os_unlink() - access to the OS unlink() system call * diff --git a/test/dm/host.c b/test/dm/host.c index f577377da6a0..ed55278a701e 100644 --- a/test/dm/host.c +++ b/test/dm/host.c @@ -62,6 +62,8 @@ static int dm_test_host(struct unit_test_state *uts) ut_assertok(fs_set_blk_dev_with_part(desc, 0)); ut_assertok(fs_write("/testing", 0, 0, 0x1000, &actwrite)); + ut_asserteq(0, blk_dflush(desc)); + ut_assertok(host_detach_file(dev)); ut_asserteq(0, plat->fd); ut_asserteq(-ENODEV, blk_get_from_parent(dev, &blk)); diff --git a/test/dm/mmc.c b/test/dm/mmc.c index cdebb9551967..714fcd1ea508 100644 --- a/test/dm/mmc.c +++ b/test/dm/mmc.c @@ -48,6 +48,8 @@ static int dm_test_mmc_blk(struct unit_test_state *uts) ut_asserteq(4, blk_dread(dev_desc, 0, 4, read)); ut_asserteq_mem(write, read, sizeof(write)); + ut_asserteq(-ENOSYS, blk_dflush(dev_desc)); + return 0; } DM_TEST(dm_test_mmc_blk, UTF_SCAN_PDATA | UTF_SCAN_FDT); -- 2.54.0

