qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] net: vhost-user: add QAPI events to report connection state
@ 2025-02-14  9:31 Laurent Vivier
  2025-02-14  9:49 ` Daniel P. Berrangé
  0 siblings, 1 reply; 2+ messages in thread
From: Laurent Vivier @ 2025-02-14  9:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Markus Armbruster, Stefano Brivio, Marc-André Lureau,
	Jason Wang, Eric Blake, Paolo Bonzini, Michael S. Tsirkin,
	Laine Stump

The netdev reports NETDEV_VHOST_USER_CONNECTED event when
the chardev is connected, and NETDEV_VHOST_USER_DISCONNECTED
when it is disconnected.

The NETDEV_VHOST_USER_CONNECTED event includes the ChardevInfo
(label, filename and frontend_open).

This allows a system manager like libvirt to detect when the server
fails.

For instance with passt:

{ 'execute': 'qmp_capabilities' }
{ "return": { } }

[killing passt here]

{ "timestamp": { "seconds": 1739517243, "microseconds": 115081 },
  "event": "NETDEV_VHOST_USER_DISCONNECTED",
  "data": { "netdev-id": "netdev0" } }

[automatic reconnection with reconnect-ms]

{ "timestamp": { "seconds": 1739517290, "microseconds": 343777 },
  "event": "NETDEV_VHOST_USER_CONNECTED",
  "data": { "netdev-id": "netdev0",
            "info": { "frontend-open": true,
                      "filename": "unix:",
                      "label": "chr0" } } }

Tested-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---

Notes:
    v2:
      - remove duplicate line info.frontend_open

 qapi/char.json   | 43 +++++++++++++++++++++++++++++++++++++++++++
 net/vhost-user.c |  7 +++++++
 2 files changed, 50 insertions(+)

diff --git a/qapi/char.json b/qapi/char.json
index f02b66c06b3e..a8094c86fb49 100644
--- a/qapi/char.json
+++ b/qapi/char.json
@@ -902,3 +902,46 @@
 { 'event': 'VSERPORT_CHANGE',
   'data': { 'id': 'str',
             'open': 'bool' } }
+
+##
+# @NETDEV_VHOST_USER_CONNECTED:
+#
+# Emitted when the vhost-user chardev is connected
+#
+# @netdev-id: QEMU netdev id that is connected
+#
+# @info: The chardev information
+#
+# Since: 10.0
+#
+# .. qmp-example::
+#
+#     <- { "timestamp": { "seconds": 1739469793, "microseconds": 683713 },
+#          "event": "NETDEV_VHOST_USER_CONNECTED",
+#          "data": { "netdev-id": "netdev0",
+#                   "info": { "frontend-open": true,
+#                             "filename": "unix:",
+#                             "label": "chr0" } } }
+#
+##
+{ 'event': 'NETDEV_VHOST_USER_CONNECTED',
+  'data': { 'netdev-id': 'str', 'info': 'ChardevInfo' } }
+
+##
+# @NETDEV_VHOST_USER_DISCONNECTED:
+#
+# Emitted when the vhost-user chardev is disconnected
+#
+# @netdev-id: QEMU netdev id that is disconnected
+#
+# Since: 10.0
+#
+# .. qmp-example::
+#
+#     <- { "timestamp": { "seconds": 1739469786, "microseconds": 822220 },
+#          "event": "NETDEV_VHOST_USER_DISCONNECTED",
+#          "data": { "netdev-id": "netdev0" } }
+#
+##
+{ 'event': 'NETDEV_VHOST_USER_DISCONNECTED',
+  'data': { 'netdev-id': 'str' } }
diff --git a/net/vhost-user.c b/net/vhost-user.c
index 12555518e838..049174f704cd 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -16,6 +16,7 @@
 #include "chardev/char-fe.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-net.h"
+#include "qapi/qapi-events-char.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
 #include "qemu/option.h"
@@ -271,6 +272,7 @@ static void chr_closed_bh(void *opaque)
     if (err) {
         error_report_err(err);
     }
+    qapi_event_send_netdev_vhost_user_disconnected(name);
 }
 
 static void net_vhost_user_event(void *opaque, QEMUChrEvent event)
@@ -278,6 +280,7 @@ static void net_vhost_user_event(void *opaque, QEMUChrEvent event)
     const char *name = opaque;
     NetClientState *ncs[MAX_QUEUE_NUM];
     NetVhostUserState *s;
+    ChardevInfo info;
     Chardev *chr;
     Error *err = NULL;
     int queues;
@@ -300,6 +303,10 @@ static void net_vhost_user_event(void *opaque, QEMUChrEvent event)
                                          net_vhost_user_watch, s);
         qmp_set_link(name, true, &err);
         s->started = true;
+        info.label = chr->label;
+        info.filename = chr->filename;
+        info.frontend_open = chr->be && chr->be->fe_is_open;
+        qapi_event_send_netdev_vhost_user_connected(name, &info);
         break;
     case CHR_EVENT_CLOSED:
         /* a close event may happen during a read/write, but vhost
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] net: vhost-user: add QAPI events to report connection state
  2025-02-14  9:31 [PATCH v2] net: vhost-user: add QAPI events to report connection state Laurent Vivier
@ 2025-02-14  9:49 ` Daniel P. Berrangé
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel P. Berrangé @ 2025-02-14  9:49 UTC (permalink / raw)
  To: Laurent Vivier
  Cc: qemu-devel, Markus Armbruster, Stefano Brivio,
	Marc-André Lureau, Jason Wang, Eric Blake, Paolo Bonzini,
	Michael S. Tsirkin, Laine Stump

