summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2014-09-04 19:41:15 +0100
committerPeter Maydell <peter.maydell@linaro.org>2014-09-04 19:41:15 +0100
commitfd884c07658d02a96a882b8457d6d7a5cd71a407 (patch)
treeda89f830084fd9e281eca8f0482c68603b51065e
parentbbb6a1e872a6f0d6c43913726b2229c0cbdd3220 (diff)
parent1d45a705fc007a13f20d18473290082eae6d1725 (diff)
downloadqemu-fd884c07658d02a96a882b8457d6d7a5cd71a407.zip
Merge remote-tracking branch 'remotes/afaerber/tags/qom-devices-for-peter' into staging
QOM infrastructure fixes and device conversions * Cleanups for recursive device unrealization # gpg: Signature made Thu 04 Sep 2014 18:17:35 BST using RSA key ID 3E7E013F # gpg: Good signature from "Andreas Färber <afaerber@suse.de>" # gpg: aka "Andreas Färber <afaerber@suse.com>" * remotes/afaerber/tags/qom-devices-for-peter: qdev: Add cleanup logic in device_set_realized() to avoid resource leak qdev: Use NULL instead of local_err for qbus_child unrealize qdev: Use error_abort instead of using local_err memory: Remove object_property_add_child_array() qom: Add automatic arrayification to object_property_add() machine: Clean up -machine handling qom: Make object_child_foreach() safe for objects removal Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--hw/core/qdev.c70
-rw-r--r--memory.c30
-rw-r--r--qom/object.c25
-rw-r--r--vl.c8
4 files changed, 79 insertions, 54 deletions
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index da1ba48c99..fcb16383a1 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -820,13 +820,13 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
}
if (value && !dev->realized) {
- if (!obj->parent && local_err == NULL) {
+ if (!obj->parent) {
static int unattached_count;
gchar *name = g_strdup_printf("device[%d]", unattached_count++);
object_property_add_child(container_get(qdev_get_machine(),
"/unattached"),
- name, obj, &local_err);
+ name, obj, &error_abort);
g_free(name);
}
@@ -834,12 +834,14 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
dc->realize(dev, &local_err);
}
- if (dev->parent_bus && dev->parent_bus->hotplug_handler &&
- local_err == NULL) {
+ if (local_err != NULL) {
+ goto fail;
+ }
+
+ if (dev->parent_bus && dev->parent_bus->hotplug_handler) {
hotplug_handler_plug(dev->parent_bus->hotplug_handler,
dev, &local_err);
- } else if (local_err == NULL &&
- object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) {
+ } else if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) {
HotplugHandler *hotplug_ctrl;
MachineState *machine = MACHINE(qdev_get_machine());
MachineClass *mc = MACHINE_GET_CLASS(machine);
@@ -852,47 +854,69 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
}
}
- if (qdev_get_vmsd(dev) && local_err == NULL) {
+ if (local_err != NULL) {
+ goto post_realize_fail;
+ }
+
+ if (qdev_get_vmsd(dev)) {
vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
dev->instance_id_alias,
dev->alias_required_for_version);
}
- if (local_err == NULL) {
- QLIST_FOREACH(bus, &dev->child_bus, sibling) {
- object_property_set_bool(OBJECT(bus), true, "realized",
+
+ QLIST_FOREACH(bus, &dev->child_bus, sibling) {
+ object_property_set_bool(OBJECT(bus), true, "realized",
&local_err);
- if (local_err != NULL) {
- break;
- }
+ if (local_err != NULL) {
+ goto child_realize_fail;
}
}
- if (dev->hotplugged && local_err == NULL) {
+ if (dev->hotplugged) {
device_reset(dev);
}
dev->pending_deleted_event = false;
} else if (!value && dev->realized) {
+ Error **local_errp = NULL;
QLIST_FOREACH(bus, &dev->child_bus, sibling) {
+ local_errp = local_err ? NULL : &local_err;
object_property_set_bool(OBJECT(bus), false, "realized",
- &local_err);
- if (local_err != NULL) {
- break;
- }
+ local_errp);
}
- if (qdev_get_vmsd(dev) && local_err == NULL) {
+ if (qdev_get_vmsd(dev)) {
vmstate_unregister(dev, qdev_get_vmsd(dev), dev);
}
- if (dc->unrealize && local_err == NULL) {
- dc->unrealize(dev, &local_err);
+ if (dc->unrealize) {
+ local_errp = local_err ? NULL : &local_err;
+ dc->unrealize(dev, local_errp);
}
dev->pending_deleted_event = true;
}
if (local_err != NULL) {
- error_propagate(errp, local_err);
- return;
+ goto fail;
}
dev->realized = value;
+ return;
+
+child_realize_fail:
+ QLIST_FOREACH(bus, &dev->child_bus, sibling) {
+ object_property_set_bool(OBJECT(bus), false, "realized",
+ NULL);
+ }
+
+ if (qdev_get_vmsd(dev)) {
+ vmstate_unregister(dev, qdev_get_vmsd(dev), dev);
+ }
+
+post_realize_fail:
+ if (dc->unrealize) {
+ dc->unrealize(dev, NULL);
+ }
+
+fail:
+ error_propagate(errp, local_err);
+ return;
}
static bool device_get_hotpluggable(Object *obj, Error **errp)
diff --git a/memory.c b/memory.c
index ef0be1c3aa..1bae951df7 100644
--- a/memory.c
+++ b/memory.c
@@ -876,30 +876,6 @@ static char *memory_region_escape_name(const char *name)
return escaped;
}
-static void object_property_add_child_array(Object *owner,
- const char *name,
- Object *child)
-{
- int i;
- char *base_name = memory_region_escape_name(name);
-
- for (i = 0; ; i++) {
- char *full_name = g_strdup_printf("%s[%d]", base_name, i);
- Error *local_err = NULL;
-
- object_property_add_child(owner, full_name, child, &local_err);
- g_free(full_name);
- if (!local_err) {
- break;
- }
-
- error_free(local_err);
- }
-
- g_free(base_name);
-}
-
-
void memory_region_init(MemoryRegion *mr,
Object *owner,
const char *name,
@@ -917,8 +893,12 @@ void memory_region_init(MemoryRegion *mr,
mr->name = g_strdup(name);
if (name) {
- object_property_add_child_array(owner, name, OBJECT(mr));
+ char *escaped_name = memory_region_escape_name(name);
+ char *name_array = g_strdup_printf("%s[*]", escaped_name);
+ object_property_add_child(owner, name_array, OBJECT(mr), &error_abort);
object_unref(OBJECT(mr));
+ g_free(name_array);
+ g_free(escaped_name);
}
}
diff --git a/qom/object.c b/qom/object.c
index 79bd0cc474..da0919a3dd 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -668,10 +668,10 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
void *opaque)
{
- ObjectProperty *prop;
+ ObjectProperty *prop, *next;
int ret = 0;
- QTAILQ_FOREACH(prop, &obj->properties, node) {
+ QTAILQ_FOREACH_SAFE(prop, &obj->properties, node, next) {
if (object_property_is_child(prop)) {
ret = fn(prop->opaque, opaque);
if (ret != 0) {
@@ -728,6 +728,27 @@ object_property_add(Object *obj, const char *name, const char *type,
void *opaque, Error **errp)
{
ObjectProperty *prop;
+ size_t name_len = strlen(name);
+
+ if (name_len >= 3 && !memcmp(name + name_len - 3, "[*]", 4)) {
+ int i;
+ ObjectProperty *ret;
+ char *name_no_array = g_strdup(name);
+
+ name_no_array[name_len - 3] = '\0';
+ for (i = 0; ; ++i) {
+ char *full_name = g_strdup_printf("%s[%d]", name_no_array, i);
+
+ ret = object_property_add(obj, full_name, type, get, set,
+ release, opaque, NULL);
+ g_free(full_name);
+ if (ret) {
+ break;
+ }
+ }
+ g_free(name_no_array);
+ return ret;
+ }
QTAILQ_FOREACH(prop, &obj->properties, node) {
if (strcmp(prop->name, name) == 0) {
diff --git a/vl.c b/vl.c
index a9fd2070e7..9c9acf5e65 100644
--- a/vl.c
+++ b/vl.c
@@ -2841,15 +2841,15 @@ static void free_and_trace(gpointer mem)
free(mem);
}
-static int object_set_property(const char *name, const char *value, void *opaque)
+static int machine_set_property(const char *name, const char *value,
+ void *opaque)
{
Object *obj = OBJECT(opaque);
StringInputVisitor *siv;
Error *local_err = NULL;
char *c, *qom_name;
- if (strcmp(name, "qom-type") == 0 || strcmp(name, "id") == 0 ||
- strcmp(name, "type") == 0) {
+ if (strcmp(name, "type") == 0) {
return 0;
}
@@ -4254,7 +4254,7 @@ int main(int argc, char **argv, char **envp)
}
machine_opts = qemu_get_machine_opts();
- if (qemu_opt_foreach(machine_opts, object_set_property, current_machine,
+ if (qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
1) < 0) {
object_unref(OBJECT(current_machine));
exit(1);