lvol: add unmap and write zeros support

Signed-off-by: Maciej Szwed <maciej.szwed@intel.com>
Change-Id: Ic11a56c5616098ff42f31f78aa96289af5965118

Reviewed-on: https://review.gerrithub.io/387611
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Maciej Szwed 2017-11-15 15:54:28 +01:00 committed by Daniel Verkamp
parent f6e075cd54
commit cf6fe9b15d
2 changed files with 65 additions and 3 deletions

View File

@ -463,9 +463,9 @@ vbdev_lvol_io_type_supported(void *ctx, enum spdk_bdev_io_type io_type)
case SPDK_BDEV_IO_TYPE_WRITE: case SPDK_BDEV_IO_TYPE_WRITE:
case SPDK_BDEV_IO_TYPE_FLUSH: case SPDK_BDEV_IO_TYPE_FLUSH:
case SPDK_BDEV_IO_TYPE_RESET: case SPDK_BDEV_IO_TYPE_RESET:
return true;
case SPDK_BDEV_IO_TYPE_UNMAP: case SPDK_BDEV_IO_TYPE_UNMAP:
case SPDK_BDEV_IO_TYPE_WRITE_ZEROES: case SPDK_BDEV_IO_TYPE_WRITE_ZEROES:
return true;
default: default:
return false; return false;
} }
@ -486,6 +486,42 @@ lvol_op_comp(void *cb_arg, int bserrno)
spdk_bdev_io_complete(bdev_io, task->status); spdk_bdev_io_complete(bdev_io, task->status);
} }
static void
lvol_unmap(struct spdk_lvol *lvol, struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
{
uint64_t start_page, num_pages;
struct spdk_blob *blob = lvol->blob;
struct lvol_task *task = (struct lvol_task *)bdev_io->driver_ctx;
start_page = bdev_io->u.bdev.offset_blocks;
num_pages = bdev_io->u.bdev.num_blocks;
task->status = SPDK_BDEV_IO_STATUS_SUCCESS;
SPDK_INFOLOG(SPDK_TRACE_VBDEV_LVOL,
"Vbdev doing unmap at offset %" PRIu64 " using %" PRIu64 " pages on device %s\n", start_page,
num_pages, bdev_io->bdev->name);
spdk_bs_io_unmap_blob(blob, ch, start_page, num_pages, lvol_op_comp, task);
}
static void
lvol_write_zeroes(struct spdk_lvol *lvol, struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
{
uint64_t start_page, num_pages;
struct spdk_blob *blob = lvol->blob;
struct lvol_task *task = (struct lvol_task *)bdev_io->driver_ctx;
start_page = bdev_io->u.bdev.offset_blocks;
num_pages = bdev_io->u.bdev.num_blocks;
task->status = SPDK_BDEV_IO_STATUS_SUCCESS;
SPDK_INFOLOG(SPDK_TRACE_VBDEV_LVOL,
"Vbdev doing write zeros at offset %" PRIu64 " using %" PRIu64 " pages on device %s\n", start_page,
num_pages, bdev_io->bdev->name);
spdk_bs_io_write_zeroes_blob(blob, ch, start_page, num_pages, lvol_op_comp, task);
}
static void static void
lvol_read(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io) lvol_read(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
{ {
@ -566,7 +602,11 @@ vbdev_lvol_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_
lvol_flush(ch, bdev_io); lvol_flush(ch, bdev_io);
break; break;
case SPDK_BDEV_IO_TYPE_UNMAP: case SPDK_BDEV_IO_TYPE_UNMAP:
lvol_unmap(lvol, ch, bdev_io);
break;
case SPDK_BDEV_IO_TYPE_WRITE_ZEROES: case SPDK_BDEV_IO_TYPE_WRITE_ZEROES:
lvol_write_zeroes(lvol, ch, bdev_io);
break;
default: default:
SPDK_INFOLOG(SPDK_TRACE_VBDEV_LVOL, "lvol: unsupported I/O type %d\n", bdev_io->type); SPDK_INFOLOG(SPDK_TRACE_VBDEV_LVOL, "lvol: unsupported I/O type %d\n", bdev_io->type);
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED); spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);

View File

@ -339,6 +339,26 @@ spdk_bs_io_write_blob(struct spdk_blob *blob, struct spdk_io_channel *channel,
{ {
} }
void
spdk_bs_io_unmap_blob(struct spdk_blob *blob, struct spdk_io_channel *channel,
uint64_t offset, uint64_t length, spdk_blob_op_complete cb_fn, void *cb_arg)
{
CU_ASSERT(blob == NULL);
CU_ASSERT(channel == g_ch);
CU_ASSERT(offset == g_io->u.bdev.offset_blocks);
CU_ASSERT(length == g_io->u.bdev.num_blocks);
}
void
spdk_bs_io_write_zeroes_blob(struct spdk_blob *blob, struct spdk_io_channel *channel,
uint64_t offset, uint64_t length, spdk_blob_op_complete cb_fn, void *cb_arg)
{
CU_ASSERT(blob == NULL);
CU_ASSERT(channel == g_ch);
CU_ASSERT(offset == g_io->u.bdev.offset_blocks);
CU_ASSERT(length == g_io->u.bdev.num_blocks);
}
void void
spdk_bs_io_writev_blob(struct spdk_blob *blob, struct spdk_io_channel *channel, spdk_bs_io_writev_blob(struct spdk_blob *blob, struct spdk_io_channel *channel,
struct iovec *iov, int iovcnt, uint64_t offset, uint64_t length, struct iovec *iov, int iovcnt, uint64_t offset, uint64_t length,
@ -840,10 +860,12 @@ ut_vbdev_lvol_io_type_supported(void)
CU_ASSERT(ret == true); CU_ASSERT(ret == true);
ret = vbdev_lvol_io_type_supported(lvol, SPDK_BDEV_IO_TYPE_RESET); ret = vbdev_lvol_io_type_supported(lvol, SPDK_BDEV_IO_TYPE_RESET);
CU_ASSERT(ret == true); CU_ASSERT(ret == true);
ret = vbdev_lvol_io_type_supported(lvol, SPDK_BDEV_IO_TYPE_UNMAP);
CU_ASSERT(ret == true);
ret = vbdev_lvol_io_type_supported(lvol, SPDK_BDEV_IO_TYPE_WRITE_ZEROES);
CU_ASSERT(ret == true);
/* Unsupported types */ /* Unsupported types */
ret = vbdev_lvol_io_type_supported(lvol, SPDK_BDEV_IO_TYPE_UNMAP);
CU_ASSERT(ret == false);
ret = vbdev_lvol_io_type_supported(lvol, SPDK_BDEV_IO_TYPE_NVME_ADMIN); ret = vbdev_lvol_io_type_supported(lvol, SPDK_BDEV_IO_TYPE_NVME_ADMIN);
CU_ASSERT(ret == false); CU_ASSERT(ret == false);
ret = vbdev_lvol_io_type_supported(lvol, SPDK_BDEV_IO_TYPE_NVME_IO); ret = vbdev_lvol_io_type_supported(lvol, SPDK_BDEV_IO_TYPE_NVME_IO);