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: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/439444
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
This commit is contained in:
Darek Stojaczyk 2019-01-08 00:38:48 +01:00 committed by Ben Walker
parent 70b86ec995
commit fb98b0e519

View File

@ -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_event_ctx *ctx = arg1;
struct spdk_vhost_dev *vdev; struct spdk_vhost_dev *vdev;
struct spdk_event *ev; struct spdk_event *ev;
int rc;
if (pthread_mutex_trylock(&g_spdk_vhost_mutex) != 0) { if (pthread_mutex_trylock(&g_spdk_vhost_mutex) != 0) {
ev = spdk_event_allocate(spdk_env_get_current_core(), ev = spdk_event_allocate(spdk_env_get_current_core(),
@ -952,13 +953,16 @@ spdk_vhost_event_async_foreach_fn(void *arg1, void *arg2)
return; return;
} }
ctx->cb_fn(vdev, arg2); rc = ctx->cb_fn(vdev, arg2);
if (rc < 0) {
goto out_unlock_return;
}
out_unlock_continue: out_unlock_continue:
vdev = spdk_vhost_dev_next(ctx->vdev_id); vdev = spdk_vhost_dev_next(ctx->vdev_id);
spdk_vhost_external_event_foreach_continue(vdev, ctx->cb_fn, arg2); spdk_vhost_external_event_foreach_continue(vdev, ctx->cb_fn, arg2);
out_unlock_return:
pthread_mutex_unlock(&g_spdk_vhost_mutex); pthread_mutex_unlock(&g_spdk_vhost_mutex);
free(ctx); free(ctx);
} }
@ -1346,13 +1350,19 @@ static void
spdk_vhost_external_event_foreach_continue(struct spdk_vhost_dev *vdev, spdk_vhost_external_event_foreach_continue(struct spdk_vhost_dev *vdev,
spdk_vhost_event_fn fn, void *arg) spdk_vhost_event_fn fn, void *arg)
{ {
int rc;
if (vdev == NULL) { if (vdev == NULL) {
fn(NULL, arg); fn(NULL, arg);
return; return;
} }
while (vdev->lcore == -1) { while (vdev->lcore == -1) {
fn(vdev, arg); rc = fn(vdev, arg);
if (rc < 0) {
return;
}
vdev = spdk_vhost_dev_next(vdev->id); vdev = spdk_vhost_dev_next(vdev->id);
if (vdev == NULL) { if (vdev == NULL) {
fn(NULL, arg); fn(NULL, arg);