From d5af6a04170881349043900027b771eff3e77f60 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Tue, 15 Jun 2021 08:58:22 -0700 Subject: [PATCH] iscsi: track whether io_device needs to be unregistered If iscsi initialization fails (due to a memory allocation failure for example), we may not even get to the point where the g_iscsi global is registered as an io_device. So then when we tear down the iscsi library using spdk_iscsi_fini(), we need to make sure we don't try to unregister g_iscsi if it wasn't registered. For now, just use the g_init_thread global to make this determination - it's set just after we register the io_device. Signed-off-by: Jim Harris Change-Id: Ic9443564ef67b9c0df0fce47a346f4608749c306 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8351 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Paul Luse Reviewed-by: Shuhei Matsumoto Reviewed-by: Ziye Yang Reviewed-by: Aleksey Marchuk --- lib/iscsi/iscsi_subsystem.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/iscsi/iscsi_subsystem.c b/lib/iscsi/iscsi_subsystem.c index 856ca16f8..c9a356ea5 100644 --- a/lib/iscsi/iscsi_subsystem.c +++ b/lib/iscsi/iscsi_subsystem.c @@ -1155,10 +1155,6 @@ spdk_iscsi_fini(spdk_iscsi_fini_cb cb_fn, void *cb_arg) static void iscsi_fini_done(void *io_device) { - free(g_iscsi.authfile); - free(g_iscsi.nodebase); - - pthread_mutex_destroy(&g_iscsi.mutex); g_fini_cb_fn(g_fini_cb_arg); } @@ -1176,7 +1172,20 @@ _iscsi_fini_dev_unreg(struct spdk_io_channel_iter *i, int status) iscsi_portal_grps_destroy(); iscsi_auth_groups_destroy(); - spdk_io_device_unregister(&g_iscsi, iscsi_fini_done); + free(g_iscsi.authfile); + free(g_iscsi.nodebase); + + pthread_mutex_destroy(&g_iscsi.mutex); + if (g_init_thread != NULL) { + /* g_init_thread is set just after the io_device is + * registered, so we can use it to determine if it + * needs to be unregistered (in cases where iscsi init + * fails). + */ + spdk_io_device_unregister(&g_iscsi, iscsi_fini_done); + } else { + iscsi_fini_done(NULL); + } } static void