nvmf/tgt: Fix issues for ctrlr+ c handling.

When receving ctrlr+c event, NVMe-oF target
could in any state. So we cannot guarantee
g_acceptor_poller is initialized or not. If
we do not handle such case, ctrlr+c will
trigger unexpected coredump issue. To
solve this issue, following methods are used.

Currently, our code in event module (lib/event/app.c)
can only receive ctrlr + c command once, so
when we receive the ctrlr+c, we should complete
the shutdown process.

The idea is to use spdk_event_call, we will only
enter shutdown process if tgt is in NVMF_TGT_RUNNING
status.

After several patch tries, I think that this solution
is much simple. Though we would like to kill after
entering the running state, it may wait some time
if users kill the application in early state, but those
operations will not be quite often in real case.

Change-Id: Id89a96b5d39f8a528e72dea8c0eb6524bdaf7ee4
Signed-off-by: Ziye Yang <optimistyzy@gmail.com>
Reviewed-on: https://review.gerrithub.io/389433
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Ziye Yang 2017-12-08 18:57:43 +08:00 committed by Daniel Verkamp
parent 9dde5e5c27
commit 7e8a611568

View File

@ -57,16 +57,38 @@ static struct spdk_poller *g_acceptor_poller = NULL;
static void nvmf_tgt_advance_state(void *arg1, void *arg2);
static void
spdk_nvmf_shutdown_cb(void)
_spdk_nvmf_shutdown_cb(void *arg1, void *arg2)
{
fprintf(stdout, "\n=========================\n");
fprintf(stdout, " NVMF shutdown signal\n");
fprintf(stdout, "=========================\n");
/* Still in initialization state, defer shutdown operation */
if (g_tgt.state < NVMF_TGT_RUNNING) {
spdk_event_call(spdk_event_allocate(spdk_env_get_current_core(),
_spdk_nvmf_shutdown_cb, NULL, NULL));
return;
} else if (g_tgt.state > NVMF_TGT_RUNNING) {
/* Already in Shutdown status, ignore the signal */
return;
}
g_tgt.state = NVMF_TGT_FINI_STOP_ACCEPTOR;
nvmf_tgt_advance_state(NULL, NULL);
}
static void
spdk_nvmf_shutdown_cb(void)
{
printf("\n=========================\n");
printf(" NVMF shutdown signal\n");
printf("=========================\n");
/* Always let the first core to handle the case */
if (spdk_env_get_current_core() != spdk_env_get_first_core()) {
spdk_event_call(spdk_event_allocate(spdk_env_get_first_core(),
_spdk_nvmf_shutdown_cb, NULL, NULL));
} else {
_spdk_nvmf_shutdown_cb(NULL, NULL);
}
}
struct spdk_nvmf_subsystem *
nvmf_tgt_create_subsystem(const char *name, enum spdk_nvmf_subtype subtype, uint32_t num_ns)
{