From 50132e48100ce26819ce7d51437db253c21b84a9 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Fri, 31 Jan 2020 10:40:03 -0700 Subject: [PATCH] nvmf: Move custom admin command handler implementation to nvmf_tgt The custom command handlers are registered by outside software. Move the implementation from lib/nvmf to the nvmf_tgt application to match the intended usage. Change-Id: Iedb7ae5356f195dfb5bb465975808c8749d16f32 Signed-off-by: Ben Walker Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/416 Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Reviewed-by: Aleksey Marchuk Reviewed-by: Michael Haeuptle Tested-by: SPDK CI Jenkins --- include/spdk/nvmf_cmd.h | 2 - lib/nvmf/Makefile | 3 +- lib/nvmf/custom_cmd_hdlr.c | 118 ------------------------ module/event/subsystems/nvmf/nvmf_tgt.c | 75 +++++++++++++++ 4 files changed, 76 insertions(+), 122 deletions(-) delete mode 100644 lib/nvmf/custom_cmd_hdlr.c diff --git a/include/spdk/nvmf_cmd.h b/include/spdk/nvmf_cmd.h index a11a25be39..b1c5005728 100644 --- a/include/spdk/nvmf_cmd.h +++ b/include/spdk/nvmf_cmd.h @@ -200,6 +200,4 @@ struct spdk_nvme_cmd *spdk_nvmf_request_get_cmd(struct spdk_nvmf_request *req); */ struct spdk_nvme_cpl *spdk_nvmf_request_get_response(struct spdk_nvmf_request *req); -int spdk_nvmf_custom_identify_hdlr(struct spdk_nvmf_request *req); - #endif /* SPDK_NVMF_CMD_H_ */ diff --git a/lib/nvmf/Makefile b/lib/nvmf/Makefile index a8c8e2075c..58952001f9 100644 --- a/lib/nvmf/Makefile +++ b/lib/nvmf/Makefile @@ -35,8 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk C_SRCS = ctrlr.c ctrlr_discovery.c ctrlr_bdev.c \ - subsystem.c nvmf.c nvmf_rpc.c transport.c tcp.c \ - custom_cmd_hdlr.c + subsystem.c nvmf.c nvmf_rpc.c transport.c tcp.c C_SRCS-$(CONFIG_RDMA) += rdma.c LIBNAME = nvmf diff --git a/lib/nvmf/custom_cmd_hdlr.c b/lib/nvmf/custom_cmd_hdlr.c deleted file mode 100644 index b82e0be6f7..0000000000 --- a/lib/nvmf/custom_cmd_hdlr.c +++ /dev/null @@ -1,118 +0,0 @@ -/*- - * BSD LICENSE - * - * Copyright (c) Hewlett Packard Enterprise Development LP - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * This is an example handler for modifying parts of the NVMF identify - * ctlr response based on the underlying NVMe device. - */ - -#include "spdk/stdinc.h" - -#include "spdk/bdev.h" -#include "spdk/nvmf_cmd.h" - -#include "spdk_internal/log.h" - -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 nvmf_cdata = {}; - struct spdk_nvmf_ctrlr *ctrlr = spdk_nvmf_request_get_ctrlr(req); - struct spdk_nvme_cpl *rsp = spdk_nvmf_request_get_response(req); - - /* This is the identify data from the NVMe drive */ - spdk_nvmf_request_get_data(req, (void **)&nvme_cdata, &length); - - /* Get the NVMF identify data */ - rc = spdk_nvmf_ctrlr_identify_ctrlr(ctrlr, &nvmf_cdata); - if (rc != SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE) { - rsp->status.sct = SPDK_NVME_SCT_GENERIC; - rsp->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR; - return; - } - - /* Fixup NVMF identify data with NVMe identify data */ - - /* Serial Number (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)); - /* Firmware Revision (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)); - /* FRU Globally Unique Identifier (FGUID) */ - - /* Copy the fixed up data back to the response */ - memcpy(nvme_cdata, &nvmf_cdata, length); -} - -int -spdk_nvmf_custom_identify_hdlr(struct spdk_nvmf_request *req) -{ - struct spdk_nvme_cmd *cmd = spdk_nvmf_request_get_cmd(req); - struct spdk_bdev *bdev; - struct spdk_bdev_desc *desc; - struct spdk_io_channel *ch; - struct spdk_nvmf_subsystem *subsys; - int rc; - - if (cmd->cdw10_bits.identify.cns != SPDK_NVME_IDENTIFY_CTRLR) { - return -1; /* continue */ - } - - subsys = spdk_nvmf_request_get_subsystem(req); - if (subsys == NULL) { - return -1; - } - - /* Only procss this request if it has exactly one namespace */ - if (spdk_nvmf_subsystem_get_max_nsid(subsys) != 1) { - return -1; - } - - /* Forward to first namespace if it supports NVME admin commands */ - rc = spdk_nvmf_request_get_bdev(1, req, &bdev, &desc, &ch); - if (rc) { - /* No bdev found for this namespace. Continue. */ - return -1; - } - - if (!spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_NVME_ADMIN)) { - return -1; - } - - return spdk_nvmf_bdev_ctrlr_nvme_passthru_admin(bdev, desc, ch, req, fixup_identify_ctrlr); -} diff --git a/module/event/subsystems/nvmf/nvmf_tgt.c b/module/event/subsystems/nvmf/nvmf_tgt.c index df869bd71c..e9b15ab446 100644 --- a/module/event/subsystems/nvmf/nvmf_tgt.c +++ b/module/event/subsystems/nvmf/nvmf_tgt.c @@ -426,6 +426,81 @@ nvmf_tgt_parse_conf_start(void *ctx) } } +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 nvmf_cdata = {}; + struct spdk_nvmf_ctrlr *ctrlr = spdk_nvmf_request_get_ctrlr(req); + struct spdk_nvme_cpl *rsp = spdk_nvmf_request_get_response(req); + + /* This is the identify data from the NVMe drive */ + spdk_nvmf_request_get_data(req, (void **)&nvme_cdata, &length); + + /* Get the NVMF identify data */ + rc = spdk_nvmf_ctrlr_identify_ctrlr(ctrlr, &nvmf_cdata); + if (rc != SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE) { + rsp->status.sct = SPDK_NVME_SCT_GENERIC; + rsp->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR; + return; + } + + /* Fixup NVMF identify data with NVMe identify data */ + + /* Serial Number (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)); + /* Firmware Revision (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)); + /* FRU Globally Unique Identifier (FGUID) */ + + /* Copy the fixed up data back to the response */ + memcpy(nvme_cdata, &nvmf_cdata, length); +} + +static int +spdk_nvmf_custom_identify_hdlr(struct spdk_nvmf_request *req) +{ + struct spdk_nvme_cmd *cmd = spdk_nvmf_request_get_cmd(req); + struct spdk_bdev *bdev; + struct spdk_bdev_desc *desc; + struct spdk_io_channel *ch; + struct spdk_nvmf_subsystem *subsys; + int rc; + + if (cmd->cdw10_bits.identify.cns != SPDK_NVME_IDENTIFY_CTRLR) { + return -1; /* continue */ + } + + subsys = spdk_nvmf_request_get_subsystem(req); + if (subsys == NULL) { + return -1; + } + + /* Only procss this request if it has exactly one namespace */ + if (spdk_nvmf_subsystem_get_max_nsid(subsys) != 1) { + return -1; + } + + /* Forward to first namespace if it supports NVME admin commands */ + rc = spdk_nvmf_request_get_bdev(1, req, &bdev, &desc, &ch); + if (rc) { + /* No bdev found for this namespace. Continue. */ + return -1; + } + + if (!spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_NVME_ADMIN)) { + return -1; + } + + return spdk_nvmf_bdev_ctrlr_nvme_passthru_admin(bdev, desc, ch, req, fixup_identify_ctrlr); +} + static void nvmf_tgt_advance_state(void) {