diff --git a/include/spdk/vhost.h b/include/spdk/vhost.h index 3f6495395..dfb0f0af2 100644 --- a/include/spdk/vhost.h +++ b/include/spdk/vhost.h @@ -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. diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 67da6a887..0a20327be 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -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) { diff --git a/lib/vhost/vhost_internal.h b/lib/vhost/vhost_internal.h index 38adf850d..a5ded833b 100644 --- a/lib/vhost/vhost_internal.h +++ b/lib/vhost/vhost_internal.h @@ -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);