From nobody Mon Apr 29 11:50:37 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508867563019269.97964757743796; Tue, 24 Oct 2017 10:52:43 -0700 (PDT) Received: from localhost ([::1]:44998 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e73NV-0006p5-AM for importer@patchew.org; Tue, 24 Oct 2017 13:52:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e73Kh-00054f-BW for qemu-devel@nongnu.org; Tue, 24 Oct 2017 13:49:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e73Kf-0000vk-0i for qemu-devel@nongnu.org; Tue, 24 Oct 2017 13:49:43 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:25804 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-0000un-CD 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 v9OHnHt4003307; Tue, 24 Oct 2017 20:49:20 +0300 (MSK) From: Jan Dakinevich To: qemu-devel@nongnu.org Date: Tue, 24 Oct 2017 20:50:03 +0300 Message-Id: <1508867404-18046-2-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 1/2] virtio: introduce `query-virtio' QMP 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_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The command is intended for gathering virtio information such as status, feature bits, negotiation status. It is convenient and useful for debug purpose. The commands returns generic virtio information for virtio such as common feature names and status bits names and information for all attached to current machine devices. Cc: Denis V. Lunev Signed-off-by: Jan Dakinevich --- hw/virtio/Makefile.objs | 3 + hw/virtio/virtio-qmp.c | 223 +++++++++++++++++++++++ hw/virtio/virtio-stub.c | 9 + qapi-schema.json | 466 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 701 insertions(+) create mode 100644 hw/virtio/virtio-qmp.c create mode 100644 hw/virtio/virtio-stub.c diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index 765d363..3524aa7 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -3,12 +3,15 @@ common-obj-y +=3D virtio-rng.o common-obj-$(CONFIG_VIRTIO_PCI) +=3D virtio-pci.o common-obj-y +=3D virtio-bus.o common-obj-y +=3D virtio-mmio.o +common-obj-y +=3D virtio-qmp.o =20 obj-y +=3D virtio.o virtio-balloon.o=20 obj-$(CONFIG_LINUX) +=3D vhost.o vhost-backend.o vhost-user.o obj-$(CONFIG_VHOST_VSOCK) +=3D vhost-vsock.o obj-y +=3D virtio-crypto.o obj-$(CONFIG_VIRTIO_PCI) +=3D virtio-crypto-pci.o +else +obj-y +=3D virtio-stub.o endif =20 common-obj-$(call lnot,$(CONFIG_LINUX)) +=3D vhost-stub.o diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c new file mode 100644 index 0000000..8192c33 --- /dev/null +++ b/hw/virtio/virtio-qmp.c @@ -0,0 +1,223 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qmp-commands.h" + +#include "hw/virtio/virtio.h" +#include "hw/virtio/virtio-net.h" +#include "hw/virtio/virtio-blk.h" +#include "hw/virtio/virtio-serial.h" +#include "hw/virtio/virtio-balloon.h" +#include "hw/virtio/virtio-scsi.h" +#ifdef CONFIG_VIRTFS +#include "hw/9pfs/virtio-9p.h" +#endif +#include "hw/virtio/virtio-gpu.h" + +#define qmp_query_virtio_features(__vdev, __info, __offset, __count,\ + __name_kind, __name_type, __name_field) = ({ \ + unsigned __idx; \ + for (__idx =3D (__count); __idx--; ) { \ + unsigned int __fbit =3D __idx + (__offset); \ + bool __host =3D virtio_host_has_feature(__vdev, __fbit); \ + bool __guest =3D virtio_vdev_has_feature(__vdev, __fbit); \ + VirtioFeatureList *__feature; \ + \ + if (!__host && !__guest) { \ + continue; \ + } \ + \ + __feature =3D g_new0(VirtioFeatureList, 1); \ + __feature->value =3D g_new0(VirtioFeature, 1); \ + __feature->value->name =3D g_new0(VirtioFeatureName, 1); \ + \ + __feature->value->host =3D __host; \ + __feature->value->guest =3D __guest; \ + \ + __feature->value->name->type =3D (__name_kind); \ + __feature->value->name->u.__name_field.data =3D (__name_type)__idx= ; \ + \ + __feature->next =3D (__info)->features; \ + (__info)->features =3D __feature; \ + } \ +}) + +#define qmp_query_virtio_features_common(__vdev, __info) \ + qmp_query_virtio_features((__vdev), (__info), VIRTIO_FEATURE_OTHER__MA= X, \ + VIRTIO_FEATURE_COMMON__MAX, VIRTIO_FEATURE_NAME_KIND_COMMON, \ + VirtioFeatureCommon, common) + +#define qmp_query_virtio_features_net(__vdev, __info) \ + qmp_query_virtio_features((__vdev), (__info), 0, \ + VIRTIO_FEATURE_NET__MAX, VIRTIO_FEATURE_NAME_KIND_NET, \ + VirtioFeatureNet, net) + +#define qmp_query_virtio_features_blk(__vdev, __info) \ + qmp_query_virtio_features((__vdev), (__info), 0, \ + VIRTIO_FEATURE_BLK__MAX, VIRTIO_FEATURE_NAME_KIND_BLK, \ + VirtioFeatureBlk, blk) + +#define qmp_query_virtio_features_serial(__vdev, __info) \ + qmp_query_virtio_features((__vdev), (__info), 0, \ + VIRTIO_FEATURE_SERIAL__MAX, VIRTIO_FEATURE_NAME_KIND_SERIAL, \ + VirtioFeatureSerial, serial) + +#define qmp_query_virtio_features_balloon(__vdev, __info) \ + qmp_query_virtio_features((__vdev), (__info), 0, \ + VIRTIO_FEATURE_BALLOON__MAX, VIRTIO_FEATURE_NAME_KIND_BALLOON, \ + VirtioFeatureBalloon, balloon) + +#define qmp_query_virtio_features_scsi(__vdev, __info) \ + qmp_query_virtio_features((__vdev), (__info), 0, \ + VIRTIO_FEATURE_SCSI__MAX, VIRTIO_FEATURE_NAME_KIND_SCSI, \ + VirtioFeatureScsi, scsi) + +#ifdef CONFIG_VIRTFS +#define qmp_query_virtio_features_virtfs(__vdev, __info) \ + qmp_query_virtio_features((__vdev), (__info), 0, \ + VIRTIO_FEATURE_VIRTFS__MAX, VIRTIO_FEATURE_NAME_KIND_VIRTFS, \ + VirtioFeatureVirtfs, virtfs) +#endif + +#define qmp_query_virtio_features_gpu(__vdev, __info) \ + qmp_query_virtio_features((__vdev), (__info), 0, \ + VIRTIO_FEATURE_GPU__MAX, VIRTIO_FEATURE_NAME_KIND_GPU, \ + VirtioFeatureGpu, gpu) + +#define qmp_query_virtio_features_other(__vdev, __info) \ + qmp_query_virtio_features((__vdev), (__info), 0, \ + VIRTIO_FEATURE_OTHER__MAX, VIRTIO_FEATURE_NAME_KIND_OTHER, \ + VirtioFeatureOther, other) + + +static VirtioInfoList *qmp_query_virtio_one(VirtIODevice *vdev) +{ + VirtioInfoList *list; + VirtioInfo *info; + unsigned int idx; + + QEMU_BUILD_BUG_ON(VIRTIO_FEATURE_COMMON__MAX !=3D 40); + QEMU_BUILD_BUG_ON(VIRTIO_FEATURE_NET__MAX !=3D 24); + QEMU_BUILD_BUG_ON(VIRTIO_FEATURE_BLK__MAX !=3D 24); + QEMU_BUILD_BUG_ON(VIRTIO_FEATURE_SCSI__MAX !=3D 24); + QEMU_BUILD_BUG_ON(VIRTIO_FEATURE_BALLOON__MAX !=3D 24); + QEMU_BUILD_BUG_ON(VIRTIO_FEATURE_SERIAL__MAX !=3D 24); + QEMU_BUILD_BUG_ON(VIRTIO_FEATURE_GPU__MAX !=3D 24); + QEMU_BUILD_BUG_ON(VIRTIO_FEATURE_OTHER__MAX !=3D 24); + + list =3D g_new0(VirtioInfoList, 1); + list->value =3D g_new0(VirtioInfo, 1); + + info =3D list->value; + info->qom_path =3D object_get_canonical_path(OBJECT(vdev)); + info->status =3D vdev->status; + info->host_features =3D vdev->host_features; + info->guest_features =3D vdev->guest_features; + + /* device status */ + for (idx =3D VIRTIO_STATUS__MAX; idx--; ) { + VirtioStatusList *status; + + if (!(vdev->status & (1 << idx))) { + continue; + } + + status =3D g_new0(VirtioStatusList, 1); + status->value =3D (VirtioStatus)idx; + + status->next =3D info->status_names; + info->status_names =3D status; + } + + /* device-specific features */ + if (object_dynamic_cast(OBJECT(vdev), TYPE_VIRTIO_NET)) { + qmp_query_virtio_features_net(vdev, info); + } else if (object_dynamic_cast(OBJECT(vdev), TYPE_VIRTIO_BLK)) { + qmp_query_virtio_features_blk(vdev, info); + } else if (object_dynamic_cast(OBJECT(vdev), TYPE_VIRTIO_SERIAL)) { + qmp_query_virtio_features_serial(vdev, info); + } else if (object_dynamic_cast(OBJECT(vdev), TYPE_VIRTIO_BALLOON)) { + qmp_query_virtio_features_balloon(vdev, info); + } else if (object_dynamic_cast(OBJECT(vdev), TYPE_VIRTIO_SCSI)) { + qmp_query_virtio_features_scsi(vdev, info); +#ifdef CONFIG_VIRTFS + } else if (object_dynamic_cast(OBJECT(vdev), TYPE_VIRTIO_9P)) { + qmp_query_virtio_features_virtfs(vdev, info); +#endif + } else if (object_dynamic_cast(OBJECT(vdev), TYPE_VIRTIO_GPU)) { + qmp_query_virtio_features_gpu(vdev, info); + } else { + qmp_query_virtio_features_other(vdev, info); + } + + /* common features */ + qmp_query_virtio_features_common(vdev, info); + + return list; +} + +typedef struct QueryVirtioEntry { + VirtIODevice *vdev; + QTAILQ_ENTRY(QueryVirtioEntry) link; +} QueryVirtioEntry; + +typedef QTAILQ_HEAD(, QueryVirtioEntry) QueryVirtioHead; + +static void qmp_query_virtio_recursive(QueryVirtioHead *head, BusState *bu= s) +{ + BusChild *kid; + + QTAILQ_FOREACH(kid, &bus->children, sibling) { + DeviceState *dev =3D kid->child; + BusState *child; + + if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_DEVICE)) { + QueryVirtioEntry *entry =3D g_new0(QueryVirtioEntry, 1); + + entry->vdev =3D VIRTIO_DEVICE(dev); + QTAILQ_INSERT_TAIL(head, entry, link); + } + QLIST_FOREACH(child, &dev->child_bus, sibling) { + qmp_query_virtio_recursive(head, child); + } + } +} + +VirtioInfoList *qmp_query_virtio(bool has_path, const char *path, Error **= errp) +{ + BusState *bus =3D sysbus_get_default(); + VirtioInfoList *list =3D NULL; + + if (!bus) { + return NULL; + } + + if (has_path) { + Object *obj =3D object_resolve_path(path, NULL); + if (!obj) { + return NULL; + } + if (!object_dynamic_cast(OBJECT(obj), TYPE_VIRTIO_DEVICE)) { + return NULL; + } + + list =3D qmp_query_virtio_one(VIRTIO_DEVICE(obj)); + } else { + QueryVirtioHead head; + QueryVirtioEntry *query, *tmp; + + QTAILQ_INIT(&head); + qmp_query_virtio_recursive(&head, bus); + + QTAILQ_FOREACH_SAFE(query, &head, link, tmp) { + VirtioInfoList *entry =3D qmp_query_virtio_one(query->vdev); + + QTAILQ_REMOVE(&head, query, link); + g_free(query); + + entry->next =3D list; + list =3D entry; + } + } + + return list; +} diff --git a/hw/virtio/virtio-stub.c b/hw/virtio/virtio-stub.c new file mode 100644 index 0000000..185d4bd --- /dev/null +++ b/hw/virtio/virtio-stub.c @@ -0,0 +1,9 @@ +#include "qemu/osdep.h" +#include "qmp-commands.h" +#include "qapi/qmp/qerror.h" + +VirtioInfoList *qmp_query_virtio(bool has_path, const char *path, Error **= errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} diff --git a/qapi-schema.json b/qapi-schema.json index a9dd043..b1645f3 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3200,3 +3200,469 @@ # Since: 2.11 ## { 'command': 'watchdog-set-action', 'data' : {'action': 'WatchdogAction'} } + +## +# @VirtioStatus: +# +# Virtio device status bits +# +# Since: 2.11 +# +## +{ + 'enum': 'VirtioStatus', + 'data': [ + 'acknowledge', + 'driver', + 'driver-ok', + 'features-ok', + 'status-reserved-4', + 'status-reserved-5', + 'needs-reset', + 'failed' + ] +} + +## +# @VirtioFeatureCommon: +# +# Virtio feature bits common to all devices +# +# Since: 2.11 +# +## +{ + 'enum': 'VirtioFeatureCommon', + 'data': [ + 'notify-on-empty', + 'common-reserved-25', + 'common-reserved-26', + 'any-layout', + 'indirect-desc', + 'event-idx', + 'bad-feature', + 'common-reserved-31', + 'version-1', + 'iommu-platform', + 'common-reserved-34', + 'common-reserved-35', + 'common-reserved-36', + 'common-reserved-37', + 'common-reserved-38', + 'common-reserved-39', + 'common-reserved-40', + 'common-reserved-41', + 'common-reserved-42', + 'common-reserved-43', + 'common-reserved-44', + 'common-reserved-45', + 'common-reserved-46', + 'common-reserved-47', + 'common-reserved-48', + 'common-reserved-49', + 'common-reserved-50', + 'common-reserved-51', + 'common-reserved-52', + 'common-reserved-53', + 'common-reserved-54', + 'common-reserved-55', + 'common-reserved-56', + 'common-reserved-57', + 'common-reserved-58', + 'common-reserved-59', + 'common-reserved-60', + 'common-reserved-61', + 'common-reserved-62', + 'common-reserved-63' + ] +} + +## +# @VirtioFeatureNet: +# +# Virtio network device feature bits +# +# Since: 2.11 +# +## +{ + 'enum': 'VirtioFeatureNet', + 'data': [ + 'csum', + 'guest-csum', + 'ctrl-guest-offloads', + 'mtu', + 'net-reserved-4', + 'mac', + 'gso', + 'guest-tso4', + 'guest-tso6', + 'guest-ecn', + 'guest-ufo', + 'host-tso4', + 'host-tso6', + 'host-ecn', + 'host-ufo', + 'mrg-rxbuf', + 'status', + 'ctrl-vq', + 'ctrl-rx', + 'ctrl-vlan', + 'ctrl-rx-extra', + 'guest-announce', + 'mq', + 'ctrl-mac-addr' + ] +} + +## +# @VirtioFeatureBlk: +# +# Virtio block device feature bits +# +# Since: 2.11 +# +## +{ + 'enum': 'VirtioFeatureBlk', + 'data': [ + 'barrier', + 'size-max', + 'seg-max', + 'blk-reserved-3', + 'geometry', + 'ro', + 'blk-size', + 'scsi', + 'blk-reserved-8', + 'flush', + 'topology', + 'config-wce', + 'mq', + 'blk-reserved-13', + 'blk-reserved-14', + 'blk-reserved-15', + 'blk-reserved-16', + 'blk-reserved-17', + 'blk-reserved-18', + 'blk-reserved-19', + 'blk-reserved-20', + 'blk-reserved-21', + 'blk-reserved-22', + 'blk-reserved-23' + ] +} + +## +# @VirtioFeatureSerial: +# +# Virtio serial device (console) feature bits +# +# Since: 2.11 +# +## +{ + 'enum': 'VirtioFeatureSerial', + 'data': [ + 'size', + 'multiport', + 'emerg-write', + 'serial-reserved-3', + 'serial-reserved-4', + 'serial-reserved-5', + 'serial-reserved-6', + 'serial-reserved-7', + 'serial-reserved-8', + 'serial-reserved-9', + 'serial-reserved-10', + 'serial-reserved-11', + 'serial-reserved-12', + 'serial-reserved-13', + 'serial-reserved-14', + 'serial-reserved-15', + 'serial-reserved-16', + 'serial-reserved-17', + 'serial-reserved-18', + 'serial-reserved-19', + 'serial-reserved-20', + 'serial-reserved-21', + 'serial-reserved-22', + 'serial-reserved-23' + ] +} + +## +# @VirtioFeatureBalloon: +# +# Virtio balloon feature bits +# +# Since: 2.11 +# +## +{ + 'enum': 'VirtioFeatureBalloon', + 'data': [ + 'must-tell-host', + 'stats-vq', + 'deflate-on-oom', + 'balloon-reserved-3', + 'balloon-reserved-4', + 'balloon-reserved-5', + 'balloon-reserved-6', + 'balloon-reserved-7', + 'balloon-reserved-8', + 'balloon-reserved-9', + 'balloon-reserved-10', + 'balloon-reserved-11', + 'balloon-reserved-12', + 'balloon-reserved-13', + 'balloon-reserved-14', + 'balloon-reserved-15', + 'balloon-reserved-16', + 'balloon-reserved-17', + 'balloon-reserved-18', + 'balloon-reserved-19', + 'balloon-reserved-20', + 'balloon-reserved-21', + 'balloon-reserved-22', + 'balloon-reserved-23' + ] +} + +## +# @VirtioFeatureScsi: +# +# Virtio scsi controller feature bits +# +# Since: 2.11 +# +## +{ + 'enum': 'VirtioFeatureScsi', + 'data': [ + 'inout', + 'hotplug', + 'change', + 't10-pi', + 'scsi-reserved-4', + 'scsi-reserved-5', + 'scsi-reserved-6', + 'scsi-reserved-7', + 'scsi-reserved-8', + 'scsi-reserved-9', + 'scsi-reserved-10', + 'scsi-reserved-11', + 'scsi-reserved-12', + 'scsi-reserved-13', + 'scsi-reserved-14', + 'scsi-reserved-15', + 'scsi-reserved-16', + 'scsi-reserved-17', + 'scsi-reserved-18', + 'scsi-reserved-19', + 'scsi-reserved-20', + 'scsi-reserved-21', + 'scsi-reserved-22', + 'scsi-reserved-23' + ] +} + +## +# @VirtioFeatureVirtfs: +# +# Virtio virtfs (9p) feature bits +# +# Since: 2.11 +# +## +{ + 'enum': 'VirtioFeatureVirtfs', + 'data': [ + 'mount-tag', + 'virtfs-reserved-1', + 'virtfs-reserved-2', + 'virtfs-reserved-3', + 'virtfs-reserved-4', + 'virtfs-reserved-5', + 'virtfs-reserved-6', + 'virtfs-reserved-7', + 'virtfs-reserved-8', + 'virtfs-reserved-9', + 'virtfs-reserved-10', + 'virtfs-reserved-11', + 'virtfs-reserved-12', + 'virtfs-reserved-13', + 'virtfs-reserved-14', + 'virtfs-reserved-15', + 'virtfs-reserved-16', + 'virtfs-reserved-17', + 'virtfs-reserved-18', + 'virtfs-reserved-19', + 'virtfs-reserved-20', + 'virtfs-reserved-21', + 'virtfs-reserved-22', + 'virtfs-reserved-23' + ] +} + +## +# @VirtioFeatureGpu: +# +# Virtio GPU device feature bits +# +# Since: 2.11 +# +## +{ + 'enum': 'VirtioFeatureGpu', + 'data': [ + 'virgl', + 'gpu-reserved-1', + 'gpu-reserved-2', + 'gpu-reserved-3', + 'gpu-reserved-4', + 'gpu-reserved-5', + 'gpu-reserved-6', + 'gpu-reserved-7', + 'gpu-reserved-8', + 'gpu-reserved-9', + 'gpu-reserved-10', + 'gpu-reserved-11', + 'gpu-reserved-12', + 'gpu-reserved-13', + 'gpu-reserved-14', + 'gpu-reserved-15', + 'gpu-reserved-16', + 'gpu-reserved-17', + 'gpu-reserved-18', + 'gpu-reserved-19', + 'gpu-reserved-20', + 'gpu-reserved-21', + 'gpu-reserved-22', + 'gpu-reserved-23' + ] +} + +## +# @VirtioFeatureOther: +# +# Feature bits of other virtio devices +# +# Since: 2.11 +# +## +{ + 'enum': 'VirtioFeatureOther', + 'data': [ + 'other-reserved-0', + 'other-reserved-1', + 'other-reserved-2', + 'other-reserved-3', + 'other-reserved-4', + 'other-reserved-5', + 'other-reserved-6', + 'other-reserved-7', + 'other-reserved-8', + 'other-reserved-9', + 'other-reserved-10', + 'other-reserved-11', + 'other-reserved-12', + 'other-reserved-13', + 'other-reserved-14', + 'other-reserved-15', + 'other-reserved-16', + 'other-reserved-17', + 'other-reserved-18', + 'other-reserved-19', + 'other-reserved-20', + 'other-reserved-21', + 'other-reserved-22', + 'other-reserved-23' + ] +} + +## +# @VirtioFeatureName: +# +# Since: 2.11 +# +## +{ + 'union': 'VirtioFeatureName', + 'data': { + 'common': 'VirtioFeatureCommon', + 'net': 'VirtioFeatureNet', + 'blk': 'VirtioFeatureBlk', + 'serial': 'VirtioFeatureSerial', + 'balloon': 'VirtioFeatureBalloon', + 'scsi': 'VirtioFeatureScsi', + 'virtfs': 'VirtioFeatureVirtfs', + 'gpu': 'VirtioFeatureGpu', + 'other': 'VirtioFeatureOther' + } +} + +## +# @VirtioFeature: +# +# Feature bit with negotiation status +# +# @host: true if host exposes the feature +# +# @guest: true if guest acknowledges the feature +# +# Since: 2.11 +# +## +{ + 'struct': 'VirtioFeature', + 'data': { + 'host': 'bool', + 'guest': 'bool', + 'name': 'VirtioFeatureName' + } +} + +## +# @VirtioInfo: +# +# Information about virtio device +# +# @qom-path: QOM path of the device +# +# @status: status bitmask +# +# @status-names: names of checked bits in status bitmask +# +# @host-features: bitmask of features, exposed by device +# +# @guest-features: bitmask of features, acknowledged by guest +# +# @features: negotiation status and names of device features +# +## +{ + 'struct': 'VirtioInfo', + 'data': { + 'qom-path': 'str', + 'status': 'uint8', + 'status-names': ['VirtioStatus'], + 'host-features': 'uint64', + 'guest-features': 'uint64', + 'features': ['VirtioFeature'] + } +} + +## +# @query-virtio: +# +# Returns virtio information such as device status and features +# +# Since: 2.11 +# +## +{ + 'command': 'query-virtio', + 'data': { '*path': 'str' }, + 'returns': ['VirtioInfo'] +} --=20 2.1.4 From nobody Mon Apr 29 11:50:37 2024 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