From nobody Wed Feb 11 05:11:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507034973157500.89074966075987; Tue, 3 Oct 2017 05:49:33 -0700 (PDT) Received: from localhost ([::1]:58439 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzMda-00060O-4o for importer@patchew.org; Tue, 03 Oct 2017 08:49:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzMcD-0005Ke-NO for qemu-devel@nongnu.org; Tue, 03 Oct 2017 08:48:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzMcC-0000Nc-1f for qemu-devel@nongnu.org; Tue, 03 Oct 2017 08:48:01 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:19160 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzMcB-0000Iz-LI for qemu-devel@nongnu.org; Tue, 03 Oct 2017 08:47:59 -0400 Received: from work.sw.ru. (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v93Cln2C003268; Tue, 3 Oct 2017 15:47:55 +0300 (MSK) From: Jan Dakinevich To: qemu-devel@nongnu.org Date: Tue, 3 Oct 2017 15:47:41 +0300 Message-Id: <1507034861-4661-3-git-send-email-jan.dakinevich@virtuozzo.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1507034861-4661-1-git-send-email-jan.dakinevich@virtuozzo.com> References: <1507034861-4661-1-git-send-email-jan.dakinevich@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH v4 2/2] virtio: add `info virtio' HMP command 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: Kevin Wolf , "Denis V. Lunev" , Amit Shah , Markus Armbruster , Jason Wang , Cornelia Huck , "Dr. David Alan Gilbert" , Max Reitz , Jan Dakinevich , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The command prints data from `query-virtio' QMP in human-readable format. Cc: Denis V. Lunev Signed-off-by: Jan Dakinevich --- hmp-commands-info.hx | 14 ++++++++++ hmp.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ hmp.h | 1 + 3 files changed, 94 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 4f1ece9..2550027 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -868,6 +868,20 @@ ETEXI }, =20 STEXI +@item info virtio +@findex virtio +Display guest and host fetures for all virtio devices. +ETEXI + + { + .name =3D "virtio", + .args_type =3D "", + .params =3D "", + .help =3D "show virtio info", + .cmd =3D hmp_info_virtio, + }, + +STEXI @end table ETEXI =20 diff --git a/hmp.c b/hmp.c index ace729d..c4dd280 100644 --- a/hmp.c +++ b/hmp.c @@ -43,6 +43,7 @@ #include "hw/intc/intc.h" #include "migration/snapshot.h" #include "migration/misc.h" +#include "hw/virtio/virtio.h" =20 #ifdef CONFIG_SPICE #include @@ -2894,3 +2895,81 @@ void hmp_info_memory_size_summary(Monitor *mon, cons= t QDict *qdict) } hmp_handle_error(mon, &err); } + +#define HMP_INFO_VIRTIO_INDENT 2 +#define HMP_INFO_VIRTIO_FIELD 32 + +static void hmp_info_virtio_print_status(Monitor *mon, VirtioInfo *info, + VirtioInfoDevice *device) +{ + VirtioInfoBitList *lbit; + const char *comma =3D ""; + + for (lbit =3D info->status_names; lbit; lbit =3D lbit->next) { + if (!(device->status & (1ull << lbit->value->bit))) { + continue; + } + monitor_printf(mon, "%s%s", comma, lbit->value->name); + comma =3D ","; + } + monitor_printf(mon, "\n"); +} + +static void hmp_info_virtio_print_features(Monitor *mon, + VirtioInfoBitList *list, + VirtioInfoDevice *device) +{ + VirtioInfoBitList *lbit; + + for (lbit =3D list; lbit; lbit =3D lbit->next) { + const char *ack =3D virtio_has_feature(device->guest_features, + lbit->value->bit) ? "acked" := ""; + if (!virtio_has_feature(device->host_features, lbit->value->bit)) { + continue; + } + monitor_printf(mon, "%*s%*s%*s\n", HMP_INFO_VIRTIO_INDENT, "", + HMP_INFO_VIRTIO_FIELD, lbit->value->name, + HMP_INFO_VIRTIO_FIELD, ack); + } +} + +static void hmp_info_virtio_print(Monitor *mon, VirtioInfo *info, + VirtioInfoDevice *device) +{ + Object *obj =3D object_resolve_path(device->qom_path, NULL); + char *path =3D qdev_get_dev_path(DEVICE(obj)); + + monitor_printf(mon, "%s at %s\n", object_get_typename(obj), path); + g_free(path); + + monitor_printf(mon, "%*sstatus: 0x%02"PRIx64" ", + HMP_INFO_VIRTIO_INDENT, "", device->status); + hmp_info_virtio_print_status(mon, info, device); + + monitor_printf(mon, "%*shost features: 0x%016"PRIx64"\n", + HMP_INFO_VIRTIO_INDENT, "", device->host_features); + monitor_printf(mon, "%*sguest features: 0x%016"PRIx64"\n", + HMP_INFO_VIRTIO_INDENT, "", device->guest_features); + + monitor_printf(mon, "%*scommon features:\n", HMP_INFO_VIRTIO_INDENT, "= "); + hmp_info_virtio_print_features(mon, info->feature_names, device); + + monitor_printf(mon, "%*sspecific features:\n", HMP_INFO_VIRTIO_INDENT,= ""); + hmp_info_virtio_print_features(mon, device->feature_names, device); +} + +void hmp_info_virtio(Monitor *mon, const QDict *qdict) +{ + Error *err =3D NULL; + VirtioInfo *info; + VirtioInfoDeviceList *ldevice; + + info =3D qmp_query_virtio(&err); + if (err) { + return; + } + + for (ldevice =3D info->devices; ldevice; ldevice =3D ldevice->next) { + hmp_info_virtio_print(mon, info, ldevice->value); + } +} diff --git a/hmp.h b/hmp.h index 3605003..3e8f30a 100644 --- a/hmp.h +++ b/hmp.h @@ -146,5 +146,6 @@ void hmp_info_ramblock(Monitor *mon, const QDict *qdict= ); void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict); void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict); void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict); +void hmp_info_virtio(Monitor *mon, const QDict *qdict); =20 #endif --=20 2.1.4