qom: Create system containers explicitly

Always explicitly create QEMU system containers upfront.

Root containers will be created when trying to fetch the root object the
1st time.  They are:

  /objects
  /chardevs
  /backend

Machine sub-containers will be created only until machine is being
initialized.  They are:

  /machine/unattached
  /machine/peripheral
  /machine/peripheral-anon

Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20241121192202.4155849-8-peterx@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
Peter Xu 2024-11-21 14:21:56 -05:00 committed by Philippe Mathieu-Daudé
parent 7c03a17c8d
commit 5cfd38a2e7
3 changed files with 39 additions and 4 deletions

View file

@ -1729,12 +1729,34 @@ const char *object_property_get_type(Object *obj, const char *name, Error **errp
return prop->type;
}
static const char *const root_containers[] = {
"chardevs",
"objects",
"backend"
};
static Object *object_root_initialize(void)
{
Object *root = object_new(TYPE_CONTAINER);
int i;
/*
* Create all QEMU system containers. "machine" and its sub-containers
* are only created when machine initializes (qemu_create_machine()).
*/
for (i = 0; i < ARRAY_SIZE(root_containers); i++) {
object_property_add_new_container(root, root_containers[i]);
}
return root;
}
Object *object_get_root(void)
{
static Object *root;
if (!root) {
root = object_new(TYPE_CONTAINER);
root = object_root_initialize();
}
return root;