examples/hello_bdev: support write_unit_size

Change-Id: Ifd9b73560d1f47d545825b69c20a1f02204596a9
Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14713
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Artur Paszkiewicz 2022-09-27 13:33:49 +02:00 committed by Tomasz Zawadzki
parent 28932f6e42
commit 65e08d1265

View File

@ -23,6 +23,7 @@ struct hello_context_t {
struct spdk_bdev_desc *bdev_desc; struct spdk_bdev_desc *bdev_desc;
struct spdk_io_channel *bdev_io_channel; struct spdk_io_channel *bdev_io_channel;
char *buff; char *buff;
uint32_t buff_size;
char *bdev_name; char *bdev_name;
struct spdk_bdev_io_wait_entry bdev_io_wait; struct spdk_bdev_io_wait_entry bdev_io_wait;
}; };
@ -79,11 +80,11 @@ hello_read(void *arg)
{ {
struct hello_context_t *hello_context = arg; struct hello_context_t *hello_context = arg;
int rc = 0; int rc = 0;
uint32_t length = spdk_bdev_get_block_size(hello_context->bdev);
SPDK_NOTICELOG("Reading io\n"); SPDK_NOTICELOG("Reading io\n");
rc = spdk_bdev_read(hello_context->bdev_desc, hello_context->bdev_io_channel, rc = spdk_bdev_read(hello_context->bdev_desc, hello_context->bdev_io_channel,
hello_context->buff, 0, length, read_complete, hello_context); hello_context->buff, 0, hello_context->buff_size, read_complete,
hello_context);
if (rc == -ENOMEM) { if (rc == -ENOMEM) {
SPDK_NOTICELOG("Queueing io\n"); SPDK_NOTICELOG("Queueing io\n");
@ -108,7 +109,6 @@ static void
write_complete(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg) write_complete(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg)
{ {
struct hello_context_t *hello_context = cb_arg; struct hello_context_t *hello_context = cb_arg;
uint32_t length;
/* Complete the I/O */ /* Complete the I/O */
spdk_bdev_free_io(bdev_io); spdk_bdev_free_io(bdev_io);
@ -124,8 +124,7 @@ write_complete(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg)
} }
/* Zero the buffer so that we can use it for reading */ /* Zero the buffer so that we can use it for reading */
length = spdk_bdev_get_block_size(hello_context->bdev); memset(hello_context->buff, 0, hello_context->buff_size);
memset(hello_context->buff, 0, length);
hello_read(hello_context); hello_read(hello_context);
} }
@ -135,11 +134,11 @@ hello_write(void *arg)
{ {
struct hello_context_t *hello_context = arg; struct hello_context_t *hello_context = arg;
int rc = 0; int rc = 0;
uint32_t length = spdk_bdev_get_block_size(hello_context->bdev);
SPDK_NOTICELOG("Writing to the bdev\n"); SPDK_NOTICELOG("Writing to the bdev\n");
rc = spdk_bdev_write(hello_context->bdev_desc, hello_context->bdev_io_channel, rc = spdk_bdev_write(hello_context->bdev_desc, hello_context->bdev_io_channel,
hello_context->buff, 0, length, write_complete, hello_context); hello_context->buff, 0, hello_context->buff_size, write_complete,
hello_context);
if (rc == -ENOMEM) { if (rc == -ENOMEM) {
SPDK_NOTICELOG("Queueing io\n"); SPDK_NOTICELOG("Queueing io\n");
@ -215,7 +214,7 @@ static void
hello_start(void *arg1) hello_start(void *arg1)
{ {
struct hello_context_t *hello_context = arg1; struct hello_context_t *hello_context = arg1;
uint32_t blk_size, buf_align; uint32_t buf_align;
int rc = 0; int rc = 0;
hello_context->bdev = NULL; hello_context->bdev = NULL;
hello_context->bdev_desc = NULL; hello_context->bdev_desc = NULL;
@ -255,9 +254,10 @@ hello_start(void *arg1)
/* Allocate memory for the write buffer. /* Allocate memory for the write buffer.
* Initialize the write buffer with the string "Hello World!" * Initialize the write buffer with the string "Hello World!"
*/ */
blk_size = spdk_bdev_get_block_size(hello_context->bdev); hello_context->buff_size = spdk_bdev_get_block_size(hello_context->bdev) *
spdk_bdev_get_write_unit_size(hello_context->bdev);
buf_align = spdk_bdev_get_buf_align(hello_context->bdev); buf_align = spdk_bdev_get_buf_align(hello_context->bdev);
hello_context->buff = spdk_dma_zmalloc(blk_size, buf_align, NULL); hello_context->buff = spdk_dma_zmalloc(hello_context->buff_size, buf_align, NULL);
if (!hello_context->buff) { if (!hello_context->buff) {
SPDK_ERRLOG("Failed to allocate buffer\n"); SPDK_ERRLOG("Failed to allocate buffer\n");
spdk_put_io_channel(hello_context->bdev_io_channel); spdk_put_io_channel(hello_context->bdev_io_channel);
@ -265,7 +265,7 @@ hello_start(void *arg1)
spdk_app_stop(-1); spdk_app_stop(-1);
return; return;
} }
snprintf(hello_context->buff, blk_size, "%s", "Hello World!\n"); snprintf(hello_context->buff, hello_context->buff_size, "%s", "Hello World!\n");
if (spdk_bdev_is_zoned(hello_context->bdev)) { if (spdk_bdev_is_zoned(hello_context->bdev)) {
hello_reset_zone(hello_context); hello_reset_zone(hello_context);