From bee8c04a4b73e46666d8876ac483bb3285dce189 Mon Sep 17 00:00:00 2001 From: Cunyin Chang Date: Mon, 27 Mar 2017 20:58:25 +0800 Subject: [PATCH] nvmf: Move the check of NVMe remove from session layer to subsystem layer. Change-Id: Icf2f7122c9af0cd6420384c93813d2e79ed9c69e Signed-off-by: Cunyin Chang --- lib/nvmf/session.c | 7 ------- lib/nvmf/subsystem.c | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/nvmf/session.c b/lib/nvmf/session.c index 2673a1f47b..6dd0bae0d0 100644 --- a/lib/nvmf/session.c +++ b/lib/nvmf/session.c @@ -638,13 +638,6 @@ spdk_nvmf_session_poll(struct spdk_nvmf_session *session) SPDK_ERRLOG("Transport poll failed for conn %p; closing connection\n", conn); spdk_nvmf_session_disconnect(conn); } - if (subsys->subtype == SPDK_NVMF_SUBTYPE_NVME) { - if (subsys->is_removed && conn->transport->conn_is_idle(conn)) { - if (subsys->ops->detach) { - subsys->ops->detach(subsys); - } - } - } } return 0; diff --git a/lib/nvmf/subsystem.c b/lib/nvmf/subsystem.c index 2c843fb1d1..1ba5157878 100644 --- a/lib/nvmf/subsystem.c +++ b/lib/nvmf/subsystem.c @@ -128,6 +128,25 @@ spdk_nvmf_subsystem_start(struct spdk_nvmf_subsystem *subsystem) return subsystem->ops->attach(subsystem); } +static bool +nvmf_subsystem_removable(struct spdk_nvmf_subsystem *subsystem) +{ + struct spdk_nvmf_session *session; + struct spdk_nvmf_conn *conn; + + if (subsystem->is_removed) { + TAILQ_FOREACH(session, &subsystem->sessions, link) { + TAILQ_FOREACH(conn, &session->connections, link) { + if (!conn->transport->conn_is_idle(conn)) { + return false; + } + } + } + return true; + } + return false; +} + void spdk_nvmf_subsystem_poll(struct spdk_nvmf_subsystem *subsystem) { @@ -142,6 +161,12 @@ spdk_nvmf_subsystem_poll(struct spdk_nvmf_subsystem *subsystem) /* For each connection in the session, check for completions */ spdk_nvmf_session_poll(session); } + + if (nvmf_subsystem_removable(subsystem)) { + if (subsystem->ops->detach) { + subsystem->ops->detach(subsystem); + } + } } static bool