From: Anthony Liguori <aliguori@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>,
Anthony Liguori <aliguori@us.ibm.com>,
Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
Jan Kiszka <jan.kiszka@siemens.com>,
Markus Armbruster <armbru@redhat.com>,
Luiz Capitulino <lcapitulino@redhat.com>,
Gerd Hoffman <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH v2 16/18] qom: optimize qdev_get_canonical_path using a parent link
Date: Fri, 2 Dec 2011 14:20:54 -0600 [thread overview]
Message-ID: <1322857256-14951-17-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1322857256-14951-1-git-send-email-aliguori@us.ibm.com>
The full tree search was a bit unreasonable.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/qdev.c | 56 ++++++++++++++++++++++++--------------------------------
hw/qdev.h | 4 ++++
2 files changed, 28 insertions(+), 32 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 5348f26..1102efd 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -1229,6 +1229,8 @@ void qdev_property_add_child(DeviceState *dev, const char *name,
NULL, NULL, child, errp);
qdev_ref(dev);
+ g_assert(child->parent == NULL);
+ child->parent = dev;
g_free(type);
}
@@ -1307,48 +1309,38 @@ void qdev_property_add_link(DeviceState *dev, const char *name,
g_free(full_type);
}
-static gchar *qdev_get_path_in(DeviceState *parent, DeviceState *dev)
+gchar *qdev_get_canonical_path(DeviceState *dev)
{
- DeviceProperty *prop;
+ DeviceState *root = qdev_get_root();
+ char *newpath = NULL, *path = NULL;
- if (parent == dev) {
- return g_strdup("");
- }
+ while (dev != root) {
+ DeviceProperty *prop = NULL;
- QTAILQ_FOREACH(prop, &parent->properties, node) {
- gchar *subpath;
+ g_assert(dev->parent != NULL);
- if (!strstart(prop->type, "child<", NULL)) {
- continue;
- }
+ QTAILQ_FOREACH(prop, &dev->parent->properties, node) {
+ if (!strstart(prop->type, "child<", NULL)) {
+ continue;
+ }
- /* Check to see if the device is one of parent's children */
- if (prop->opaque == dev) {
- return g_strdup(prop->name);
+ if (prop->opaque == dev) {
+ if (path) {
+ newpath = g_strdup_printf("%s/%s", prop->name, path);
+ g_free(path);
+ path = newpath;
+ } else {
+ path = g_strdup(prop->name);
+ }
+ break;
+ }
}
- /* Check to see if the device is a child of our child */
- subpath = qdev_get_path_in(prop->opaque, dev);
- if (subpath) {
- gchar *path;
+ g_assert(prop != NULL);
- path = g_strdup_printf("%s/%s", prop->name, subpath);
- g_free(subpath);
-
- return path;
- }
+ dev = dev->parent;
}
- return NULL;
-}
-
-gchar *qdev_get_canonical_path(DeviceState *dev)
-{
- gchar *path, *newpath;
-
- path = qdev_get_path_in(qdev_get_root(), dev);
- g_assert(path != NULL);
-
newpath = g_strdup_printf("/%s", path);
g_free(path);
diff --git a/hw/qdev.h b/hw/qdev.h
index 4351e2e..fdab848 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -92,6 +92,10 @@ struct DeviceState {
uint32_t ref;
QTAILQ_HEAD(, DeviceProperty) properties;
+
+ /* Do not, under any circumstance, use this parent link below anywhere
+ * outside of qdev.c. You have been warned. */
+ DeviceState *parent;
};
typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
--
1.7.4.1
next prev parent reply other threads:[~2011-12-02 20:23 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-02 20:20 [Qemu-devel] [PATCH v2 00/18] qom: dynamic properties and composition tree (v2) Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 01/18] qom: add a reference count to qdev objects Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 02/18] qom: add new dynamic property infrastructure based on Visitors (v2) Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 03/18] qom: register legacy properties as new style properties (v2) Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 04/18] qom: introduce root device Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 05/18] qdev: provide an interface to return canonical path from root (v2) Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 06/18] qdev: provide a path resolution (v2) Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 07/18] qom: add child properties (composition) (v2) Anthony Liguori
2011-12-08 15:38 ` Kevin Wolf
2011-12-08 16:45 ` Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 08/18] qom: add link properties (v2) Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 09/18] qapi: allow a 'gen' key to suppress code generation Anthony Liguori
2011-12-08 16:04 ` Kevin Wolf
2011-12-08 16:45 ` Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 10/18] qmp: add qom-list command Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 11/18] qom: qom_{get, set} monitor commands (v2) Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 12/18] qdev: add explicitly named devices to the root complex Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 13/18] dev: add an anonymous peripheral container Anthony Liguori
2011-12-08 16:27 ` Kevin Wolf
2011-12-08 16:44 ` Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 14/18] rtc: make piix3 set the rtc as a child (v2) Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 15/18] rtc: add a dynamic property for retrieving the date Anthony Liguori
2011-12-09 11:26 ` Kevin Wolf
2011-12-09 13:08 ` Anthony Liguori
2011-12-09 14:04 ` Kevin Wolf
2011-12-09 14:25 ` Anthony Liguori
2011-12-13 9:27 ` Kevin Wolf
2011-12-13 9:48 ` Gerd Hoffmann
2011-12-13 13:33 ` Anthony Liguori
2011-12-13 13:31 ` Anthony Liguori
2011-12-13 13:49 ` Kevin Wolf
2011-12-02 20:20 ` Anthony Liguori [this message]
2011-12-09 11:13 ` [Qemu-devel] [PATCH v2 16/18] qom: optimize qdev_get_canonical_path using a parent link Kevin Wolf
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 17/18] qmp: make qmp.py easier to use Anthony Liguori
2011-12-02 20:20 ` [Qemu-devel] [PATCH v2 18/18] qom: add test tools (v2) Anthony Liguori
2011-12-09 11:19 ` Kevin Wolf
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=1322857256-14951-17-git-send-email-aliguori@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--cc=jan.kiszka@siemens.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.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).