util: add spdk_iov_one()

It's common to set up an iovec around a single buffer; add a helper for
this.

Signed-off-by: John Levon <john.levon@nutanix.com>
Change-Id: Ic4183e29d78549ec102045c6af0b5ff448cb5c59
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16192
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
This commit is contained in:
John Levon 2023-01-07 13:27:40 +00:00 committed by Tomasz Zawadzki
parent 47568c65de
commit 9fa252375a
8 changed files with 53 additions and 24 deletions

View File

@ -102,6 +102,8 @@ with the replacement string.
New API `spdk_iov_memset()` was added to memset an iovec.
New API `spdk_iov_one()` was added to initialize an iovec for a single buffer.
### json
Added API `spdk_json_write_double` and `spdk_json_write_named_double` to allow

View File

@ -149,6 +149,12 @@ size_t spdk_ioviter_next(struct spdk_ioviter *iter, void **src, void **dst);
void
spdk_iov_memset(struct iovec *iovs, int iovcnt, int c);
/**
* Initialize an iovec with just the single given buffer.
*/
void
spdk_iov_one(struct iovec *iov, int *iovcnt, void *buf, size_t buflen);
/**
* Copy the data described by the source iovec to the destination iovec.
*

View File

@ -18,6 +18,14 @@ spdk_iov_memset(struct iovec *iovs, int iovcnt, int c)
}
}
void
spdk_iov_one(struct iovec *iov, int *iovcnt, void *buf, size_t buflen)
{
iov->iov_base = buf;
iov->iov_len = buflen;
*iovcnt = 1;
}
size_t
spdk_ioviter_first(struct spdk_ioviter *iter,
struct iovec *siov, size_t siovcnt,

View File

@ -136,6 +136,7 @@
spdk_ioviter_first;
spdk_ioviter_next;
spdk_iov_memset;
spdk_iov_one;
spdk_copy_iovs_to_buf;
spdk_copy_buf_to_iovs;
spdk_memset_s;

View File

@ -325,6 +325,7 @@ test_get_log_page(void)
req.rsp = &rsp;
req.data = &data;
req.length = sizeof(data);
spdk_iov_one(req.iov, &req.iovcnt, &data, req.length);
/* Get Log Page - all valid */
memset(&cmd, 0, sizeof(cmd));
@ -360,6 +361,7 @@ test_get_log_page(void)
memset(&cmd, 0, sizeof(cmd));
memset(&rsp, 0, sizeof(rsp));
req.data = NULL;
req.iovcnt = 0;
cmd.nvme_cmd.opc = SPDK_NVME_OPC_GET_LOG_PAGE;
cmd.nvme_cmd.cdw10_bits.get_log_page.lid = SPDK_NVME_LOG_ERROR;
cmd.nvme_cmd.cdw10_bits.get_log_page.numdl = spdk_nvme_bytes_to_numd(req.length);
@ -480,9 +482,10 @@ test_connect(void)
memset(&req, 0, sizeof(req));
req.qpair = &qpair;
req.length = sizeof(connect_data);
req.xfer = SPDK_NVME_DATA_HOST_TO_CONTROLLER;
req.data = &connect_data;
req.length = sizeof(connect_data);
spdk_iov_one(req.iov, &req.iovcnt, &connect_data, req.length);
req.cmd = &cmd;
req.rsp = &rsp;
@ -882,9 +885,7 @@ test_get_ns_id_desc_list(void)
req.xfer = SPDK_NVME_DATA_CONTROLLER_TO_HOST;
req.data = buf;
req.length = sizeof(buf);
req.iovcnt = 1;
req.iov[0].iov_base = req.data;
req.iov[0].iov_len = req.length;
spdk_iov_one(req.iov, &req.iovcnt, &buf, req.length);
memset(&cmd, 0, sizeof(cmd));
cmd.nvme_cmd.opc = SPDK_NVME_OPC_IDENTIFY;
@ -1792,6 +1793,7 @@ test_custom_admin_cmd(void)
req.xfer = SPDK_NVME_DATA_CONTROLLER_TO_HOST;
req.data = buf;
req.length = sizeof(buf);
spdk_iov_one(req.iov, &req.iovcnt, &buf, req.length);
memset(&cmd, 0, sizeof(cmd));
cmd.nvme_cmd.opc = 0xc1;
@ -2295,6 +2297,7 @@ test_rae(void)
req[i].rsp = &rsp[i];
req[i].data = &data;
req[i].length = sizeof(data);
spdk_iov_one(req[i].iov, &req[i].iovcnt, &data, req[i].length);
cmd[i].nvme_cmd.opc = SPDK_NVME_OPC_GET_LOG_PAGE;
cmd[i].nvme_cmd.cdw10_bits.get_log_page.lid =
@ -2392,16 +2395,17 @@ test_nvmf_ctrlr_create_destruct(void)
cmd.connect_cmd.kato = 120000;
req.qpair = &qpair;
req.length = sizeof(connect_data);
req.xfer = SPDK_NVME_DATA_HOST_TO_CONTROLLER;
req.data = &connect_data;
req.length = sizeof(connect_data);
spdk_iov_one(req.iov, &req.iovcnt, &connect_data, req.length);
req.cmd = &cmd;
req.rsp = &rsp;
TAILQ_INSERT_TAIL(&qpair.outstanding, &req, link);
sgroups[subsystem.id].mgmt_io_outstanding++;
ctrlr = nvmf_ctrlr_create(&subsystem, &req, &req.cmd->connect_cmd, req.data);
ctrlr = nvmf_ctrlr_create(&subsystem, &req, &req.cmd->connect_cmd, req.iov[0].iov_base);
poll_threads();
SPDK_CU_ASSERT_FATAL(ctrlr != NULL);
CU_ASSERT(req.qpair->ctrlr == ctrlr);
@ -2912,7 +2916,6 @@ test_nvmf_ctrlr_get_features_host_behavior_support(void)
struct spdk_nvmf_request req = {};
struct spdk_nvmf_qpair qpair = {};
struct spdk_nvmf_ctrlr ctrlr = {};
struct spdk_nvme_host_behavior *host_behavior;
struct spdk_nvme_host_behavior behavior = {};
union nvmf_h2c_msg cmd = {};
union nvmf_c2h_msg rsp = {};
@ -2923,9 +2926,8 @@ test_nvmf_ctrlr_get_features_host_behavior_support(void)
req.rsp = &rsp;
/* Invalid data */
req.length = sizeof(struct spdk_nvme_host_behavior);
req.data = NULL;
req.length = sizeof(struct spdk_nvme_host_behavior);
req.iovcnt = 0;
rc = nvmf_ctrlr_get_features_host_behavior_support(&req);
@ -2937,9 +2939,7 @@ test_nvmf_ctrlr_get_features_host_behavior_support(void)
/* Wrong structure length */
req.data = &behavior;
req.length = sizeof(struct spdk_nvme_host_behavior) - 1;
req.iovcnt = 1;
req.iov[0].iov_base = req.data;
req.iov[0].iov_len = req.length;
spdk_iov_one(req.iov, &req.iovcnt, &behavior, req.length);
rc = nvmf_ctrlr_get_features_host_behavior_support(&req);
CU_ASSERT(rc == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE);
@ -2949,17 +2949,14 @@ test_nvmf_ctrlr_get_features_host_behavior_support(void)
/* Get Features Host Behavior Support Success */
req.data = &behavior;
req.length = sizeof(struct spdk_nvme_host_behavior);
req.iovcnt = 1;
req.iov[0].iov_base = req.data;
req.iov[0].iov_len = req.length;
spdk_iov_one(req.iov, &req.iovcnt, &behavior, req.length);
ctrlr.acre_enabled = true;
host_behavior = (struct spdk_nvme_host_behavior *)req.data;
host_behavior->acre = false;
behavior.acre = false;
rc = nvmf_ctrlr_get_features_host_behavior_support(&req);
CU_ASSERT(rc == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE);
CU_ASSERT(host_behavior->acre == true);
CU_ASSERT(behavior.acre == true);
}
static void

