From da01835d84a12aa76cde2686a382d1d3984e9d6e Mon Sep 17 00:00:00 2001 From: GangCao Date: Mon, 20 Aug 2018 18:48:27 -0400 Subject: [PATCH] lib/nvmf: handle the failed case when activating the subsystem In the case of failing to spdk_nvmf_poll_group_add_subsystem() operation, the subsystem still needs to initialize the related queue so that later coming request can be properly queued. Also needs to correctly handle the expected state in this failed condition so that when destroying the subsystem, it could be properly handled. Change-Id: I419f2ac7164c25258c3911952c38b9433fca762b Signed-off-by: GangCao Reviewed-on: https://review.gerrithub.io/422799 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- lib/nvmf/nvmf.c | 7 ++++--- lib/nvmf/subsystem.c | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/nvmf/nvmf.c b/lib/nvmf/nvmf.c index de039ef4b..4733fcafa 100644 --- a/lib/nvmf/nvmf.c +++ b/lib/nvmf/nvmf.c @@ -883,17 +883,18 @@ spdk_nvmf_poll_group_add_subsystem(struct spdk_nvmf_poll_group *group, struct spdk_nvmf_subsystem *subsystem, spdk_nvmf_poll_group_mod_done cb_fn, void *cb_arg) { - struct spdk_nvmf_subsystem_poll_group *sgroup; int rc = 0; + struct spdk_nvmf_subsystem_poll_group *sgroup = &group->sgroups[subsystem->id]; + + TAILQ_INIT(&sgroup->queued); rc = poll_group_update_subsystem(group, subsystem); if (rc) { + sgroup->state = SPDK_NVMF_SUBSYSTEM_INACTIVE; goto fini; } - sgroup = &group->sgroups[subsystem->id]; sgroup->state = SPDK_NVMF_SUBSYSTEM_ACTIVE; - TAILQ_INIT(&sgroup->queued); fini: if (cb_fn) { cb_fn(cb_arg, rc); diff --git a/lib/nvmf/subsystem.c b/lib/nvmf/subsystem.c index cf13f892c..874da4a4b 100644 --- a/lib/nvmf/subsystem.c +++ b/lib/nvmf/subsystem.c @@ -389,6 +389,11 @@ spdk_nvmf_subsystem_set_state(struct spdk_nvmf_subsystem *subsystem, state == SPDK_NVMF_SUBSYSTEM_ACTIVE) { expected_old_state = SPDK_NVMF_SUBSYSTEM_RESUMING; } + /* This is for the case when activating the subsystem fails. */ + if (actual_old_state == SPDK_NVMF_SUBSYSTEM_ACTIVATING && + state == SPDK_NVMF_SUBSYSTEM_DEACTIVATING) { + expected_old_state = SPDK_NVMF_SUBSYSTEM_ACTIVATING; + } actual_old_state = __sync_val_compare_and_swap(&subsystem->state, expected_old_state, state); } assert(actual_old_state == expected_old_state);