All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: "Daniel P. Berrange" <berrange@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	qemu-devel@nongnu.org, "Markus Armbruster" <armbru@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"John Snow" <jsnow@redhat.com>,
	"Stefan Berger" <stefanb@linux.ibm.com>
Subject: Re: [PATCH v2 00/44] Make qdev static property API usable by any QOM type
Date: Fri, 6 Nov 2020 16:10:34 -0500	[thread overview]
Message-ID: <20201106211034.GY5733@habkost.net> (raw)
In-Reply-To: <20201106155013.GX5733@habkost.net>

On Fri, Nov 06, 2020 at 10:50:19AM -0500, Eduardo Habkost wrote:
> On Fri, Nov 06, 2020 at 10:45:11AM +0100, Kevin Wolf wrote:
> > Am 04.11.2020 um 16:59 hat Eduardo Habkost geschrieben:
> > > This series refactor the qdev property code so the static
> > > property system can be used by any QOM type.  As an example, at
> > > the end of the series some properties in TYPE_MACHINE are
> > > converted to static properties to demonstrate the new API.
> > > 
> > > Changes v1 -> v2
> > > ----------------
> > > 
> > > * Rename functions and source files to call the new feature
> > >   "field property" instead of "static property"
> > > 
> > > * Change the API signature from an array-based interface similar
> > >   to device_class_set_props() to a object_property_add()-like
> > >   interface.
> > > 
> > >   This means instead of doing this:
> > > 
> > >     object_class_property_add_static_props(oc, my_array_of_props);
> > > 
> > >   properties are registered like this:
> > > 
> > >     object_class_property_add_field(oc, "property-name"
> > >                                     PROP_XXX(MyState, my_field),
> > >                                     prop_allow_set_always);
> > > 
> > >   where PROP_XXX is a PROP_* macro like PROP_STRING, PROP_BOOL,
> > >   etc.
> > 
> > In comparison, I really like the resulting code from the array based
> > interface in v1 better.
> > 
> > I think it's mostly for two reasons: First, the array is much more
> > compact and easier to read. And maybe even more importantly, you know
> > it's static data and only static data. The function based interface can
> > be mixed with other code or the parameter list can contain calls to
> > other functions with side effects, so there are a lot more opportunities
> > for surprises.
> 
> This is a really good point, and I strongly agree with it.
> Letting code do funny tricks at runtime is one of the reasons QOM
> properties became hard to introspect.
> 
> > 
> > What I didn't like about the v1 interface is that there is still a
> > separate object_class_property_set_description() for each property, but
> > I think that could have been fixed by moving the description to the
> > definitions in the array, too.
> 
> This would be very easy to implement.

This was implemented at:
https://gitlab.com/ehabkost/qemu/-/commits/work/qdev-make-generic

This is the interface I'd like to submit as v3:

static Property machine_props[] = {
    DEFINE_PROP_STRING("kernel", MachineState, kernel_filename,
                       .description = "Linux kernel image file"),
    DEFINE_PROP_STRING("initrd", MachineState, initrd_filename,
                       .description = "Linux initial ramdisk file"),
    DEFINE_PROP_STRING("append", MachineState, kernel_cmdline,
                       .description = "Linux kernel command line"),
    DEFINE_PROP_STRING("dtb", MachineState, dtb,
                       .description = "Linux kernel device tree file"),
    DEFINE_PROP_STRING("dumpdtb", MachineState, dumpdtb,
                       .description = "Dump current dtb to a file and quit"),
    DEFINE_PROP_STRING("dt-compatible", MachineState, dt_compatible,
                       .description = "Overrides the \"compatible\" "
                                      "property of the dt root node"),
    DEFINE_PROP_STRING("firmware", MachineState, firmware,
                       .description = "Firmware image"),
    DEFINE_PROP_STRING("memory-backend", MachineState, ram_memdev_id,
                       .description = "ID of memory backend object"),
    DEFINE_PROP_BOOL("dump-guest-core", MachineState, dump_guest_core, true,
                     .description = "Include guest memory in a core dump"),
    DEFINE_PROP_BOOL("mem-merge", MachineState, mem_merge, true,
                     .description = "Enable/disable memory merge support"),
    DEFINE_PROP_BOOL("graphics", MachineState, enable_graphics, true,
                     .description = "Set on/off to enable/disable graphics emulation"),
    DEFINE_PROP_BOOL("suppress-vmdesc", MachineState, suppress_vmdesc, false,
                     .description = "Set on to disable self-describing migration"),
    DEFINE_PROP_UINT32("phandle-start", MachineState, phandle_start, 0,
                       .description = "The first phandle ID we may generate dynamically"),
    DEFINE_PROP_END_OF_LIST(),
};

