QEMU-Rust Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Fabiano Rosas <farosas@suse.de>
Cc: "Peter Xu" <peterx@redhat.com>,
	qemu-devel@nongnu.org, qemu-arm@nongnu.org,
	"Cédric Le Goater" <clg@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@mailo.com>,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@yandex-team.ru>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Dr . David Alan Gilbert" <dave@treblig.org>,
	"Eric Blake" <eblake@redhat.com>,
	"Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Kevin Wolf" <kwolf@redhat.com>,
	"Sana Sharma" <sansshar@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Juraj Marcin" <jmarcin@redhat.com>,
	qemu-rust@nongnu.org, "Markus Armbruster" <armbru@redhat.com>,
	"Mark Cave-Ayland" <mark.caveayland@nutanix.com>
Subject: Re: [PATCH v2 05/10] qom: Create object-property-ptr.[ch]
Date: Thu, 11 Jun 2026 15:40:29 +0100	[thread overview]
Message-ID: <airI3UKeVVRUdQHq@redhat.com> (raw)
In-Reply-To: <87h5n94001.fsf@suse.de>

On Thu, Jun 11, 2026 at 11:36:46AM -0300, Fabiano Rosas wrote:
> Daniel P. Berrangé <berrange@redhat.com> writes:
> 
> > On Wed, Jun 10, 2026 at 02:39:09PM -0400, Peter Xu wrote:
> >> On Wed, Jun 10, 2026 at 05:15:59PM +0100, Daniel P. Berrangé wrote:
> >> > On Tue, Jun 09, 2026 at 01:25:09PM -0400, Peter Xu wrote:
> >> > > Create object-property-ptr.[ch] files to include all the helpers for
> >> > > object_property_add*_ptr().
> >> > > 
> >> > > These set of helpers are handy because they look extremely familiar with
> >> > > qdev-properties, allowing the caller to provide a pointer and it will
> >> > > manage all the setters and getters.
> >> > > 
> >> > > The follow up patches may introduce more of such helpers.  Since object.c
> >> > > has been already too big, split that part out.
> >> > 
> >> > The "ptr" helpers are all instance level properties which is a concept
> >> > we discourage from new usage, in favour of class level properties.
> >> > 
> >> > I don't think we should be adding more "ptr" helpers, but rather
> >> > planning to eliminiate the (surprisingly little) usage of the
> >> > existing ones.
> >> 
> >> The other way to do similar thing is qdev's offset way, but IMHO that's
> >> more awkward to remember an offset of a pointer then do math everytime.
> >> Essentially, from technical pov we need at least one uintptr_t to store
> >> either (1) offset, or (2) field pointer when there's a field that is bound
> >> to a prop.  IMHO (2) can be better otherwise we'll need to do all the maths
> >> to calculate offsets then when access we add the offset back and do a force
> >> cast.  It seems not necessary.
> >
> > There shouldn't be any need to play with field offsets either. Just
> > define the setters & getters to directly access the fields.
> >
> > Take some samples from the "machine_class_init" in hw/core/machine.c
> > as an example of the normal design pattern:
> >
> >     object_class_property_add_str(oc, "dumpdtb",
> >         machine_get_dumpdtb, machine_set_dumpdtb);
> >     object_class_property_set_description(oc, "dumpdtb",
> >         "Dump current dtb to a file and quit");
> >
> >    ..snip..
> >
> >     object_class_property_add_bool(oc, "dump-guest-core",
> >         machine_get_dump_guest_core, machine_set_dump_guest_core);
> >     object_class_property_set_description(oc, "dump-guest-core",
> >         "Include guest memory in a core dump");
> >
> > These are paired with:
> >
> >   static char *machine_get_dumpdtb(Object *obj, Error **errp)
> >   {
> >       MachineState *ms = MACHINE(obj);
> >
> >       return g_strdup(ms->dumpdtb);
> >   }
> >
> >   static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp)
> >   {
> >       MachineState *ms = MACHINE(obj);
> >
> >       g_free(ms->dumpdtb);
> >       ms->dumpdtb = g_strdup(value);
> >   }
> >
> > and
> >
> >   static bool machine_get_dump_guest_core(Object *obj, Error **errp)
> >   {
> >       MachineState *ms = MACHINE(obj);
> >
> >       return ms->dump_guest_core;
> >   }
> >
> >   static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp)
> >   {
> >       MachineState *ms = MACHINE(obj);
> >
> >       if (!value && QEMU_MADV_DONTDUMP == QEMU_MADV_INVALID) {
> >           error_setg(errp, "Dumping guest memory cannot be disabled on this host");
> >           return;
> >       }
> >       ms->dump_guest_core = value;
> >   }
> >
> >
> > and defaults (if needed) are set in  the instance init method:
> >
> >   static void machine_initfn(Object *obj)
> >   {
> >       MachineState *ms = MACHINE(obj);
> >       MachineClass *mc = MACHINE_GET_CLASS(obj);
> >
> >       ms->dump_guest_core = true;
> >       ms->mem_merge = (QEMU_MADV_MERGEABLE != QEMU_MADV_INVALID);
> >       ...
> >   }
> >
> 
> Thanks for the practical example. In this usage, do you think there
> would be a way to avoid having 53 getters and setters? We often run into
> this issue of the rest of QEMU having just a handful of options and
> migration having a ton. Anything we can do to streamline this would be
> good.

