Replace EventNotifier with the new generic QemuEvent service. CC: Michael S. Tsirkin <m...@redhat.com> Signed-off-by: Jan Kiszka <jan.kis...@siemens.com> --- hw/vhost.c | 4 +- hw/virtio-pci.c | 61 ++++++++++++++++++++++-------------------------------- hw/virtio.c | 12 +++++----- hw/virtio.h | 6 ++-- 4 files changed, 36 insertions(+), 47 deletions(-)
diff --git a/hw/vhost.c b/hw/vhost.c index 8d3ba5b..c7bd8b7 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -673,14 +673,14 @@ static int vhost_virtqueue_init(struct vhost_dev *dev, r = -errno; goto fail_alloc; } - file.fd = event_notifier_get_fd(virtio_queue_get_host_notifier(vvq)); + file.fd = qemu_event_get_signal_fd(virtio_queue_get_host_event(vvq)); r = ioctl(dev->control, VHOST_SET_VRING_KICK, &file); if (r) { r = -errno; goto fail_kick; } - file.fd = event_notifier_get_fd(virtio_queue_get_guest_notifier(vvq)); + file.fd = qemu_event_get_signal_fd(virtio_queue_get_guest_event(vvq)); r = ioctl(dev->control, VHOST_SET_VRING_CALL, &file); if (r) { r = -errno; diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index a0fb7c1..9b9e69a 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -162,53 +162,47 @@ static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy, int n, bool assign) { VirtQueue *vq = virtio_get_queue(proxy->vdev, n); - EventNotifier *notifier = virtio_queue_get_host_notifier(vq); + QemuEvent *event = virtio_queue_get_host_event(vq); int r = 0; if (assign) { - r = event_notifier_init(notifier, 1); - if (r < 0) { - error_report("%s: unable to init event notifier: %d", - __func__, r); - return r; - } + qemu_event_init(event, true); memory_region_add_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY, 2, - true, n, event_notifier_get_fd(notifier)); + true, n, qemu_event_get_signal_fd(event)); } else { memory_region_del_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY, 2, - true, n, event_notifier_get_fd(notifier)); + true, n, qemu_event_get_signal_fd(event)); /* Handle the race condition where the guest kicked and we deassigned * before we got around to handling the kick. */ - if (event_notifier_test_and_clear(notifier)) { + if (qemu_event_consume(event)) { virtio_queue_notify_vq(vq); } - event_notifier_cleanup(notifier); + qemu_event_destroy(event); } return r; } -static void virtio_pci_host_notifier_read(void *opaque) +static void virtio_pci_host_event(void *opaque) { VirtQueue *vq = opaque; - EventNotifier *n = virtio_queue_get_host_notifier(vq); - if (event_notifier_test_and_clear(n)) { - virtio_queue_notify_vq(vq); - } + QemuEvent *event = virtio_queue_get_host_event(vq); + + qemu_event_consume(event); + virtio_queue_notify_vq(vq); } static void virtio_pci_set_host_notifier_fd_handler(VirtIOPCIProxy *proxy, int n, bool assign) { VirtQueue *vq = virtio_get_queue(proxy->vdev, n); - EventNotifier *notifier = virtio_queue_get_host_notifier(vq); + QemuEvent *event = virtio_queue_get_host_event(vq); + if (assign) { - qemu_set_fd_handler(event_notifier_get_fd(notifier), - virtio_pci_host_notifier_read, NULL, vq); + qemu_event_set_handler(event, virtio_pci_host_event, vq); } else { - qemu_set_fd_handler(event_notifier_get_fd(notifier), - NULL, NULL, NULL); + qemu_event_set_handler(event, NULL, NULL); } } @@ -530,32 +524,27 @@ static unsigned virtio_pci_get_features(void *opaque) return proxy->host_features; } -static void virtio_pci_guest_notifier_read(void *opaque) +static void virtio_pci_guest_event(void *opaque) { VirtQueue *vq = opaque; - EventNotifier *n = virtio_queue_get_guest_notifier(vq); - if (event_notifier_test_and_clear(n)) { - virtio_irq(vq); - } + QemuEvent *event = virtio_queue_get_guest_event(vq); + + qemu_event_consume(event); + virtio_irq(vq); } static int virtio_pci_set_guest_notifier(void *opaque, int n, bool assign) { VirtIOPCIProxy *proxy = opaque; VirtQueue *vq = virtio_get_queue(proxy->vdev, n); - EventNotifier *notifier = virtio_queue_get_guest_notifier(vq); + QemuEvent *event = virtio_queue_get_guest_event(vq); if (assign) { - int r = event_notifier_init(notifier, 0); - if (r < 0) { - return r; - } - qemu_set_fd_handler(event_notifier_get_fd(notifier), - virtio_pci_guest_notifier_read, NULL, vq); + qemu_event_init(event, false); + qemu_event_set_handler(event, virtio_pci_guest_event, vq); } else { - qemu_set_fd_handler(event_notifier_get_fd(notifier), - NULL, NULL, NULL); - event_notifier_cleanup(notifier); + qemu_event_set_handler(event, NULL, NULL); + qemu_event_destroy(event); } return 0; diff --git a/hw/virtio.c b/hw/virtio.c index 064aecf..7f43663 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -76,9 +76,9 @@ struct VirtQueue uint16_t vector; void (*handle_output)(VirtIODevice *vdev, VirtQueue *vq); + QemuEvent guest_event; + QemuEvent host_event; VirtIODevice *vdev; - EventNotifier guest_notifier; - EventNotifier host_notifier; }; /* virt queue functions */ @@ -966,11 +966,11 @@ VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n) return vdev->vq + n; } -EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq) +QemuEvent *virtio_queue_get_guest_event(VirtQueue *vq) { - return &vq->guest_notifier; + return &vq->guest_event; } -EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq) +QemuEvent *virtio_queue_get_host_event(VirtQueue *vq) { - return &vq->host_notifier; + return &vq->host_event; } diff --git a/hw/virtio.h b/hw/virtio.h index 400c092..199b0d8 100644 --- a/hw/virtio.h +++ b/hw/virtio.h @@ -19,7 +19,7 @@ #include "qdev.h" #include "sysemu.h" #include "block.h" -#include "event_notifier.h" +#include "qemu-thread.h" #ifdef CONFIG_LINUX #include "9p.h" #endif @@ -229,8 +229,8 @@ 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); -EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq); -EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq); +QemuEvent *virtio_queue_get_guest_event(VirtQueue *vq); +QemuEvent *virtio_queue_get_host_event(VirtQueue *vq); void virtio_queue_notify_vq(VirtQueue *vq); void virtio_irq(VirtQueue *vq); #endif -- 1.7.3.4