Commit 47568c65 authored by John Levon's avatar John Levon Committed by Tomasz Zawadzki
Browse files

util: add spdk_iov_memset()



And use it in a couple of places.

Signed-off-by: default avatarJohn Levon <john.levon@nutanix.com>
Change-Id: I4b86cef0e9489c1435c0206dd6c5cda4ffe4d33a
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16191


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent eb7506a1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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
with the replacement string.

New API `spdk_iov_memset()` was added to memset an iovec.

### json

Added API `spdk_json_write_double` and `spdk_json_write_named_double` to allow
+20 −14
Original line number Diff line number Diff line
@@ -104,20 +104,6 @@ spdk_divide_round_up(uint64_t num, uint64_t 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.
 */
@@ -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);

/**
 * 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.
 */
+1 −14
Original line number Diff line number Diff line
@@ -60,19 +60,6 @@ struct copy_iovs_ctx {
	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
_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) {
		_clear_iovs(req->iov, req->iovcnt);
		spdk_iov_memset(req->iov, req->iovcnt, 0);
	}

	if (ctrlr->subsys->subtype == SPDK_NVMF_SUBTYPE_DISCOVERY) {
+13 −0
Original line number Diff line number Diff line
@@ -5,6 +5,19 @@

#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
spdk_ioviter_first(struct spdk_ioviter *iter,
		   struct iovec *siov, size_t siovcnt,
+1 −0
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@
	spdk_iovmove;
	spdk_ioviter_first;
	spdk_ioviter_next;
	spdk_iov_memset;
	spdk_copy_iovs_to_buf;
	spdk_copy_buf_to_iovs;
	spdk_memset_s;
Loading