[PATCH 09/33] vhost-user: keep QIOChannelSocket for backend channel

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 09/33] vhost-user: keep QIOChannelSocket for backend channel
Posted by Vladimir Sementsov-Ogievskiy 3 months ago
Keep QIOChannelSocket pointer instead of more generic
QIOChannel. No real difference for now, but it would
be simpler to migrate socket fd in further commit.

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

diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 46f09f5988..fe9d91348d 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -244,7 +244,7 @@ struct vhost_user {
     struct vhost_dev *dev;
     /* Shared between vhost devs of the same virtio device */
     VhostUserState *user;
-    QIOChannel *backend_ioc;
+    QIOChannelSocket *backend_sioc;
     GSource *backend_src;
     NotifierWithReturn postcopy_notifier;
     struct PostCopyFD  postcopy_fd;
@@ -1789,8 +1789,8 @@ static void close_backend_channel(struct vhost_user *u)
     g_source_destroy(u->backend_src);
     g_source_unref(u->backend_src);
     u->backend_src = NULL;
-    object_unref(OBJECT(u->backend_ioc));
-    u->backend_ioc = NULL;
+    object_unref(OBJECT(u->backend_sioc));
+    u->backend_sioc = NULL;
 }
 
 static gboolean backend_read(QIOChannel *ioc, GIOCondition condition,
@@ -1897,7 +1897,6 @@ static int vhost_setup_backend_channel(struct vhost_dev *dev)
     bool reply_supported =
         vhost_user_has_prot(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK);
     Error *local_err = NULL;
-    QIOChannel *ioc;
 
     if (!vhost_user_has_prot(dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ)) {
         return 0;
@@ -1909,15 +1908,15 @@ static int vhost_setup_backend_channel(struct vhost_dev *dev)
         return -saved_errno;
     }
 
-    ioc = QIO_CHANNEL(qio_channel_socket_new_fd(sv[0], &local_err));
-    if (!ioc) {
+    u->backend_sioc = qio_channel_socket_new_fd(sv[0], &local_err);
+    if (!u->backend_sioc) {
         error_report_err(local_err);
         return -ECONNREFUSED;
     }
-    u->backend_ioc = ioc;
-    u->backend_src = qio_channel_add_watch_source(u->backend_ioc,
-                                                G_IO_IN | G_IO_HUP,
-                                                backend_read, dev, NULL, NULL);
+    u->backend_src = qio_channel_add_watch_source(QIO_CHANNEL(u->backend_sioc),
+                                                  G_IO_IN | G_IO_HUP,
+                                                  backend_read, dev,
+                                                  NULL, NULL);
 
     if (reply_supported) {
         msg.hdr.flags |= VHOST_USER_NEED_REPLY_MASK;
@@ -2321,7 +2320,7 @@ static int vhost_user_backend_cleanup(struct vhost_dev *dev)
         close(u->postcopy_fd.fd);
         u->postcopy_fd.handler = NULL;
     }
-    if (u->backend_ioc) {
+    if (u->backend_sioc) {
         close_backend_channel(u);
     }
     g_free(u->region_rb);
-- 
2.48.1
Re: [PATCH 09/33] vhost-user: keep QIOChannelSocket for backend channel
Posted by Raphael Norwitz 1 month ago
Acked-by: Raphael Norwitz <raphael.s.norwitz@gmail.com>

On Wed, Aug 13, 2025 at 1:01 PM Vladimir Sementsov-Ogievskiy
<vsementsov@yandex-team.ru> wrote:
>
> Keep QIOChannelSocket pointer instead of more generic
> QIOChannel. No real difference for now, but it would
> be simpler to migrate socket fd in further commit.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>  hw/virtio/vhost-user.c | 21 ++++++++++-----------
>  1 file changed, 10 insertions(+), 11 deletions(-)
>
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> index 46f09f5988..fe9d91348d 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -244,7 +244,7 @@ struct vhost_user {
>      struct vhost_dev *dev;
>      /* Shared between vhost devs of the same virtio device */
>      VhostUserState *user;
> -    QIOChannel *backend_ioc;
> +    QIOChannelSocket *backend_sioc;
>      GSource *backend_src;
>      NotifierWithReturn postcopy_notifier;
>      struct PostCopyFD  postcopy_fd;
> @@ -1789,8 +1789,8 @@ static void close_backend_channel(struct vhost_user *u)
>      g_source_destroy(u->backend_src);
>      g_source_unref(u->backend_src);
>      u->backend_src = NULL;
> -    object_unref(OBJECT(u->backend_ioc));
> -    u->backend_ioc = NULL;
> +    object_unref(OBJECT(u->backend_sioc));
> +    u->backend_sioc = NULL;
>  }
>
>  static gboolean backend_read(QIOChannel *ioc, GIOCondition condition,
> @@ -1897,7 +1897,6 @@ static int vhost_setup_backend_channel(struct vhost_dev *dev)
>      bool reply_supported =
>          vhost_user_has_prot(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK);
>      Error *local_err = NULL;
> -    QIOChannel *ioc;
>
>      if (!vhost_user_has_prot(dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ)) {
>          return 0;
> @@ -1909,15 +1908,15 @@ static int vhost_setup_backend_channel(struct vhost_dev *dev)
>          return -saved_errno;
>      }
>
> -    ioc = QIO_CHANNEL(qio_channel_socket_new_fd(sv[0], &local_err));
> -    if (!ioc) {
> +    u->backend_sioc = qio_channel_socket_new_fd(sv[0], &local_err);
> +    if (!u->backend_sioc) {
>          error_report_err(local_err);
>          return -ECONNREFUSED;
>      }
> -    u->backend_ioc = ioc;
> -    u->backend_src = qio_channel_add_watch_source(u->backend_ioc,
> -                                                G_IO_IN | G_IO_HUP,
> -                                                backend_read, dev, NULL, NULL);
> +    u->backend_src = qio_channel_add_watch_source(QIO_CHANNEL(u->backend_sioc),
> +                                                  G_IO_IN | G_IO_HUP,
> +                                                  backend_read, dev,
> +                                                  NULL, NULL);
>
>      if (reply_supported) {
>          msg.hdr.flags |= VHOST_USER_NEED_REPLY_MASK;
> @@ -2321,7 +2320,7 @@ static int vhost_user_backend_cleanup(struct vhost_dev *dev)
>          close(u->postcopy_fd.fd);
>          u->postcopy_fd.handler = NULL;
>      }
> -    if (u->backend_ioc) {
> +    if (u->backend_sioc) {
>          close_backend_channel(u);
>      }
>      g_free(u->region_rb);
> --
> 2.48.1
>
>