From be4a5602ce7d3e2d9cc7ff6cde0b0dcb99d647c8 Mon Sep 17 00:00:00 2001 From: GangCao Date: Thu, 19 Dec 2019 17:33:49 -0500 Subject: [PATCH] blobfs: write IO directly if it is lba aligned UT also added for the block aligned write and verification of the written data. Change-Id: I8751f437c71dd7f3a4556fee420460d6dffdd4e5 Signed-off-by: GangCao Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478424 Community-CI: SPDK CI Jenkins Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- lib/blobfs/blobfs.c | 18 +++++++++++++ .../blobfs/blobfs_async_ut/blobfs_async_ut.c | 26 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/lib/blobfs/blobfs.c b/lib/blobfs/blobfs.c index c28843dc3..92fc26b6f 100644 --- a/lib/blobfs/blobfs.c +++ b/lib/blobfs/blobfs.c @@ -1792,6 +1792,18 @@ __get_page_parameters(struct spdk_file *file, uint64_t offset, uint64_t length, *num_lba = (end_lba - *start_lba + 1); } +static bool +__is_lba_aligned(struct spdk_file *file, uint64_t offset, uint64_t length) +{ + uint32_t lba_size = spdk_bs_get_io_unit_size(file->fs->bs); + + if ((offset % lba_size == 0) && (length % lba_size == 0)) { + return true; + } + + return false; +} + static void _fs_request_setup_iovs(struct spdk_fs_request *req, struct iovec *iovs, uint32_t iovcnt) { @@ -1854,6 +1866,12 @@ __readvwritev(struct spdk_file *file, struct spdk_io_channel *_channel, if (!is_read && file->length < offset + length) { spdk_file_truncate_async(file, offset + length, __do_blob_read, req); + } else if (!is_read && __is_lba_aligned(file, offset, length)) { + _copy_iovs_to_buf(args->op.rw.pin_buf, args->op.rw.length, args->iovs, args->iovcnt); + spdk_blob_io_write(args->file->blob, args->op.rw.channel, + args->op.rw.pin_buf, + args->op.rw.start_lba, args->op.rw.num_lba, + __rw_done, req); } else { __do_blob_read(req, 0); } diff --git a/test/unit/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c b/test/unit/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c index cfeb954fe..f9b075373 100644 --- a/test/unit/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c +++ b/test/unit/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c @@ -490,6 +490,32 @@ fs_writev_readv_async(void) CU_ASSERT(g_fserrno == 0); CU_ASSERT(memcmp(r_buf, w_buf, sizeof(r_buf)) == 0); + /* Overwrite file with block aligned */ + g_fserrno = 1; + memset(w_buf, 0x6a, sizeof(w_buf)); + w_iov[0].iov_base = w_buf; + w_iov[0].iov_len = 2048; + w_iov[1].iov_base = w_buf + 2048; + w_iov[1].iov_len = 2048; + spdk_file_writev_async(g_file, fs->sync_target.sync_io_channel, + w_iov, 2, 0, 4096, fs_op_complete, NULL); + poll_threads(); + CU_ASSERT(g_fserrno == 0); + CU_ASSERT(g_file->length == 4096); + + /* Read file to verify the overwritten data */ + g_fserrno = 1; + memset(r_buf, 0x0, sizeof(r_buf)); + r_iov[0].iov_base = r_buf; + r_iov[0].iov_len = 2048; + r_iov[1].iov_base = r_buf + 2048; + r_iov[1].iov_len = 2048; + spdk_file_readv_async(g_file, fs->sync_target.sync_io_channel, + r_iov, 2, 0, 4096, fs_op_complete, NULL); + poll_threads(); + CU_ASSERT(g_fserrno == 0); + CU_ASSERT(memcmp(r_buf, w_buf, sizeof(r_buf)) == 0); + g_fserrno = 1; spdk_file_close_async(g_file, fs_op_complete, NULL); poll_threads();