Commit d476d106 authored by Darek Stojaczyk's avatar Darek Stojaczyk
Browse files

vhost: reorder foreach_sesion_continue



Put it next to other functions in this call chain.

Change-Id: Ic621855b028f9bd110cdcda86b3a182369ec5e90
Signed-off-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459165


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent 74243e36
Loading
Loading
Loading
Loading
+62 −62
Original line number Diff line number Diff line
@@ -1019,6 +1019,68 @@ out_unlock:
	free(ctx);
}

static void
foreach_session_continue(struct spdk_vhost_dev *vdev,
			 struct spdk_vhost_session *vsession,
			 spdk_vhost_session_fn fn, void *arg)
{
	struct spdk_vhost_session_fn_ctx *ev_ctx;
	int rc;

	if (vsession == NULL) {
		goto out_finish_foreach;
	}

	while (!vsession->started) {
		if (vsession->initialized) {
			rc = fn(vdev, vsession, arg);
			if (rc < 0) {
				return;
			}
		}

		vsession = spdk_vhost_session_next(vdev, vsession->id);
		if (vsession == NULL) {
			goto out_finish_foreach;
		}
	}

	ev_ctx = calloc(1, sizeof(*ev_ctx));
	if (ev_ctx == NULL) {
		SPDK_ERRLOG("Failed to alloc vhost event.\n");
		assert(false);
		return;
	}

	ev_ctx->vdev = vdev;
	ev_ctx->vsession_id = vsession->id;
	ev_ctx->cb_fn = fn;
	ev_ctx->user_ctx = arg;

	spdk_thread_send_msg(vsession->poll_group->thread,
			     foreach_session_continue_cb, ev_ctx);
	return;

out_finish_foreach:
	/* there are no more sessions to iterate through, so call the
	 * fn one last time with vsession == NULL
	 */
	assert(vdev->pending_async_op_num > 0);
	vdev->pending_async_op_num--;
	fn(vdev, NULL, arg);
}

void
spdk_vhost_dev_foreach_session(struct spdk_vhost_dev *vdev,
			       spdk_vhost_session_fn fn, void *arg)
{
	struct spdk_vhost_session *vsession = TAILQ_FIRST(&vdev->vsessions);

	assert(vdev->pending_async_op_num < UINT32_MAX);
	vdev->pending_async_op_num++;
	foreach_session_continue(vdev, vsession, fn, arg);
}

static void
_stop_session(struct spdk_vhost_session *vsession)
{
@@ -1332,68 +1394,6 @@ destroy_connection(int vid)
	pthread_mutex_unlock(&g_spdk_vhost_mutex);
}

static void
foreach_session_continue(struct spdk_vhost_dev *vdev,
			 struct spdk_vhost_session *vsession,
			 spdk_vhost_session_fn fn, void *arg)
{
	struct spdk_vhost_session_fn_ctx *ev_ctx;
	int rc;

	if (vsession == NULL) {
		goto out_finish_foreach;
	}

	while (!vsession->started) {
		if (vsession->initialized) {
			rc = fn(vdev, vsession, arg);
			if (rc < 0) {
				return;
			}
		}

		vsession = spdk_vhost_session_next(vdev, vsession->id);
		if (vsession == NULL) {
			goto out_finish_foreach;
		}
	}

	ev_ctx = calloc(1, sizeof(*ev_ctx));
	if (ev_ctx == NULL) {
		SPDK_ERRLOG("Failed to alloc vhost event.\n");
		assert(false);
		return;
	}

	ev_ctx->vdev = vdev;
	ev_ctx->vsession_id = vsession->id;
	ev_ctx->cb_fn = fn;
	ev_ctx->user_ctx = arg;

	spdk_thread_send_msg(vsession->poll_group->thread,
			     foreach_session_continue_cb, ev_ctx);
	return;

out_finish_foreach:
	/* there are no more sessions to iterate through, so call the
	 * fn one last time with vsession == NULL
	 */
	assert(vdev->pending_async_op_num > 0);
	vdev->pending_async_op_num--;
	fn(vdev, NULL, arg);
}

void
spdk_vhost_dev_foreach_session(struct spdk_vhost_dev *vdev,
			       spdk_vhost_session_fn fn, void *arg)
{
	struct spdk_vhost_session *vsession = TAILQ_FIRST(&vdev->vsessions);

	assert(vdev->pending_async_op_num < UINT32_MAX);
	vdev->pending_async_op_num++;
	foreach_session_continue(vdev, vsession, fn, arg);
}

void
spdk_vhost_lock(void)
{