From 09897660602615f7a2b2a8b78c09d3382dca075d Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Thu, 30 Jun 2022 13:54:38 +0800 Subject: [PATCH] test/deallocated_value: shutdown controllers before the quit The test tool doesn't shutdown controllers when exiting the process, so here we shutdown the controllers, also fix the exceptions when no active Namespaces in controller. Change-Id: I21cbdb1e7bdf37a06f66b917a2bb9bd94e06b444 Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13495 Tested-by: SPDK CI Jenkins Reviewed-by: Konrad Sztyber Reviewed-by: Ben Walker Community-CI: Broadcom CI --- .../deallocated_value/deallocated_value.c | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/test/nvme/deallocated_value/deallocated_value.c b/test/nvme/deallocated_value/deallocated_value.c index 318c163bf..150367051 100644 --- a/test/nvme/deallocated_value/deallocated_value.c +++ b/test/nvme/deallocated_value/deallocated_value.c @@ -20,6 +20,11 @@ * be all bytes set to 00h, all bytes set to FFh, or the last data written to the associated logical block". */ +struct ctrlr_entry { + struct spdk_nvme_ctrlr *ctrlr; + TAILQ_ENTRY(ctrlr_entry) link; +}; + struct ns_entry { struct spdk_nvme_ctrlr *ctrlr; struct spdk_nvme_ns *ns; @@ -42,6 +47,7 @@ struct deallocate_context { int matches_FFh; }; +static TAILQ_HEAD(, ctrlr_entry) g_controllers = TAILQ_HEAD_INITIALIZER(g_controllers); static struct ns_entry *g_namespaces = NULL; static struct spdk_nvme_transport_id g_trid = {}; @@ -416,20 +422,30 @@ static void attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts) { - int num_ns; + struct ctrlr_entry *entry; + int nsid; struct spdk_nvme_ns *ns; + entry = malloc(sizeof(struct ctrlr_entry)); + if (entry == NULL) { + perror("ctrlr_entry malloc"); + exit(1); + } printf("Attached to %s\n", trid->traddr); + /* * Use only the first namespace from each controller since we are testing controller level functionality. */ - num_ns = spdk_nvme_ctrlr_get_num_ns(ctrlr); - if (num_ns < 1) { + nsid = spdk_nvme_ctrlr_get_first_active_ns(ctrlr); + if (nsid < 1) { printf("No valid namespaces in controller\n"); } else { - ns = spdk_nvme_ctrlr_get_ns(ctrlr, 1); + ns = spdk_nvme_ctrlr_get_ns(ctrlr, nsid); register_ns(ctrlr, ns); } + + entry->ctrlr = ctrlr; + TAILQ_INSERT_TAIL(&g_controllers, entry, link); } static void @@ -467,6 +483,8 @@ main(int argc, char **argv) { int rc; struct spdk_env_opts opts; + struct ctrlr_entry *ctrlr_entry, *tmp_ctrlr_entry; + struct spdk_nvme_detach_ctx *detach_ctx = NULL; spdk_env_opts_init(&opts); rc = parse_args(argc, argv, &opts); @@ -488,12 +506,30 @@ main(int argc, char **argv) return 1; } - if (g_namespaces == NULL) { + if (TAILQ_EMPTY(&g_controllers)) { fprintf(stderr, "no NVMe controllers found\n"); return 1; } + if (g_namespaces == NULL) { + fprintf(stderr, "no Namespaces found\n"); + rc = 1; + goto cleanup; + } + printf("Initialization complete.\n"); deallocate_test(); - return 0; + +cleanup: + TAILQ_FOREACH_SAFE(ctrlr_entry, &g_controllers, link, tmp_ctrlr_entry) { + TAILQ_REMOVE(&g_controllers, ctrlr_entry, link); + spdk_nvme_detach_async(ctrlr_entry->ctrlr, &detach_ctx); + free(ctrlr_entry); + } + + if (detach_ctx) { + spdk_nvme_detach_poll(detach_ctx); + } + + return rc; }