Commit 70a82d9a authored by John Levon's avatar John Levon Committed by Tomasz Zawadzki
Browse files

nvmf: add spdk_nvmf_request_copy_*_buf()



Also deprecate the existing spdk_nvmf_request_data() API, which is
incompatible with iovecs.

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent cc3184b8
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -13,6 +13,11 @@ multiple readers.

New function `spdk_env_get_main_core` was added.

### nvmf

New `spdk_nvmf_request_copy_to/from_buf()` APIs have been added, which support
iovecs, unlike the deprecated `spdk_nvmf_request_get_data()`.

## v23.01

### accel
+25 −0
Original line number Diff line number Diff line
@@ -197,12 +197,37 @@ struct spdk_nvmf_subsystem *spdk_nvmf_request_get_subsystem(struct spdk_nvmf_req
/**
 * Get the data and length associated with this request.
 *
 *
 * \param req The NVMe-oF request
 * \param data The data buffer associated with this request
 * \param length The length of the data buffer
 */
void spdk_nvmf_request_get_data(struct spdk_nvmf_request *req, void **data, uint32_t *length);

/**
 * Copy the data from the given @buf into the request iovec.
 *
 * \param req The NVMe-oF request
 * \param buf The data buffer
 * \param buflen The length of the data buffer
 *
 * \return the number of bytes copied
 */
size_t spdk_nvmf_request_copy_from_buf(struct spdk_nvmf_request *req,
				       void *buf, size_t buflen);

/**
 * Copy the data from the request iovec into the given @buf.
 *
 * \param req The NVMe-oF request
 * \param buf The data buffer
 * \param buflen The length of the data buffer
 *
 * \return the number of bytes copied
 */
size_t spdk_nvmf_request_copy_to_buf(struct spdk_nvmf_request *req,
				     void *buf, size_t buflen);

/**
 * Get the NVMe-oF command associated with this request.
 *
+24 −0
Original line number Diff line number Diff line
@@ -4664,13 +4664,37 @@ struct spdk_nvmf_subsystem *spdk_nvmf_request_get_subsystem(struct spdk_nvmf_req
	return req->qpair->ctrlr->subsys;
}

SPDK_LOG_DEPRECATION_REGISTER(nvmf_request_get_data, "spdk_nvmf_request_get_data",
			      "SPDK 23.09", 60);

void
spdk_nvmf_request_get_data(struct spdk_nvmf_request *req, void **data, uint32_t *length)
{
	SPDK_LOG_DEPRECATED(nvmf_request_get_data);
	*data = req->data;
	*length = req->length;
}

size_t
spdk_nvmf_request_copy_from_buf(struct spdk_nvmf_request *req,
				void *buf, size_t buflen)
{
	struct spdk_iov_xfer ix;

	spdk_iov_xfer_init(&ix, req->iov, req->iovcnt);
	return spdk_iov_xfer_from_buf(&ix, buf, buflen);
}

size_t
spdk_nvmf_request_copy_to_buf(struct spdk_nvmf_request *req,
			      void *buf, size_t buflen)
{
	struct spdk_iov_xfer ix;

	spdk_iov_xfer_init(&ix, req->iov, req->iovcnt);
	return spdk_iov_xfer_to_buf(&ix, buf, buflen);
}

struct spdk_nvmf_subsystem *spdk_nvmf_ctrlr_get_subsystem(struct spdk_nvmf_ctrlr *ctrlr)
{
	return ctrlr->subsys;
+2 −0
Original line number Diff line number Diff line
@@ -91,6 +91,8 @@
	spdk_nvmf_set_custom_admin_cmd_hdlr;
	spdk_nvmf_set_passthru_admin_cmd;
	spdk_nvmf_bdev_ctrlr_nvme_passthru_admin;
	spdk_nvmf_request_copy_from_buf;
	spdk_nvmf_request_copy_to_buf;
	spdk_nvmf_request_get_bdev;
	spdk_nvmf_request_get_ctrlr;
	spdk_nvmf_request_get_subsystem;
+10 −9
Original line number Diff line number Diff line
@@ -325,15 +325,16 @@ nvmf_tgt_create_target(void)
static void
fixup_identify_ctrlr(struct spdk_nvmf_request *req)
{
	uint32_t length;
	int rc;
	struct spdk_nvme_ctrlr_data *nvme_cdata;
	struct spdk_nvme_ctrlr_data nvme_cdata = {};
	struct spdk_nvme_ctrlr_data nvmf_cdata = {};
	struct spdk_nvmf_ctrlr *ctrlr = spdk_nvmf_request_get_ctrlr(req);
	struct spdk_nvme_cpl *rsp = spdk_nvmf_request_get_response(req);
	size_t datalen;
	int rc;

	/* This is the identify data from the NVMe drive */
	spdk_nvmf_request_get_data(req, (void **)&nvme_cdata, &length);
	datalen = spdk_nvmf_request_copy_to_buf(req, &nvme_cdata,
						sizeof(nvme_cdata));

	/* Get the NVMF identify data */
	rc = spdk_nvmf_ctrlr_identify_ctrlr(ctrlr, &nvmf_cdata);
@@ -346,17 +347,17 @@ fixup_identify_ctrlr(struct spdk_nvmf_request *req)
	/* Fixup NVMF identify data with NVMe identify data */

	/* Serial Number (SN) */
	memcpy(&nvmf_cdata.sn[0], &nvme_cdata->sn[0], sizeof(nvmf_cdata.sn));
	memcpy(&nvmf_cdata.sn[0], &nvme_cdata.sn[0], sizeof(nvmf_cdata.sn));
	/* Model Number (MN) */
	memcpy(&nvmf_cdata.mn[0], &nvme_cdata->mn[0], sizeof(nvmf_cdata.mn));
	memcpy(&nvmf_cdata.mn[0], &nvme_cdata.mn[0], sizeof(nvmf_cdata.mn));
	/* Firmware Revision (FR) */
	memcpy(&nvmf_cdata.fr[0], &nvme_cdata->fr[0], sizeof(nvmf_cdata.fr));
	memcpy(&nvmf_cdata.fr[0], &nvme_cdata.fr[0], sizeof(nvmf_cdata.fr));
	/* IEEE OUI Identifier (IEEE) */
	memcpy(&nvmf_cdata.ieee[0], &nvme_cdata->ieee[0], sizeof(nvmf_cdata.ieee));
	memcpy(&nvmf_cdata.ieee[0], &nvme_cdata.ieee[0], sizeof(nvmf_cdata.ieee));
	/* FRU Globally Unique Identifier (FGUID) */

	/* Copy the fixed up data back to the response */
	memcpy(nvme_cdata, &nvmf_cdata, length);
	spdk_nvmf_request_copy_from_buf(req, &nvmf_cdata, datalen);
}

static int