vhost: introduce spdk_vhost_dev_foreach_session

When device is changed, e.g. the underlying bdev is
hotremoved, all sessions need to be notified. For
instance, Vhost-SCSI would send an additional hotremove
eventq message. That's why we introduce a helper
function to iterate through all active sessions.

Eventually, we may want to poll different sessions
from different lcores, so there will be some kind of
internal cross-lcore message management required
- just like there is one for spdk_vhost_call_external_event_foreach().
For now, though, we can get away with a dumbest
implementation.

We still want to keep this API internal for the time
being. The end-user (RPC) should only modify the
device, and the whole concept of sessions should be
completely encapsulated.

Change-Id: I2e142632c07a23daeac15cabea4cffecf984e455
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/418736
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Darek Stojaczyk 2018-12-16 00:49:00 +01:00 committed by Jim Harris
parent f82a175706
commit 1e18d9cd9d
2 changed files with 46 additions and 0 deletions

View File

@ -1349,6 +1349,21 @@ spdk_vhost_external_event_foreach_continue(struct spdk_vhost_dev *vdev,
spdk_vhost_event_async_send(vdev, fn, arg, true);
}
void
spdk_vhost_dev_foreach_session(struct spdk_vhost_dev *vdev,
spdk_vhost_session_fn fn, void *arg)
{
int rc = 0;
if (vdev->session != NULL) {
rc = fn(vdev, vdev->session, arg);
}
if (rc >= 0) {
fn(vdev, NULL, arg);
}
}
void
spdk_vhost_call_external_event_foreach(spdk_vhost_event_fn fn, void *arg)
{

View File

@ -191,6 +191,25 @@ struct spdk_vhost_dev_destroy_ctx {
void *event_ctx;
};
/**
* Synchronized vhost session event used for backend callbacks.
*
* \param vdev vhost device. If the device has been deleted
* in the meantime, this function will be called one last
* time with vdev == NULL.
* \param vsession vhost session. If all sessions have been
* iterated through, this function will be called one last
* time with vsession == NULL.
* \param arg user-provided parameter.
*
* \return negative values will break the foreach call, meaning
* the function won't be called again. Return codes zero and
* positive don't have any effect.
*/
typedef int (*spdk_vhost_session_fn)(struct spdk_vhost_dev *vdev,
struct spdk_vhost_session *vsession,
void *arg);
struct spdk_vhost_dev *spdk_vhost_dev_find(const char *ctrlr_name);
void *spdk_vhost_gpa_to_vva(struct spdk_vhost_session *vsession, uint64_t addr, uint64_t len);
@ -272,6 +291,18 @@ int spdk_vhost_dev_unregister(struct spdk_vhost_dev *vdev);
int spdk_vhost_scsi_controller_construct(void);
int spdk_vhost_blk_controller_construct(void);
void spdk_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.
*
* \param vdev vhost device
* \param fn function to call
* \param arg additional argument to \c fn
*/
void spdk_vhost_dev_foreach_session(struct spdk_vhost_dev *dev,
spdk_vhost_session_fn fn, void *arg);
void spdk_vhost_dev_backend_event_done(void *event_ctx, int response);
void spdk_vhost_lock(void);
void spdk_vhost_unlock(void);