All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: stefanha@redhat.com, qemu-devel@nongnu.org
Cc: Laurent Vivier <lvivier@redhat.com>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>
Subject: [PULL 26/26] net: stream: add QAPI events to report connection state
Date: Fri, 28 Oct 2022 13:48:35 +0800	[thread overview]
Message-ID: <20221028054835.29674-27-jasowang@redhat.com> (raw)
In-Reply-To: <20221028054835.29674-1-jasowang@redhat.com>

From: Laurent Vivier <lvivier@redhat.com>

The netdev reports NETDEV_STREAM_CONNECTED event when the backend
is connected, and NETDEV_STREAM_DISCONNECTED when it is disconnected.

The NETDEV_STREAM_CONNECTED event includes the destination address.

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

For instance with passt:

{ 'execute': 'qmp_capabilities' }
{ "return": { } }
{ "timestamp": { "seconds": 1666341395, "microseconds": 505347 },
    "event": "NETDEV_STREAM_CONNECTED",
    "data": { "netdev-id": "netdev0",
        "addr": { "path": "/tmp/passt_1.socket", "type": "unix" } } }

[killing passt here]

{ "timestamp": { "seconds": 1666341430, "microseconds": 968694 },
    "event": "NETDEV_STREAM_DISCONNECTED",
    "data": { "netdev-id": "netdev0" } }

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 net/stream.c  |  5 +++++
 qapi/net.json | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/net/stream.c b/net/stream.c
index 54c67e1..53b7040 100644
--- a/net/stream.c
+++ b/net/stream.c
@@ -38,6 +38,7 @@
 #include "io/channel.h"
 #include "io/channel-socket.h"
 #include "io/net-listener.h"