static void machine_class_init(ObjectClass *oc, void *data)
{
    ...
    object_class_add_field_properties(oc, machine_props, prop_allow_set_always);
    ...
}



> 
> > 
> > On Fri, Oct 30, 2020 at 06:10:34PM +0100, Paolo Bonzini wrote:
> > > On 29/10/20 23:02, Eduardo Habkost wrote:
> > > > +static Property machine_props[] = {
> > > > +    DEFINE_PROP_STRING("kernel", MachineState, kernel_filename),
> > > > +    DEFINE_PROP_STRING("initrd", MachineState, initrd_filename),
> > > > +    DEFINE_PROP_STRING("append", MachineState, kernel_cmdline),
> > > > +    DEFINE_PROP_STRING("dtb", MachineState, dtb),
> > > > +    DEFINE_PROP_STRING("dumpdtb", MachineState, dumpdtb),
> > > > +    DEFINE_PROP_STRING("dt-compatible", MachineState, dt_compatible),
> > > > +    DEFINE_PROP_STRING("firmware", MachineState, firmware),
> > > > +    DEFINE_PROP_STRING("memory-backend", MachineState, ram_memdev_id),
> > > > +    DEFINE_PROP_END_OF_LIST(),
> > > > +};
> > > > +
> > >
> > > While I think generalizing the _code_ for static properties is obviously
> > > a good idea, I am not sure about generalizing the interface for adding them.
> > >
> > > The reason is that we already have a place for adding properties in
> > > class_init, and having a second makes things "less local", so to speak.
> > 
> > As long as you have the function call to apply the properites array in
> > .class_init, it should be obvious enough what you're doing.
> > 
> > Of course, I think we should refrain from mixing both styles in a single
> > object, but generally speaking the array feels so much better that I
> > don't think we should reject it just because QOM only had a different
> > interface so far (and the property array is preexisting in qdev, too, so
> > we already have differences between objects - in fact, the majority of
> > objects is probably qdev today).
> 
> This is also a strong argument.  The QEMU code base has ~500
> matches for "object*_property_add*" calls, and ~2100 for
> "DEFINE_PROP*".
> 
> Converting qdev arrays to object_class_property_add_*() calls
> would be a huge effort with no gains.  The end result would be
> two different APIs for registering class field properties
> coexisting for a long time, and people still confused on what's
> the preferred API.
> 
> -- 
> Eduardo

-- 
Eduardo



  reply	other threads:[~2020-11-06 21:11 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-04 15:59 [PATCH v2 00/44] Make qdev static property API usable by any QOM type Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 01/44] cs4231: Get rid of empty property array Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 02/44] cpu: Move cpu_common_props to hw/core/cpu.c Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 03/44] qdev: Move property code to qdev-properties.[ch] Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 04/44] qdev: Check dev->realized at set_size() Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 05/44] sparc: Check dev->realized at sparc_set_nwindows() Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 06/44] qdev: Don't use dev->id on set_size32() error message Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 07/44] qdev: Make PropertyInfo.print method get Object* argument Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 08/44] qdev: Make bit_prop_set() " Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 09/44] qdev: Make qdev_get_prop_ptr() get Object* arg Eduardo Habkost
