From 5fb7330151a740c8da8c0376524f5521ee79606f Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Mon, 24 Jun 2019 09:00:19 +0200 Subject: [PATCH] vhost: introduce g_vhost_init_thread Enforce spdk_vhost_fini() to be called on the same thread which called spdk_vhost_init(). We'll also use the newly added g_vhost_init_thread for other purposes later on. Change-Id: I99aebeda2d8ddaf42554aa422c32ed935634595f Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459159 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker --- lib/vhost/vhost.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 255be107a..d965a3748 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -57,7 +57,9 @@ static struct spdk_cpuset *g_tmp_cpuset; /* Path to folder where character device will be created. Can be set by user. */ static char dev_dirname[PATH_MAX] = ""; -static struct spdk_thread *g_fini_thread; +/* Thread performing all vhost management operations */ +static struct spdk_thread *g_vhost_init_thread; + static spdk_vhost_fini_cb g_fini_cpl_cb; struct spdk_vhost_session_fn_ctx { @@ -1489,6 +1491,9 @@ spdk_vhost_init(spdk_vhost_init_cb init_cb) size_t len; int ret; + g_vhost_init_thread = spdk_get_thread(); + assert(g_vhost_init_thread != NULL); + if (dev_dirname[0] == '\0') { if (getcwd(dev_dirname, sizeof(dev_dirname) - 1) == NULL) { SPDK_ERRLOG("getcwd failed (%d): %s\n", errno, spdk_strerror(errno)); @@ -1553,7 +1558,7 @@ session_shutdown(void *arg) } SPDK_INFOLOG(SPDK_LOG_VHOST, "Exiting\n"); - spdk_thread_send_msg(g_fini_thread, _spdk_vhost_fini, NULL); + spdk_thread_send_msg(g_vhost_init_thread, _spdk_vhost_fini, NULL); return NULL; } @@ -1563,7 +1568,7 @@ spdk_vhost_fini(spdk_vhost_fini_cb fini_cb) pthread_t tid; int rc; - g_fini_thread = spdk_get_thread(); + assert(spdk_get_thread() == g_vhost_init_thread); g_fini_cpl_cb = fini_cb; /* rte_vhost API for removing sockets is not asynchronous. Since it may call SPDK