From 54bfde6a09130575d9e2e014da87a88a77a643a0 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 6 Feb 2018 09:00:03 -0700 Subject: [PATCH] nvmf: allow removal of listen addresses at runtime Change-Id: I53ffdd061ba068070f66a752780229ecfe53e737 Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/398688 Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu --- include/spdk/nvmf.h | 12 ++++++++++++ lib/nvmf/subsystem.c | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/spdk/nvmf.h b/include/spdk/nvmf.h index 0132033b6..d3fd8cfe0 100644 --- a/include/spdk/nvmf.h +++ b/include/spdk/nvmf.h @@ -317,6 +317,18 @@ const char *spdk_nvmf_host_get_nqn(struct spdk_nvmf_host *host); int spdk_nvmf_subsystem_add_listener(struct spdk_nvmf_subsystem *subsystem, struct spdk_nvme_transport_id *trid); +/** + * Stop accepting new connections on the address provided + * + * May only be performed on subsystems in the PAUSED or INACTIVE states. + * + * \param subsystem Subsystem to remove listener from + * \param trid The address to no longer accept connections from + * \return 0 on success. Negated errno value on failure. + */ +int spdk_nvmf_subsystem_remove_listener(struct spdk_nvmf_subsystem *subsystem, + const struct spdk_nvme_transport_id *trid); + /** * Check if connections originated from the given address are allowed to connect to the subsystem. * diff --git a/lib/nvmf/subsystem.c b/lib/nvmf/subsystem.c index de07186cf..dd9cf3fb5 100644 --- a/lib/nvmf/subsystem.c +++ b/lib/nvmf/subsystem.c @@ -700,6 +700,28 @@ spdk_nvmf_subsystem_add_listener(struct spdk_nvmf_subsystem *subsystem, return 0; } +int +spdk_nvmf_subsystem_remove_listener(struct spdk_nvmf_subsystem *subsystem, + const struct spdk_nvme_transport_id *trid) +{ + struct spdk_nvmf_listener *listener; + + if (!(subsystem->state == SPDK_NVMF_SUBSYSTEM_INACTIVE || + subsystem->state == SPDK_NVMF_SUBSYSTEM_PAUSED)) { + return -EAGAIN; + } + + listener = _spdk_nvmf_subsystem_find_listener(subsystem, trid); + if (listener == NULL) { + return -ENOENT; + } + + TAILQ_REMOVE(&subsystem->listeners, listener, link); + free(listener); + + return 0; +} + /* * TODO: this is the whitelist and will be called during connection setup */