From nobody Mon Feb 9 17:24:49 2026 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508867484100682.8650231334954; Tue, 24 Oct 2017 10:51:24 -0700 (PDT) Received: from localhost ([::1]:44994 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e73M1-0005r1-H0 for importer@patchew.org; Tue, 24 Oct 2017 13:51:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42476) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e73Kh-00054d-AE for qemu-devel@nongnu.org; Tue, 24 Oct 2017 13:49:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e73Ke-0000vd-Rs for qemu-devel@nongnu.org; Tue, 24 Oct 2017 13:49:43 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:9536 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 1e73Ke-0000um-C5 for qemu-devel@nongnu.org; Tue, 24 Oct 2017 13:49:40 -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 v9OHnHt5003307; Tue, 24 Oct 2017 20:49:21 +0300 (MSK) From: Jan Dakinevich To: qemu-devel@nongnu.org Date: Tue, 24 Oct 2017 20:50:04 +0300 Message-Id: <1508867404-18046-3-git-send-email-jan.dakinevich@virtuozzo.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1508867404-18046-1-git-send-email-jan.dakinevich@virtuozzo.com> References: <1508867404-18046-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] [RFC v5 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" , "Michael S. Tsirkin" , Cornelia Huck , Markus Armbruster , "Dr. David Alan Gilbert" , Jan Dakinevich , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 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 | 122 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ hmp.h | 1 + 3 files changed, 137 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 54c3e5e..292280a 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -868,6 +868,20 @@ enabled) memory in bytes. ETEXI =20 STEXI +@item info virtio +@findex virtio +Display guest and host fetures for all virtio devices. +ETEXI + + { + .name =3D "virtio", + .args_type =3D "path:s?", + .params =3D "[path]", + .help =3D "show virtio info", + .cmd =3D hmp_info_virtio, + }, + +STEXI @end table ETEXI =20 diff --git a/hmp.c b/hmp.c index ec61329..440e48c 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 @@ -2901,3 +2902,124 @@ void hmp_info_memory_size_summary(Monitor *mon, con= st QDict *qdict) } hmp_handle_error(mon, &err); } + +#define HMP_INFO_VIRTIO_INDENT 2 +#define HMP_INFO_VIRTIO_ITEM 16 +#define HMP_INFO_VIRTIO_FIELD 24 + +static void hmp_info_virtio_print_status(Monitor *mon, VirtioInfo *info) +{ + VirtioStatusList *status; + const char *space =3D " "; + + monitor_printf(mon, "%*s%-*s0x%02"PRIx8"", HMP_INFO_VIRTIO_INDENT, "", + HMP_INFO_VIRTIO_ITEM, "status:", info->status); + + for (status =3D info->status_names; status; status =3D status->next) { + monitor_printf(mon, "%s%s", space, VirtioStatus_str(status->value)= ); + space =3D ","; + } + + monitor_printf(mon, "\n"); +} + +static void hmp_info_virtio_print_features(Monitor *mon, VirtioInfo *info) +{ + VirtioFeatureList *head; + + monitor_printf(mon, "%*s%-*s0x%016"PRIx64"\n", HMP_INFO_VIRTIO_INDENT,= "", + HMP_INFO_VIRTIO_ITEM, "host features:", + info->host_features); + monitor_printf(mon, "%*s%-*s0x%016"PRIx64"\n", HMP_INFO_VIRTIO_INDENT,= "", + HMP_INFO_VIRTIO_ITEM, "guest features:", + info->guest_features); + + if (info->features) { + monitor_printf(mon, "%*s%-*s\n", HMP_INFO_VIRTIO_INDENT, "", + HMP_INFO_VIRTIO_ITEM, "feature names:"); + monitor_printf(mon, "%*s%-*s%-*s%-*s%-*s\n", HMP_INFO_VIRTIO_INDEN= T, "", + HMP_INFO_VIRTIO_FIELD, "TYPE", + HMP_INFO_VIRTIO_FIELD, "NAME", + HMP_INFO_VIRTIO_FIELD, "HOST", + HMP_INFO_VIRTIO_FIELD, "GUEST"); + } + + for (head =3D info->features; head; head =3D head->next) { + VirtioFeature *feature =3D head->value; + const char *type =3D VirtioFeatureNameKind_str(feature->name->type= ); + const char *host =3D feature->host ? "true" : "false"; + const char *guest =3D feature->guest ? "true" : "false"; + const char *name; + + switch (feature->name->type) { + case VIRTIO_FEATURE_NAME_KIND_COMMON: + name =3D VirtioFeatureCommon_str(feature->name->u.common.data); + break; + case VIRTIO_FEATURE_NAME_KIND_NET: + name =3D VirtioFeatureNet_str(feature->name->u.net.data); + break; + case VIRTIO_FEATURE_NAME_KIND_BLK: + name =3D VirtioFeatureBlk_str(feature->name->u.blk.data); + break; + case VIRTIO_FEATURE_NAME_KIND_SERIAL: + name =3D VirtioFeatureSerial_str(feature->name->u.serial.data); + break; + case VIRTIO_FEATURE_NAME_KIND_BALLOON: + name =3D VirtioFeatureBalloon_str(feature->name->u.balloon.dat= a); + break; + case VIRTIO_FEATURE_NAME_KIND_SCSI: + name =3D VirtioFeatureScsi_str(feature->name->u.scsi.data); + break; + case VIRTIO_FEATURE_NAME_KIND_VIRTFS: + name =3D VirtioFeatureVirtfs_str(feature->name->u.virtfs.data); + break; + case VIRTIO_FEATURE_NAME_KIND_GPU: + name =3D VirtioFeatureGpu_str(feature->name->u.gpu.data); + break; + default: + case VIRTIO_FEATURE_NAME_KIND_OTHER: + name =3D VirtioFeatureOther_str(feature->name->u.other.data); + break; + } + + monitor_printf(mon, "%*s%-*s%-*s%-*s%-*s\n", HMP_INFO_VIRTIO_INDEN= T, "", + HMP_INFO_VIRTIO_FIELD, type, + HMP_INFO_VIRTIO_FIELD, name, + HMP_INFO_VIRTIO_FIELD, host, + HMP_INFO_VIRTIO_FIELD, guest); + } +} + +static void hmp_info_virtio_print(Monitor *mon, VirtioInfo *info) +{ + Object *obj =3D object_resolve_path(info->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, "%*s%-*s%s\n", HMP_INFO_VIRTIO_INDENT, "", + HMP_INFO_VIRTIO_ITEM, "QOM path:", info->qom_path); + + hmp_info_virtio_print_status(mon, info); + hmp_info_virtio_print_features(mon, info); +} + +void hmp_info_virtio(Monitor *mon, const QDict *qdict) +{ + const char *path =3D qdict_get_try_str(qdict, "path"); + Error *err =3D NULL; + VirtioInfoList *head, *info; + + + head =3D qmp_query_virtio(!!path, path, &err); + if (err) { + return; + } + + for (info =3D head; info; info =3D info->next) { + hmp_info_virtio_print(mon, info->value); + } + + qapi_free_VirtioInfoList(head); +} 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