vhost: add a separate cpl cb to foreach_session()
Currently vhost_dev_foreach_session() accepts a single callback function for both iterating through all active sessions and for signaling the end of iteration (called last time with vsession param == NULL). Now that the final signal has completely different semantics and is called on a specific thread, it makes sense to put it in a separate function. While here, remove the one-line description of spdk_vhost_session_fn typepef. It wasn't helpful anyway. Change-Id: I56b97180110874a813e666f964bb51c39a8ce6bb Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/466732 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
880ddb7436
commit
1eba43239e
@ -79,9 +79,15 @@ struct vhost_session_fn_ctx {
|
||||
/** ID of the session to send event to. */
|
||||
uint32_t vsession_id;
|
||||
|
||||
/** User callback function to be executed on given thread. */
|
||||
/** User provided function to be executed on session's thread. */
|
||||
spdk_vhost_session_fn cb_fn;
|
||||
|
||||
/**
|
||||
* User provided function to be called on the init thread
|
||||
* after iterating through all sessions.
|
||||
*/
|
||||
spdk_vhost_dev_fn cpl_fn;
|
||||
|
||||
/** Custom user context */
|
||||
void *user_ctx;
|
||||
};
|
||||
@ -373,11 +379,6 @@ static int
|
||||
vhost_session_set_coalescing(struct spdk_vhost_dev *vdev,
|
||||
struct spdk_vhost_session *vsession, void *ctx)
|
||||
{
|
||||
if (vsession == NULL) {
|
||||
/* nothing to do */
|
||||
return 0;
|
||||
}
|
||||
|
||||
vsession->coalescing_delay_time_base =
|
||||
vdev->coalescing_delay_us * spdk_get_ticks_hz() / 1000000ULL;
|
||||
vsession->coalescing_io_rate_threshold =
|
||||
@ -417,7 +418,7 @@ spdk_vhost_set_coalescing(struct spdk_vhost_dev *vdev, uint32_t delay_base_us,
|
||||
return rc;
|
||||
}
|
||||
|
||||
vhost_dev_foreach_session(vdev, vhost_session_set_coalescing, NULL);
|
||||
vhost_dev_foreach_session(vdev, vhost_session_set_coalescing, NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -991,8 +992,9 @@ foreach_session_finish_cb(void *arg1)
|
||||
|
||||
assert(vdev->pending_async_op_num > 0);
|
||||
vdev->pending_async_op_num--;
|
||||
/* Call fn one last time with vsession == NULL */
|
||||
ctx->cb_fn(vdev, NULL, ctx->user_ctx);
|
||||
if (ctx->cpl_fn != NULL) {
|
||||
ctx->cpl_fn(vdev, ctx->user_ctx);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_vhost_mutex);
|
||||
free(ctx);
|
||||
@ -1076,7 +1078,9 @@ foreach_session_continue(struct vhost_session_fn_ctx *ev_ctx,
|
||||
|
||||
void
|
||||
vhost_dev_foreach_session(struct spdk_vhost_dev *vdev,
|
||||
spdk_vhost_session_fn fn, void *arg)
|
||||
spdk_vhost_session_fn fn,
|
||||
spdk_vhost_dev_fn cpl_fn,
|
||||
void *arg)
|
||||
{
|
||||
struct spdk_vhost_session *vsession = TAILQ_FIRST(&vdev->vsessions);
|
||||
struct vhost_session_fn_ctx *ev_ctx;
|
||||
@ -1090,6 +1094,7 @@ vhost_dev_foreach_session(struct spdk_vhost_dev *vdev,
|
||||
|
||||
ev_ctx->vdev = vdev;
|
||||
ev_ctx->cb_fn = fn;
|
||||
ev_ctx->cpl_fn = cpl_fn;
|
||||
ev_ctx->user_ctx = arg;
|
||||
|
||||
assert(vdev->pending_async_op_num < UINT32_MAX);
|
||||
|
@ -576,11 +576,6 @@ vhost_session_bdev_remove_cb(struct spdk_vhost_dev *vdev,
|
||||
{
|
||||
struct spdk_vhost_blk_session *bvsession;
|
||||
|
||||
if (vsession == NULL) {
|
||||
vhost_dev_bdev_remove_cpl_cb(vdev, ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bvsession = (struct spdk_vhost_blk_session *)vsession;
|
||||
if (bvsession->requestq_poller) {
|
||||
spdk_poller_unregister(&bvsession->requestq_poller);
|
||||
@ -599,7 +594,8 @@ bdev_remove_cb(void *remove_ctx)
|
||||
bvdev->vdev.name);
|
||||
|
||||
spdk_vhost_lock();
|
||||
vhost_dev_foreach_session(&bvdev->vdev, vhost_session_bdev_remove_cb, NULL);
|
||||
vhost_dev_foreach_session(&bvdev->vdev, vhost_session_bdev_remove_cb,
|
||||
vhost_dev_bdev_remove_cpl_cb, NULL);
|
||||
spdk_vhost_unlock();
|
||||
}
|
||||
|
||||
|
@ -191,12 +191,8 @@ struct spdk_vhost_dev {
|
||||
};
|
||||
|
||||
/**
|
||||
* Synchronized vhost session event used for backend callbacks.
|
||||
*
|
||||
* \param vdev vhost device.
|
||||
* \param vsession vhost session. If all sessions have been
|
||||
* iterated through, this function will be called one last
|
||||
* time with vsession == NULL.
|
||||
* \param vsession vhost session.
|
||||
* \param arg user-provided parameter.
|
||||
*
|
||||
* \return negative values will break the foreach call, meaning
|
||||
@ -207,6 +203,12 @@ typedef int (*spdk_vhost_session_fn)(struct spdk_vhost_dev *vdev,
|
||||
struct spdk_vhost_session *vsession,
|
||||
void *arg);
|
||||
|
||||
/**
|
||||
* \param vdev vhost device.
|
||||
* \param arg user-provided parameter.
|
||||
*/
|
||||
typedef void (*spdk_vhost_dev_fn)(struct spdk_vhost_dev *vdev, void *arg);
|
||||
|
||||
struct spdk_vhost_dev_backend {
|
||||
uint64_t virtio_features;
|
||||
uint64_t disabled_features;
|
||||
@ -310,16 +312,20 @@ int vhost_blk_controller_construct(void);
|
||||
void vhost_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
|
||||
|
||||
/*
|
||||
* Call function for each active session on the provided
|
||||
* vhost device. The function will be called one-by-one
|
||||
* on each session's thread.
|
||||
* Call a function for each session of the provided vhost device.
|
||||
* The function will be called one-by-one on each session's thread.
|
||||
*
|
||||
* \param vdev vhost device
|
||||
* \param fn function to call
|
||||
* \param arg additional argument to \c fn
|
||||
* \param fn function to call on each session's thread
|
||||
* \param cpl_fn function to be called at the end of the iteration on
|
||||
* the vhost management thread.
|
||||
* Optional, can be NULL.
|
||||
* \param arg additional argument to the both callbacks
|
||||
*/
|
||||
void vhost_dev_foreach_session(struct spdk_vhost_dev *dev,
|
||||
spdk_vhost_session_fn fn, void *arg);
|
||||
spdk_vhost_session_fn fn,
|
||||
spdk_vhost_dev_fn cpl_fn,
|
||||
void *arg);
|
||||
|
||||
/**
|
||||
* Call a function on the provided lcore and block until either
|
||||
|
@ -218,16 +218,8 @@ vhost_scsi_session_process_removed(struct spdk_vhost_dev *vdev,
|
||||
struct spdk_vhost_session *vsession, void *ctx)
|
||||
{
|
||||
unsigned scsi_tgt_num = (unsigned)(uintptr_t)ctx;
|
||||
struct spdk_vhost_scsi_session *svsession;
|
||||
struct spdk_scsi_dev_session_state *state;
|
||||
|
||||
if (vsession == NULL) {
|
||||
vhost_scsi_dev_process_removed_cpl_cb(vdev, ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
svsession = (struct spdk_vhost_scsi_session *)vsession;
|
||||
state = &svsession->scsi_dev_state[scsi_tgt_num];
|
||||
struct spdk_vhost_scsi_session *svsession = (struct spdk_vhost_scsi_session *)vsession;
|
||||
struct spdk_scsi_dev_session_state *state = &svsession->scsi_dev_state[scsi_tgt_num];
|
||||
|
||||
if (state->dev != NULL) {
|
||||
/* there's still a session that references this device,
|
||||
@ -261,6 +253,7 @@ process_removed_devs(struct spdk_vhost_scsi_session *svsession)
|
||||
spdk_vhost_lock();
|
||||
vhost_dev_foreach_session(&svsession->svdev->vdev,
|
||||
vhost_scsi_session_process_removed,
|
||||
vhost_scsi_dev_process_removed_cpl_cb,
|
||||
(void *)(uintptr_t)i);
|
||||
spdk_vhost_unlock();
|
||||
}
|
||||
@ -940,18 +933,11 @@ vhost_scsi_session_add_tgt(struct spdk_vhost_dev *vdev,
|
||||
struct spdk_vhost_session *vsession, void *ctx)
|
||||
{
|
||||
unsigned scsi_tgt_num = (unsigned)(uintptr_t)ctx;
|
||||
struct spdk_vhost_scsi_session *svsession;
|
||||
struct spdk_vhost_scsi_session *svsession = (struct spdk_vhost_scsi_session *)vsession;
|
||||
struct spdk_scsi_dev_session_state *session_sdev = &svsession->scsi_dev_state[scsi_tgt_num];
|
||||
struct spdk_scsi_dev_vhost_state *vhost_sdev;
|
||||
struct spdk_scsi_dev_session_state *session_sdev;
|
||||
int rc;
|
||||
|
||||
if (vsession == NULL) {
|
||||
vhost_scsi_dev_add_tgt_cpl_cb(vdev, ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
svsession = (struct spdk_vhost_scsi_session *)vsession;
|
||||
session_sdev = &svsession->scsi_dev_state[scsi_tgt_num];
|
||||
if (!vsession->started || session_sdev->dev != NULL) {
|
||||
/* Nothing to do. */
|
||||
return 0;
|
||||
@ -1059,6 +1045,7 @@ spdk_vhost_scsi_dev_add_tgt(struct spdk_vhost_dev *vdev, int scsi_tgt_num,
|
||||
vdev->name, scsi_tgt_num, bdev_name);
|
||||
|
||||
vhost_dev_foreach_session(vdev, vhost_scsi_session_add_tgt,
|
||||
vhost_scsi_dev_add_tgt_cpl_cb,
|
||||
(void *)(uintptr_t)scsi_tgt_num);
|
||||
return scsi_tgt_num;
|
||||
}
|
||||
@ -1089,16 +1076,8 @@ vhost_scsi_session_remove_tgt(struct spdk_vhost_dev *vdev,
|
||||
{
|
||||
struct scsi_tgt_hotplug_ctx *ctx = _ctx;
|
||||
unsigned scsi_tgt_num = ctx->scsi_tgt_num;
|
||||
struct spdk_vhost_scsi_session *svsession;
|
||||
struct spdk_scsi_dev_session_state *state;
|
||||
|
||||
if (vsession == NULL) {
|
||||
vhost_scsi_dev_remove_tgt_cpl_cb(vdev, _ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
svsession = (struct spdk_vhost_scsi_session *)vsession;
|
||||
state = &svsession->scsi_dev_state[scsi_tgt_num];
|
||||
struct spdk_vhost_scsi_session *svsession = (struct spdk_vhost_scsi_session *)vsession;
|
||||
struct spdk_scsi_dev_session_state *state = &svsession->scsi_dev_state[scsi_tgt_num];
|
||||
|
||||
if (!vsession->started || state->dev == NULL) {
|
||||
/* Nothing to do */
|
||||
@ -1163,7 +1142,8 @@ spdk_vhost_scsi_dev_remove_tgt(struct spdk_vhost_dev *vdev, unsigned scsi_tgt_nu
|
||||
scsi_dev_state->remove_ctx = cb_arg;
|
||||
scsi_dev_state->status = VHOST_SCSI_DEV_REMOVING;
|
||||
|
||||
vhost_dev_foreach_session(vdev, vhost_scsi_session_remove_tgt, ctx);
|
||||
vhost_dev_foreach_session(vdev, vhost_scsi_session_remove_tgt,
|
||||
vhost_scsi_dev_remove_tgt_cpl_cb, ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1425,6 +1405,7 @@ destroy_session_poller_cb(void *arg)
|
||||
/* try to detach it globally */
|
||||
vhost_dev_foreach_session(vsession->vdev,
|
||||
vhost_scsi_session_process_removed,
|
||||
vhost_scsi_dev_process_removed_cpl_cb,
|
||||
(void *)(uintptr_t)i);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user