diff --git a/lib/nvmf/subsystem.c b/lib/nvmf/subsystem.c index bf01bffd0..3945fdf21 100644 --- a/lib/nvmf/subsystem.c +++ b/lib/nvmf/subsystem.c @@ -860,6 +860,11 @@ spdk_nvmf_subsystem_remove_host(struct spdk_nvmf_subsystem *subsystem, const cha } nvmf_subsystem_remove_host(subsystem, host); + + if (!TAILQ_EMPTY(&subsystem->listeners)) { + nvmf_update_discovery_log(subsystem->tgt, hostnqn); + } + 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 f7433db74..1ee2c5601 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 @@ -370,9 +370,32 @@ test_discovery_log(void) nvmf_get_discovery_log_page(&tgt, hostnqn, &iov, 1, offsetof(struct spdk_nvmf_discovery_log_page, entries[0]), sizeof(*entry), &trid); CU_ASSERT(entry->trtype == 42); + + /* remove the host and verify that the discovery log contains nothing */ + rc = spdk_nvmf_subsystem_remove_host(subsystem, hostnqn); + CU_ASSERT(rc == 0); + + /* Get only the header, no entries */ + 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), + &trid); + CU_ASSERT(disc_log->genctr != 0); + CU_ASSERT(disc_log->numrec == 0); + + /* destroy the subsystem and verify that the discovery log contains nothing */ subsystem->state = SPDK_NVMF_SUBSYSTEM_INACTIVE; rc = spdk_nvmf_subsystem_destroy(subsystem, NULL, NULL); CU_ASSERT(rc == 0); + + /* Get only the header, no entries */ + 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), + &trid); + CU_ASSERT(disc_log->genctr != 0); + CU_ASSERT(disc_log->numrec == 0); + free(tgt.subsystems); }