[PATCH 20/33] hw/virtio/virtio-bus: refactor virtio_bus_set_host_notifier()

Vladimir Sementsov-Ogievskiy posted 33 patches 3 months ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, "Gonglei (Arei)" <arei.gonglei@huawei.com>, Zhenwei Pi <pizhenwei@bytedance.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Raphael Norwitz <raphael@enfabrica.net>, Jason Wang <jasowang@redhat.com>, Fam Zheng <fam@euphon.net>, "Alex Bennée" <alex.bennee@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Laurent Vivier <lvivier@redhat.com>
There is a newer version of this series
[PATCH 20/33] hw/virtio/virtio-bus: refactor virtio_bus_set_host_notifier()
Posted by Vladimir Sementsov-Ogievskiy 3 months ago
The logic kept as is. Reaftor to simplify further changes.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 hw/virtio/virtio-bus.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
index 11adfbf3ab..c7e3941b1e 100644
--- a/hw/virtio/virtio-bus.c
+++ b/hw/virtio/virtio-bus.c
@@ -293,20 +293,18 @@ int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign)
                          __func__, strerror(-r), r);
             return r;
         }
-        r = k->ioeventfd_assign(proxy, notifier, n, true);
-        if (r < 0) {
-            error_report("%s: unable to assign ioeventfd: %d", __func__, r);
-            virtio_bus_cleanup_host_notifier(bus, n);
-        }
-    } else {
-        k->ioeventfd_assign(proxy, notifier, n, false);
     }
 
-    if (r == 0) {
-        virtio_queue_set_host_notifier_enabled(vq, assign);
+    r = k->ioeventfd_assign(proxy, notifier, n, assign);
+    if (r < 0 && assign) {
+        error_report("%s: unable to assign ioeventfd: %d", __func__, r);
+        virtio_bus_cleanup_host_notifier(bus, n);
+        return r;
     }
 
-    return r;
+    virtio_queue_set_host_notifier_enabled(vq, assign);
+
+    return 0;
 }
 
 void virtio_bus_cleanup_host_notifier(VirtioBusState *bus, int n)
-- 
2.48.1
Re: [PATCH 20/33] hw/virtio/virtio-bus: refactor virtio_bus_set_host_notifier()
Posted by Raphael Norwitz 1 month ago
Reviewed-by: Raphael Norwitz <raphael.s.norwitz@gmail.com>

On Wed, Aug 13, 2025 at 12:52 PM Vladimir Sementsov-Ogievskiy
<vsementsov@yandex-team.ru> wrote:
>
> The logic kept as is. Reaftor to simplify further changes.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>  hw/virtio/virtio-bus.c | 18 ++++++++----------
>  1 file changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
> index 11adfbf3ab..c7e3941b1e 100644
> --- a/hw/virtio/virtio-bus.c
> +++ b/hw/virtio/virtio-bus.c
> @@ -293,20 +293,18 @@ int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign)
>                           __func__, strerror(-r), r);
>              return r;
>          }
> -        r = k->ioeventfd_assign(proxy, notifier, n, true);
> -        if (r < 0) {
> -            error_report("%s: unable to assign ioeventfd: %d", __func__, r);
> -            virtio_bus_cleanup_host_notifier(bus, n);
> -        }
> -    } else {
> -        k->ioeventfd_assign(proxy, notifier, n, false);
>      }
>
> -    if (r == 0) {
> -        virtio_queue_set_host_notifier_enabled(vq, assign);
> +    r = k->ioeventfd_assign(proxy, notifier, n, assign);
> +    if (r < 0 && assign) {
> +        error_report("%s: unable to assign ioeventfd: %d", __func__, r);
> +        virtio_bus_cleanup_host_notifier(bus, n);
> +        return r;
>      }
>
> -    return r;
> +    virtio_queue_set_host_notifier_enabled(vq, assign);
> +
> +    return 0;
>  }
>
>  void virtio_bus_cleanup_host_notifier(VirtioBusState *bus, int n)
> --
> 2.48.1
>
>
Re: [PATCH 20/33] hw/virtio/virtio-bus: refactor virtio_bus_set_host_notifier()
Posted by Philippe Mathieu-Daudé 3 months ago
On 13/8/25 18:48, Vladimir Sementsov-Ogievskiy wrote:
> The logic kept as is. Reaftor to simplify further changes.

Typo "refactor".

> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>   hw/virtio/virtio-bus.c | 18 ++++++++----------
>   1 file changed, 8 insertions(+), 10 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>