diff --git a/app/nvmf_tgt/nvmf_tgt.c b/app/nvmf_tgt/nvmf_tgt.c index 20caa74eb..998c81890 100644 --- a/app/nvmf_tgt/nvmf_tgt.c +++ b/app/nvmf_tgt/nvmf_tgt.c @@ -191,7 +191,7 @@ nvmf_tgt_create_subsystem(const char *name, enum spdk_nvmf_subtype subtype, struct spdk_nvmf_subsystem *subsystem; struct nvmf_tgt_subsystem *app_subsys; - if (spdk_nvmf_find_subsystem(name)) { + if (spdk_nvmf_tgt_find_subsystem(g_tgt, name)) { SPDK_ERRLOG("Subsystem already exist\n"); return NULL; } diff --git a/include/spdk/nvmf.h b/include/spdk/nvmf.h index 5d7fff4da..83f6385df 100644 --- a/include/spdk/nvmf.h +++ b/include/spdk/nvmf.h @@ -105,6 +105,12 @@ struct spdk_nvmf_subsystem *spdk_nvmf_create_subsystem(struct spdk_nvmf_tgt *tgt spdk_nvmf_subsystem_connect_fn connect_cb, spdk_nvmf_subsystem_disconnect_fn disconnect_cb); +/** + * Search the target for a subsystem with the given NQN + */ +struct spdk_nvmf_subsystem *spdk_nvmf_tgt_find_subsystem(struct spdk_nvmf_tgt *tgt, + const char *subnqn); + /** * Initialize the subsystem on the thread that will be used to poll it. * @@ -114,8 +120,6 @@ int spdk_nvmf_subsystem_start(struct spdk_nvmf_subsystem *subsystem); void spdk_nvmf_delete_subsystem(struct spdk_nvmf_subsystem *subsystem); -struct spdk_nvmf_subsystem *spdk_nvmf_find_subsystem(const char *subnqn); - /** * Allow the given host NQN to connect to the given subsystem. * diff --git a/lib/nvmf/ctrlr.c b/lib/nvmf/ctrlr.c index 95aacb658..a30834a84 100644 --- a/lib/nvmf/ctrlr.c +++ b/lib/nvmf/ctrlr.c @@ -205,6 +205,7 @@ spdk_nvmf_ctrlr_connect(struct spdk_nvmf_qpair *qpair, struct spdk_nvmf_fabric_connect_data *data, struct spdk_nvmf_fabric_connect_rsp *rsp) { + struct spdk_nvmf_tgt *tgt; struct spdk_nvmf_ctrlr *ctrlr; struct spdk_nvmf_subsystem *subsystem; @@ -227,7 +228,9 @@ spdk_nvmf_ctrlr_connect(struct spdk_nvmf_qpair *qpair, SPDK_TRACELOG(SPDK_TRACE_NVMF, " subnqn: \"%s\"\n", data->subnqn); SPDK_TRACELOG(SPDK_TRACE_NVMF, " hostnqn: \"%s\"\n", data->hostnqn); - subsystem = spdk_nvmf_find_subsystem(data->subnqn); + tgt = qpair->transport->tgt; + + subsystem = spdk_nvmf_tgt_find_subsystem(tgt, data->subnqn); if (subsystem == NULL) { SPDK_ERRLOG("Could not find subsystem '%s'\n", data->subnqn); INVALID_CONNECT_DATA(subnqn); @@ -238,9 +241,9 @@ spdk_nvmf_ctrlr_connect(struct spdk_nvmf_qpair *qpair, * SQSIZE is a 0-based value, so it must be at least 1 (minimum queue depth is 2) and * strictly less than max_queue_depth. */ - if (cmd->sqsize == 0 || cmd->sqsize >= subsystem->tgt->opts.max_queue_depth) { + if (cmd->sqsize == 0 || cmd->sqsize >= tgt->opts.max_queue_depth) { SPDK_ERRLOG("Invalid SQSIZE %u (min 1, max %u)\n", - cmd->sqsize, subsystem->tgt->opts.max_queue_depth - 1); + cmd->sqsize, tgt->opts.max_queue_depth - 1); INVALID_CONNECT_CMD(sqsize); return; } diff --git a/lib/nvmf/nvmf.c b/lib/nvmf/nvmf.c index a28f2f878..f7491b110 100644 --- a/lib/nvmf/nvmf.c +++ b/lib/nvmf/nvmf.c @@ -112,6 +112,24 @@ spdk_nvmf_tgt_destroy(struct spdk_nvmf_tgt *tgt) } } +struct spdk_nvmf_subsystem * +spdk_nvmf_tgt_find_subsystem(struct spdk_nvmf_tgt *tgt, const char *subnqn) +{ + struct spdk_nvmf_subsystem *subsystem; + + if (!subnqn) { + return NULL; + } + + TAILQ_FOREACH(subsystem, &tgt->subsystems, entries) { + if (strcmp(subnqn, subsystem->subnqn) == 0) { + return subsystem; + } + } + + return NULL; +} + struct spdk_nvmf_transport * spdk_nvmf_tgt_get_transport(struct spdk_nvmf_tgt *tgt, enum spdk_nvme_transport_type type) { diff --git a/lib/nvmf/request.c b/lib/nvmf/request.c index ad5658e69..1c87ebeae 100644 --- a/lib/nvmf/request.c +++ b/lib/nvmf/request.c @@ -123,6 +123,7 @@ invalid_connect_response(struct spdk_nvmf_fabric_connect_rsp *rsp, uint8_t iattr static spdk_nvmf_request_exec_status nvmf_process_connect(struct spdk_nvmf_request *req) { + struct spdk_nvmf_tgt *tgt; struct spdk_nvmf_subsystem *subsystem; struct spdk_nvmf_fabric_connect_data *data = (struct spdk_nvmf_fabric_connect_data *) req->data; @@ -160,7 +161,9 @@ nvmf_process_connect(struct spdk_nvmf_request *req) return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; } - subsystem = spdk_nvmf_find_subsystem(data->subnqn); + tgt = req->qpair->transport->tgt; + + subsystem = spdk_nvmf_tgt_find_subsystem(tgt, data->subnqn); if (subsystem == NULL) { SPDK_ERRLOG("Could not find subsystem '%s'\n", data->subnqn); INVALID_CONNECT_DATA(subnqn); diff --git a/lib/nvmf/subsystem.c b/lib/nvmf/subsystem.c index 65d6fd87e..9b0ac0400 100644 --- a/lib/nvmf/subsystem.c +++ b/lib/nvmf/subsystem.c @@ -46,24 +46,6 @@ #include "spdk_internal/bdev.h" #include "spdk_internal/log.h" -struct spdk_nvmf_subsystem * -spdk_nvmf_find_subsystem(const char *subnqn) -{ - struct spdk_nvmf_subsystem *subsystem; - - if (!subnqn) { - return NULL; - } - - TAILQ_FOREACH(subsystem, &g_nvmf_tgt.subsystems, entries) { - if (strcmp(subnqn, subsystem->subnqn) == 0) { - return subsystem; - } - } - - return NULL; -} - struct spdk_nvmf_subsystem * spdk_nvmf_find_subsystem_with_cntlid(uint16_t cntlid) { diff --git a/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c b/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c index ebe99afb3..9552d838a 100644 --- a/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c +++ b/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c @@ -48,7 +48,7 @@ spdk_nvmf_find_subsystem_with_cntlid(uint16_t cntlid) } struct spdk_nvmf_subsystem * -spdk_nvmf_find_subsystem(const char *subnqn) +spdk_nvmf_tgt_find_subsystem(struct spdk_nvmf_tgt *tgt, const char *subnqn) { return NULL; } diff --git a/test/unit/lib/nvmf/request.c/request_ut.c b/test/unit/lib/nvmf/request.c/request_ut.c index 1db259927..82ac17869 100644 --- a/test/unit/lib/nvmf/request.c/request_ut.c +++ b/test/unit/lib/nvmf/request.c/request_ut.c @@ -139,7 +139,7 @@ spdk_nvmf_get_discovery_log_page(void *buffer, uint64_t offset, uint32_t length) } struct spdk_nvmf_subsystem * -spdk_nvmf_find_subsystem(const char *subnqn) +spdk_nvmf_tgt_find_subsystem(struct spdk_nvmf_tgt *tgt, const char *subnqn) { return NULL; } diff --git a/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c b/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c index c1b7d5a8c..755ecc0ff 100644 --- a/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c +++ b/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c @@ -273,13 +273,6 @@ nvmf_test_create_subsystem(void) CU_ASSERT(subsystem == NULL); } -static void -nvmf_test_find_subsystem(void) -{ - CU_ASSERT_PTR_NULL(spdk_nvmf_find_subsystem(NULL)); - CU_ASSERT_PTR_NULL(spdk_nvmf_find_subsystem("fake")); -} - int main(int argc, char **argv) { CU_pSuite suite = NULL; @@ -298,8 +291,7 @@ int main(int argc, char **argv) if ( CU_add_test(suite, "create_subsystem", nvmf_test_create_subsystem) == NULL || CU_add_test(suite, "nvmf_tgt_listen", test_spdk_nvmf_tgt_listen) == NULL || - CU_add_test(suite, "nvmf_subsystem_add_ns", test_spdk_nvmf_subsystem_add_ns) == NULL || - CU_add_test(suite, "find_subsystem", nvmf_test_find_subsystem) == NULL) { + CU_add_test(suite, "nvmf_subsystem_add_ns", test_spdk_nvmf_subsystem_add_ns) == NULL) { CU_cleanup_registry(); return CU_get_error(); }