From 4d5bedcebc1a55da0c0074bb127d071b1242567b Mon Sep 17 00:00:00 2001 From: Paul Luse Date: Mon, 16 Jul 2018 17:10:57 -0700 Subject: [PATCH] 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 Reviewed-on: https://review.gerrithub.io/419446 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto Reviewed-by: Changpeng Liu Chandler-Test-Pool: SPDK Automated Test System --- lib/bdev/bdev.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index 1c0871da0..44a25d515 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -628,9 +628,11 @@ spdk_bdev_init_complete(int rc) * For modules that need to know when subsystem init is complete, * inform them now. */ - TAILQ_FOREACH(m, &g_bdev_mgr.bdev_modules, internal.tailq) { - if (m->init_complete) { - m->init_complete(); + if (rc == 0) { + TAILQ_FOREACH(m, &g_bdev_mgr.bdev_modules, internal.tailq) { + if (m->init_complete) { + m->init_complete(); + } } } @@ -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; }