event/subsystem: solve the subsystem init and destroy conflict

We have conflict to handle the NVMf subsystem shut
down. The situation is that:

If there is shutdown request (e.g., ctrlr+c),
we may have subsystem finalization and subsystem
initialization conflict (e.g., have NVMf subsystem fini and
intialization together), we will have coredump
issue like #682.

If we interrupt the initialization of the subsystem,
following works should do:

1  Do not initilize the next subsystem.
2  Recycle the resources in each subsystem via the
spdk_subsystem_fini related function. And this patch will
do the general thing, but will not consider the detailed
interrupt policy in each subsystem.

Change-Id: I2438b4a2462acb05d8c8e06dfff3da3d388d4b70
Signed-off-by: Ziye Yang <ziye.yang@intel.com>
Reviewed-on: https://review.gerrithub.io/c/446189 (master)
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/447459
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Ziye Yang 2019-02-26 17:51:40 +08:00 committed by Ben Walker
parent 6481d80514
commit d07cc7d35d

View File

@ -42,6 +42,7 @@ struct spdk_subsystem_list g_subsystems = TAILQ_HEAD_INITIALIZER(g_subsystems);
struct spdk_subsystem_depend_list g_subsystems_deps = TAILQ_HEAD_INITIALIZER(g_subsystems_deps);
static struct spdk_subsystem *g_next_subsystem;
static bool g_subsystems_initialized = false;
static bool g_subsystems_init_interrupted = false;
static struct spdk_event *g_app_start_event;
static struct spdk_event *g_app_stop_event;
static uint32_t g_fini_core;
@ -116,6 +117,11 @@ subsystem_sort(void)
void
spdk_subsystem_init_next(int rc)
{
/* The initialization is interrupted by the spdk_subsystem_fini, so just return */
if (g_subsystems_init_interrupted) {
return;
}
if (rc) {
SPDK_ERRLOG("Init subsystem %s failed\n", g_next_subsystem->name);
spdk_app_stop(rc);
@ -190,11 +196,11 @@ _spdk_subsystem_fini_next(void *arg1, void *arg2)
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);
if (g_subsystems_initialized || g_subsystems_init_interrupted) {
g_next_subsystem = TAILQ_PREV(g_next_subsystem, spdk_subsystem_list, tailq);
} else {
g_subsystems_init_interrupted = true;
}
}
while (g_next_subsystem) {