Commit fb98b0e5 authored by Darek Stojaczyk's avatar Darek Stojaczyk Committed by Ben Walker
Browse files

vhost: allow breaking from the external_event_foreach() chain



Returning negative value from a `foreach` callback
will now break the entire chain. This is required
for refactoring spdk_vhost_dev_foreach_session() to
use the same mechanism as external events. Before
we actually do the refactor, we add the only feature
that external events were missing.

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarPawel Wodkowski <pawelx.wodkowski@intel.com>
parent 70b86ec9
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -920,6 +920,7 @@ spdk_vhost_event_async_foreach_fn(void *arg1, void *arg2)
	struct spdk_vhost_dev_event_ctx *ctx = arg1;
	struct spdk_vhost_dev *vdev;
	struct spdk_event *ev;
	int rc;

	if (pthread_mutex_trylock(&g_spdk_vhost_mutex) != 0) {
		ev = spdk_event_allocate(spdk_env_get_current_core(),
@@ -952,13 +953,16 @@ spdk_vhost_event_async_foreach_fn(void *arg1, void *arg2)
		return;
	}

	ctx->cb_fn(vdev, arg2);
	rc = ctx->cb_fn(vdev, arg2);
	if (rc < 0) {
		goto out_unlock_return;
	}

out_unlock_continue:
	vdev = spdk_vhost_dev_next(ctx->vdev_id);
	spdk_vhost_external_event_foreach_continue(vdev, ctx->cb_fn, arg2);
out_unlock_return:
	pthread_mutex_unlock(&g_spdk_vhost_mutex);

	free(ctx);
}

@@ -1346,13 +1350,19 @@ static void
spdk_vhost_external_event_foreach_continue(struct spdk_vhost_dev *vdev,
		spdk_vhost_event_fn fn, void *arg)
{
	int rc;

	if (vdev == NULL) {
		fn(NULL, arg);
		return;
	}

	while (vdev->lcore == -1) {
		fn(vdev, arg);
		rc = fn(vdev, arg);
		if (rc < 0) {
			return;
		}

		vdev = spdk_vhost_dev_next(vdev->id);
		if (vdev == NULL) {
			fn(NULL, arg);