mirror of
https://git.proxmox.com/git/qemu
synced 2025-08-07 09:40:44 +00:00
qom: optimize qdev_get_canonical_path using a parent link
The full tree search was a bit unreasonable. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
182970509b
commit
b2b6c39a79
46
hw/qdev.c
46
hw/qdev.c
@ -1229,6 +1229,8 @@ void qdev_property_add_child(DeviceState *dev, const char *name,
|
|||||||
NULL, NULL, child, errp);
|
NULL, NULL, child, errp);
|
||||||
|
|
||||||
qdev_ref(child);
|
qdev_ref(child);
|
||||||
|
g_assert(child->parent == NULL);
|
||||||
|
child->parent = dev;
|
||||||
|
|
||||||
g_free(type);
|
g_free(type);
|
||||||
}
|
}
|
||||||
@ -1307,47 +1309,37 @@ void qdev_property_add_link(DeviceState *dev, const char *name,
|
|||||||
g_free(full_type);
|
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) {
|
while (dev != root) {
|
||||||
return g_strdup("");
|
DeviceProperty *prop = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
QTAILQ_FOREACH(prop, &parent->properties, node) {
|
g_assert(dev->parent != NULL);
|
||||||
gchar *subpath;
|
|
||||||
|
|
||||||
|
QTAILQ_FOREACH(prop, &dev->parent->properties, node) {
|
||||||
if (!strstart(prop->type, "child<", NULL)) {
|
if (!strstart(prop->type, "child<", NULL)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check to see if the device is one of parent's children */
|
|
||||||
if (prop->opaque == dev) {
|
if (prop->opaque == dev) {
|
||||||
return g_strdup(prop->name);
|
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;
|
|
||||||
|
|
||||||
path = g_strdup_printf("%s/%s", prop->name, subpath);
|
|
||||||
g_free(subpath);
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
g_assert(prop != NULL);
|
||||||
}
|
|
||||||
|
|
||||||
gchar *qdev_get_canonical_path(DeviceState *dev)
|
dev = dev->parent;
|
||||||
{
|
}
|
||||||
gchar *path, *newpath;
|
|
||||||
|
|
||||||
path = qdev_get_path_in(qdev_get_root(), dev);
|
|
||||||
g_assert(path != NULL);
|
|
||||||
|
|
||||||
newpath = g_strdup_printf("/%s", path);
|
newpath = g_strdup_printf("/%s", path);
|
||||||
g_free(path);
|
g_free(path);
|
||||||
|
@ -92,6 +92,10 @@ struct DeviceState {
|
|||||||
uint32_t ref;
|
uint32_t ref;
|
||||||
|
|
||||||
QTAILQ_HEAD(, DeviceProperty) properties;
|
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);
|
typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
|
||||||
|
Loading…
Reference in New Issue
Block a user