diff --git a/examples/nvme/abort/abort.c b/examples/nvme/abort/abort.c index 61960bfb6..ea1147994 100644 --- a/examples/nvme/abort/abort.c +++ b/examples/nvme/abort/abort.c @@ -1074,8 +1074,8 @@ int main(int argc, char **argv) } if (spdk_env_init(&opts) < 0) { fprintf(stderr, "Unable to initialize SPDK env\n"); - rc = -1; - goto cleanup; + unregister_trids(); + return -1; } g_tsc_rate = spdk_get_ticks_hz(); @@ -1135,6 +1135,8 @@ cleanup: unregister_namespaces(); unregister_controllers(); + spdk_env_fini(); + if (rc != 0) { fprintf(stderr, "%s: errors occurred\n", argv[0]); } diff --git a/examples/nvme/arbitration/arbitration.c b/examples/nvme/arbitration/arbitration.c index 76f8211b0..3d7dd1a8a 100644 --- a/examples/nvme/arbitration/arbitration.c +++ b/examples/nvme/arbitration/arbitration.c @@ -1093,7 +1093,7 @@ main(int argc, char **argv) struct worker_thread *worker, *main_worker; unsigned main_core; char task_pool_name[30]; - uint32_t task_count; + uint32_t task_count = 0; struct spdk_env_opts opts; rc = parse_args(argc, argv); @@ -1114,15 +1114,18 @@ main(int argc, char **argv) g_arbitration.tsc_rate = spdk_get_ticks_hz(); if (register_workers() != 0) { - return 1; + rc = 1; + goto exit; } if (register_controllers() != 0) { - return 1; + rc = 1; + goto exit; } if (associate_workers_with_ns() != 0) { - return 1; + rc = 1; + goto exit; } snprintf(task_pool_name, sizeof(task_pool_name), "task_pool_%d", getpid()); @@ -1140,7 +1143,8 @@ main(int argc, char **argv) sizeof(struct arb_task), 0, SPDK_ENV_SOCKET_ID_ANY); if (task_pool == NULL) { fprintf(stderr, "could not initialize task pool\n"); - return 1; + rc = 1; + goto exit; } print_configuration(argv[0]); @@ -1166,10 +1170,12 @@ main(int argc, char **argv) print_stats(); +exit: unregister_controllers(); - cleanup(task_count); + spdk_env_fini(); + if (rc != 0) { fprintf(stderr, "%s: errors occurred\n", argv[0]); } diff --git a/examples/nvme/discovery_aer/discovery_aer.c b/examples/nvme/discovery_aer/discovery_aer.c index bd801185c..14974b067 100644 --- a/examples/nvme/discovery_aer/discovery_aer.c +++ b/examples/nvme/discovery_aer/discovery_aer.c @@ -327,5 +327,7 @@ int main(int argc, char **argv) spdk_nvme_detach_poll(detach_ctx); } + spdk_env_fini(); + return 0; } diff --git a/examples/nvme/fio_plugin/fio_plugin.c b/examples/nvme/fio_plugin/fio_plugin.c index db3b31686..e2d8934bb 100644 --- a/examples/nvme/fio_plugin/fio_plugin.c +++ b/examples/nvme/fio_plugin/fio_plugin.c @@ -1464,6 +1464,10 @@ static void spdk_fio_cleanup(struct thread_data *td) pthread_join(g_ctrlr_thread_id, NULL); } } + + if (g_spdk_env_initialized) { + spdk_env_fini(); + } } /* This function enables addition of SPDK parameters to the fio config diff --git a/examples/nvme/hello_world/hello_world.c b/examples/nvme/hello_world/hello_world.c index 25c2fd420..d47ac25c7 100644 --- a/examples/nvme/hello_world/hello_world.c +++ b/examples/nvme/hello_world/hello_world.c @@ -507,14 +507,14 @@ int main(int argc, char **argv) rc = spdk_nvme_probe(&g_trid, NULL, probe_cb, attach_cb, NULL); if (rc != 0) { fprintf(stderr, "spdk_nvme_probe() failed\n"); - cleanup(); - return 1; + rc = 1; + goto exit; } if (TAILQ_EMPTY(&g_controllers)) { fprintf(stderr, "no NVMe controllers found\n"); - cleanup(); - return 1; + rc = 1; + goto exit; } printf("Initialization complete.\n"); @@ -524,5 +524,8 @@ int main(int argc, char **argv) spdk_vmd_fini(); } - return 0; +exit: + cleanup(); + spdk_env_fini(); + return rc; } diff --git a/examples/nvme/hotplug/hotplug.c b/examples/nvme/hotplug/hotplug.c index 0d774f8ec..e99f28fb8 100644 --- a/examples/nvme/hotplug/hotplug.c +++ b/examples/nvme/hotplug/hotplug.c @@ -555,7 +555,8 @@ int main(int argc, char **argv) /* Detect the controllers that are plugged in at startup. */ if (register_controllers() != 0) { - return 1; + rc = 1; + goto cleanup; } fprintf(stderr, "Initialization complete. Starting I/O...\n"); @@ -564,14 +565,17 @@ int main(int argc, char **argv) if (g_expected_insert_times != -1 && g_insert_times != g_expected_insert_times) { fprintf(stderr, "Expected inserts %d != actual inserts %d\n", g_expected_insert_times, g_insert_times); - return 1; + rc = 1; + goto cleanup; } if (g_expected_removal_times != -1 && g_removal_times != g_expected_removal_times) { fprintf(stderr, "Expected removals %d != actual removals %d\n", g_expected_removal_times, g_removal_times); - return 1; + rc = 1; } - return 0; +cleanup: + spdk_env_fini(); + return rc; } diff --git a/examples/nvme/identify/identify.c b/examples/nvme/identify/identify.c index 038bef314..92e0c9e3c 100644 --- a/examples/nvme/identify/identify.c +++ b/examples/nvme/identify/identify.c @@ -2246,7 +2246,8 @@ int main(int argc, char **argv) ctrlr = spdk_nvme_connect(&g_trid, &opts, sizeof(opts)); if (!ctrlr) { fprintf(stderr, "spdk_nvme_connect() failed\n"); - return 1; + rc = 1; + goto exit; } g_controllers_found++; @@ -2254,7 +2255,8 @@ int main(int argc, char **argv) spdk_nvme_detach_async(ctrlr, &g_detach_ctx); } else if (spdk_nvme_probe(&g_trid, NULL, probe_cb, attach_cb, NULL) != 0) { fprintf(stderr, "spdk_nvme_probe() failed\n"); - return 1; + rc = 1; + goto exit; } if (g_detach_ctx) { @@ -2265,9 +2267,12 @@ int main(int argc, char **argv) fprintf(stderr, "No NVMe controllers found.\n"); } +exit: if (g_vmd) { spdk_vmd_fini(); } - return 0; + spdk_env_fini(); + + return rc; } diff --git a/examples/nvme/nvme_manage/nvme_manage.c b/examples/nvme/nvme_manage/nvme_manage.c index 236311761..a671f835d 100644 --- a/examples/nvme/nvme_manage/nvme_manage.c +++ b/examples/nvme/nvme_manage/nvme_manage.c @@ -1634,6 +1634,7 @@ int main(int argc, char **argv) if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) { fprintf(stderr, "spdk_nvme_probe() failed\n"); + spdk_env_fini(); return 1; } @@ -1704,5 +1705,7 @@ int main(int argc, char **argv) spdk_nvme_detach_poll(detach_ctx); } + spdk_env_fini(); + return 0; } diff --git a/examples/nvme/perf/perf.c b/examples/nvme/perf/perf.c index a549e2b22..e81198135 100644 --- a/examples/nvme/perf/perf.c +++ b/examples/nvme/perf/perf.c @@ -2860,12 +2860,13 @@ int main(int argc, char **argv) rc = pthread_mutex_init(&g_stats_mutex, NULL); if (rc != 0) { fprintf(stderr, "Failed to init mutex\n"); - goto cleanup; + return -1; } if (spdk_env_init(&opts) < 0) { fprintf(stderr, "Unable to initialize SPDK env\n"); - rc = -1; - goto cleanup; + unregister_trids(); + pthread_mutex_destroy(&g_stats_mutex); + return -1; } rc = setup_sig_handlers(); @@ -2956,6 +2957,8 @@ cleanup: unregister_controllers(); unregister_workers(); + spdk_env_fini(); + pthread_mutex_destroy(&g_stats_mutex); if (rc != 0) { diff --git a/examples/nvme/reconnect/reconnect.c b/examples/nvme/reconnect/reconnect.c index 5f5370d76..23b1ba00d 100644 --- a/examples/nvme/reconnect/reconnect.c +++ b/examples/nvme/reconnect/reconnect.c @@ -1095,8 +1095,8 @@ int main(int argc, char **argv) opts.hugepage_single_segments = g_dpdk_mem_single_seg; if (spdk_env_init(&opts) < 0) { fprintf(stderr, "Unable to initialize SPDK env\n"); - rc = 1; - goto cleanup; + unregister_trids(); + return 1; } g_tsc_rate = spdk_get_ticks_hz(); @@ -1159,6 +1159,8 @@ cleanup: unregister_controllers(); unregister_workers(); + spdk_env_fini(); + if (rc != 0) { fprintf(stderr, "%s: errors occurred\n", argv[0]); /*