Commit d5af6a04 authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

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: default avatarJim 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: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarPaul Luse <paul.e.luse@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarZiye Yang <ziye.yang@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
parent b4af31de
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -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();

	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