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 <gang.cao@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478424 Community-CI: SPDK CI Jenkins <sys_sgci@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
5df1966375
commit
be4a5602ce
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user