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 <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448228
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
Darek Stojaczyk 2019-03-17 13:08:25 +01:00 committed by Jim Harris
parent 64d76e50cc
commit 2cddd571ee
5 changed files with 49 additions and 18 deletions

View File

@ -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)
{

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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;