On Fri, Feb 14, 2025 at 10:31:10AM +0100, Laurent Vivier wrote:
> The netdev reports NETDEV_VHOST_USER_CONNECTED event when
> the chardev is connected, and NETDEV_VHOST_USER_DISCONNECTED
> when it is disconnected.
> 
> The NETDEV_VHOST_USER_CONNECTED event includes the ChardevInfo
> (label, filename and frontend_open).
> 
> This allows a system manager like libvirt to detect when the server
> fails.
> 
> For instance with passt:
> 
> { 'execute': 'qmp_capabilities' }
> { "return": { } }
> 
> [killing passt here]
> 
> { "timestamp": { "seconds": 1739517243, "microseconds": 115081 },
>   "event": "NETDEV_VHOST_USER_DISCONNECTED",
>   "data": { "netdev-id": "netdev0" } }
> 
> [automatic reconnection with reconnect-ms]
> 
> { "timestamp": { "seconds": 1739517290, "microseconds": 343777 },
>   "event": "NETDEV_VHOST_USER_CONNECTED",
>   "data": { "netdev-id": "netdev0",
>             "info": { "frontend-open": true,
>                       "filename": "unix:",
>                       "label": "chr0" } } }

I'm wondering what the benefit of including the chardev info
is here ? It seems like the netdev-id is sufficient for the
mgmt app to handle the situation

The 'filename' is a legacy representation of the ChardevBackend
struct info, that we shouldn't propagate to new places IMHO.

The 'frontend-open' flag meanwhile is liable to be out of date
since events are delivered asychronously.

So at most the chardev 'id' is appropriate to be included (yes,
'id' not 'label' which is another legacy internal term). None
the less, I still figure that the mgmt app would lookup the
details via the netdev-id, not chardev, so not convinced we
even need the chardev.

