nvme: Eliminate CONSTRUCT_NS state

This can be done immediately after receiving the controller identify
data for now.

Change-Id: I527a44c4d1f4d3ad2eeb8fc77e07086c2358cac3
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9300
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Ben Walker 2021-08-17 15:04:53 -07:00 committed by Tomasz Zawadzki
parent 4ecbc5bb0e
commit 72eab36037
3 changed files with 32 additions and 31 deletions

View File

@ -1233,8 +1233,6 @@ nvme_ctrlr_state_string(enum nvme_ctrlr_state state)
return "identify active ns";
case NVME_CTRLR_STATE_WAIT_FOR_IDENTIFY_ACTIVE_NS:
return "wait for identify active ns";
case NVME_CTRLR_STATE_CONSTRUCT_NS:
return "construct namespaces";
case NVME_CTRLR_STATE_IDENTIFY_NS:
return "identify ns";
case NVME_CTRLR_STATE_WAIT_FOR_IDENTIFY_NS:
@ -2099,22 +2097,33 @@ out:
}
}
static int nvme_ctrlr_construct_namespaces(struct spdk_nvme_ctrlr *ctrlr);
static void
_nvme_active_ns_ctx_deleter(struct nvme_active_ns_ctx *ctx)
{
int rc;
struct spdk_nvme_ctrlr *ctrlr = ctx->ctrlr;
if (ctx->state == NVME_ACTIVE_NS_STATE_ERROR) {
nvme_ctrlr_destruct_namespaces(ctrlr);
nvme_active_ns_ctx_destroy(ctx);
nvme_ctrlr_set_state(ctrlr, NVME_CTRLR_STATE_ERROR, NVME_TIMEOUT_INFINITE);
return;
}
assert(ctx->state == NVME_ACTIVE_NS_STATE_DONE);
rc = nvme_ctrlr_construct_namespaces(ctrlr);
if (rc) {
NVME_CTRLR_ERRLOG(ctrlr, "Unable to construct namespace array!\n");
nvme_active_ns_ctx_destroy(ctx);
nvme_ctrlr_set_state(ctrlr, NVME_CTRLR_STATE_ERROR, NVME_TIMEOUT_INFINITE);
return;
}
nvme_ctrlr_identify_active_ns_swap(ctrlr, &ctx->new_ns_list);
nvme_active_ns_ctx_destroy(ctx);
nvme_ctrlr_set_state(ctrlr, NVME_CTRLR_STATE_CONSTRUCT_NS, ctrlr->opts.admin_timeout_ms);
nvme_ctrlr_set_state(ctrlr, NVME_CTRLR_STATE_IDENTIFY_NS, ctrlr->opts.admin_timeout_ms);
}
static void
@ -3520,14 +3529,6 @@ nvme_ctrlr_process_init(struct spdk_nvme_ctrlr *ctrlr)
_nvme_ctrlr_identify_active_ns(ctrlr);
break;
case NVME_CTRLR_STATE_CONSTRUCT_NS:
rc = nvme_ctrlr_construct_namespaces(ctrlr);
if (!rc) {
nvme_ctrlr_set_state(ctrlr, NVME_CTRLR_STATE_IDENTIFY_NS,
ctrlr->opts.admin_timeout_ms);
}
break;
case NVME_CTRLR_STATE_IDENTIFY_NS:
rc = nvme_ctrlr_identify_namespaces(ctrlr);
break;

View File

