From 1d4801292951872c98c30ebde0e43cf840b40f3a Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Fri, 9 Mar 2018 17:04:35 -0700 Subject: [PATCH] nvmf: set serial number after creating subsystem Remove the serial number from the parameters of spdk_nvmf_construct_subsystem(). Change-Id: Ib6d394cc98fddf85fc878fe0a8c8aa0fdcddf7f4 Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/403378 Reviewed-by: Jim Harris Tested-by: SPDK Automated Test System Reviewed-by: Shuhei Matsumoto Reviewed-by: Changpeng Liu --- lib/event/subsystems/nvmf/conf.c | 32 +++++++++++--------------- lib/event/subsystems/nvmf/event_nvmf.h | 3 +-- lib/event/subsystems/nvmf/nvmf_rpc.c | 8 +++++-- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/lib/event/subsystems/nvmf/conf.c b/lib/event/subsystems/nvmf/conf.c index f5d6216105..f29b8102e5 100644 --- a/lib/event/subsystems/nvmf/conf.c +++ b/lib/event/subsystems/nvmf/conf.c @@ -178,14 +178,23 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp) } sn = spdk_conf_section_get_val(sp, "SN"); + if (sn == NULL) { + SPDK_ERRLOG("Subsystem %s: missing serial number\n", nqn); + return -1; + } - subsystem = spdk_nvmf_construct_subsystem(nqn, - sn); - + subsystem = spdk_nvmf_construct_subsystem(nqn); if (subsystem == NULL) { goto done; } + if (spdk_nvmf_subsystem_set_sn(subsystem, sn)) { + SPDK_ERRLOG("Subsystem %s: invalid serial number '%s'\n", nqn, sn); + spdk_nvmf_subsystem_destroy(subsystem); + subsystem = NULL; + goto done; + } + for (i = 0; ; i++) { struct spdk_nvmf_ns_opts ns_opts; struct spdk_bdev *bdev; @@ -347,8 +356,7 @@ spdk_nvmf_parse_conf(void) } struct spdk_nvmf_subsystem * - spdk_nvmf_construct_subsystem(const char *name, - const char *sn) + spdk_nvmf_construct_subsystem(const char *name) { struct spdk_nvmf_subsystem *subsystem; @@ -363,19 +371,5 @@ struct spdk_nvmf_subsystem * return NULL; } - if (sn == NULL) { - SPDK_ERRLOG("Subsystem %s: missing serial number\n", name); - goto error; - } - - if (spdk_nvmf_subsystem_set_sn(subsystem, sn)) { - SPDK_ERRLOG("Subsystem %s: invalid serial number '%s'\n", name, sn); - goto error; - } - return subsystem; - -error: - spdk_nvmf_subsystem_destroy(subsystem); - return NULL; } diff --git a/lib/event/subsystems/nvmf/event_nvmf.h b/lib/event/subsystems/nvmf/event_nvmf.h index 2d788e2886..0db610fc9c 100644 --- a/lib/event/subsystems/nvmf/event_nvmf.h +++ b/lib/event/subsystems/nvmf/event_nvmf.h @@ -77,7 +77,6 @@ int spdk_nvmf_parse_conf(void); struct spdk_nvmf_subsystem *nvmf_tgt_create_subsystem(const char *name, enum spdk_nvmf_subtype subtype, uint32_t num_ns); -struct spdk_nvmf_subsystem *spdk_nvmf_construct_subsystem(const char *name, - const char *sn); +struct spdk_nvmf_subsystem *spdk_nvmf_construct_subsystem(const char *name); #endif diff --git a/lib/event/subsystems/nvmf/nvmf_rpc.c b/lib/event/subsystems/nvmf/nvmf_rpc.c index e6518ad71d..bd42a24837 100644 --- a/lib/event/subsystems/nvmf/nvmf_rpc.c +++ b/lib/event/subsystems/nvmf/nvmf_rpc.c @@ -605,12 +605,16 @@ spdk_rpc_construct_nvmf_subsystem(struct spdk_jsonrpc_request *request, SPDK_NOTICELOG("Ignoring it and continuing.\n"); } - subsystem = spdk_nvmf_construct_subsystem(req.nqn, - req.serial_number); + subsystem = spdk_nvmf_construct_subsystem(req.nqn); if (!subsystem) { goto invalid; } + if (spdk_nvmf_subsystem_set_sn(subsystem, req.serial_number)) { + SPDK_ERRLOG("Subsystem %s: invalid serial number '%s'\n", req.nqn, req.serial_number); + goto invalid; + } + for (i = 0; i < req.hosts.num_hosts; i++) { spdk_nvmf_subsystem_add_host(subsystem, req.hosts.hosts[i]); }