util: add spdk_iov_memset()
And use it in a couple of places. Signed-off-by: John Levon <john.levon@nutanix.com> Change-Id: I4b86cef0e9489c1435c0206dd6c5cda4ffe4d33a Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16191 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
This commit is contained in:
parent
eb7506a1b4
commit
47568c65de
@ -100,6 +100,8 @@ caused a function callback in file descriptor group to execute.
|
|||||||
A new API `spdk_strcpy_replace` was added to replace all occurrences of the search string
|
A new API `spdk_strcpy_replace` was added to replace all occurrences of the search string
|
||||||
with the replacement string.
|
with the replacement string.
|
||||||
|
|
||||||
|
New API `spdk_iov_memset()` was added to memset an iovec.
|
||||||
|
|
||||||
### json
|
### json
|
||||||
|
|
||||||
Added API `spdk_json_write_double` and `spdk_json_write_named_double` to allow
|
Added API `spdk_json_write_double` and `spdk_json_write_named_double` to allow
|
||||||
|
@ -104,20 +104,6 @@ spdk_divide_round_up(uint64_t num, uint64_t divisor)
|
|||||||
return (num + divisor - 1) / divisor;
|
return (num + divisor - 1) / divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy the data described by the source iovec to the destination iovec.
|
|
||||||
*
|
|
||||||
* \return The number of bytes copied.
|
|
||||||
*/
|
|
||||||
size_t spdk_iovcpy(struct iovec *siov, size_t siovcnt, struct iovec *diov, size_t diovcnt);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Same as spdk_iovcpy(), but the src/dst buffers might overlap.
|
|
||||||
*
|
|
||||||
* \return The number of bytes copied.
|
|
||||||
*/
|
|
||||||
size_t spdk_iovmove(struct iovec *siov, size_t siovcnt, struct iovec *diov, size_t diovcnt);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An iovec iterator. Can be allocated on the stack.
|
* An iovec iterator. Can be allocated on the stack.
|
||||||
*/
|
*/
|
||||||
@ -157,6 +143,26 @@ size_t spdk_ioviter_first(struct spdk_ioviter *iter,
|
|||||||
*/
|
*/
|
||||||
size_t spdk_ioviter_next(struct spdk_ioviter *iter, void **src, void **dst);
|
size_t spdk_ioviter_next(struct spdk_ioviter *iter, void **src, void **dst);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Operate like memset across an iovec.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
spdk_iov_memset(struct iovec *iovs, int iovcnt, int c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy the data described by the source iovec to the destination iovec.
|
||||||
|
*
|
||||||
|
* \return The number of bytes copied.
|
||||||
|
*/
|
||||||
|
size_t spdk_iovcpy(struct iovec *siov, size_t siovcnt, struct iovec *diov, size_t diovcnt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as spdk_iovcpy(), but the src/dst buffers might overlap.
|
||||||
|
*
|
||||||
|
* \return The number of bytes copied.
|
||||||
|
*/
|
||||||
|
size_t spdk_iovmove(struct iovec *siov, size_t siovcnt, struct iovec *diov, size_t diovcnt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy iovs contents to buf through memcpy.
|
* Copy iovs contents to buf through memcpy.
|
||||||
*/
|
*/
|
||||||
|
@ -60,19 +60,6 @@ struct copy_iovs_ctx {
|
|||||||
size_t cur_iov_offset;
|
size_t cur_iov_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
|
||||||
_clear_iovs(struct iovec *iovs, int iovcnt)
|
|
||||||
{
|
|
||||||
int iov_idx = 0;
|
|
||||||
struct iovec *iov;
|
|
||||||
|
|
||||||
while (iov_idx < iovcnt) {
|
|
||||||
iov = &iovs[iov_idx];
|
|
||||||
memset(iov->iov_base, 0, iov->iov_len);
|
|
||||||
iov_idx++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_init_copy_iovs_ctx(struct copy_iovs_ctx *copy_ctx, struct iovec *iovs, int iovcnt)
|
_init_copy_iovs_ctx(struct copy_iovs_ctx *copy_ctx, struct iovec *iovs, int iovcnt)
|
||||||
{
|
{
|
||||||
@ -3570,7 +3557,7 @@ nvmf_ctrlr_process_admin_cmd(struct spdk_nvmf_request *req)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (req->data && spdk_nvme_opc_get_data_transfer(cmd->opc) == SPDK_NVME_DATA_CONTROLLER_TO_HOST) {
|
if (req->data && spdk_nvme_opc_get_data_transfer(cmd->opc) == SPDK_NVME_DATA_CONTROLLER_TO_HOST) {
|
||||||
_clear_iovs(req->iov, req->iovcnt);
|
spdk_iov_memset(req->iov, req->iovcnt, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctrlr->subsys->subtype == SPDK_NVMF_SUBTYPE_DISCOVERY) {
|
if (ctrlr->subsys->subtype == SPDK_NVMF_SUBTYPE_DISCOVERY) {
|
||||||
|
@ -5,6 +5,19 @@
|
|||||||
|
|
||||||
#include "spdk/util.h"
|
#include "spdk/util.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
spdk_iov_memset(struct iovec *iovs, int iovcnt, int c)
|
||||||
|
{
|
||||||
|
int iov_idx = 0;
|
||||||
|
struct iovec *iov;
|
||||||
|
|
||||||
|
while (iov_idx < iovcnt) {
|
||||||
|
iov = &iovs[iov_idx];
|
||||||
|
memset(iov->iov_base, c, iov->iov_len);
|
||||||
|
iov_idx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
spdk_ioviter_first(struct spdk_ioviter *iter,
|
spdk_ioviter_first(struct spdk_ioviter *iter,
|
||||||
struct iovec *siov, size_t siovcnt,
|
struct iovec *siov, size_t siovcnt,
|
||||||
|
@ -135,6 +135,7 @@
|
|||||||
spdk_iovmove;
|
spdk_iovmove;
|
||||||
spdk_ioviter_first;
|
spdk_ioviter_first;
|
||||||
spdk_ioviter_next;
|
spdk_ioviter_next;
|
||||||
|
spdk_iov_memset;
|
||||||
spdk_copy_iovs_to_buf;
|
spdk_copy_iovs_to_buf;
|
||||||
spdk_copy_buf_to_iovs;
|
spdk_copy_buf_to_iovs;
|
||||||
spdk_memset_s;
|
spdk_memset_s;
|
||||||
|
@ -1512,10 +1512,15 @@ test_nvmf_ns_reservation_report(void)
|
|||||||
struct spdk_nvme_reservation_status_extended_data *status_data;
|
struct spdk_nvme_reservation_status_extended_data *status_data;
|
||||||
struct spdk_nvmf_registrant *reg;
|
struct spdk_nvmf_registrant *reg;
|
||||||
|
|
||||||
req.data = calloc(1, sizeof(*status_data) + sizeof(*ctrlr_data) * 2);
|
req.length = sizeof(*status_data) + sizeof(*ctrlr_data) * 2;
|
||||||
|
req.data = calloc(1, req.length);
|
||||||
reg = calloc(2, sizeof(struct spdk_nvmf_registrant));
|
reg = calloc(2, sizeof(struct spdk_nvmf_registrant));
|
||||||
SPDK_CU_ASSERT_FATAL(req.data != NULL && reg != NULL);
|
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;
|
||||||
|
|
||||||
req.cmd = &cmd;
|
req.cmd = &cmd;
|
||||||
req.rsp = &rsp;
|
req.rsp = &rsp;
|
||||||
ns.gen = 1;
|
ns.gen = 1;
|
||||||
@ -1554,7 +1559,7 @@ test_nvmf_ns_reservation_report(void)
|
|||||||
CU_ASSERT(!spdk_uuid_compare((struct spdk_uuid *)ctrlr_data->hostid, ®[1].hostid));
|
CU_ASSERT(!spdk_uuid_compare((struct spdk_uuid *)ctrlr_data->hostid, ®[1].hostid));
|
||||||
|
|
||||||
/* extended controller data structure */
|
/* extended controller data structure */
|
||||||
memset(req.data, 0, sizeof(*status_data) + sizeof(*ctrlr_data) * 2);
|
spdk_iov_memset(req.iov, req.iovcnt, 0);
|
||||||
memset(req.rsp, 0, sizeof(*req.rsp));
|
memset(req.rsp, 0, sizeof(*req.rsp));
|
||||||
cmd.nvme_cmd.cdw11_bits.resv_report.eds = false;
|
cmd.nvme_cmd.cdw11_bits.resv_report.eds = false;
|
||||||
|
|
||||||
@ -1563,7 +1568,7 @@ test_nvmf_ns_reservation_report(void)
|
|||||||
CU_ASSERT(req.rsp->nvme_cpl.status.sct == SPDK_NVME_SCT_GENERIC);
|
CU_ASSERT(req.rsp->nvme_cpl.status.sct == SPDK_NVME_SCT_GENERIC);
|
||||||
|
|
||||||
/* Transfer length invalid */
|
/* Transfer length invalid */
|
||||||
memset(req.data, 0, sizeof(*status_data) + sizeof(*ctrlr_data) * 2);
|
spdk_iov_memset(req.iov, req.iovcnt, 0);
|
||||||
memset(req.rsp, 0, sizeof(*req.rsp));
|
memset(req.rsp, 0, sizeof(*req.rsp));
|
||||||
cmd.nvme_cmd.cdw11_bits.resv_report.eds = true;
|
cmd.nvme_cmd.cdw11_bits.resv_report.eds = true;
|
||||||
cmd.nvme_cmd.cdw10 = 0;
|
cmd.nvme_cmd.cdw10 = 0;
|
||||||
|
@ -245,6 +245,28 @@ test_buf_to_iovs(void)
|
|||||||
CU_ASSERT(_check_val(ddata, 64, 7) == 0);
|
CU_ASSERT(_check_val(ddata, 64, 7) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_memset(void)
|
||||||
|
{
|
||||||
|
struct iovec iov[4];
|
||||||
|
uint8_t iov_buffer[64];
|
||||||
|
|
||||||
|
memset(&iov_buffer, 1, sizeof(iov_buffer));
|
||||||
|
|
||||||
|
iov[0].iov_base = iov_buffer;
|
||||||
|
iov[0].iov_len = 5;
|
||||||
|
iov[1].iov_base = iov[0].iov_base + iov[0].iov_len;
|
||||||
|
iov[1].iov_len = 15;
|
||||||
|
iov[2].iov_base = iov[1].iov_base + iov[1].iov_len;
|
||||||
|
iov[2].iov_len = 21;
|
||||||
|
iov[3].iov_base = iov[2].iov_base + iov[2].iov_len;
|
||||||
|
iov[3].iov_len = 23;
|
||||||
|
|
||||||
|
spdk_iov_memset(iov, 4, 0);
|
||||||
|
|
||||||
|
CU_ASSERT(_check_val(iov_buffer, 64, 0) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -261,6 +283,7 @@ main(int argc, char **argv)
|
|||||||
CU_ADD_TEST(suite, test_complex_iov);
|
CU_ADD_TEST(suite, test_complex_iov);
|
||||||
CU_ADD_TEST(suite, test_iovs_to_buf);
|
CU_ADD_TEST(suite, test_iovs_to_buf);
|
||||||
CU_ADD_TEST(suite, test_buf_to_iovs);
|
CU_ADD_TEST(suite, test_buf_to_iovs);
|
||||||
|
CU_ADD_TEST(suite, test_memset);
|
||||||
|
|
||||||
CU_basic_set_mode(CU_BRM_VERBOSE);
|
CU_basic_set_mode(CU_BRM_VERBOSE);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user