Commit 0a992c64 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

lib/vhost: Fix passing wrong data to callback to vhost_dev_foreach_session()



Not context passed to vhost_dev_for_each_session() but struct
spdk_vhost_session had been passed to the callback to
vhost_dev_for_each_session() by mistake.

This patch fixes the bug. Besides, rename ctx by ev_ctx to avoid
potential future degradation.

Fixes issue #1306.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I8ceed4e1bb7c0c27fb75516527e3bad91a054b02
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1432


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKarol Latecki <karol.latecki@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
parent 89519ebc
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -793,8 +793,8 @@ vhost_session_send_event(struct spdk_vhost_session *vsession,
static void
foreach_session_finish_cb(void *arg1)
{
	struct vhost_session_fn_ctx *ctx = arg1;
	struct spdk_vhost_dev *vdev = ctx->vdev;
	struct vhost_session_fn_ctx *ev_ctx = arg1;
	struct spdk_vhost_dev *vdev = ev_ctx->vdev;

	if (pthread_mutex_trylock(&g_vhost_mutex) != 0) {
		spdk_thread_send_msg(spdk_get_thread(),
@@ -804,20 +804,20 @@ foreach_session_finish_cb(void *arg1)

	assert(vdev->pending_async_op_num > 0);
	vdev->pending_async_op_num--;
	if (ctx->cpl_fn != NULL) {
		ctx->cpl_fn(vdev, ctx->user_ctx);
	if (ev_ctx->cpl_fn != NULL) {
		ev_ctx->cpl_fn(vdev, ev_ctx->user_ctx);
	}

	pthread_mutex_unlock(&g_vhost_mutex);
	free(ctx);
	free(ev_ctx);
}

static void
foreach_session(void *arg1)
{
	struct vhost_session_fn_ctx *ctx = arg1;
	struct vhost_session_fn_ctx *ev_ctx = arg1;
	struct spdk_vhost_session *vsession;
	struct spdk_vhost_dev *vdev = ctx->vdev;
	struct spdk_vhost_dev *vdev = ev_ctx->vdev;
	int rc;

	if (pthread_mutex_trylock(&g_vhost_mutex) != 0) {
@@ -827,7 +827,7 @@ foreach_session(void *arg1)

	TAILQ_FOREACH(vsession, &vdev->vsessions, tailq) {
		if (vsession->initialized) {
			rc = ctx->cb_fn(vdev, vsession, ctx);
			rc = ev_ctx->cb_fn(vdev, vsession, ev_ctx->user_ctx);
			if (rc < 0) {
				goto out;
			}