lib/vhost: rename device stop function calls
Existing `vhost_user_session_send_event` is only used to stop vhost user device's session now, so we rename it to `vhost_user_wait_for_session_stop` and also rename the whole function calls when stopping the device with more apposite names. Change-Id: Ib8ea48273e85f7856ca2dfca57b5fd933ac4cf7a Signed-off-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15296 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
73f06e0d57
commit
b0df03c531
@ -53,6 +53,9 @@ struct vhost_session_fn_ctx {
|
||||
void *user_ctx;
|
||||
};
|
||||
|
||||
static int vhost_user_wait_for_session_stop(struct spdk_vhost_session *vsession,
|
||||
unsigned timeout_sec, const char *errmsg);
|
||||
|
||||
static void
|
||||
__attribute__((constructor))
|
||||
_vhost_user_sem_init(void)
|
||||
@ -857,13 +860,11 @@ vhost_register_memtable_if_required(struct spdk_vhost_session *vsession, int vid
|
||||
static int
|
||||
_stop_session(struct spdk_vhost_session *vsession)
|
||||
{
|
||||
struct spdk_vhost_dev *vdev = vsession->vdev;
|
||||
struct spdk_vhost_user_dev *user_vdev = to_user_dev(vdev);
|
||||
struct spdk_vhost_virtqueue *q;
|
||||
int rc;
|
||||
uint16_t i;
|
||||
|
||||
rc = user_vdev->user_backend->stop_session(vsession);
|
||||
rc = vhost_user_wait_for_session_stop(vsession, 3, "stop session");
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("Couldn't stop device with vid %d.\n", vsession->vid);
|
||||
return rc;
|
||||
@ -1273,13 +1274,6 @@ wait_for_semaphore(int timeout_sec, const char *errmsg)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
vhost_session_cb_done(int rc)
|
||||
{
|
||||
g_dpdk_response = rc;
|
||||
sem_post(&g_dpdk_sem);
|
||||
}
|
||||
|
||||
void
|
||||
vhost_user_session_stop_done(struct spdk_vhost_session *vsession, int response)
|
||||
{
|
||||
@ -1287,11 +1281,12 @@ vhost_user_session_stop_done(struct spdk_vhost_session *vsession, int response)
|
||||
vsession->started = false;
|
||||
}
|
||||
|
||||
vhost_session_cb_done(response);
|
||||
g_dpdk_response = response;
|
||||
sem_post(&g_dpdk_sem);
|
||||
}
|
||||
|
||||
static void
|
||||
vhost_event_cb(void *arg1)
|
||||
vhost_user_session_stop_event(void *arg1)
|
||||
{
|
||||
struct vhost_session_fn_ctx *ctx = arg1;
|
||||
struct spdk_vhost_dev *vdev = ctx->vdev;
|
||||
@ -1299,19 +1294,18 @@ vhost_event_cb(void *arg1)
|
||||
struct spdk_vhost_session *vsession;
|
||||
|
||||
if (pthread_mutex_trylock(&user_dev->lock) != 0) {
|
||||
spdk_thread_send_msg(spdk_get_thread(), vhost_event_cb, arg1);
|
||||
spdk_thread_send_msg(spdk_get_thread(), vhost_user_session_stop_event, arg1);
|
||||
return;
|
||||
}
|
||||
|
||||
vsession = vhost_session_find_by_id(vdev, ctx->vsession_id);
|
||||
ctx->cb_fn(vdev, vsession, NULL);
|
||||
user_dev->user_backend->stop_session(vdev, vsession, NULL);
|
||||
pthread_mutex_unlock(&user_dev->lock);
|
||||
}
|
||||
|
||||
int
|
||||
vhost_user_session_send_event(struct spdk_vhost_session *vsession,
|
||||
spdk_vhost_session_fn cb_fn, unsigned timeout_sec,
|
||||
const char *errmsg)
|
||||
static int
|
||||
vhost_user_wait_for_session_stop(struct spdk_vhost_session *vsession,
|
||||
unsigned timeout_sec, const char *errmsg)
|
||||
{
|
||||
struct vhost_session_fn_ctx ev_ctx = {0};
|
||||
struct spdk_vhost_dev *vdev = vsession->vdev;
|
||||
@ -1319,9 +1313,8 @@ vhost_user_session_send_event(struct spdk_vhost_session *vsession,
|
||||
|
||||
ev_ctx.vdev = vdev;
|
||||
ev_ctx.vsession_id = vsession->id;
|
||||
ev_ctx.cb_fn = cb_fn;
|
||||
|
||||
spdk_thread_send_msg(vdev->thread, vhost_event_cb, &ev_ctx);
|
||||
spdk_thread_send_msg(vdev->thread, vhost_user_session_stop_event, &ev_ctx);
|
||||
|
||||
pthread_mutex_unlock(&user_dev->lock);
|
||||
wait_for_semaphore(timeout_sec, errmsg);
|
||||
|
@ -1397,7 +1397,7 @@ destroy_session_poller_cb(void *arg)
|
||||
}
|
||||
|
||||
static int
|
||||
vhost_blk_stop_cb(struct spdk_vhost_dev *vdev,
|
||||
vhost_blk_stop(struct spdk_vhost_dev *vdev,
|
||||
struct spdk_vhost_session *vsession, void *unused)
|
||||
{
|
||||
struct spdk_vhost_blk_session *bvsession = to_blk_session(vsession);
|
||||
@ -1420,13 +1420,6 @@ vhost_blk_stop_cb(struct spdk_vhost_dev *vdev,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
vhost_blk_stop(struct spdk_vhost_session *vsession)
|
||||
{
|
||||
return vhost_user_session_send_event(vsession, vhost_blk_stop_cb,
|
||||
3, "stop session");
|
||||
}
|
||||
|
||||
static void
|
||||
vhost_blk_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w)
|
||||
{
|
||||
|
@ -222,7 +222,7 @@ struct spdk_vhost_user_dev_backend {
|
||||
size_t session_ctx_size;
|
||||
|
||||
spdk_vhost_session_fn start_session;
|
||||
int (*stop_session)(struct spdk_vhost_session *vsession);
|
||||
spdk_vhost_session_fn stop_session;
|
||||
int (*alloc_vq_tasks)(struct spdk_vhost_session *vsession, uint16_t qid);
|
||||
};
|
||||
|
||||
@ -435,49 +435,13 @@ void vhost_user_dev_foreach_session(struct spdk_vhost_dev *dev,
|
||||
void *arg);
|
||||
|
||||
/**
|
||||
* Call a function on the provided lcore and block until either
|
||||
* vhost_user_session_start_done() or vhost_user_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. 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
|
||||
* 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
|
||||
* \return return the code passed to spdk_vhost_session_event_done().
|
||||
*/
|
||||
int vhost_user_session_send_event(struct spdk_vhost_session *vsession,
|
||||
spdk_vhost_session_fn cb_fn, unsigned timeout_sec,
|
||||
const char *errmsg);
|
||||
|
||||
/**
|
||||
* Finish a blocking spdk_vhost_user_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
|
||||
* vhost_user_dev_foreach_session()).
|
||||
*
|
||||
* Must be called under the global vhost lock.
|
||||
*
|
||||
* \param vsession vhost session
|
||||
* \param response return code
|
||||
*/
|
||||
void vhost_user_session_start_done(struct spdk_vhost_session *vsession, int response);
|
||||
|
||||
/**
|
||||
* Finish a blocking spdk_vhost_user_session_send_event() call and finally
|
||||
* Finish a blocking vhost_user_wait_for_session_stop() 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
|
||||
* vhost_user_dev_foreach_session()). After this call, the session-
|
||||
* related messages will be once again processed by any arbitrary thread.
|
||||
*
|
||||
* Must be called under the global vhost lock.
|
||||
*
|
||||
* Must be called under the global vhost mutex.
|
||||
* Must be called under the vhost user device's session access lock.
|
||||
*
|
||||
* \param vsession vhost session
|
||||
* \param response return code
|
||||
|
@ -114,7 +114,8 @@ struct spdk_vhost_scsi_task {
|
||||
|
||||
static int vhost_scsi_start(struct spdk_vhost_dev *vdev,
|
||||
struct spdk_vhost_session *vsession, void *unused);
|
||||
static int vhost_scsi_stop(struct spdk_vhost_session *vsession);
|
||||
static int vhost_scsi_stop(struct spdk_vhost_dev *vdev,
|
||||
struct spdk_vhost_session *vsession, void *unused);
|
||||
static void vhost_scsi_dump_info_json(struct spdk_vhost_dev *vdev,
|
||||
struct spdk_json_write_ctx *w);
|
||||
static void vhost_scsi_write_config_json(struct spdk_vhost_dev *vdev,
|
||||
@ -1473,7 +1474,7 @@ destroy_session_poller_cb(void *arg)
|
||||
}
|
||||
|
||||
static int
|
||||
vhost_scsi_stop_cb(struct spdk_vhost_dev *vdev,
|
||||
vhost_scsi_stop(struct spdk_vhost_dev *vdev,
|
||||
struct spdk_vhost_session *vsession, void *unused)
|
||||
{
|
||||
struct spdk_vhost_scsi_session *svsession = to_scsi_session(vsession);
|
||||
@ -1504,13 +1505,6 @@ vhost_scsi_stop_cb(struct spdk_vhost_dev *vdev,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
vhost_scsi_stop(struct spdk_vhost_session *vsession)
|
||||
{
|
||||
return vhost_user_session_send_event(vsession, vhost_scsi_stop_cb,
|
||||
3, "stop session");
|
||||
}
|
||||
|
||||
static void
|
||||
vhost_scsi_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user