There's nothing standard in QOM, but in patch 10 in this series
Peter has a DEFINE_TLS_PROP_HELPERS() which macro-ized the
repetitive getters/setters for the TLS string properties. The
duplicate code still exists in the binary of course, just hidden
from the source.


> >> Is there any pointer I can read about the discussion previously on this?
> >
> > I don't know that there's a particular thread in recent times
> > that I'd point to, just my ancient series from when I introduced
> > class properties for QOM back in 2015 and started the effort to
> > convert away from instances properties.
> >
> >   https://lists.gnu.org/archive/html/qemu-devel/2015-08/msg03112.html
> >
> 
> Anything we can do to avoid stumbling into this again? Should we add
> some words to object_property_add() discouraging instance properties?

Yeah, it is probably worth adding some guidance to the docs there.

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|



  reply	other threads:[~2026-06-11 14:41 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09 17:25 [PATCH v2 00/10] migration/qom: Remove TYPE_DEVICE dependency on migration object Peter Xu
2026-06-09 17:25 ` [PATCH v2 01/10] migration: Use OBJECT_DECLARE_SIMPLE_TYPE Peter Xu
2026-06-09 22:55   ` Fabiano Rosas
2026-06-10 13:56   ` Daniel P. Berrangé
2026-06-10 15:15   ` Mark Cave-Ayland
2026-06-09 17:25 ` [PATCH v2 02/10] qdev: Export global_props() Peter Xu
2026-06-09 22:55   ` Fabiano Rosas
2026-06-10 15:18   ` Mark Cave-Ayland
2026-06-09 17:25 ` [PATCH v2 03/10] qdev: Introduce DEFINE_PROP_*_NODEFAULT for bool/uint32 Peter Xu
2026-06-10 15:25   ` Mark Cave-Ayland
2026-06-09 17:25 ` [PATCH v2 04/10] hw/arm: Use nodefault version of qdev props when not needed Peter Xu
2026-06-10 15:31   ` Mark Cave-Ayland
2026-06-09 17:25 ` [PATCH v2 05/10] qom: Create object-property-ptr.[ch] Peter Xu
2026-06-10 16:15   ` Daniel P. Berrangé
2026-06-10 18:39     ` Peter Xu
2026-06-10 20:37       ` Fabiano Rosas
2026-06-11 13:52       ` Daniel P. Berrangé
2026-06-11 14:36         ` Fabiano Rosas
2026-06-11 14:40           ` Daniel P. Berrangé [this message]
2026-06-16 21:02             ` Peter Xu
2026-06-17 12:25               ` Fabiano Rosas
2026-06-17 12:27                 ` Daniel P. Berrangé
2026-06-11 12:54   ` Mark Cave-Ayland
2026-06-11 13:53     ` Peter Xu
2026-06-09 17:25 ` [PATCH v2 06/10] qom: Add object_property_add_bool_ptr() Peter Xu
2026-06-09 23:18   ` Fabiano Rosas
2026-06-11 12:59   ` Mark Cave-Ayland
2026-06-09 17:25 ` [PATCH v2 07/10] qom: Add object_property_add_size_ptr() Peter Xu
2026-06-09 23:18   ` Fabiano Rosas
2026-06-09 17:25 ` [PATCH v2 08/10] qom: Add object_property_add_*_ptr_def() Peter Xu
2026-06-09 23:21   ` Fabiano Rosas
2026-06-11 14:03   ` Mark Cave-Ayland
2026-06-09 17:25 ` [PATCH v2 09/10] qom: Allow default values for instance properties Peter Xu
2026-06-10 16:19   ` Daniel P. Berrangé
2026-06-11 14:08   ` Mark Cave-Ayland
2026-06-11 14:17     ` Daniel P. Berrangé
2026-06-11 15:24       ` Mark Cave-Ayland
2026-06-09 17:25 ` [PATCH v2 10/10] migration: Switch to TYPE_OBJECT with object properties Peter Xu
2026-06-10 16:13   ` Daniel P. Berrangé
2026-06-10 18:46     ` Peter Xu
2026-06-10 19:53       ` Fabiano Rosas
2026-06-10 20:18         ` Fabiano Rosas
2026-06-10 16:29   ` Daniel P. Berrangé
2026-06-10 18:51     ` Peter Xu
2026-06-09 22:54 ` [PATCH v2 00/10] migration/qom: Remove TYPE_DEVICE dependency on migration object Fabiano Rosas
2026-06-10 18:30   ` Peter Xu
2026-06-11 13:31     ` Daniel P. Berrangé

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=airI3UKeVVRUdQHq@redhat.com \
    --to=berrange@redhat.com \
    --cc=armbru@redhat.com \
    --cc=clg@redhat.com \
    --cc=dave@treblig.org \
    --cc=eblake@redhat.com \
    --cc=farosas@suse.de \
    --cc=jmarcin@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mark.caveayland@nutanix.com \
    --cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=philmd@mailo.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    --cc=sansshar@redhat.com \
    --cc=vsementsov@yandex-team.ru \
    /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