From 5d541746f3faf651f71ea6f7552785240ae69f94 Mon Sep 17 00:00:00 2001 From: GangCao Date: Thu, 5 Dec 2019 22:03:02 -0500 Subject: [PATCH] nvmf: properly cleanup when failing to create subsystem In the case of using CONF file, if two subsystems are assigned with same subnqn, it fails at the second subsystem creation, however the state machine is not set correctly. The fix here is to properly set the state machine to roll back the operations and destroy the created subsystem and exit the application cleanly. Change-Id: I4356802a12f7a2982485f61a69eceeb979033788 Signed-off-by: GangCao Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/476904 Community-CI: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Tested-by: SPDK CI Jenkins --- module/event/subsystems/nvmf/nvmf_tgt.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/module/event/subsystems/nvmf/nvmf_tgt.c b/module/event/subsystems/nvmf/nvmf_tgt.c index d8b5767a4..bac92ad98 100644 --- a/module/event/subsystems/nvmf/nvmf_tgt.c +++ b/module/event/subsystems/nvmf/nvmf_tgt.c @@ -93,12 +93,17 @@ _spdk_nvmf_shutdown_cb(void *arg1) if (g_tgt_state < NVMF_TGT_RUNNING) { spdk_thread_send_msg(spdk_get_thread(), _spdk_nvmf_shutdown_cb, NULL); return; - } else if (g_tgt_state > NVMF_TGT_RUNNING) { + } else if (g_tgt_state != NVMF_TGT_RUNNING && g_tgt_state != NVMF_TGT_ERROR) { /* Already in Shutdown status, ignore the signal */ return; } - g_tgt_state = NVMF_TGT_FINI_STOP_SUBSYSTEMS; + if (g_tgt_state == NVMF_TGT_ERROR) { + /* Parse configuration error */ + g_tgt_state = NVMF_TGT_FINI_FREE_RESOURCES; + } else { + g_tgt_state = NVMF_TGT_FINI_STOP_SUBSYSTEMS; + } nvmf_tgt_advance_state(); }