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 <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/447676
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Darek Stojaczyk 2019-03-11 13:14:19 +01:00 committed by Ben Walker
parent 6f48bf7cb6
commit f373369a9c
5 changed files with 35 additions and 11 deletions

View File

@ -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

View File

@ -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.
*

View File

@ -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.
*

View File

@ -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)
{

View File

@ -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();
}