module/vmd: move subsystem start to ->init()

This makes sure that if the app is killed before the subsystems have
been initialized (i.e. before framework_start_init is called), we don't
leak resources.  Before this change, we initialized the VMD library and
registered the hotplug poller from the context of the RPC and we only
freed it in subsystem's fini().  However, if subsystems were never
initialized, we never freed them.

Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I56b746c46b94135ef56a478c5f80194ebe51a942
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13951
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tom Nabarro <tom.nabarro@intel.com>
This commit is contained in:
Konrad Sztyber 2022-07-04 16:28:31 +02:00 committed by Tomasz Zawadzki
parent 55bdd88506
commit dc5b33d982
3 changed files with 19 additions and 16 deletions

View File

@ -6,6 +6,6 @@
#ifndef EVENT_VMD_H
#define EVENT_VMD_H
int vmd_subsystem_init(void);
void vmd_subsystem_enable(void);
#endif

View File

@ -18,26 +18,31 @@
static struct spdk_poller *g_hotplug_poller;
static bool g_enabled;
void
vmd_subsystem_enable(void)
{
g_enabled = true;
}
static int
vmd_hotplug_monitor(void *ctx)
{
return spdk_vmd_hotplug_monitor();
}
int
static void
vmd_subsystem_init(void)
{
int rc;
int rc = 0;
if (g_enabled) {
SPDK_ERRLOG("The initialization has already been performed\n");
return -EBUSY;
if (!g_enabled) {
goto out;
}
rc = spdk_vmd_init();
if (spdk_likely(rc != 0)) {
SPDK_ERRLOG("Failed to initialize the VMD library\n");
return rc;
goto out;
}
assert(g_hotplug_poller == NULL);
@ -45,12 +50,11 @@ vmd_subsystem_init(void)
g_hotplug_poller = SPDK_POLLER_REGISTER(vmd_hotplug_monitor, NULL, 1000000ULL);
if (g_hotplug_poller == NULL) {
SPDK_ERRLOG("Failed to register hotplug monitor poller\n");
return -ENOMEM;
rc = -ENOMEM;
goto out;
}
g_enabled = true;
return 0;
out:
spdk_subsystem_init_next(rc);
}
static void
@ -81,6 +85,7 @@ vmd_write_config_json(struct spdk_json_write_ctx *w)
static struct spdk_subsystem g_spdk_subsystem_vmd = {
.name = "vmd",
.init = vmd_subsystem_init,
.fini = vmd_subsystem_fini,
.write_config_json = vmd_write_config_json,
};

View File

@ -14,11 +14,9 @@
static void
rpc_vmd_enable(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
{
int rc;
vmd_subsystem_enable();
rc = vmd_subsystem_init();
spdk_jsonrpc_send_bool_response(request, rc == 0);
spdk_jsonrpc_send_bool_response(request, true);
}
SPDK_RPC_REGISTER("enable_vmd", rpc_vmd_enable, SPDK_RPC_STARTUP)