@ -640,11 +640,6 @@ enum nvme_ctrlr_state {
*/
NVME_CTRLR_STATE_WAIT_FOR_IDENTIFY_ACTIVE_NS,
/**
* Construct Namespace data structures of the controller.
*/
NVME_CTRLR_STATE_CONSTRUCT_NS,
/**
* Get Identify Namespace Data structure for each NS.
*/

View File

@ -2035,7 +2035,12 @@ test_nvme_ctrlr_test_active_ns(void)
ctrlr.vs.bits.mjr = 1;
ctrlr.vs.bits.mnr = minor;
ctrlr.vs.bits.ter = 0;
ctrlr.num_ns = ctrlr.cdata.nn = 1531;
ctrlr.cdata.nn = 1531;
ctrlr.ns = calloc(ctrlr.cdata.nn, sizeof(struct spdk_nvme_ns));
SPDK_CU_ASSERT_FATAL(ctrlr.ns != NULL);
ctrlr.num_ns = ctrlr.cdata.nn;
nvme_ctrlr_identify_active_ns(&ctrlr);
for (nsid = 1; nsid <= ctrlr.num_ns; nsid++) {
@ -2225,7 +2230,7 @@ test_nvme_ctrlr_init_set_nvmf_ioccsz(void)
CU_ASSERT(nvme_ctrlr_process_init(&ctrlr) == 0);
CU_ASSERT(ctrlr.state == NVME_CTRLR_STATE_IDENTIFY_ACTIVE_NS);
CU_ASSERT(nvme_ctrlr_process_init(&ctrlr) == 0);
CU_ASSERT(ctrlr.state == NVME_CTRLR_STATE_CONSTRUCT_NS);
CU_ASSERT(ctrlr.state == NVME_CTRLR_STATE_IDENTIFY_NS);
CU_ASSERT(ctrlr.ioccsz_bytes == 0);
CU_ASSERT(ctrlr.icdoff == 0);
@ -2244,7 +2249,7 @@ test_nvme_ctrlr_init_set_nvmf_ioccsz(void)
CU_ASSERT(nvme_ctrlr_process_init(&ctrlr) == 0);
CU_ASSERT(ctrlr.state == NVME_CTRLR_STATE_IDENTIFY_ACTIVE_NS);
CU_ASSERT(nvme_ctrlr_process_init(&ctrlr) == 0);
CU_ASSERT(ctrlr.state == NVME_CTRLR_STATE_CONSTRUCT_NS);
CU_ASSERT(ctrlr.state == NVME_CTRLR_STATE_IDENTIFY_NS);
CU_ASSERT(ctrlr.ioccsz_bytes == 4096);
CU_ASSERT(ctrlr.icdoff == 1);
@ -2265,7 +2270,7 @@ test_nvme_ctrlr_init_set_nvmf_ioccsz(void)
CU_ASSERT(nvme_ctrlr_process_init(&ctrlr) == 0);
CU_ASSERT(ctrlr.state == NVME_CTRLR_STATE_IDENTIFY_ACTIVE_NS);
CU_ASSERT(nvme_ctrlr_process_init(&ctrlr) == 0);
CU_ASSERT(ctrlr.state == NVME_CTRLR_STATE_CONSTRUCT_NS);
CU_ASSERT(ctrlr.state == NVME_CTRLR_STATE_IDENTIFY_NS);
CU_ASSERT(ctrlr.ioccsz_bytes == 4096);
CU_ASSERT(ctrlr.icdoff == 1);
@ -2286,7 +2291,7 @@ test_nvme_ctrlr_init_set_nvmf_ioccsz(void)
CU_ASSERT(nvme_ctrlr_process_init(&ctrlr) == 0);
CU_ASSERT(ctrlr.state == NVME_CTRLR_STATE_IDENTIFY_ACTIVE_NS);
CU_ASSERT(nvme_ctrlr_process_init(&ctrlr) == 0);
CU_ASSERT(ctrlr.state == NVME_CTRLR_STATE_CONSTRUCT_NS);
CU_ASSERT(ctrlr.state == NVME_CTRLR_STATE_IDENTIFY_NS);
CU_ASSERT(ctrlr.ioccsz_bytes == 4096);
CU_ASSERT(ctrlr.icdoff == 1);
@ -2307,7 +2312,7 @@ test_nvme_ctrlr_init_set_nvmf_ioccsz(void)
CU_ASSERT(nvme_ctrlr_process_init(&ctrlr) == 0);
CU_ASSERT(ctrlr.state == NVME_CTRLR_STATE_IDENTIFY_ACTIVE_NS);
CU_ASSERT(nvme_ctrlr_process_init(&ctrlr) == 0);
CU_ASSERT(ctrlr.state == NVME_CTRLR_STATE_CONSTRUCT_NS);
CU_ASSERT(ctrlr.state == NVME_CTRLR_STATE_IDENTIFY_NS);
CU_ASSERT(ctrlr.ioccsz_bytes == 0);
CU_ASSERT(ctrlr.icdoff == 0);
@ -2487,8 +2492,8 @@ test_nvme_ctrlr_active_ns_list_v0(void)
ctrlr.cdata.nn = 1024;
ctrlr.state = NVME_CTRLR_STATE_IDENTIFY_ACTIVE_NS;
SPDK_CU_ASSERT_FATAL(nvme_ctrlr_process_init(&ctrlr) == 0); /* -> CONSTRUCT_NS */
SPDK_CU_ASSERT_FATAL(ctrlr.state == NVME_CTRLR_STATE_CONSTRUCT_NS);
SPDK_CU_ASSERT_FATAL(nvme_ctrlr_process_init(&ctrlr) == 0);
SPDK_CU_ASSERT_FATAL(ctrlr.state == NVME_CTRLR_STATE_IDENTIFY_NS);
CU_ASSERT(spdk_nvme_ctrlr_is_active_ns(&ctrlr, 1));
CU_ASSERT(spdk_nvme_ctrlr_is_active_ns(&ctrlr, 1024));
CU_ASSERT(!spdk_nvme_ctrlr_is_active_ns(&ctrlr, 1025));
@ -2518,8 +2523,8 @@ test_nvme_ctrlr_active_ns_list_v2(void)
/* No active namespaces */
memset(active_ns_list, 0, sizeof(active_ns_list));
ctrlr.state = NVME_CTRLR_STATE_IDENTIFY_ACTIVE_NS;
SPDK_CU_ASSERT_FATAL(nvme_ctrlr_process_init(&ctrlr) == 0); /* -> CONSTRUCT_NS */
SPDK_CU_ASSERT_FATAL(ctrlr.state == NVME_CTRLR_STATE_CONSTRUCT_NS);
SPDK_CU_ASSERT_FATAL(nvme_ctrlr_process_init(&ctrlr) == 0);
SPDK_CU_ASSERT_FATAL(ctrlr.state == NVME_CTRLR_STATE_IDENTIFY_NS);
CU_ASSERT(!spdk_nvme_ctrlr_is_active_ns(&ctrlr, 1));
CU_ASSERT(!spdk_nvme_ctrlr_is_active_ns(&ctrlr, 1024));
CU_ASSERT(!spdk_nvme_ctrlr_is_active_ns(&ctrlr, 1025));
@ -2537,8 +2542,8 @@ test_nvme_ctrlr_active_ns_list_v2(void)
ctrlr.state = NVME_CTRLR_STATE_IDENTIFY_ACTIVE_NS;
g_active_ns_list = active_ns_list;
g_active_ns_list_length = SPDK_COUNTOF(active_ns_list);
SPDK_CU_ASSERT_FATAL(nvme_ctrlr_process_init(&ctrlr) == 0); /* -> CONSTRUCT_NS */
SPDK_CU_ASSERT_FATAL(ctrlr.state == NVME_CTRLR_STATE_CONSTRUCT_NS);
SPDK_CU_ASSERT_FATAL(nvme_ctrlr_process_init(&ctrlr) == 0);
SPDK_CU_ASSERT_FATAL(ctrlr.state == NVME_CTRLR_STATE_IDENTIFY_NS);
CU_ASSERT(spdk_nvme_ctrlr_is_active_ns(&ctrlr, 1));
CU_ASSERT(spdk_nvme_ctrlr_is_active_ns(&ctrlr, 1024));
CU_ASSERT(!spdk_nvme_ctrlr_is_active_ns(&ctrlr, 1025));
@ -2556,8 +2561,8 @@ test_nvme_ctrlr_active_ns_list_v2(void)
}
ctrlr.state = NVME_CTRLR_STATE_IDENTIFY_ACTIVE_NS;
SPDK_CU_ASSERT_FATAL(nvme_ctrlr_process_init(&ctrlr) == 0); /* -> CONSTRUCT_NS */
SPDK_CU_ASSERT_FATAL(ctrlr.state == NVME_CTRLR_STATE_CONSTRUCT_NS);
SPDK_CU_ASSERT_FATAL(nvme_ctrlr_process_init(&ctrlr) == 0);
SPDK_CU_ASSERT_FATAL(ctrlr.state == NVME_CTRLR_STATE_IDENTIFY_NS);
CU_ASSERT(spdk_nvme_ctrlr_is_active_ns(&ctrlr, 1));
CU_ASSERT(spdk_nvme_ctrlr_is_active_ns(&ctrlr, 1023));
CU_ASSERT(!spdk_nvme_ctrlr_is_active_ns(&ctrlr, 1024));