From 2cddd571eed3da4762900e3b530d00feb4bf88a1 Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Sun, 17 Mar 2019 13:08:25 +0100 Subject: [PATCH] vhost: add spdk_vhost_session_start_done/stop_done Split spdk_vhost_session_event_done() into two separate functions. This is just a preparation for the next patch. Change-Id: I05e046e4b963387f058d2b822d7493c761eebbbb Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448228 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu --- lib/vhost/vhost.c | 16 ++++++++++++++-- lib/vhost/vhost_blk.c | 6 +++--- lib/vhost/vhost_internal.h | 35 +++++++++++++++++++++++++++-------- lib/vhost/vhost_nvme.c | 6 +++--- lib/vhost/vhost_scsi.c | 4 ++-- 5 files changed, 49 insertions(+), 18 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index a0506fbc9..5b538f2ba 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -872,8 +872,8 @@ spdk_vhost_allocate_reactor(struct spdk_cpuset *cpumask) return selected_core; } -void -spdk_vhost_session_event_done(struct spdk_vhost_session *vsession, int response) +static void +complete_session_event(struct spdk_vhost_session *vsession, int response) { struct spdk_vhost_session_fn_ctx *ctx = vsession->event_ctx; @@ -881,6 +881,18 @@ spdk_vhost_session_event_done(struct spdk_vhost_session *vsession, int response) sem_post(&ctx->sem); } +void +spdk_vhost_session_start_done(struct spdk_vhost_session *vsession, int response) +{ + complete_session_event(vsession, response); +} + +void +spdk_vhost_session_stop_done(struct spdk_vhost_session *vsession, int response) +{ + complete_session_event(vsession, response); +} + static void spdk_vhost_event_cb(void *arg1, void *arg2) { diff --git a/lib/vhost/vhost_blk.c b/lib/vhost/vhost_blk.c index 7a73aa1fd..89c830159 100644 --- a/lib/vhost/vhost_blk.c +++ b/lib/vhost/vhost_blk.c @@ -722,7 +722,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(vsession, rc); + spdk_vhost_session_start_done(vsession, rc); return rc; } @@ -772,7 +772,7 @@ destroy_session_poller_cb(void *arg) free_task_pool(bvsession); spdk_poller_unregister(&bvsession->stop_poller); - spdk_vhost_session_event_done(vsession, 0); + spdk_vhost_session_stop_done(vsession, 0); spdk_vhost_unlock(); return -1; @@ -796,7 +796,7 @@ spdk_vhost_blk_stop_cb(struct spdk_vhost_dev *vdev, return 0; err: - spdk_vhost_session_event_done(vsession, -1); + spdk_vhost_session_stop_done(vsession, -1); return -1; } diff --git a/lib/vhost/vhost_internal.h b/lib/vhost/vhost_internal.h index a62c0db19..46d5f3f65 100644 --- a/lib/vhost/vhost_internal.h +++ b/lib/vhost/vhost_internal.h @@ -318,13 +318,13 @@ void spdk_vhost_dev_foreach_session(struct spdk_vhost_dev *dev, spdk_vhost_session_fn fn, void *arg); /** - * Call the provided function on the session's lcore and block until - * spdk_vhost_session_event_done() is called. + * Call a function on the provided session's lcore and block until either + * spdk_vhost_session_start_done() or spdk_vhost_session_stop_done() + * is called. * * This must be called under the global vhost mutex, which this function - * will unlock for the time it's waiting. This makes it prone to data races, - * so practically it is only useful for session start/stop and still - * has to be used with extra caution. + * will unlock for the time it's waiting. It's meant to be called only + * from start/stop session callbacks. * * \param vsession vhost session * \param cb_fn the function to call. The void *arg parameter in cb_fn @@ -335,17 +335,36 @@ void spdk_vhost_dev_foreach_session(struct spdk_vhost_dev *dev, * \return return the code passed to spdk_vhost_session_event_done(). */ int spdk_vhost_session_send_event(struct spdk_vhost_session *vsession, - spdk_vhost_session_fn cb_fn, unsigned timeout_sec, const char *errmsg); + spdk_vhost_session_fn cb_fn, unsigned timeout_sec, + const char *errmsg); /** - * Finish a blocking spdk_vhost_session_send_event() call. + * Finish a blocking spdk_vhost_session_send_event() call and finally + * start the session. This must be called on the target lcore, which + * will now receive all session-related messages (e.g. from + * spdk_vhost_dev_foreach_session()). + * + * Must be called under the global vhost lock. + * + * \param vsession vhost session + * \param response return code + */ +void spdk_vhost_session_start_done(struct spdk_vhost_session *vsession, int response); + +/** + * Finish a blocking spdk_vhost_session_send_event() call and finally + * stop the session. This must be called on the session's lcore which + * used to receive all session-related messages (e.g. from + * spdk_vhost_dev_foreach_session()). + * + * Must be called under the global vhost lock. * * Must be called under the global vhost mutex. * * \param vsession vhost session * \param response return code */ -void spdk_vhost_session_event_done(struct spdk_vhost_session *vsession, int response); +void spdk_vhost_session_stop_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); diff --git a/lib/vhost/vhost_nvme.c b/lib/vhost/vhost_nvme.c index 5097785b0..fa519de5d 100644 --- a/lib/vhost/vhost_nvme.c +++ b/lib/vhost/vhost_nvme.c @@ -1106,7 +1106,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(vsession, 0); + spdk_vhost_session_start_done(vsession, 0); return 0; } @@ -1186,7 +1186,7 @@ destroy_device_poller_cb(void *arg) nvme->dataplane_started = false; spdk_poller_unregister(&nvme->stop_poller); - spdk_vhost_session_event_done(nvme->vsession, 0); + spdk_vhost_session_stop_done(nvme->vsession, 0); spdk_vhost_unlock(); return -1; @@ -1199,7 +1199,7 @@ spdk_vhost_nvme_stop_cb(struct spdk_vhost_dev *vdev, struct spdk_vhost_nvme_dev *nvme = to_nvme_dev(vdev); if (nvme == NULL) { - spdk_vhost_session_event_done(vsession, -1); + spdk_vhost_session_stop_done(vsession, -1); return -1; } diff --git a/lib/vhost/vhost_scsi.c b/lib/vhost/vhost_scsi.c index 6d87f7119..515dbce05 100644 --- a/lib/vhost/vhost_scsi.c +++ b/lib/vhost/vhost_scsi.c @@ -1314,7 +1314,7 @@ spdk_vhost_scsi_start_cb(struct spdk_vhost_dev *vdev, MGMT_POLL_PERIOD_US); } out: - spdk_vhost_session_event_done(vsession, rc); + spdk_vhost_session_start_done(vsession, rc); return rc; } @@ -1387,7 +1387,7 @@ destroy_session_poller_cb(void *arg) free_task_pool(svsession); spdk_poller_unregister(&svsession->stop_poller); - spdk_vhost_session_event_done(vsession, 0); + spdk_vhost_session_stop_done(vsession, 0); spdk_vhost_unlock(); return -1;