bdev: cleanup if bdev init doesn't complete all the way

In the event that one bdev module failed, we'd leak a bunch
of stuff from any that init'd correctly beforehand.  Also
added a guard around the calling of modile init_done routines
so that it's not done if module init didn't work.

Change-Id: I4e6170e1eee67b131252ed30d0d20124d2c5ff35
Signed-off-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-on: https://review.gerrithub.io/419446
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
Paul Luse 2018-07-16 17:10:57 -07:00 committed by Changpeng Liu
parent 4996d7b5c5
commit 4d5bedcebc

View File

@ -628,11 +628,13 @@ spdk_bdev_init_complete(int rc)
* For modules that need to know when subsystem init is complete,
* inform them now.
*/
if (rc == 0) {
TAILQ_FOREACH(m, &g_bdev_mgr.bdev_modules, internal.tailq) {
if (m->init_complete) {
m->init_complete();
}
}
}
cb_fn(cb_arg, rc);
}
@ -707,6 +709,13 @@ spdk_bdev_modules_init(void)
return rc;
}
static void
spdk_bdev_init_failed(void *cb_arg)
{
spdk_bdev_init_complete(-1);
return;
}
void
spdk_bdev_initialize(spdk_bdev_init_cb cb_fn, void *cb_arg)
{
@ -811,7 +820,7 @@ spdk_bdev_initialize(spdk_bdev_init_cb cb_fn, void *cb_arg)
rc = spdk_bdev_modules_init();
if (rc != 0) {
SPDK_ERRLOG("bdev modules init failed\n");
spdk_bdev_init_complete(-1);
spdk_bdev_finish(spdk_bdev_init_failed, NULL);
return;
}