qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
	qemu-devel@nongnu.org, "Eduardo Habkost" <eduardo@habkost.net>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Juraj Marcin" <jmarcin@redhat.com>,
	"Cédric Le Goater" <clg@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Fabiano Rosas" <farosas@suse.de>
Subject: Re: [PATCH 10/12] qom: Create system containers explicitly
Date: Thu, 21 Nov 2024 13:03:40 -0500	[thread overview]
Message-ID: <Zz91_IoN0e5E0v2k@x1n> (raw)
In-Reply-To: <c68b260a-b4ee-48ec-9f5c-3c72a58f424b@linaro.org>

On Thu, Nov 21, 2024 at 06:29:06PM +0100, Philippe Mathieu-Daudé wrote:
> On 21/11/24 18:17, Peter Xu wrote:
> > On Thu, Nov 21, 2024 at 02:01:45PM +0100, Philippe Mathieu-Daudé wrote:
> > > On 21/11/24 11:30, Daniel P. Berrangé wrote:
> > > > On Wed, Nov 20, 2024 at 04:57:01PM -0500, Peter Xu wrote:
> > > > > 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(-)
> > > > 
> > > > 
> > > > > 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");
> > > > 
> > > > This is where I would expect 'backend' to have been created
> > > > rather than ui/console.c, though you could potentially make
> > > > a case to create it from the machine function, snice console
> > > > stuff can't be used outside of the machine context, while
> > > > chardevs/objects can be used in qemu-img/qemu-nbd, etc
> > 
> > Would it hurt if we do it altogether here even if it won't be used in
> > qemu-img/qemu-nbd?
> > 
> > IMHO we should either make it simple (assuming empty containers won't hurt
> > there..), or we should just leave "backend" to ui/ code, so we don't assume
> > which binary is using the ui code: whoever uses it will create the container.
> > 
> > > 
> > > What about creating "backend" container in qemu_create_machine()?
> > 
> > I remember I started with that but it didn't work.  IIRC that's because
> > machine_initfn() (or somewhere around the init code) requires the
> > containers to present, hence it's too late even if we create the containers
> > right after this line:
> > 
> >      current_machine = MACHINE(object_new_with_class(OBJECT_CLASS(machine_class)));
> 
> So qemu_create_machine_containers() really belongs to qemu_create_machine()
> =)

Frankly, I don't immediately get this line..

But when I was trying again just to check my memory, I can't see anything
crash anymore, moving things over.

So while I'll test some more, I can switch to that if I cannot reproduce
any issue with it.  That's:

===8<===

diff --git a/hw/core/machine.c b/hw/core/machine.c
index ed613ec4cb..a72c001c3d 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -1193,27 +1193,11 @@ static void machine_class_base_init(ObjectClass *oc, void *data)
     }
 }
 
-static const char *const 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++) {
-        object_property_add_new_container(machine, machine_containers[i]);
-    }
-}
-
 static void machine_initfn(Object *obj)
 {
     MachineState *ms = MACHINE(obj);
     MachineClass *mc = MACHINE_GET_CLASS(obj);
 
-    qemu_create_machine_containers(obj);
     ms->dump_guest_core = true;
     ms->mem_merge = (QEMU_MADV_MERGEABLE != QEMU_MADV_INVALID);
     ms->enable_graphics = true;
diff --git a/system/vl.c b/system/vl.c
index 822f7ff656..cdc0b6e10c 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -2112,6 +2112,21 @@ static void parse_memory_options(void)
     loc_pop(&loc);
 }
 
