diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 38e618ff4..987c15c59 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -43,12 +43,6 @@ #include "spdk_internal/memory.h" -struct vhost_poll_group { - struct spdk_thread *thread; - unsigned ref; - TAILQ_ENTRY(vhost_poll_group) tailq; -}; - static TAILQ_HEAD(, vhost_poll_group) g_poll_groups = TAILQ_HEAD_INITIALIZER(g_poll_groups); /* Temporary cpuset for poll group assignment */ @@ -893,11 +887,27 @@ vhost_get_poll_group(struct spdk_cpuset *cpumask) return selected_pg; } +static struct vhost_poll_group * +_get_current_poll_group(void) +{ + struct vhost_poll_group *pg; + struct spdk_thread *cur_thread = spdk_get_thread(); + + TAILQ_FOREACH(pg, &g_poll_groups, tailq) { + if (pg->thread == cur_thread) { + return pg; + } + } + + return NULL; +} + void vhost_session_start_done(struct spdk_vhost_session *vsession, int response) { if (response == 0) { vsession->started = true; + vsession->poll_group = _get_current_poll_group(); assert(vsession->poll_group != NULL); assert(vsession->poll_group->ref < UINT_MAX); vsession->poll_group->ref++; @@ -958,7 +968,6 @@ vhost_session_send_event(struct vhost_poll_group *pg, ev_ctx.vsession_id = vsession->id; ev_ctx.cb_fn = cb_fn; - vsession->poll_group = pg; spdk_thread_send_msg(pg->thread, vhost_event_cb, &ev_ctx); pthread_mutex_unlock(&g_vhost_mutex); diff --git a/lib/vhost/vhost_internal.h b/lib/vhost/vhost_internal.h index 0f46649d1..32011e086 100644 --- a/lib/vhost/vhost_internal.h +++ b/lib/vhost/vhost_internal.h @@ -94,7 +94,11 @@ #define SPDK_VHOST_DISABLED_FEATURES ((1ULL << VIRTIO_RING_F_EVENT_IDX) | \ (1ULL << VIRTIO_F_NOTIFY_ON_EMPTY)) -struct vhost_poll_group; +struct vhost_poll_group { + struct spdk_thread *thread; + unsigned ref; + TAILQ_ENTRY(vhost_poll_group) tailq; +}; struct spdk_vhost_virtqueue { struct rte_vhost_vring vring;