vhost: expose vdevs to the public API
Vhost external events no longer do any asynchronous calls, they only lock the vhost mutex and directly call the provided function. The mutex encapsulation isn't worth the additional complexity of splitting each vdev-handling code into multiple functions, so we expose low-level APIs that should eventually replace external events entirely. Instead of: ``` static int do_something_cb(struct spdk_vhost_dev *vdev, void *arg) { struct my_data *ctx = arg; /* access the vdev and ctx */ free(ctx); } struct my_data *ctx = calloc(...); rc = spdk_vhost_call_external_event("my_vdev", do_something_cb, ctx); if (rc != 0) { /* err handling */ } ``` We can now do just: ``` spdk_vhost_lock(); vdev = spdk_vhost_dev_find("my_vdev"); if (vdev == NULL) { /* err handling */ } /* access the vdev any context data */ spdk_vhost_unlock(); ``` Change-Id: I06e1e149d6dd006720b021d3bef8d9b7bfaeceaa Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/c/440377 Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
5abe0ec852
commit
08de94d0dd
@ -109,6 +109,33 @@ void spdk_vhost_shutdown_cb(void);
|
||||
*/
|
||||
struct spdk_vhost_dev;
|
||||
|
||||
/**
|
||||
* Lock the global vhost mutex, which synchronizes all the vhost device accesses.
|
||||
*/
|
||||
void spdk_vhost_lock(void);
|
||||
|
||||
/**
|
||||
* Unlock the global vhost mutex.
|
||||
*/
|
||||
void spdk_vhost_unlock(void);
|
||||
|
||||
/**
|
||||
* Find a vhost device by name.
|
||||
*
|
||||
* \return vhost device or NULL
|
||||
*/
|
||||
struct spdk_vhost_dev *spdk_vhost_dev_find(const char *name);
|
||||
|
||||
/**
|
||||
* Get the next vhost device. If there's no more devices to iterate
|
||||
* through, NULL will be returned.
|
||||
*
|
||||
* \param vdev vhost device. If NULL, this function will return the
|
||||
* very first device.
|
||||
* \return vdev vhost device or NULL
|
||||
*/
|
||||
struct spdk_vhost_dev *spdk_vhost_dev_next(struct spdk_vhost_dev *vdev);
|
||||
|
||||
/**
|
||||
* Synchronized vhost event used for user callbacks.
|
||||
*
|
||||
@ -300,6 +327,7 @@ int spdk_vhost_dev_remove(struct spdk_vhost_dev *vdev);
|
||||
*/
|
||||
struct spdk_bdev *spdk_vhost_blk_get_dev(struct spdk_vhost_dev *ctrlr);
|
||||
|
||||
|
||||
/**
|
||||
* Call function on reactor of given vhost device. If device is not in use, the
|
||||
* event will be called right away on the caller's thread.
|
||||
|
@ -597,6 +597,16 @@ spdk_vhost_free_reactor(uint32_t lcore)
|
||||
g_num_ctrlrs[lcore]--;
|
||||
}
|
||||
|
||||
struct spdk_vhost_dev *
|
||||
spdk_vhost_dev_next(struct spdk_vhost_dev *vdev)
|
||||
{
|
||||
if (vdev == NULL) {
|
||||
return TAILQ_FIRST(&g_spdk_vhost_devices);
|
||||
}
|
||||
|
||||
return TAILQ_NEXT(vdev, tailq);
|
||||
}
|
||||
|
||||
struct spdk_vhost_dev *
|
||||
spdk_vhost_dev_find(const char *ctrlr_name)
|
||||
{
|
||||
|
@ -221,8 +221,6 @@ struct spdk_vhost_dev_backend {
|
||||
int (*remove_device)(struct spdk_vhost_dev *vdev);
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
uint16_t spdk_vhost_vq_avail_ring_get(struct spdk_vhost_virtqueue *vq, uint16_t *reqs,
|
||||
@ -346,8 +344,6 @@ void spdk_vhost_session_event_done(void *event_ctx, int response);
|
||||
void spdk_vhost_free_reactor(uint32_t lcore);
|
||||
uint32_t spdk_vhost_allocate_reactor(struct spdk_cpuset *cpumask);
|
||||
|
||||
void spdk_vhost_lock(void);
|
||||
void spdk_vhost_unlock(void);
|
||||
int spdk_remove_vhost_controller(struct spdk_vhost_dev *vdev);
|
||||
int spdk_vhost_nvme_admin_passthrough(int vid, void *cmd, void *cqe, void *buf);
|
||||
int spdk_vhost_nvme_set_cq_call(int vid, uint16_t qid, int fd);
|
||||
|
Loading…
x
Reference in New Issue
Block a user