diff --git a/lib/nvmf/subsystem.c b/lib/nvmf/subsystem.c index 668c7664e..bf01bffd0 100644 --- a/lib/nvmf/subsystem.c +++ b/lib/nvmf/subsystem.c @@ -837,7 +837,9 @@ spdk_nvmf_subsystem_add_host(struct spdk_nvmf_subsystem *subsystem, const char * TAILQ_INSERT_HEAD(&subsystem->hosts, host, link); - nvmf_update_discovery_log(subsystem->tgt, hostnqn); + if (!TAILQ_EMPTY(&subsystem->listeners)) { + nvmf_update_discovery_log(subsystem->tgt, hostnqn); + } pthread_mutex_unlock(&subsystem->mutex); @@ -946,7 +948,9 @@ spdk_nvmf_subsystem_set_allow_any_host(struct spdk_nvmf_subsystem *subsystem, bo { pthread_mutex_lock(&subsystem->mutex); subsystem->flags.allow_any_host = allow_any_host; - nvmf_update_discovery_log(subsystem->tgt, NULL); + if (!TAILQ_EMPTY(&subsystem->listeners)) { + nvmf_update_discovery_log(subsystem->tgt, NULL); + } pthread_mutex_unlock(&subsystem->mutex); return 0; diff --git a/test/unit/lib/nvmf/ctrlr_discovery.c/ctrlr_discovery_ut.c b/test/unit/lib/nvmf/ctrlr_discovery.c/ctrlr_discovery_ut.c index de3f4d9f7..f7433db74 100644 --- a/test/unit/lib/nvmf/ctrlr_discovery.c/ctrlr_discovery_ut.c +++ b/test/unit/lib/nvmf/ctrlr_discovery.c/ctrlr_discovery_ut.c @@ -313,9 +313,19 @@ test_discovery_log(void) /* Add one subsystem and verify that the discovery log contains it */ subsystem = spdk_nvmf_subsystem_create(&tgt, "nqn.2016-06.io.spdk:subsystem1", SPDK_NVMF_SUBTYPE_NVME, 0); - subsystem->flags.allow_any_host = true; SPDK_CU_ASSERT_FATAL(subsystem != NULL); + rc = spdk_nvmf_subsystem_add_host(subsystem, hostnqn); + CU_ASSERT(rc == 0); + + /* Get only genctr (first field in the header) */ + memset(buffer, 0xCC, sizeof(buffer)); + disc_log = (struct spdk_nvmf_discovery_log_page *)buffer; + nvmf_get_discovery_log_page(&tgt, hostnqn, &iov, 1, 0, sizeof(disc_log->genctr), + &trid); + /* No listeners yet on new subsystem, so genctr should still be 0. */ + CU_ASSERT(disc_log->genctr == 0); + test_gen_trid(&trid, SPDK_NVME_TRANSPORT_RDMA, SPDK_NVMF_ADRFAM_IPV4, "1234", "5678"); spdk_nvmf_subsystem_add_listener(subsystem, &trid, _subsystem_add_listen_done, NULL); subsystem->state = SPDK_NVMF_SUBSYSTEM_ACTIVE;