From patchwork Thu Oct 20 09:16:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13012962 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 80C9BC4332F for ; Thu, 20 Oct 2022 10:09:25 +0000 (UTC) Received: from localhost ([::1]:41524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olSUO-00046o-DD for qemu-devel@archiver.kernel.org; Thu, 20 Oct 2022 06:09:24 -0400 Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olRwL-0001PT-V4 for qemu-devel@archiver.kernel.org; Thu, 20 Oct 2022 05:34:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olRfp-00032F-PU for qemu-devel@nongnu.org; Thu, 20 Oct 2022 05:17:11 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:47683) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olRfn-0005LK-Bq for qemu-devel@nongnu.org; Thu, 20 Oct 2022 05:17:09 -0400 Received: from lenovo-t14s.redhat.com ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MnJdE-1pUiej3hw4-00jGVW; Thu, 20 Oct 2022 11:16:58 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , xen-devel@lists.xenproject.org, Eric Blake , Stefano Stabellini , Paolo Bonzini , Greg Kurz , Jason Wang , Anthony Perard , Thomas Huth , David Gibson , "Michael S. Tsirkin" , Laurent Vivier , Samuel Thibault , "Dr. David Alan Gilbert" , Paul Durrant , Stefan Weil , Markus Armbruster Subject: [PATCH v12 17/17] net: stream: add QAPI events to report connection state Date: Thu, 20 Oct 2022 11:16:24 +0200 Message-Id: <20221020091624.48368-18-lvivier@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221020091624.48368-1-lvivier@redhat.com> References: <20221020091624.48368-1-lvivier@redhat.com> MIME-Version: 1.0 X-Provags-ID: V03:K1:BMDXyw1i1PI1BNI3n7CxEZG2rEIig4qtmnIwVCRGZ8kKuSpDNWI 98LDzrvkBaD9Bb3ATUXF1OOjYAn4yNd4WeYdWUa0WtW9Fr8wNSWKYGoSIrVDEAEiq8Xaztt 0tg5+FMrdIviR82NsvaGYRBpvnCm+GWlexSe/UqcyhbPyPW1f2UGMgPpiB5idNsMbx77bal 7eYe5nvCTOQt8ijOekPkw== X-UI-Out-Filterresults: notjunk:1;V03:K0:5idzqakK7aA=:PdmSNBYPYZN6TfRGlZGxqf uJclGnrR2L7r2m8dJvBYB7KrlSsacFT4neCZ8eMhl1JRDu2DIvQMi9zxNpLKy8Crrt78iZiFZ QfWb8sveZegpSHE0EjeRd6akS9J6nTYRz7r9H0RH3p7bm42bJoCTKkBPtitRMyZak9bo7IVi2 igAYHAoAukxcz2Mz7gKuf0TqKxxlYoqhzQi6t2YXq0Upy9nIE3WJKcDD7lsm/3ODL2l2/fOZ6 OkdPFKWN8Dzqblx+sqORbAyo2hqYurEsDJqAGJEiDfYq8x+Y2N/TAS5On4PRhBocTRV0kVLQT AIXeQK8Lu/3C2XypbG2CJhWvcl4SS2vPxTaiU6FYe3YrAx+vbGOkY5DWXwm20Ofg7y5UoF9eY HVQIgj7ySsUiyz42rfesplZ85mGEne+VxePIMSJxxgTCj4Bq1Ywed8xkLiJr7j023tA5PTRPV ghBPg4jkjPzUfuDnlXbnmcOIvd0I6xYiABPjvxCHPpS3FLqL/CVgmHAZdabkR9H8YVx1QsgAM vRx8S0ngRcl+sScr4hdF7jgfh19V3g4Lc5VYV/vL9toDdnek9+CZXdJ0xA2Da+x3mALebsnqf Lm5ns6V0U5q+LlKEyY+dZpxhNNChd4YFpfra3mfIdUpW1ltJB0LLcLbwjzUd6LknTI3P2cnj0 hXsN9+xgjKzkfthpOpwn2+vrtPKc2Ix9j6rkvlvd14bZ5tkH4Vi67XEU/M+13qUhpsC8EDu9o 7OSM0VF2Y8ZZ5v+lJSEdUwdBmSdcKEJdwTXcDfUsBhHjHg45G35YWAtEKyLdBxKGMYJN0niJg 9tNRCkK Received-SPF: permerror client-ip=212.227.126.187; envelope-from=lvivier@redhat.com; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_FAIL=0.001, SPF_HELO_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 URI of the destination address. Signed-off-by: Laurent Vivier Acked-by: Michael S. Tsirkin --- net/stream.c | 11 +++++++++-- qapi/net.json | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/net/stream.c b/net/stream.c index 95d6b910407d..8ad757cefbdf 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; @@ -243,9 +246,10 @@ static void net_stream_listen(QIONetListener *listener, g_assert(addr != NULL); uri = socket_uri(addr); qemu_set_info_str(&s->nc, uri); - g_free(uri); qapi_free_SocketAddress(addr); + qapi_event_send_netdev_stream_connected(s->nc.name, uri); + g_free(uri); } static void net_stream_server_listening(QIOTask *task, gpointer opaque) @@ -317,12 +321,12 @@ static void net_stream_client_connected(QIOTask *task, gpointer opaque) g_assert(addr != NULL); uri = socket_uri(addr); qemu_set_info_str(&s->nc, uri); - g_free(uri); ret = qemu_socket_try_set_nonblock(sioc->fd); if (addr->type == SOCKET_ADDRESS_TYPE_FD && ret < 0) { qemu_set_info_str(&s->nc, "can't use file descriptor %s (errno %d)", addr->u.fd.str, -ret); + g_free(uri); qapi_free_SocketAddress(addr); goto error; } @@ -338,6 +342,9 @@ static void net_stream_client_connected(QIOTask *task, gpointer opaque) s, NULL); s->nc.link_down = false; + qapi_event_send_netdev_stream_connected(s->nc.name, uri); + g_free(uri); + return; error: object_unref(OBJECT(s->ioc)); diff --git a/qapi/net.json b/qapi/net.json index 39388b1b6c41..569ab7fd37e3 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -895,3 +895,49 @@ ## { '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 +# @uri: The Uniform Resource Identifier identifying the destination address +# +# Since: 7.2 +# +# Example: +# +# <- { 'event': 'NETDEV_STREAM_CONNECTED', +# 'data': {'uri': 'tcp:::1:1234', 'netdev-id': 'netdev0'}, +# 'timestamp': {'seconds': 1663330564, 'microseconds': 804317} } +# +# or +# +# <- { 'event': 'NETDEV_STREAM_CONNECTED', +# 'data': {'uri': ''unix:/tmp/qemu0', 'netdev-id': 'netdev0'}, +# 'timestamp': {'seconds': 1663330564, 'microseconds': 804317} } +# +## +{ 'event': 'NETDEV_STREAM_CONNECTED', + 'data': { 'netdev-id': 'str', + 'uri': 'str' } } + +## +# @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' } }