From 5bdbe36ee90f8943b7b969cb7f279f82b890c942 Mon Sep 17 00:00:00 2001 From: Dariusz Stojaczyk Date: Fri, 17 Nov 2017 13:36:15 +0100 Subject: [PATCH] event/subsystem: fix subsystem init failure handling Deinitialize only those subsystem that have been fully initialized. Change-Id: I86cdd4cda0a80c107956843ed8198072e898a743 Signed-off-by: Dariusz Stojaczyk Reviewed-on: https://review.gerrithub.io/386892 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/event/subsystem.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/event/subsystem.c b/lib/event/subsystem.c index 19b7a7489..4f0f42113 100644 --- a/lib/event/subsystem.c +++ b/lib/event/subsystem.c @@ -43,6 +43,7 @@ static TAILQ_HEAD(spdk_subsystem_list, spdk_subsystem) g_subsystems = static TAILQ_HEAD(subsystem_depend, spdk_subsystem_depend) g_depends = TAILQ_HEAD_INITIALIZER(g_depends); static struct spdk_subsystem *g_next_subsystem; +static bool g_subsystems_initialized = false; static struct spdk_event *g_app_start_event; static struct spdk_event *g_app_stop_event; static uint32_t g_fini_core; @@ -117,9 +118,8 @@ void spdk_subsystem_init_next(int rc) { if (rc) { - spdk_app_stop(rc); - assert(g_next_subsystem != NULL); SPDK_ERRLOG("Init subsystem %s failed\n", g_next_subsystem->name); + spdk_app_stop(rc); return; } @@ -130,6 +130,7 @@ spdk_subsystem_init_next(int rc) } if (!g_next_subsystem) { + g_subsystems_initialized = true; spdk_event_call(g_app_start_event); return; } @@ -183,8 +184,17 @@ _spdk_subsystem_fini_next(void *arg1, void *arg2) assert(g_fini_core == spdk_env_get_current_core()); if (!g_next_subsystem) { - g_next_subsystem = TAILQ_LAST(&g_subsystems, spdk_subsystem_list); + /* If the initialized flag is false, then we've failed to initialize + * the very first subsystem and no de-init is needed + */ + if (g_subsystems_initialized) { + g_next_subsystem = TAILQ_LAST(&g_subsystems, spdk_subsystem_list); + } } else { + /* We rewind the g_next_subsystem unconditionally - even when some subsystem failed + * to initialize. It is assumed that subsystem which failed to initialize does not + * need to be deinitialized. + */ g_next_subsystem = TAILQ_PREV(g_next_subsystem, spdk_subsystem_list, tailq); }