Hi Vladimir, On 13/8/25 18:48, Vladimir Sementsov-Ogievskiy wrote:
virtio-pci and virtio-mmiio handle config notifier equally but
Typo virtio-mmio.
with different code (mmio adds a separate function, when pci use common function). Let's chose the more compact way (pci) and reuse it for mmio. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@yandex-team.ru> --- hw/virtio/virtio-mmio.c | 41 +++++------------------------ hw/virtio/virtio-pci.c | 34 +++--------------------- hw/virtio/virtio.c | 48 +++++++++++++++++++++++++++++++--- include/hw/virtio/virtio-pci.h | 3 --- include/hw/virtio/virtio.h | 7 +++-- 5 files changed, 58 insertions(+), 75 deletions(-)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 9a81ad912e..7880c3bcd9 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c
+static void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev, + VirtQueue *vq, + int n, bool assign, + bool with_irqfd) +{ + if (n == VIRTIO_CONFIG_IRQ_IDX) { + virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irqfd); + } else { + virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd); + } +} + +int virtio_queue_set_guest_notifier(VirtIODevice *vdev, int n, bool assign, + bool with_irqfd) +{ + VirtQueue *vq = NULL; + EventNotifier *notifier = NULL; + + if (n == VIRTIO_CONFIG_IRQ_IDX) { + notifier = virtio_config_get_guest_notifier(vdev); + } else { + vq = virtio_get_queue(vdev, n); + notifier = virtio_queue_get_guest_notifier(vq); + } + + if (assign) { + int r = event_notifier_init(notifier, 0); + if (r < 0) { + return r; + } + virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, true, with_irqfd); + } else { + virtio_pci_set_guest_notifier_fd_handler(vdev, vq, n, false, + with_irqfd); + event_notifier_cleanup(notifier); + } + + return 0; +}
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index c594764f23..8b9db08ddf 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h
-void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev, - bool assign, bool with_irqfd); + +int virtio_queue_set_guest_notifier(VirtIODevice *vdev, int n, bool assign, + bool with_irqfd);
Please add a @docstring to document (@n in particular). Thanks, Phil.