@@ -421,8 +421,8 @@ static unsigned virtio_pci_get_features(void *opaque)
static void virtio_pci_guest_notifier_read(void *opaque)
{
- VirtQueue *vq = opaque;
- EventNotifier *n = virtio_queue_get_guest_notifier(vq);
+ EventNotifier *n = opaque;
+ VirtQueue *vq = virtqueue_from_guest_notifier(n);
if (event_notifier_test_and_clear(n)) {
virtio_irq(vq);
}
@@ -440,7 +440,7 @@ static int virtio_pci_set_guest_notifier(void *opaque, int n, bool assign)
return r;
}
qemu_set_fd_handler(event_notifier_get_fd(notifier),
- virtio_pci_guest_notifier_read, NULL, vq);
+ virtio_pci_guest_notifier_read, NULL, notifier);
} else {
qemu_set_fd_handler(event_notifier_get_fd(notifier),
NULL, NULL, NULL);
@@ -805,6 +805,11 @@ VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n)
return vdev->vq + n;
}
+VirtQueue *virtqueue_from_guest_notifier(EventNotifier *e)
+{
+ return container_of(e, VirtQueue, guest_notifier);
+}
+
EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq)
{
return &vq->guest_notifier;
@@ -210,6 +210,7 @@ target_phys_addr_t virtio_queue_get_ring_size(VirtIODevice *vdev, int n);
uint16_t virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n);
void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx);
VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n);
+VirtQueue *virtqueue_from_guest_notifier(EventNotifier *vq);
EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq);
EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq);
void virtio_irq(VirtQueue *vq);
This changes the opaque pointer passed to the handler, from being the virtqueue to being the eventnotifier. It is useful as soon as the eventnotifier will be able to set its own (type-safe) handler. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- I don't have a vhost-enabled machine yet. So only compile-tested for now, but pretty trivial. hw/virtio-pci.c | 6 +++--- hw/virtio.c | 5 +++++ hw/virtio.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-)