diff --git a/CHANGELOG.md b/CHANGELOG.md index 49fd90f29..00d82cf33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/include/spdk/nvmf_cmd.h b/include/spdk/nvmf_cmd.h index 697a253bd..aaa5233d9 100644 --- a/include/spdk/nvmf_cmd.h +++ b/include/spdk/nvmf_cmd.h @@ -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. * diff --git a/lib/nvmf/ctrlr.c b/lib/nvmf/ctrlr.c index f7973629d..b0370b642 100644 --- a/lib/nvmf/ctrlr.c +++ b/lib/nvmf/ctrlr.c @@ -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; diff --git a/lib/nvmf/spdk_nvmf.map b/lib/nvmf/spdk_nvmf.map index 6b2c3d2c7..411fbdd6d 100644 --- a/lib/nvmf/spdk_nvmf.map +++ b/lib/nvmf/spdk_nvmf.map @@ -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; diff --git a/module/event/subsystems/nvmf/nvmf_tgt.c b/module/event/subsystems/nvmf/nvmf_tgt.c index 2f23d0e64..aa223c154 100644 --- a/module/event/subsystems/nvmf/nvmf_tgt.c +++ b/module/event/subsystems/nvmf/nvmf_tgt.c @@ -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