From f373369a9c981b1f318e86531b3a8b4148d162e1 Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Mon, 11 Mar 2019 13:14:19 +0100 Subject: [PATCH] env: add spdk_env_fini() The function now has to be called before application exit. At the moment it only frees the dynamically allocated DPDK command line option strings - something that was previously done from an atexit() callback - but there's more to free there. Note: the function descriptions were partially copied from equivalent DPDK functions. Change-Id: I5f4a6607fdfadff9325917259f58fcbc2cedba1a Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/447676 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- CHANGELOG.md | 6 ++++++ include/spdk/env.h | 8 ++++++++ include/spdk/env_dpdk.h | 8 ++++++++ lib/env_dpdk/init.c | 23 ++++++++++++----------- lib/event/app.c | 1 + 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 117c6ef6b..b767456a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,12 @@ For retrieving physical addresses, spdk_vtophys() should be used instead. Dropped support for DPDK 17.07 and earlier, which SPDK won't even compile with right now. +### env + +spdk_env_fini() and spdk_env_dpdk_post_fini() were added to release any resources +allocated by spdk_env_init() or spdk_env_dpdk_post_init() respectively. It is expected +that common usage of those functions is to call them just before terminating the process. + ## v19.01: ### ocf bdev diff --git a/include/spdk/env.h b/include/spdk/env.h index d8bca3cf0..534983d78 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -168,6 +168,14 @@ void spdk_env_opts_init(struct spdk_env_opts *opts); */ int spdk_env_init(const struct spdk_env_opts *opts); +/** + * Release any resources of the environment library that were alllocated with + * spdk_env_init(). After this call, no SPDK env function calls may be made. + * It is expected that common usage of this function is to call it just before + * terminating the process. + */ +void spdk_env_fini(void); + /** * Allocate a pinned memory buffer with the given size and alignment. * diff --git a/include/spdk/env_dpdk.h b/include/spdk/env_dpdk.h index a5e0a6113..9729ad560 100644 --- a/include/spdk/env_dpdk.h +++ b/include/spdk/env_dpdk.h @@ -52,6 +52,14 @@ extern "C" { */ int spdk_env_dpdk_post_init(void); +/** + * Release any resources of the environment library that were alllocated with + * spdk_env_dpdk_post_init(). After this call, no DPDK function calls may + * be made. It is expected that common usage of this function is to call it + * just before terminating the process. + */ +void spdk_env_dpdk_post_fini(void); + /** * Check if DPDK was initialized external to the SPDK env_dpdk library. * diff --git a/lib/env_dpdk/init.c b/lib/env_dpdk/init.c index f459d10a4..55452b77b 100644 --- a/lib/env_dpdk/init.c +++ b/lib/env_dpdk/init.c @@ -174,13 +174,6 @@ spdk_push_arg(char *args[], int *argcount, char *arg) return tmp; } -static void -spdk_destruct_eal_cmdline(void) -{ - spdk_free_args(g_eal_cmdline, g_eal_cmdline_argcount); -} - - static int spdk_build_eal_cmdline(const struct spdk_env_opts *opts) { @@ -365,10 +358,6 @@ spdk_build_eal_cmdline(const struct spdk_env_opts *opts) g_eal_cmdline = args; g_eal_cmdline_argcount = argcount; - if (atexit(spdk_destruct_eal_cmdline) != 0) { - fprintf(stderr, "Failed to register cleanup handler\n"); - } - return argcount; } @@ -389,6 +378,12 @@ spdk_env_dpdk_post_init(void) return 0; } +void +spdk_env_dpdk_post_fini(void) +{ + spdk_free_args(g_eal_cmdline, g_eal_cmdline_argcount); +} + int spdk_env_init(const struct spdk_env_opts *opts) { @@ -449,6 +444,12 @@ spdk_env_init(const struct spdk_env_opts *opts) return spdk_env_dpdk_post_init(); } +void +spdk_env_fini(void) +{ + spdk_env_dpdk_post_fini(); +} + bool spdk_env_dpdk_external_init(void) { diff --git a/lib/event/app.c b/lib/event/app.c index 0b17fb8ff..5ebac602a 100644 --- a/lib/event/app.c +++ b/lib/event/app.c @@ -696,6 +696,7 @@ spdk_app_fini(void) { spdk_trace_cleanup(); spdk_reactors_fini(); + spdk_env_fini(); spdk_conf_free(g_spdk_app.config); spdk_log_close(); }