From: Jonah Palmer <jonah.palmer@oracle.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
qemu-devel@nongnu.org, lvivier@redhat.com,
"Alex Bennée" <alex.bennee@linaro.org>,
"Markus Armbruster" <armbru@redhat.com>
Cc: mst@redhat.com, qemu_oss@crudebyte.com, kraxel@redhat.com,
si-wei.liu@oracle.com, joao.m.martins@oracle.com,
eblake@redhat.com, qemu-block@nongnu.org, david@redhat.com,
arei.gonglei@huawei.com, marcandre.lureau@redhat.com,
thuth@redhat.com, michael.roth@amd.com, groug@kaod.org,
dgilbert@redhat.com, eric.auger@redhat.com, stefanha@redhat.com,
boris.ostrovsky@oracle.com, kwolf@redhat.com,
mathieu.poirier@linaro.org, raphael.norwitz@nutanix.com,
pbonzini@redhat.com
Subject: Re: [PATCH v15 1/6] qmp: add QMP command x-query-virtio
Date: Fri, 2 Dec 2022 07:23:53 -0500 [thread overview]
Message-ID: <31d76035-3b8c-c9a1-4fd3-d3cc6af5f69c@oracle.com> (raw)
In-Reply-To: <6c7189cd-b6dc-e954-f39e-b90ccb6e0361@linaro.org>
[-- Attachment #1: Type: text/plain, Size: 5969 bytes --]
On 11/30/22 11:16, Philippe Mathieu-Daudé wrote:
> Hi,
>
> On 11/8/22 14:24, Jonah Palmer wrote:
>> From: Laurent Vivier <lvivier@redhat.com>
>>
>> This new command lists all the instances of VirtIODevices with
>> their canonical QOM path and name.
>>
>> [Jonah: @virtio_list duplicates information that already exists in
>> the QOM composition tree. However, extracting necessary information
>> from this tree seems to be a bit convoluted.
>>
>> Instead, we still create our own list of realized virtio devices
>> but use @qmp_qom_get with the device's canonical QOM path to confirm
>> that the device exists and is realized. If the device exists but
>> is actually not realized, then we remove it from our list (for
>> synchronicity to the QOM composition tree).
>>
>> Also, the QMP command @x-query-virtio is redundant as @qom-list
>> and @qom-get are sufficient to search '/machine/' for realized
>> virtio devices. However, @x-query-virtio is much more convenient
>> in listing realized virtio devices.]
>>
>> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
>> Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
>> ---
>> hw/virtio/meson.build | 2 ++
>> hw/virtio/virtio-stub.c | 14 ++++++++
>> hw/virtio/virtio.c | 44 ++++++++++++++++++++++++
>> include/hw/virtio/virtio.h | 1 +
>> qapi/meson.build | 1 +
>> qapi/qapi-schema.json | 1 +
>> qapi/virtio.json | 68 ++++++++++++++++++++++++++++++++++++++
>> tests/qtest/qmp-cmd-test.c | 1 +
>> 8 files changed, 132 insertions(+)
>> create mode 100644 hw/virtio/virtio-stub.c
>> create mode 100644 qapi/virtio.json
>
>> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
>> index 5d607aeaa0..bdfa82e9c0 100644
>> --- a/hw/virtio/virtio.c
>> +++ b/hw/virtio/virtio.c
>> @@ -13,12 +13,18 @@
>> #include "qemu/osdep.h"
>> #include "qapi/error.h"
>> +#include "qapi/qmp/qdict.h"
>> +#include "qapi/qapi-commands-virtio.h"
>> +#include "qapi/qapi-commands-qom.h"
>> +#include "qapi/qapi-visit-virtio.h"
>> +#include "qapi/qmp/qjson.h"
>> #include "cpu.h"
>> #include "trace.h"
>> #include "qemu/error-report.h"
>> #include "qemu/log.h"
>> #include "qemu/main-loop.h"
>> #include "qemu/module.h"
>> +#include "qom/object_interfaces.h"
>> #include "hw/virtio/virtio.h"
>> #include "migration/qemu-file-types.h"
>> #include "qemu/atomic.h"
>> @@ -29,6 +35,9 @@
>> #include "sysemu/runstate.h"
>> #include "standard-headers/linux/virtio_ids.h"
>> +/* QAPI list of realized VirtIODevices */
>> +static QTAILQ_HEAD(, VirtIODevice) virtio_list;
>> +
>> /*
>> * The alignment to use between consumer and producer parts of vring.
>> * x86 pagesize again. This is the default, used by transports like
>> PCI
>> @@ -3698,6 +3707,7 @@ static void virtio_device_realize(DeviceState
>> *dev, Error **errp)
>> vdev->listener.commit = virtio_memory_listener_commit;
>> vdev->listener.name = "virtio";
>> memory_listener_register(&vdev->listener, vdev->dma_as);
>> + QTAILQ_INSERT_TAIL(&virtio_list, vdev, next);
>> }
>> static void virtio_device_unrealize(DeviceState *dev)
>> @@ -3712,6 +3722,7 @@ static void virtio_device_unrealize(DeviceState
>> *dev)
>> vdc->unrealize(dev);
>> }
>> + QTAILQ_REMOVE(&virtio_list, vdev, next);
>> g_free(vdev->bus_name);
>> vdev->bus_name = NULL;
>> }
>> @@ -3885,6 +3896,8 @@ static void
>> virtio_device_class_init(ObjectClass *klass, void *data)
>> vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl;
>> vdc->legacy_features |= VIRTIO_LEGACY_FEATURES;
>> +
>> + QTAILQ_INIT(&virtio_list);
>> }
>> bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
>> @@ -3895,6 +3908,37 @@ bool
>> virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
>> return virtio_bus_ioeventfd_enabled(vbus);
>> }
>> +VirtioInfoList *qmp_x_query_virtio(Error **errp)
>> +{
>> + VirtioInfoList *list = NULL;
>> + VirtioInfoList *node;
>> + VirtIODevice *vdev;
>> +
>> + QTAILQ_FOREACH(vdev, &virtio_list, next) {
>> + DeviceState *dev = DEVICE(vdev);
>> + Error *err = NULL;
>> + QObject *obj = qmp_qom_get(dev->canonical_path, "realized",
>> &err);
>> +
>> + if (err == NULL) {
>> + GString *is_realized = qobject_to_json_pretty(obj, true);
>> + /* virtio device is NOT realized, remove it from list */
>
> Why not check dev->realized instead of calling qmp_qom_get() &
> qobject_to_json_pretty()?
This check queries the QOM composition tree to check that the device actually exists and is
realized. In other words, we just want to confirm with the QOM composition tree for the device.
This was done to have some kind of synchronicity between @virtio_list and the QOM composition
tree, since the list duplicates information that already exists in the tree.
This check was recommended in v10 and added in v11 of this patch series.
>
>> + if (!strncmp(is_realized->str, "false", 4)) {
>> + QTAILQ_REMOVE(&virtio_list, vdev, next);
>> + } else {
>> + node = g_new0(VirtioInfoList, 1);
>> + node->value = g_new(VirtioInfo, 1);
>> + node->value->path = g_strdup(dev->canonical_path);
>> + node->value->name = g_strdup(vdev->name);
>> + QAPI_LIST_PREPEND(list, node->value);
>> + }
>> + g_string_free(is_realized, true);
>> + }
>> + qobject_unref(obj);
>> + }
>> +
>> + return list;
>> +}
[-- Attachment #2: Type: text/html, Size: 10914 bytes --]
next prev parent reply other threads:[~2022-12-02 12:25 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-11 12:24 [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices Jonah Palmer
2022-08-11 12:24 ` [PATCH v15 1/6] qmp: add QMP command x-query-virtio Jonah Palmer
2022-11-30 16:16 ` Philippe Mathieu-Daudé
2022-12-02 12:23 ` Jonah Palmer [this message]
2022-12-02 14:17 ` Philippe Mathieu-Daudé
2022-12-02 15:21 ` Markus Armbruster
2022-12-07 8:47 ` Jonah Palmer
2022-12-07 13:22 ` Markus Armbruster
2022-12-09 8:54 ` Jonah Palmer
2025-05-01 22:15 ` Philippe Mathieu-Daudé
2022-08-11 12:24 ` [PATCH v15 2/6] qmp: add QMP command x-query-virtio-status Jonah Palmer
2025-05-01 22:09 ` Philippe Mathieu-Daudé
2025-05-05 6:30 ` Thomas Huth
2025-05-05 7:29 ` Laurent Vivier
2025-05-08 7:51 ` Markus Armbruster
2025-05-08 10:44 ` Philippe Mathieu-Daudé
2022-08-11 12:24 ` [PATCH v15 3/6] qmp: decode feature & status bits in virtio-status Jonah Palmer
2022-08-11 12:24 ` [PATCH v15 4/6] qmp: add QMP commands for virtio/vhost queue-status Jonah Palmer
2022-08-11 12:24 ` [PATCH v15 5/6] qmp: add QMP command x-query-virtio-queue-element Jonah Palmer
2022-08-11 12:24 ` [PATCH v15 6/6] hmp: add virtio commands Jonah Palmer
2022-09-27 8:36 ` [PATCH v15 0/6] hmp,qmp: Add commands to introspect virtio devices Jonah Palmer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=31d76035-3b8c-c9a1-4fd3-d3cc6af5f69c@oracle.com \
--to=jonah.palmer@oracle.com \
--cc=alex.bennee@linaro.org \
--cc=arei.gonglei@huawei.com \
--cc=armbru@redhat.com \
--cc=boris.ostrovsky@oracle.com \
--cc=david@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=eric.auger@redhat.com \
--cc=groug@kaod.org \
--cc=joao.m.martins@oracle.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=lvivier@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mathieu.poirier@linaro.org \
--cc=michael.roth@amd.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu_oss@crudebyte.com \
--cc=raphael.norwitz@nutanix.com \
--cc=si-wei.liu@oracle.com \
--cc=stefanha@redhat.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).