From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
To: qemu-devel@nongnu.org, Jonah Palmer <jonah.palmer@oracle.com>
Cc: philmd@linaro.org, laurent@vivier.eu, mst@redhat.com,
boris.ostrovsky@oracle.com, alex.bennee@linaro.org,
viresh.kumar@linaro.org, armbru@redhat.com, pbonzini@redhat.com,
berrange@redhat.com, eduardo@habkost.net
Subject: Re: [PATCH v3 1/3] qmp: remove virtio_list, search QOM tree instead
Date: Thu, 03 Aug 2023 19:40:46 +0300 [thread overview]
Message-ID: <ytsdr.hu96pu2zioj@linaro.org> (raw)
In-Reply-To: <20230803145500.2108691-2-jonah.palmer@oracle.com>
On Thu, 03 Aug 2023 17:54, Jonah Palmer <jonah.palmer@oracle.com> wrote:
>-VirtioInfoList *qmp_x_query_virtio(Error **errp)
>+static int query_dev_child(Object *child, void *opaque)
> {
>- VirtioInfoList *list = NULL;
>- VirtioInfo *node;
>- VirtIODevice *vdev;
>+ VirtioInfoList **vdevs = opaque;
>+ Object *dev = object_dynamic_cast(child, TYPE_VIRTIO_DEVICE);
>+ if (dev != NULL && DEVICE(dev)->realized) {
>+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
>+
>+ VirtioInfo *info = g_new(VirtioInfo, 1);
>+
>+ /* Get canonical path of device */
>+ gchar *path = object_get_canonical_path(dev);
(You can use g_autofree char * here)
>+
>+ info->path = g_strdup(path);
>+ info->name = g_strdup(vdev->name);
>+ QAPI_LIST_PREPEND(*vdevs, info);
>
>- 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 */
>- if (!strncmp(is_realized->str, "false", 4)) {
>- QTAILQ_REMOVE(&virtio_list, vdev, next);
>- } else {
>- node = g_new(VirtioInfo, 1);
>- node->path = g_strdup(dev->canonical_path);
>- node->name = g_strdup(vdev->name);
>- QAPI_LIST_PREPEND(list, node);
>- }
>- g_string_free(is_realized, true);
>- }
>- qobject_unref(obj);
>+ g_free(path);
>+ } else {
>+ object_unref(dev);
> }
The object_unref should not happen only in the else branch, no? Though
it's not clear to me where the ref count was previously incremented.
>+ object_child_foreach_recursive(object_get_root(), query_dev_child,
>&vdevs);
>+ if (vdevs == NULL) {
>+ error_setg(errp, "No virtio devices found");
>+ return NULL;
(No need for early return here)
> }
>- return NULL;
>+ return vdevs;
>+}
>+
>+VirtIODevice *qmp_find_virtio_device(const char *path)
>+{
>+ /* Verify the canonical path is a realized virtio device */
>+ Object *dev = object_dynamic_cast(object_resolve_path(path, NULL),
>+ TYPE_VIRTIO_DEVICE);
>+ if (!dev || !DEVICE(dev)->realized) {
>+ object_unref(dev);
Same as before with object refs
next prev parent reply other threads:[~2023-08-03 17:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 14:54 [PATCH v3 0/3] qmp, vhost-user: Remove virtio_list & update virtio introspection Jonah Palmer
2023-08-03 14:54 ` [PATCH v3 1/3] qmp: remove virtio_list, search QOM tree instead Jonah Palmer
2023-08-03 15:05 ` Daniel P. Berrangé
2023-08-04 14:00 ` Jonah Palmer
2023-08-03 16:40 ` Manos Pitsidianakis [this message]
2023-08-04 14:17 ` Jonah Palmer
2023-08-03 14:54 ` [PATCH v3 2/3] qmp: update virtio feature maps, vhost-user-gpio introspection Jonah Palmer
2023-08-03 16:38 ` Manos Pitsidianakis
2023-08-03 14:55 ` [PATCH v3 3/3] vhost-user: move VhostUserProtocolFeature definition to header file Jonah Palmer
2023-08-03 16:32 ` Manos Pitsidianakis
2023-08-03 19:50 ` [PATCH v3 0/3] qmp,vhost-user: Remove virtio_list & update virtio introspection Michael S. Tsirkin
2023-08-04 14:27 ` [PATCH v3 0/3] qmp, vhost-user: " 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=ytsdr.hu96pu2zioj@linaro.org \
--to=manos.pitsidianakis@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=boris.ostrovsky@oracle.com \
--cc=eduardo@habkost.net \
--cc=jonah.palmer@oracle.com \
--cc=laurent@vivier.eu \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=viresh.kumar@linaro.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.