+#include "qapi/qapi-events-net.h"
 
 typedef struct NetStreamState {
     NetClientState nc;
@@ -168,6 +169,8 @@ static gboolean net_stream_send(QIOChannel *ioc,
         s->nc.link_down = true;
         qemu_set_info_str(&s->nc, "");
 
+        qapi_event_send_netdev_stream_disconnected(s->nc.name);
+
         return G_SOURCE_REMOVE;
     }
     buf = buf1;
@@ -244,6 +247,7 @@ static void net_stream_listen(QIONetListener *listener,
     uri = socket_uri(addr);
     qemu_set_info_str(&s->nc, uri);
     g_free(uri);
+    qapi_event_send_netdev_stream_connected(s->nc.name, addr);
     qapi_free_SocketAddress(addr);
 }
 
@@ -335,6 +339,7 @@ static void net_stream_client_connected(QIOTask *task, gpointer opaque)
     s->ioc_read_tag = qio_channel_add_watch(s->ioc, G_IO_IN, net_stream_send,
                                             s, NULL);
     s->nc.link_down = false;
+    qapi_event_send_netdev_stream_connected(s->nc.name, addr);
     qapi_free_SocketAddress(addr);
 
     return;
diff --git a/qapi/net.json b/qapi/net.json
index cbc8d77..522ac58 100644
--- a/qapi/net.json
+++ b/qapi/net.json
@@ -898,3 +898,52 @@
 ##
 { 'event': 'FAILOVER_NEGOTIATED',
   'data': {'device-id': 'str'} }
+
+##
+# @NETDEV_STREAM_CONNECTED:
+#
+# Emitted when the netdev stream backend is connected
+#
+# @netdev-id: QEMU netdev id that is connected
+# @addr: The destination address
+#
+# Since: 7.2
+#
+# Example:
+#
+# <- { "event": "NETDEV_STREAM_CONNECTED",
+#      "data": { "netdev-id": "netdev0",
+#                "addr": { "port": "47666", "ipv6": true,
+#                          "host": "::1", "type": "inet" } },
+#      "timestamp": { "seconds": 1666269863, "microseconds": 311222 } }
+#
+# or
+#
+# <- { "event": "NETDEV_STREAM_CONNECTED",
+#      "data": { "netdev-id": "netdev0",
+#                "addr": { "path": "/tmp/qemu0", "type": "unix" } },
+#      "timestamp": { "seconds": 1666269706, "microseconds": 413651 } }
+#
+##
+{ 'event': 'NETDEV_STREAM_CONNECTED',
+  'data': { 'netdev-id': 'str',
+            'addr': 'SocketAddress' } }
+
+##
+# @NETDEV_STREAM_DISCONNECTED:
+#
+# Emitted when the netdev stream backend is disconnected
+#
+# @netdev-id: QEMU netdev id that is disconnected
+#
+# Since: 7.2
+#
+# Example:
+#
+# <- { 'event': 'NETDEV_STREAM_DISCONNECTED',
+#      'data': {'netdev-id': 'netdev0'},
+#      'timestamp': {'seconds': 1663330937, 'microseconds': 526695} }
+#
+##
+{ 'event': 'NETDEV_STREAM_DISCONNECTED',
+  'data': { 'netdev-id': 'str' } }
-- 
2.7.4



  parent reply	other threads:[~2022-10-28  5:58 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-28  5:48 [PULL 00/26] Net patches Jason Wang
2022-10-28  5:48 ` [PULL 01/26] virtio-net: fix bottom-half packet TX on asynchronous completion Jason Wang
2022-10-28  5:48 ` [PULL 02/26] virtio-net: fix TX timer with tx_burst Jason Wang
2022-10-28  5:48 ` [PULL 03/26] vdpa: Delete duplicated vdpa_feature_bits entry Jason Wang
2022-10-28  5:48 ` [PULL 04/26] vdpa: Remove shadow CVQ command check Jason Wang
2022-10-28  5:48 ` [PULL 05/26] vhost-vdpa: allow passing opened vhostfd to vhost-vdpa Jason Wang
2022-10-31 13:22   ` Peter Maydell
2022-10-28  5:48 ` [PULL 06/26] net: improve error message for missing netdev backend Jason Wang
2022-10-28  5:48 ` [PULL 07/26] vhost: allocate event_idx fields on vring Jason Wang
2022-10-28  5:48 ` [PULL 08/26] vhost: toggle device callbacks using used event idx Jason Wang
2022-10-28  5:48 ` [PULL 09/26] vhost: use avail event idx on vhost_svq_kick Jason Wang
2022-10-28  5:48 ` [PULL 10/26] vhost: Accept event idx flag Jason Wang
2022-10-28  5:48 ` [PULL 11/26] net: introduce convert_host_port() Jason Wang
2022-10-28  5:48 ` [PULL 12/26] net: remove the @errp argument of net_client_inits() Jason Wang
2022-10-28  5:48 ` [PULL 13/26] net: simplify net_client_parse() error management Jason Wang
2022-10-28  5:48 ` [PULL 14/26] qapi: net: introduce a way to bypass qemu_opts_parse_noisily() Jason Wang
2022-10-28  5:48 ` [PULL 15/26] net: introduce qemu_set_info_str() function Jason Wang
2022-10-28  5:48 ` [PULL 16/26] qapi: net: add stream and dgram netdevs Jason Wang
2022-10-28  5:48 ` [PULL 17/26] net: socket: Don't ignore EINVAL on netdev socket connection Jason Wang
2022-10-28  5:48 ` [PULL 18/26] net: stream: " Jason Wang
2022-10-28  5:48 ` [PULL 19/26] net: stream: add unix socket Jason Wang
2022-10-28  5:48 ` [PULL 20/26] net: dgram: make dgram_dst generic Jason Wang
2022-10-28  5:48 ` [PULL 21/26] net: dgram: move mcast specific code from net_socket_fd_init_dgram() Jason Wang
2022-10-28  5:48 ` [PULL 22/26] net: dgram: add unix socket Jason Wang
2022-10-28  5:48 ` [PULL 23/26] qemu-sockets: move and rename SocketAddress_to_str() Jason Wang
2022-10-28  5:48 ` [PULL 24/26] qemu-sockets: update socket_uri() and socket_parse() to be consistent Jason Wang
2022-10-28  5:48 ` [PULL 25/26] net: stream: move to QIO to enable additional parameters Jason Wang
2022-10-28  5:48 ` Jason Wang [this message]
2022-10-31 10:13 ` [PULL 00/26] Net patches Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221028054835.29674-27-jasowang@redhat.com \
    --to=jasowang@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.