2020-11-04 15:59   ` Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 10/44] qdev: Make qdev_find_global_prop() get Object* argument Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 11/44] qdev: Make check_prop_still_unset() " Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 12/44] qdev: Make error_set_from_qdev_prop_error() " Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 13/44] qdev: Move UUID property to qdev-properties-system.c Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 14/44] qdev: Move softmmu properties to qdev-properties-system.h Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 15/44] qdev: Reuse DEFINE_PROP in all DEFINE_PROP_* macros Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 16/44] sparc: Use DEFINE_PROP for nwindows property Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 17/44] qdev: Get just property name at error_set_from_qdev_prop_error() Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 18/44] qdev: Avoid using prop->name unnecessarily Eduardo Habkost
2020-11-04 17:25   ` Stefan Berger
2020-11-04 15:59 ` [PATCH v2 19/44] qdev: Add name parameter to qdev_class_add_property() Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 20/44] qdev: Add name argument to PropertyInfo.create method Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 21/44] qdev: Wrap getters and setters in separate helpers Eduardo Habkost
2020-11-04 15:59 ` [PATCH v2 22/44] qdev: Move dev->realized check to qdev_property_set() Eduardo Habkost
2020-11-04 15:59   ` Eduardo Habkost
2020-11-04 17:28   ` Stefan Berger
2020-11-04 17:28     ` Stefan Berger
2020-11-04 16:00 ` [PATCH v2 23/44] qdev: Make PropertyInfo.create return ObjectProperty* Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 24/44] qdev: Make qdev_class_add_property() more flexible Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 25/44] qdev: Separate generic and device-specific property registration Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 26/44] qdev: Rename Property.name to Property.qdev_prop_name Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 27/44] qdev: Don't set qdev_prop_name for array elements Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 28/44] qdev: Avoid unnecessary DeviceState* variable at set_prop_arraylen() Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 29/44] qdev: Remove ArrayElementProperty.propname field Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 30/44] qdev: Get rid of ArrayElementProperty struct Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 31/44] qdev: Reuse object_property_add_field() when adding array elements Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 32/44] qom: Add allow_set callback to ObjectProperty Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 33/44] qdev: Make qdev_prop_allow_set() a ObjectProperty.allow_set callback Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 34/44] qdev: Make qdev_propinfo_get_uint16() static Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 35/44] qdev: Rename qdev_propinfo_* to field_prop_* Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 36/44] qdev: Rename qdev_get_prop_ptr() to object_field_prop_ptr() Eduardo Habkost
2020-11-04 16:00   ` Eduardo Habkost
2020-11-05 18:49   ` Stefan Berger
2020-11-05 18:49     ` Stefan Berger
2020-11-04 16:00 ` [PATCH v2 37/44] qdev: Move qdev_prop_tpm declaration to tpm_prop.h Eduardo Habkost
2020-11-05 18:50   ` Stefan Berger
2020-11-04 16:00 ` [PATCH v2 38/44] qdev: Rename qdev_prop_* to prop_info_* Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 39/44] qdev: PROP_* macros Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 40/44] qdev: Move core field property code to QOM Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 41/44] qdev: Move base property types to qom/property-types.c Eduardo Habkost
2020-11-04 16:36   ` Paolo Bonzini
2020-11-04 20:50     ` Eduardo Habkost
2020-11-05  9:36       ` Paolo Bonzini
2020-11-04 16:00 ` [PATCH v2 42/44] qom: Include static property API reference in documentation Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 43/44] tests: Use field properties at check-qom-proplist test case Eduardo Habkost
2020-11-04 16:00 ` [PATCH v2 44/44] machine: Register most properties as field properties Eduardo Habkost
2020-11-04 16:36 ` [PATCH v2 00/44] Make qdev static property API usable by any QOM type no-reply
2020-11-06  9:45 ` Kevin Wolf
2020-11-06 15:50   ` Eduardo Habkost
2020-11-06 21:10     ` Eduardo Habkost [this message]
2020-11-08 14:05       ` Paolo Bonzini
2020-11-09 11:34         ` Kevin Wolf
2020-11-09 14:15           ` Paolo Bonzini
2020-11-09 15:21             ` Eduardo Habkost
2020-11-09 16:34               ` Paolo Bonzini
2020-11-09 17:16                 ` Eduardo Habkost
2020-11-09 17:33                   ` Paolo Bonzini
2020-11-09 18:55                     ` Eduardo Habkost
2020-11-09 19:27                       ` Paolo Bonzini
2020-11-09 20:28                         ` Eduardo Habkost
2020-11-10 10:38                           ` Kevin Wolf
2020-11-11 18:39                             ` Eduardo Habkost
2020-11-12  8:11                               ` Paolo Bonzini
2020-11-12 14:53                                 ` Eduardo Habkost
2020-11-10 10:58                           ` Paolo Bonzini
2020-11-10 17:03                             ` Eduardo Habkost

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=20201106211034.GY5733@habkost.net \
    --to=ehabkost@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanb@linux.ibm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.