View File

@ -728,10 +728,11 @@ test_nvmf_bdev_ctrlr_cmd(void)
cmd.nvme_cmd.cdw11 = 0;
cmd.nvme_cmd.cdw12 = 0;
cmd.nvme_cmd.cdw12_bits.copy.nr = 0;
req.length = 32;
range.slba = 512;
range.nlb = 511;
req.data = &range;
req.length = 32;
spdk_iov_one(req.iov, &req.iovcnt, &range, req.length);
rc = nvmf_bdev_ctrlr_copy_cmd(&bdev, NULL, &ch, &req);
CU_ASSERT(rc == SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS);

View File

@ -591,8 +591,9 @@ ut_reservation_build_req(uint32_t length)
req = calloc(1, sizeof(*req));
assert(req != NULL);
req->data = calloc(1, length);
assert(req->data != NULL);
spdk_iov_one(req->iov, &req->iovcnt, calloc(1, length), length);
assert(req->iov[0].iov_base != NULL);
req->data = req->iov[0].iov_base;
req->length = length;
req->cmd = (union nvmf_h2c_msg *)calloc(1, sizeof(union nvmf_h2c_msg));
@ -1517,9 +1518,7 @@ test_nvmf_ns_reservation_report(void)
reg = calloc(2, sizeof(struct spdk_nvmf_registrant));
SPDK_CU_ASSERT_FATAL(req.data != NULL && reg != NULL);
req.iov[0].iov_base = req.data;
req.iov[0].iov_len = req.length;
req.iovcnt = 1;
spdk_iov_one(req.iov, &req.iovcnt, req.data, req.length);
req.cmd = &cmd;
req.rsp = &rsp;

View File

@ -267,6 +267,20 @@ test_memset(void)
CU_ASSERT(_check_val(iov_buffer, 64, 0) == 0);
}
static void
test_iov_one(void)
{
struct iovec iov = { 0 };
int iovcnt;
char buf[4];
spdk_iov_one(&iov, &iovcnt, buf, sizeof(buf));
CU_ASSERT(iov.iov_base == buf);
CU_ASSERT(iov.iov_len == sizeof(buf));
CU_ASSERT(iovcnt == 1);
}
int
main(int argc, char **argv)
{
@ -284,6 +298,7 @@ main(int argc, char **argv)
CU_ADD_TEST(suite, test_iovs_to_buf);
CU_ADD_TEST(suite, test_buf_to_iovs);
CU_ADD_TEST(suite, test_memset);
CU_ADD_TEST(suite, test_iov_one);
CU_basic_set_mode(CU_BRM_VERBOSE);