Peter Xu <pet...@redhat.com> writes:

> Always explicitly create QEMU system containers upfront.
>
> Root containers will be created when trying to fetch the root object the
> 1st time.

Which ones are affected?

Not a fan of creating stuff on first use, unless there may not be any
use.  But no worse than before.

>            Machine sub-containers will be created only until machine is
> being initialized.
>
> Signed-off-by: Peter Xu <pet...@redhat.com>
> ---
>  hw/core/machine.c | 19 ++++++++++++++++---
>  qom/object.c      | 16 +++++++++++++++-
>  2 files changed, 31 insertions(+), 4 deletions(-)
>
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index a35c4a8fae..a184dbf8f0 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -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);

We now additionally create "/machine/unattached" here.  

>      ms->dump_guest_core = true;
>      ms->mem_merge = (QEMU_MADV_MERGEABLE != QEMU_MADV_INVALID);
>      ms->enable_graphics = true;
> diff --git a/qom/object.c b/qom/object.c
> index 214d6eb4c1..810e6f2bd9 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -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();

We now additonally create "/chardevs" and "/objects" here, not just "/".

>      }
>  
>      return root;


Reply via email to