From ef1437b31307fbc26f11caca4b6dd0b8ac3353a5 Mon Sep 17 00:00:00 2001 From: Young Tack Jin Date: Wed, 6 Sep 2017 14:25:37 -0700 Subject: [PATCH] nvme: support meta data on vendor specific commands spdk_nvme_ctrlr_cmd_io_raw_with_md() will be verified on Cosmos+ OpenSSD as soon as it will support meta data. Change-Id: Ib5f3f1f1eba66d0147a566804395bfa5ec959c2f Signed-off-by: Young Tack Jin Reviewed-on: https://review.gerrithub.io/377428 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Jim Harris --- include/spdk/nvme.h | 19 +++++++++++++++ lib/nvme/nvme_ctrlr_cmd.c | 23 +++++++++++++++++++ .../nvme/nvme_ctrlr_cmd.c/nvme_ctrlr_cmd_ut.c | 20 ++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/include/spdk/nvme.h b/include/spdk/nvme.h index eb32b3e20..f655771fd 100644 --- a/include/spdk/nvme.h +++ b/include/spdk/nvme.h @@ -567,6 +567,25 @@ int spdk_nvme_ctrlr_cmd_io_raw(struct spdk_nvme_ctrlr *ctrlr, void *buf, uint32_t len, spdk_nvme_cmd_cb cb_fn, void *cb_arg); +/** + * \brief Send the given NVM I/O command with metadata to the NVMe controller. + * + * This is a low level interface for submitting I/O commands directly. Prefer + * the spdk_nvme_ns_cmd_* functions instead. The validity of the command will + * not be checked! + * + * When constructing the nvme_command it is not necessary to fill out the PRP + * list/SGL or the CID. The driver will handle both of those for you. + * + * The command is submitted to a qpair allocated by spdk_nvme_ctrlr_alloc_io_qpair(). + * The user must ensure that only one thread submits I/O on a given qpair at any given time. + */ +int spdk_nvme_ctrlr_cmd_io_raw_with_md(struct spdk_nvme_ctrlr *ctrlr, + struct spdk_nvme_qpair *qpair, + struct spdk_nvme_cmd *cmd, + void *buf, uint32_t len, void *md_buf, + spdk_nvme_cmd_cb cb_fn, void *cb_arg); + /** * \brief Process any outstanding completions for I/O submitted on a queue pair. * diff --git a/lib/nvme/nvme_ctrlr_cmd.c b/lib/nvme/nvme_ctrlr_cmd.c index 3726f0689..ad22abe99 100644 --- a/lib/nvme/nvme_ctrlr_cmd.c +++ b/lib/nvme/nvme_ctrlr_cmd.c @@ -53,6 +53,29 @@ spdk_nvme_ctrlr_cmd_io_raw(struct spdk_nvme_ctrlr *ctrlr, return nvme_qpair_submit_request(qpair, req); } +int +spdk_nvme_ctrlr_cmd_io_raw_with_md(struct spdk_nvme_ctrlr *ctrlr, + struct spdk_nvme_qpair *qpair, + struct spdk_nvme_cmd *cmd, + void *buf, uint32_t len, void *md_buf, + spdk_nvme_cmd_cb cb_fn, void *cb_arg) +{ + struct nvme_request *req; + struct nvme_payload payload; + + payload.type = NVME_PAYLOAD_TYPE_CONTIG; + payload.u.contig = buf; + payload.md = md_buf; + + req = nvme_allocate_request(qpair, &payload, len, cb_fn, cb_arg); + if (req == NULL) + return -ENOMEM; + + memcpy(&req->cmd, cmd, sizeof(req->cmd)); + + return nvme_qpair_submit_request(qpair, req); +} + int spdk_nvme_ctrlr_cmd_admin_raw(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_cmd *cmd, diff --git a/test/unit/lib/nvme/nvme_ctrlr_cmd.c/nvme_ctrlr_cmd_ut.c b/test/unit/lib/nvme/nvme_ctrlr_cmd.c/nvme_ctrlr_cmd_ut.c index 6c8d5ac9b..913f449e7 100644 --- a/test/unit/lib/nvme/nvme_ctrlr_cmd.c/nvme_ctrlr_cmd_ut.c +++ b/test/unit/lib/nvme/nvme_ctrlr_cmd.c/nvme_ctrlr_cmd_ut.c @@ -121,6 +121,13 @@ static void verify_io_raw_cmd(struct nvme_request *req) CU_ASSERT(memcmp(&req->cmd, &command, sizeof(req->cmd)) == 0); } +static void verify_io_raw_cmd_with_md(struct nvme_request *req) +{ + struct spdk_nvme_cmd command = {}; + + CU_ASSERT(memcmp(&req->cmd, &command, sizeof(req->cmd)) == 0); +} + static void verify_intel_smart_log_page(struct nvme_request *req) { uint32_t temp_cdw10; @@ -488,6 +495,18 @@ test_io_raw_cmd(void) spdk_nvme_ctrlr_cmd_io_raw(&ctrlr, &qpair, &cmd, NULL, 1, NULL, NULL); } +static void +test_io_raw_cmd_with_md(void) +{ + struct spdk_nvme_ctrlr ctrlr = {}; + struct spdk_nvme_qpair qpair = {}; + struct spdk_nvme_cmd cmd = {}; + + verify_fn = verify_io_raw_cmd_with_md; + + spdk_nvme_ctrlr_cmd_io_raw_with_md(&ctrlr, &qpair, &cmd, NULL, 1, NULL, NULL, NULL); +} + static void test_get_log_pages(void) { @@ -593,6 +612,7 @@ int main(int argc, char **argv) || CU_add_test(suite, "test ctrlr cmd get_feature", test_get_feature_cmd) == NULL || CU_add_test(suite, "test ctrlr cmd abort_cmd", test_abort_cmd) == NULL || CU_add_test(suite, "test ctrlr cmd io_raw_cmd", test_io_raw_cmd) == NULL + || CU_add_test(suite, "test ctrlr cmd io_raw_cmd_with_md", test_io_raw_cmd_with_md) == NULL || CU_add_test(suite, "test ctrlr cmd namespace_attach", test_namespace_attach) == NULL || CU_add_test(suite, "test ctrlr cmd namespace_detach", test_namespace_detach) == NULL || CU_add_test(suite, "test ctrlr cmd namespace_create", test_namespace_create) == NULL