virtio: drop *_set_guest_notifier_fd_handler() helpers
Now they don't make code more readable. Let's better put the whole logic into virtio_queue_set_guest_notifier(). Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Reviewed-by: Daniil Tatianin <d-tatianin@yandex-team.ru> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260420200339.708640-9-vsementsov@yandex-team.ru>
Vladimir Sementsov-Ogievskiy committed
Apr 20, 2026 at 23:03 UTC
a443f8a671ed7ac8441d3739c42ca7b74433d843
1 file changed
+17
-58
hw/virtio/virtio.c
+17
-58
@@ -3836,73 +3836,32 @@ static void virtio_config_guest_notifier_read(EventNotifier *n)
3836
}
3837
}
3838
3839
-static void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq,
3840
- bool assign,
3841
- bool with_irqfd)
3842
-{
3843
- if (assign && !with_irqfd) {
3844
- event_notifier_set_handler(&vq->guest_notifier,
3845
- virtio_queue_guest_notifier_read);
3846
- } else {
3847
- event_notifier_set_handler(&vq->guest_notifier, NULL);
3848
- }
3849
- if (!assign) {
3850
- /* Test and clear notifier before closing it,
3851
- * in case poll callback didn't have time to run. */
3852
- virtio_queue_guest_notifier_read(&vq->guest_notifier);
3853
- }
3854
-}
3855
-
3856
-static void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev,
3857
- bool assign, bool with_irqfd)
3858
-{
3859
- EventNotifier *n;
3860
- n = &vdev->config_notifier;
3861
- if (assign && !with_irqfd) {
3862
- event_notifier_set_handler(n, virtio_config_guest_notifier_read);
3863
- } else {
3864
- event_notifier_set_handler(n, NULL);
3865
- }
3866
- if (!assign) {
3867
- /* Test and clear notifier before closing it,*/
3868
- /* in case poll callback didn't have time to run. */
3869
- virtio_config_guest_notifier_read(n);
3870
- }
3871
-}
3872
-
3873
-static void virtio_set_guest_notifier_fd_handler(VirtIODevice *vdev,
3874
- VirtQueue *vq,
3875
- int n, bool assign,
3876
- bool with_irqfd)
3877
-{
3878
- if (n == VIRTIO_CONFIG_IRQ_IDX) {
3879
- virtio_config_set_guest_notifier_fd_handler(vdev, assign, with_irqfd);
3880
- } else {
3881
- virtio_queue_set_guest_notifier_fd_handler(vq, assign, with_irqfd);
3882
- }
3883
-}
3884
-
3839
int virtio_set_guest_notifier(VirtIODevice *vdev, int n, bool assign,
3840
bool with_irqfd)
3841
{
3888
- VirtQueue *vq = NULL;
3889
- EventNotifier *notifier = NULL;
3890
-
3891
- if (n == VIRTIO_CONFIG_IRQ_IDX) {
3892
- notifier = virtio_config_get_guest_notifier(vdev);
3893
- } else {
3894
- vq = virtio_get_queue(vdev, n);
3895
- notifier = virtio_queue_get_guest_notifier(vq);
3896
- }
3842
+ bool is_config = n == VIRTIO_CONFIG_IRQ_IDX;
3843
+ VirtQueue *vq = is_config ? NULL : virtio_get_queue(vdev, n);
3844
+ EventNotifier *notifier = is_config ?
3845
+ virtio_config_get_guest_notifier(vdev) :
3846
+ virtio_queue_get_guest_notifier(vq);
3847
+ EventNotifierHandler *read_fn = is_config ?
3848
+ virtio_config_guest_notifier_read :
3849
+ virtio_queue_guest_notifier_read;
3850
3851
if (assign) {
3852
int r = event_notifier_init(notifier, 0);
3853
if (r < 0) {
3854
return r;
3855
}
3903
- virtio_set_guest_notifier_fd_handler(vdev, vq, n, true, with_irqfd);
3904
- } else {
3905
- virtio_set_guest_notifier_fd_handler(vdev, vq, n, false, with_irqfd);
3856
+ }
3857
+
3858
+ event_notifier_set_handler(notifier,
3859
+ (assign && !with_irqfd) ? read_fn : NULL);
3860
+
3861
+ if (!assign) {
3862
+ /* Test and clear notifier before closing it,*/
3863
+ /* in case poll callback didn't have time to run. */
3864
+ read_fn(notifier);
3865
event_notifier_cleanup(notifier);
3866
}
3867