+static const char *const 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++) {
+        object_property_add_new_container(machine, machine_containers[i]);
+    }
+}
+
 static void qemu_create_machine(QDict *qdict)
 {
     MachineClass *machine_class = select_machine(qdict, &error_fatal);
@@ -2120,6 +2135,7 @@ static void qemu_create_machine(QDict *qdict)
     current_machine = MACHINE(object_new_with_class(OBJECT_CLASS(machine_class)));
     object_property_add_child(object_get_root(), "machine",
                               OBJECT(current_machine));
+    qemu_create_machine_containers(OBJECT(current_machine));
     object_property_add_child(machine_get_container("unattached"),
                               "sysbus", OBJECT(sysbus_get_default()));
 

-- 
Peter Xu



  reply	other threads:[~2024-11-21 18:05 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-20 21:56 [PATCH 00/12] QOM: container_get() removal Peter Xu
2024-11-20 21:56 ` [PATCH 01/12] qom: Add TYPE_CONTAINER macro Peter Xu
2024-11-21  9:20   ` Philippe Mathieu-Daudé
2024-11-21 10:04   ` Daniel P. Berrangé
2024-11-20 21:56 ` [PATCH 02/12] qom: New container_create() Peter Xu
2024-11-21 10:05   ` Daniel P. Berrangé
2024-11-21 13:20   ` Markus Armbruster
2024-11-21 16:18     ` Peter Xu
2024-11-20 21:56 ` [PATCH 03/12] tests: Fix test-qdev-global-props on anonymous qdev realize() Peter Xu
2024-11-21  9:20   ` Philippe Mathieu-Daudé
2024-11-21 10:16   ` Daniel P. Berrangé
2024-11-20 21:56 ` [PATCH 04/12] tests: Explicitly create containers in test_qom_partial_path() Peter Xu
2024-11-21  9:19   ` Philippe Mathieu-Daudé
2024-11-21 10:16   ` Daniel P. Berrangé
2024-11-20 21:56 ` [PATCH 05/12] ui/console: Explicitly create "/backend" container Peter Xu
2024-11-21  9:19   ` Philippe Mathieu-Daudé
2024-11-21 10:26   ` Daniel P. Berrangé
2024-11-21 16:27     ` Peter Xu
2024-11-20 21:56 ` [PATCH 06/12] hw/ppc: Explicitly create the drc container Peter Xu
2024-11-21  9:35   ` Philippe Mathieu-Daudé
2024-11-21 16:36     ` Peter Xu
2024-11-21 17:14       ` Philippe Mathieu-Daudé
2024-11-20 21:56 ` [PATCH 07/12] ppc/e500: Avoid abuse of container_get() Peter Xu
2024-11-21  9:38   ` Cédric Le Goater
2024-11-21  9:48     ` Cédric Le Goater
2024-11-21 16:41       ` Peter Xu
2024-11-21 17:17         ` Philippe Mathieu-Daudé
2024-11-21 10:28   ` Daniel P. Berrangé
2024-11-20 21:56 ` [PATCH 08/12] qdev: Make qdev_get_machine() not use container_get() Peter Xu
2024-11-21 10:21   ` Daniel P. Berrangé
2024-11-21 16:48     ` Peter Xu
2024-11-20 21:57 ` [PATCH 09/12] qdev: Add machine_get_container() Peter Xu
2024-11-21  9:23   ` Philippe Mathieu-Daudé
2024-11-21 10:23   ` Daniel P. Berrangé
2024-11-21 13:23   ` Markus Armbruster
2024-11-20 21:57 ` [PATCH 10/12] qom: Create system containers explicitly Peter Xu
2024-11-21  9:13   ` Philippe Mathieu-Daudé
2024-11-21 10:30   ` Daniel P. Berrangé
2024-11-21 13:01     ` Philippe Mathieu-Daudé
2024-11-21 17:17       ` Peter Xu
2024-11-21 17:29         ` Philippe Mathieu-Daudé
2024-11-21 18:03           ` Peter Xu [this message]
2024-11-21 19:03             ` Philippe Mathieu-Daudé
2024-11-21 13:31   ` Markus Armbruster
2024-11-21 17:24     ` Peter Xu
2024-11-20 21:57 ` [PATCH 11/12] qom: Add object_get_container() Peter Xu
2024-11-21  9:23   ` Philippe Mathieu-Daudé
2024-11-21 10:30   ` Daniel P. Berrangé
2024-11-20 21:57 ` [PATCH 12/12] qom: Drop container_get() Peter Xu
2024-11-21 10:32   ` Daniel P. Berrangé
2024-11-21  9:18 ` [PATCH 00/12] QOM: container_get() removal Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zz91_IoN0e5E0v2k@x1n \
    --to=peterx@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=clg@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=farosas@suse.de \
    --cc=jmarcin@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).