From 4c1757ffb98b33f2a3d97989811fecc67cba4a45 Mon Sep 17 00:00:00 2001 From: Peng Lian Date: Tue, 14 Dec 2021 07:04:58 -0500 Subject: [PATCH] nvmf: update discovery log when removing hostnqn In NVMF Revision spec 1.1a, discovery log should be updated when removing hostnqn of subsystem. Update unit test to check the discovery log when removing hostnqn and destroying subsystem. Signed-off-by: Peng Lian Change-Id: I51c597a2493295a677a7aa68e4f13a887f7e1140 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10668 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Reviewed-by: Aleksey Marchuk --- lib/nvmf/subsystem.c | 5 ++++ .../ctrlr_discovery.c/ctrlr_discovery_ut.c | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+) 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); }