@@ -1193,14 +1193,27 @@ static void machine_class_base_init(ObjectClass *oc, void *data)
}
}
+const char *machine_containers[] = {
+ "unattached",
+ "peripheral",
+ "peripheral-anon"
+};
+
+static void qemu_create_machine_containers(Object *machine)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(machine_containers); i++) {
+ container_create(machine, machine_containers[i]);
+ }
+}
+
static void machine_initfn(Object *obj)
{
MachineState *ms = MACHINE(obj);
MachineClass *mc = MACHINE_GET_CLASS(obj);
- container_get(obj, "/peripheral");
- container_get(obj, "/peripheral-anon");
-
+ qemu_create_machine_containers(obj);
ms->dump_guest_core = true;
ms->mem_merge = (QEMU_MADV_MERGEABLE != QEMU_MADV_INVALID);
ms->enable_graphics = true;
@@ -1734,12 +1734,26 @@ const char *object_property_get_type(Object *obj, const char *name, Error **errp
return prop->type;
}
+static Object *object_root_initialize(void)
+{
+ Object *root = object_new(TYPE_CONTAINER);
+
+ /*
+ * Create all QEMU system containers. "machine" and its sub-containers
+ * are only created when machine initializes (qemu_create_machine()).
+ */
+ container_create(root, "chardevs");
+ container_create(root, "objects");
+
+ return root;
+}
+
Object *object_get_root(void)
{
static Object *root;
if (!root) {
- root = object_new(TYPE_CONTAINER);
+ root = object_root_initialize();
}
return root;
Always explicitly create QEMU system containers upfront. Root containers will be created when trying to fetch the root object the 1st time. Machine sub-containers will be created only until machine is being initialized. Signed-off-by: Peter Xu <peterx@redhat.com> --- hw/core/machine.c | 19 ++++++++++++++++--- qom/object.c | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-)