vhost: encapsulate synchronous event ctx within the generic vhost layer
The context had to be previously carried around by particular vhost backend code and now it's embedded inside the generic vsession struct. This serves mostly as a cleanup. Change-Id: I7b6ac2c3cb5d60a035d56affbf42fe5d4697f0f6 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448223 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
parent
880b8b8af3
commit
3b760a4d09
@ -865,9 +865,9 @@ spdk_vhost_allocate_reactor(struct spdk_cpuset *cpumask)
|
||||
}
|
||||
|
||||
void
|
||||
spdk_vhost_session_event_done(void *event_ctx, int response)
|
||||
spdk_vhost_session_event_done(struct spdk_vhost_session *vsession, int response)
|
||||
{
|
||||
struct spdk_vhost_session_fn_ctx *ctx = event_ctx;
|
||||
struct spdk_vhost_session_fn_ctx *ctx = vsession->event_ctx;
|
||||
|
||||
ctx->response = response;
|
||||
sem_post(&ctx->sem);
|
||||
@ -880,7 +880,7 @@ spdk_vhost_event_cb(void *arg1, void *arg2)
|
||||
struct spdk_vhost_session *vsession;
|
||||
|
||||
vsession = spdk_vhost_session_find_by_id(ctx->vdev, ctx->vsession_id);
|
||||
ctx->cb_fn(ctx->vdev, vsession, ctx);
|
||||
ctx->cb_fn(ctx->vdev, vsession, NULL);
|
||||
}
|
||||
|
||||
static void spdk_vhost_external_event_foreach_continue(struct spdk_vhost_dev *vdev,
|
||||
@ -957,6 +957,8 @@ spdk_vhost_session_send_event(struct spdk_vhost_session *vsession,
|
||||
ev_ctx.vdev = vsession->vdev;
|
||||
ev_ctx.vsession_id = vsession->id;
|
||||
ev_ctx.cb_fn = cb_fn;
|
||||
|
||||
vsession->event_ctx = &ev_ctx;
|
||||
ev = spdk_event_allocate(vsession->lcore, spdk_vhost_event_cb, &ev_ctx, NULL);
|
||||
assert(ev);
|
||||
spdk_event_call(ev);
|
||||
@ -973,6 +975,7 @@ spdk_vhost_session_send_event(struct spdk_vhost_session *vsession,
|
||||
|
||||
sem_destroy(&ev_ctx.sem);
|
||||
pthread_mutex_lock(&g_spdk_vhost_mutex);
|
||||
vsession->event_ctx = NULL;
|
||||
return ev_ctx.response;
|
||||
}
|
||||
|
||||
|
@ -674,7 +674,7 @@ alloc_task_pool(struct spdk_vhost_blk_session *bvsession)
|
||||
|
||||
static int
|
||||
spdk_vhost_blk_start_cb(struct spdk_vhost_dev *vdev,
|
||||
struct spdk_vhost_session *vsession, void *event_ctx)
|
||||
struct spdk_vhost_session *vsession, void *unused)
|
||||
{
|
||||
struct spdk_vhost_blk_dev *bvdev;
|
||||
struct spdk_vhost_blk_session *bvsession;
|
||||
@ -721,7 +721,7 @@ spdk_vhost_blk_start_cb(struct spdk_vhost_dev *vdev,
|
||||
SPDK_INFOLOG(SPDK_LOG_VHOST, "Started poller for vhost controller %s on lcore %d\n",
|
||||
vdev->name, vsession->lcore);
|
||||
out:
|
||||
spdk_vhost_session_event_done(event_ctx, rc);
|
||||
spdk_vhost_session_event_done(vsession, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -767,14 +767,14 @@ destroy_session_poller_cb(void *arg)
|
||||
|
||||
free_task_pool(bvsession);
|
||||
spdk_poller_unregister(&bvsession->destroy_ctx.poller);
|
||||
spdk_vhost_session_event_done(bvsession->destroy_ctx.event_ctx, 0);
|
||||
spdk_vhost_session_event_done(vsession, 0);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
spdk_vhost_blk_stop_cb(struct spdk_vhost_dev *vdev,
|
||||
struct spdk_vhost_session *vsession, void *event_ctx)
|
||||
struct spdk_vhost_session *vsession, void *unused)
|
||||
{
|
||||
struct spdk_vhost_blk_session *bvsession;
|
||||
|
||||
@ -784,14 +784,13 @@ spdk_vhost_blk_stop_cb(struct spdk_vhost_dev *vdev,
|
||||
goto err;
|
||||
}
|
||||
|
||||
bvsession->destroy_ctx.event_ctx = event_ctx;
|
||||
spdk_poller_unregister(&bvsession->requestq_poller);
|
||||
bvsession->destroy_ctx.poller = spdk_poller_register(destroy_session_poller_cb,
|
||||
bvsession, 1000);
|
||||
return 0;
|
||||
|
||||
err:
|
||||
spdk_vhost_session_event_done(event_ctx, -1);
|
||||
spdk_vhost_session_event_done(vsession, -1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -150,6 +150,8 @@ struct spdk_vhost_session {
|
||||
struct spdk_vhost_virtqueue virtqueue[SPDK_VHOST_MAX_VQUEUES];
|
||||
|
||||
TAILQ_ENTRY(spdk_vhost_session) tailq;
|
||||
|
||||
struct spdk_vhost_session_fn_ctx *event_ctx;
|
||||
};
|
||||
|
||||
struct spdk_vhost_dev {
|
||||
@ -184,7 +186,6 @@ struct spdk_vhost_dev {
|
||||
|
||||
struct spdk_vhost_dev_destroy_ctx {
|
||||
struct spdk_poller *poller;
|
||||
void *event_ctx;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -331,7 +332,7 @@ void spdk_vhost_dev_foreach_session(struct spdk_vhost_dev *dev,
|
||||
*
|
||||
* \param vsession vhost session
|
||||
* \param cb_fn the function to call. The void *arg parameter in cb_fn
|
||||
* must be passed to spdk_vhost_session_event_done().
|
||||
* is always NULL.
|
||||
* \param timeout_sec timeout in seconds. This function will still
|
||||
* block after the timeout expires, but will print the provided errmsg.
|
||||
* \param errmsg error message to print once the timeout expires
|
||||
@ -343,10 +344,10 @@ int spdk_vhost_session_send_event(struct spdk_vhost_session *vsession,
|
||||
/**
|
||||
* Finish a blocking spdk_vhost_session_send_event() call.
|
||||
*
|
||||
* \param event_ctx event context
|
||||
* \param vsession vhost session
|
||||
* \param response return code
|
||||
*/
|
||||
void spdk_vhost_session_event_done(void *event_ctx, int response);
|
||||
void spdk_vhost_session_event_done(struct spdk_vhost_session *vsession, int response);
|
||||
|
||||
struct spdk_vhost_session *spdk_vhost_session_find_by_vid(int vid);
|
||||
void spdk_vhost_session_install_rte_compat_hooks(struct spdk_vhost_session *vsession);
|
||||
|
@ -1076,7 +1076,7 @@ alloc_task_pool(struct spdk_vhost_nvme_dev *nvme)
|
||||
|
||||
static int
|
||||
spdk_vhost_nvme_start_cb(struct spdk_vhost_dev *vdev,
|
||||
struct spdk_vhost_session *vsession, void *event_ctx)
|
||||
struct spdk_vhost_session *vsession, void *unused)
|
||||
{
|
||||
struct spdk_vhost_nvme_dev *nvme = to_nvme_dev(vdev);
|
||||
struct spdk_vhost_nvme_ns *ns_dev;
|
||||
@ -1105,7 +1105,7 @@ spdk_vhost_nvme_start_cb(struct spdk_vhost_dev *vdev,
|
||||
/* Start the NVMe Poller */
|
||||
nvme->requestq_poller = spdk_poller_register(nvme_worker, nvme, 0);
|
||||
|
||||
spdk_vhost_session_event_done(event_ctx, 0);
|
||||
spdk_vhost_session_event_done(vsession, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1184,14 +1184,14 @@ destroy_device_poller_cb(void *arg)
|
||||
}
|
||||
|
||||
spdk_poller_unregister(&nvme->destroy_ctx.poller);
|
||||
spdk_vhost_session_event_done(nvme->destroy_ctx.event_ctx, 0);
|
||||
spdk_vhost_session_event_done(nvme->vsession, 0);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
spdk_vhost_nvme_stop_cb(struct spdk_vhost_dev *vdev,
|
||||
struct spdk_vhost_session *vsession, void *event_ctx)
|
||||
struct spdk_vhost_session *vsession, void *unused)
|
||||
{
|
||||
struct spdk_vhost_nvme_dev *nvme = to_nvme_dev(vdev);
|
||||
|
||||
@ -1202,7 +1202,6 @@ spdk_vhost_nvme_stop_cb(struct spdk_vhost_dev *vdev,
|
||||
free_task_pool(nvme);
|
||||
SPDK_NOTICELOG("Stopping Device %u, Path %s\n", vsession->vid, vdev->path);
|
||||
|
||||
nvme->destroy_ctx.event_ctx = event_ctx;
|
||||
spdk_poller_unregister(&nvme->requestq_poller);
|
||||
nvme->destroy_ctx.poller = spdk_poller_register(destroy_device_poller_cb, nvme, 1000);
|
||||
|
||||
|
@ -1258,7 +1258,7 @@ alloc_task_pool(struct spdk_vhost_scsi_session *svsession)
|
||||
|
||||
static int
|
||||
spdk_vhost_scsi_start_cb(struct spdk_vhost_dev *vdev,
|
||||
struct spdk_vhost_session *vsession, void *event_ctx)
|
||||
struct spdk_vhost_session *vsession, void *unused)
|
||||
{
|
||||
struct spdk_vhost_scsi_dev *svdev;
|
||||
struct spdk_vhost_scsi_session *svsession;
|
||||
@ -1313,7 +1313,7 @@ spdk_vhost_scsi_start_cb(struct spdk_vhost_dev *vdev,
|
||||
MGMT_POLL_PERIOD_US);
|
||||
}
|
||||
out:
|
||||
spdk_vhost_session_event_done(event_ctx, rc);
|
||||
spdk_vhost_session_event_done(vsession, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -1383,20 +1383,19 @@ destroy_session_poller_cb(void *arg)
|
||||
free_task_pool(svsession);
|
||||
|
||||
spdk_poller_unregister(&svsession->destroy_ctx.poller);
|
||||
spdk_vhost_session_event_done(svsession->destroy_ctx.event_ctx, 0);
|
||||
spdk_vhost_session_event_done(vsession, 0);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
spdk_vhost_scsi_stop_cb(struct spdk_vhost_dev *vdev,
|
||||
struct spdk_vhost_session *vsession, void *event_ctx)
|
||||
struct spdk_vhost_session *vsession, void *unused)
|
||||
{
|
||||
struct spdk_vhost_scsi_session *svsession;
|
||||
|
||||
svsession = to_scsi_session(vsession);
|
||||
assert(svsession != NULL);
|
||||
svsession->destroy_ctx.event_ctx = event_ctx;
|
||||
spdk_poller_unregister(&svsession->requestq_poller);
|
||||
spdk_poller_unregister(&svsession->mgmt_poller);
|
||||
svsession->destroy_ctx.poller = spdk_poller_register(destroy_session_poller_cb,
|
||||
|
Loading…
Reference in New Issue
Block a user