QOM infrastructure fixes and device conversions
* Cleanups for recursive device unrealization -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAABAgAGBQJUCJ6vAAoJEPou0S0+fgE/9M8QAJc6gPpnZtwd7QAPORhJaKbd nlRYOAmtGhh/NufuE+azbM3mZkWfbadVYt8hviLVVNSVaV/2iH+nMhKxwYwlC2EH pBYLH251VJILTqiFQ92xvCnL911q6MYBTLvLLFPs1MiJufi1pYC3qC47184TMxCF MQCwPJRMbQEMfppAe3IvpoGyfVXptMrgcauBrv0hGV7prJ4jlyWcRNiB28oi3cth l9ysLwn38aqshYvPwiWlJSibXMJGU4uxqmgTu9W5OdzNs6UOTzSFNKZdN7S0BTQy 4y0eB63qkB+U4sc4X4Y7qzgh0VxzK6AKSht3jK05VVYG3OuYEBQ3qjI+oTrlvT/d i75MTbIm6XmCa5ctQGxgcE3FiyE0ZafzIoSFNedp0QmN4hgIseX29WdZkwIp0t6Q d/lnMOxrFT7GAy/WHs9a9N71CydO84E47JeLhbIA+UoqAW3JVYKXtPoIEyc6xf5Z w23TZQhzV/CzJ5BDK8H6Ppi+PFTgu4idH26QzxUdO3ih7yTMKFbg7UM5eQXi+qea /jM8ST7Wh23k/XWaPI74hofp843NObG4JUN+8Ax0U5dP5xr2lvddsEicD7dUTTjJ R3MdV09o1Az7f20HWo/x3zXak6lK6HF7WlB8r+Hl6G4Ucd/KI5qf2I9eI3amyXk3 hSOFlEcqz6lnUhFywh2z =njHv -----END PGP SIGNATURE----- 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>
This commit is contained in:
commit
fd884c0765
@ -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)
|
||||
|
30
memory.c
30
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
25
qom/object.c
25
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) {
|
||||
|
8
vl.c
8
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);
|
||||
|
Loading…
Reference in New Issue
Block a user