[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC 05/10] vhost: Add vhost_dev_from_virtio
From: |
Eugenio Pérez |
Subject: |
[RFC 05/10] vhost: Add vhost_dev_from_virtio |
Date: |
Fri, 29 Jan 2021 21:54:10 +0100 |
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
include/hw/virtio/vhost.h | 1 +
hw/virtio/vhost.c | 17 +++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index 4a8bc75415..fca076e3f0 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -123,6 +123,7 @@ uint64_t vhost_get_features(struct vhost_dev *hdev, const
int *feature_bits,
void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits,
uint64_t features);
bool vhost_has_free_slot(void);
+struct vhost_dev *vhost_dev_from_virtio(const VirtIODevice *vdev);
int vhost_net_set_backend(struct vhost_dev *hdev,
struct vhost_vring_file *file);
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 28c7d78172..8683d507f5 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -61,6 +61,23 @@ bool vhost_has_free_slot(void)
return slots_limit > used_memslots;
}
+/*
+ * Get the vhost device associated to a VirtIO device.
+ */
+struct vhost_dev *vhost_dev_from_virtio(const VirtIODevice *vdev)
+{
+ struct vhost_dev *hdev;
+
+ QLIST_FOREACH(hdev, &vhost_devices, entry) {
+ if (hdev->vdev == vdev) {
+ return hdev;
+ }
+ }
+
+ assert(hdev);
+ return NULL;
+}
+
static void vhost_dev_sync_region(struct vhost_dev *dev,
MemoryRegionSection *section,
uint64_t mfirst, uint64_t mlast,
--
2.27.0
- [RFC 00/10] vDPA shadow virtqueue - notifications forwarding, Eugenio Pérez, 2021/01/29
- [RFC 01/10] virtio: Add virtqueue_set_handler, Eugenio Pérez, 2021/01/29
- [RFC 02/10] virtio: Add set_vq_handler, Eugenio Pérez, 2021/01/29
- [RFC 03/10] virtio: Add virtio_queue_get_idx, Eugenio Pérez, 2021/01/29
- [RFC 04/10] virtio: Add virtio_queue_host_notifier_status, Eugenio Pérez, 2021/01/29
- [RFC 05/10] vhost: Add vhost_dev_from_virtio,
Eugenio Pérez <=
- [RFC 07/10] vhost: Add VhostShadowVirtqueue, Eugenio Pérez, 2021/01/29
- [RFC 06/10] vhost: Save masked_notifier state, Eugenio Pérez, 2021/01/29
- [RFC 08/10] vhost: Add x-vhost-enable-shadow-vq qmp, Eugenio Pérez, 2021/01/29
- [RFC 10/10] vhost: Route host->guest notification through shadow virtqueue, Eugenio Pérez, 2021/01/29
- [RFC 09/10] vhost: Route guest->host notification through shadow virtqueue, Eugenio Pérez, 2021/01/29