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 <james.r.harris@intel.com>
Change-Id: Ic9443564ef67b9c0df0fce47a346f4608749c306

Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8351
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Ziye Yang <ziye.yang@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Jim Harris 2021-06-15 08:58:22 -07:00 committed by Tomasz Zawadzki
parent b4af31de92
commit d5af6a0417

View File

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