From nobody Sat Sep 28 20:55:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1546884619063651.272223322777; Mon, 7 Jan 2019 10:10:19 -0800 (PST) Received: from localhost ([127.0.0.1]:38989 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ggZLt-0003lc-Hk for importer@patchew.org; Mon, 07 Jan 2019 13:10:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ggZ7f-0007Cc-C3 for qemu-devel@nongnu.org; Mon, 07 Jan 2019 12:55:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ggZ7c-0003EI-3C for qemu-devel@nongnu.org; Mon, 07 Jan 2019 12:55:35 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:50674) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ggZ7Y-0002o0-Q4 for qemu-devel@nongnu.org; Mon, 07 Jan 2019 12:55:30 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x07HsBKh099038; Mon, 7 Jan 2019 17:55:17 GMT Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2ptm0ty8ca-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Jan 2019 17:55:16 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x07HtG5U023794 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 7 Jan 2019 17:55:16 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x07HtGoB030026; Mon, 7 Jan 2019 17:55:16 GMT Received: from ban25x6uut28.us.oracle.com (/10.153.73.28) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 Jan 2019 09:55:15 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=BSr3YC9+RJmq8+o7uv2zw6SOOGI2JWGR7TgxZsRm6aA=; b=ROF9MZR0HBeE1jv56TUlrCmVrx+kBOc/Mz24cfWxyRs/cZxuWPQK5ZcznVCnd3fTLZli MUYeBKw0HvebPNgWbDeGPAyqbupcKbIClSDIZeF2qtyid6dXPlKSsZOYEtwUxXp358y6 bz1eMjdFg2tQpzqPpucc41KOdoOaf8AZckSmdElxfm68Rp+3Xq3svxPYHcQyxcV/u9aC 0ZIEwUrBhWHvgj71Wsaevwb0r4zNWfexrlUKRJM/6UMJjvvpwT/StoT1qvX5rmksga2j QRMPnQX1bSshFu/PgEIVxVlLYBamMz+z9toJg6Ef7i4evammDJqpEfPdi/qkzf+sFWWm wA== From: Venu Busireddy To: venu.busireddy@oracle.com, "Michael S. Tsirkin" , Marcel Apfelbaum Date: Mon, 7 Jan 2019 12:54:48 -0500 Message-Id: <1546883690-17798-4-git-send-email-venu.busireddy@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1546883690-17798-1-git-send-email-venu.busireddy@oracle.com> References: <1546883690-17798-1-git-send-email-venu.busireddy@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9129 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901070153 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [PATCH v2 3/5] virtio_net: Add a query command for FAILOVER_STANDBY_CHANGED event. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a query command to check the status of the FAILOVER_STANDBY_CHANGED state of the virtio_net devices. Signed-off-by: Venu Busireddy --- hw/net/virtio-net.c | 16 ++++++++++++ include/hw/virtio/virtio-net.h | 1 + include/net/net.h | 2 ++ net/net.c | 59 ++++++++++++++++++++++++++++++++++++++= ++++ qapi/net.json | 46 ++++++++++++++++++++++++++++++++ 5 files changed, 124 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 7b1bcde..a4e07ac 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -263,9 +263,11 @@ static void virtio_net_failover_notify_event(VirtIONet= *n, uint8_t status) */ if ((status & VIRTIO_CONFIG_S_DRIVER_OK) && (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK))) { + n->standby_enabled =3D true; qapi_event_send_failover_standby_changed(!!ncn, ncn, path, tru= e); } else if ((!(status & VIRTIO_CONFIG_S_DRIVER_OK)) && (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) { + n->standby_enabled =3D false; qapi_event_send_failover_standby_changed(!!ncn, ncn, path, fal= se); } } @@ -448,6 +450,19 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClie= ntState *nc) return info; } =20 +static StandbyStatusInfo *virtio_net_query_standby_status(NetClientState *= nc) +{ + StandbyStatusInfo *info; + VirtIONet *n =3D qemu_get_nic_opaque(nc); + + info =3D g_malloc0(sizeof(*info)); + info->device =3D g_strdup(n->netclient_name); + info->path =3D g_strdup(object_get_canonical_path(OBJECT(n->qdev))); + info->enabled =3D n->standby_enabled; + + return info; +} + static void virtio_net_reset(VirtIODevice *vdev) { VirtIONet *n =3D VIRTIO_NET(vdev); @@ -1923,6 +1938,7 @@ static NetClientInfo net_virtio_info =3D { .receive =3D virtio_net_receive, .link_status_changed =3D virtio_net_set_link_status, .query_rx_filter =3D virtio_net_query_rxfilter, + .query_standby_status =3D virtio_net_query_standby_status, }; =20 static bool virtio_net_guest_notifier_pending(VirtIODevice *vdev, int idx) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 4d7f3c8..9071e96 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -103,6 +103,7 @@ typedef struct VirtIONet { int announce_counter; bool needs_vnet_hdr_swap; bool mtu_bypass_backend; + bool standby_enabled; } VirtIONet; =20 void virtio_net_set_netclient_name(VirtIONet *n, const char *name, diff --git a/include/net/net.h b/include/net/net.h index ec13702..61e8513 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -50,6 +50,7 @@ typedef void (NetCleanup) (NetClientState *); typedef void (LinkStatusChanged)(NetClientState *); typedef void (NetClientDestructor)(NetClientState *); typedef RxFilterInfo *(QueryRxFilter)(NetClientState *); +typedef StandbyStatusInfo *(QueryStandbyStatus)(NetClientState *); typedef bool (HasUfo)(NetClientState *); typedef bool (HasVnetHdr)(NetClientState *); typedef bool (HasVnetHdrLen)(NetClientState *, int); @@ -71,6 +72,7 @@ typedef struct NetClientInfo { NetCleanup *cleanup; LinkStatusChanged *link_status_changed; QueryRxFilter *query_rx_filter; + QueryStandbyStatus *query_standby_status; NetPoll *poll; HasUfo *has_ufo; HasVnetHdr *has_vnet_hdr; diff --git a/net/net.c b/net/net.c index 1f7d626..a6d8e73 100644 --- a/net/net.c +++ b/net/net.c @@ -1320,6 +1320,65 @@ RxFilterInfoList *qmp_query_rx_filter(bool has_name,= const char *name, return filter_list; } =20 +StandbyStatusInfoList *qmp_query_standby_status(bool has_device, + const char *device, + Error **errp) +{ + NetClientState *nc; + StandbyStatusInfoList *status_list =3D NULL, *last_entry =3D NULL; + + QTAILQ_FOREACH(nc, &net_clients, next) { + StandbyStatusInfoList *entry; + StandbyStatusInfo *info; + + if (has_device && strcmp(nc->name, device) !=3D 0) { + continue; + } + + /* only query standby status information of NIC */ + if (nc->info->type !=3D NET_CLIENT_DRIVER_NIC) { + if (has_device) { + error_setg(errp, "net client(%s) isn't a NIC", device); + return NULL; + } + continue; + } + + /* only query information on queue 0 since the info is per nic, + * not per queue + */ + if (nc->queue_index !=3D 0) + continue; + + if (nc->info->query_standby_status) { + info =3D nc->info->query_standby_status(nc); + entry =3D g_malloc0(sizeof(*entry)); + entry->value =3D info; + + if (!status_list) { + status_list =3D entry; + } else { + last_entry->next =3D entry; + } + last_entry =3D entry; + } else if (has_device) { + error_setg(errp, "net client(%s) doesn't support" + " standby status querying", device); + return NULL; + } + + if (has_device) { + break; + } + } + + if (status_list =3D=3D NULL && has_device) { + error_setg(errp, "invalid net client name: %s", device); + } + + return status_list; +} + void hmp_info_network(Monitor *mon, const QDict *qdict) { NetClientState *nc, *peer; diff --git a/qapi/net.json b/qapi/net.json index 6a6d6fe..633ac87 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -711,3 +711,49 @@ ## { 'event': 'FAILOVER_STANDBY_CHANGED', 'data': {'*device': 'str', 'path': 'str', 'enabled': 'bool'} } + +## +# @StandbyStatusInfo: +# +# Standby status information for a virtio_net device. +# +# @device: Indicates the virtio_net device. +# +# @path: Indicates the device path. +# +# @enabled: true if the virtio_net driver is loaded. +# false if the virtio_net driver is unloaded or the guest reboot= ed. +# +# Since: 4.0 +## +{ 'struct': 'StandbyStatusInfo', + 'data': {'device': 'str', 'path': 'str', 'enabled': 'bool'} } + +## +# @query-standby-status: +# +# Return Standby status information for all virtio_net devices, +# or for the given virtio_net device. +# +# @device: Name of the virtio_net device. +# +# Returns: List of @StandbyStatusInfo for all virtio_net devices, +# or for the given virtio_net device. +# Returns an error if the given @device doesn't exist. +# +# Since: 4.0 +# +# Example: +# +# -> { "execute": "query-standby-status", "arguments": { "device": "net0" = } } +# <- { "return": [ +# { 'device': 'net0', +# 'path': '/machine/peripheral/net0/virtio-backend', +# 'enabled': 'true' +# } +# ] +# } +# +## +{ 'command': 'query-standby-status', 'data': { '*device': 'str' }, + 'returns': ['StandbyStatusInfo'] }