vhost: reorder foreach_sesion_continue
Put it next to other functions in this call chain. Change-Id: Ic621855b028f9bd110cdcda86b3a182369ec5e90 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459165 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
74243e36b9
commit
d476d10665
@ -1019,6 +1019,68 @@ out_unlock:
|
|||||||
free(ctx);
|
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
|
static void
|
||||||
_stop_session(struct spdk_vhost_session *vsession)
|
_stop_session(struct spdk_vhost_session *vsession)
|
||||||
{
|
{
|
||||||
@ -1332,68 +1394,6 @@ destroy_connection(int vid)
|
|||||||
pthread_mutex_unlock(&g_spdk_vhost_mutex);
|
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
|
void
|
||||||
spdk_vhost_lock(void)
|
spdk_vhost_lock(void)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user