> 
> Tested-by: Stefano Brivio <sbrivio@redhat.com>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
> 
> Notes:
>     v2:
>       - remove duplicate line info.frontend_open
> 
>  qapi/char.json   | 43 +++++++++++++++++++++++++++++++++++++++++++
>  net/vhost-user.c |  7 +++++++
>  2 files changed, 50 insertions(+)
> 
> diff --git a/qapi/char.json b/qapi/char.json
> index f02b66c06b3e..a8094c86fb49 100644
> --- a/qapi/char.json
> +++ b/qapi/char.json
> @@ -902,3 +902,46 @@
>  { 'event': 'VSERPORT_CHANGE',
>    'data': { 'id': 'str',
>              'open': 'bool' } }
> +
> +##
> +# @NETDEV_VHOST_USER_CONNECTED:
> +#
> +# Emitted when the vhost-user chardev is connected
> +#
> +# @netdev-id: QEMU netdev id that is connected
> +#
> +# @info: The chardev information
> +#
> +# Since: 10.0
> +#
> +# .. qmp-example::
> +#
> +#     <- { "timestamp": { "seconds": 1739469793, "microseconds": 683713 },
> +#          "event": "NETDEV_VHOST_USER_CONNECTED",
> +#          "data": { "netdev-id": "netdev0",
> +#                   "info": { "frontend-open": true,
> +#                             "filename": "unix:",
> +#                             "label": "chr0" } } }
> +#
> +##
> +{ 'event': 'NETDEV_VHOST_USER_CONNECTED',
> +  'data': { 'netdev-id': 'str', 'info': 'ChardevInfo' } }
> +
> +##
> +# @NETDEV_VHOST_USER_DISCONNECTED:
> +#
> +# Emitted when the vhost-user chardev is disconnected
> +#
> +# @netdev-id: QEMU netdev id that is disconnected
> +#
> +# Since: 10.0
> +#
> +# .. qmp-example::
> +#
> +#     <- { "timestamp": { "seconds": 1739469786, "microseconds": 822220 },
> +#          "event": "NETDEV_VHOST_USER_DISCONNECTED",
> +#          "data": { "netdev-id": "netdev0" } }
> +#
> +##
> +{ 'event': 'NETDEV_VHOST_USER_DISCONNECTED',
> +  'data': { 'netdev-id': 'str' } }
> diff --git a/net/vhost-user.c b/net/vhost-user.c
> index 12555518e838..049174f704cd 100644
> --- a/net/vhost-user.c
> +++ b/net/vhost-user.c
> @@ -16,6 +16,7 @@
>  #include "chardev/char-fe.h"
>  #include "qapi/error.h"
>  #include "qapi/qapi-commands-net.h"
> +#include "qapi/qapi-events-char.h"
>  #include "qemu/config-file.h"
>  #include "qemu/error-report.h"
>  #include "qemu/option.h"
> @@ -271,6 +272,7 @@ static void chr_closed_bh(void *opaque)
>      if (err) {
>          error_report_err(err);
>      }
> +    qapi_event_send_netdev_vhost_user_disconnected(name);
>  }
>  
>  static void net_vhost_user_event(void *opaque, QEMUChrEvent event)
> @@ -278,6 +280,7 @@ static void net_vhost_user_event(void *opaque, QEMUChrEvent event)
>      const char *name = opaque;
>      NetClientState *ncs[MAX_QUEUE_NUM];
>      NetVhostUserState *s;
> +    ChardevInfo info;
>      Chardev *chr;
>      Error *err = NULL;
>      int queues;
> @@ -300,6 +303,10 @@ static void net_vhost_user_event(void *opaque, QEMUChrEvent event)
>                                           net_vhost_user_watch, s);
>          qmp_set_link(name, true, &err);
>          s->started = true;
> +        info.label = chr->label;
> +        info.filename = chr->filename;
> +        info.frontend_open = chr->be && chr->be->fe_is_open;

I gues 

> +        qapi_event_send_netdev_vhost_user_connected(name, &info);
>          break;
>      case CHR_EVENT_CLOSED:
>          /* a close event may happen during a read/write, but vhost
> -- 
> 2.48.1
> 
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-02-14  9:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-14  9:31 [PATCH v2] net: vhost-user: add QAPI events to report connection state Laurent Vivier
2025-02-14  9:49 ` Daniel P. Berrangé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).