qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH for-3.2 v4 25/28] machine: add compat-props interface
Date: Fri, 30 Nov 2018 13:34:56 +0100	[thread overview]
Message-ID: <20181130133456.727fe935@redhat.com> (raw)
In-Reply-To: <20181129174900.GP18284@habkost.net>

On Thu, 29 Nov 2018 15:49:00 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:

> On Tue, Nov 27, 2018 at 01:27:58PM +0400, Marc-André Lureau wrote:
> > Let's make compatiblity properties an interface, so that objects other
> > than QDev can benefit from having machine compatiblity properties.
> > 
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>  
> [...]
> > diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> > index 3b31b2c025..b0ee05f837 100644
> > --- a/hw/core/qdev.c
> > +++ b/hw/core/qdev.c
> > @@ -970,28 +970,8 @@ static void device_initfn(Object *obj)
> >      QLIST_INIT(&dev->gpios);
> >  }
> >  
> > -static const GPtrArray *ac_compat_props;
> > -static const GPtrArray *mc_compat_props;
> > -
> > -void accel_register_compat_props(const GPtrArray *props)
> > -{
> > -    ac_compat_props = props;
> > -}
> > -
> > -void machine_register_compat_props(const GPtrArray *props)
> > -{
> > -    mc_compat_props = props;
> > -}
> > -
> >  static void device_post_init(Object *obj)
> >  {
> > -    if (ac_compat_props) {
> > -        object_apply_global_props(obj, ac_compat_props, &error_abort);
> > -    }
> > -    if (mc_compat_props) {
> > -        object_apply_global_props(obj, mc_compat_props, &error_abort);
> > -    }
> > -
> >      qdev_prop_set_globals(DEVICE(obj));
> >  }
> >  
> > @@ -1124,6 +1104,10 @@ static const TypeInfo device_type_info = {
> >      .class_init = device_class_init,
> >      .abstract = true,
> >      .class_size = sizeof(DeviceClass),
> > +    .interfaces = (InterfaceInfo[]) {
> > +        { TYPE_COMPAT_PROPS },
> > +        { }
> > +    }  
> 
> At first I thought TYPE_COMPAT_PROPS was a practical way to
> implement this feature, but now I'm worried: the ordering between
> compat_props_post_init() qdev_prop_set_globals() is very
> important (user-provided globals must always be set after compat
> props), and here the ordering is implicit and easy to break
> accidentally.
> 
> What if instead of a QOM interface we just provide a simple
> object_apply_compat_props() function?  e.g.:
> 
> qdev.c:
> 
>   static void device_post_init(Object *obj)
>   {
>       object_apply_compat_props(obj);
>       apply_user_provided_globals(obj);
>   }
> 
> object_interface.c:
> 
>   void user_creatable_complete(Object *obj, Error **errp)
>   {
>       object_apply_compat_props(obj);
>       ...
>       ucc->complete(...)
>   }
this would work as long as nothing is happening between
object_new() ... user_creatable_complete() but look at
current users of user_creatable_complete() so it's
fragile too.

Reasons for compat props interface are the same as for
instance_post_init/device_post_init.

the thing we can do here is getting rid of device_post_init
and making device override TYPE_COMPAT_PROPS::instance_post_init
to make explicit ordering like we do everywhere else:

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 6b3cc55..46ad6f5 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -1033,11 +1033,19 @@ static void device_unparent(Object *obj)
     }
 }
 
+device_compat_props()
+{
+    dc->parent_compat_props()
+    apply_global_props()
+}
+
 static void device_class_init(ObjectClass *class, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(class);
 
     class->unparent = device_unparent;
+    dc->parent_compat_props = COMPAT_PROPS_GET_CLASS(class)->instance_post_init
+    COMPAT_PROPS_GET_CLASS(class)->instance_post_init = device_compat_props()
 
     /* by default all devices were considered as hotpluggable,
      * so with intent to check it in generic qdev_unplug() /

> Most people don't understand QOM interfaces and their
> initialization ordering rules.  Everybody understands C function
> calls.
> 
> > [...]  
> 

  reply	other threads:[~2018-11-30 12:50 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-27  9:27 [Qemu-devel] [PATCH for-3.2 v4 00/28] Generalize machine compatibility properties Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 01/28] target/xtensa: gdbstub fix register counting Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 02/28] target/xtensa: drop num_[core_]regs from dc232b/dc233c configs Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 03/28] target/xtensa: xtfpga: provide default memory sizes Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 04/28] MAINTAINERS: add missing xtensa patterns Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 05/28] 9p: fix QEMU crash when renaming files Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 06/28] MAINTAINERS: Assign some more files in the hw/arm/ directory Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 07/28] MAINTAINERS: Add an ARM SMMU section Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 08/28] net: cadence_gem: Remove incorrect assert() Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 09/28] tests: qdev_prop_check_globals() doesn't return "all_used" Marc-André Lureau
2018-11-27 13:40   ` Eduardo Habkost
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 10/28] qom: make interface types abstract Marc-André Lureau
2018-11-27 13:41   ` Eduardo Habkost
2018-11-27 13:55     ` Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 11/28] qom: make user_creatable_complete() specific to UserCreatable Marc-André Lureau
2018-11-27 13:45   ` Eduardo Habkost
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 12/28] accel: register global_props like machine globals Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 13/28] qdev: move qdev_prop_register_global_list() to tests Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 14/28] qom: remove unimplemented class_finalize Marc-André Lureau
2018-11-27 12:52   ` Eduardo Habkost
2018-11-28 17:44   ` Igor Mammedov
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 15/28] hw: apply accel compat properties without touching globals Marc-André Lureau
2018-11-27 19:40   ` Eduardo Habkost
2018-11-27 20:02     ` Marc-André Lureau
2018-11-29 16:02       ` Eduardo Habkost
2018-11-28 17:49   ` Igor Mammedov
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 16/28] hw: apply machine " Marc-André Lureau
2018-11-27 12:56   ` Eduardo Habkost
2018-11-27 13:10     ` Marc-André Lureau
2018-11-27 13:35       ` Eduardo Habkost
2018-11-28 17:40         ` Igor Mammedov
2018-11-28 17:53           ` Eduardo Habkost
2018-11-29 10:32           ` Marc-André Lureau
2018-11-29 17:50             ` Eduardo Habkost
2018-11-29 21:36               ` Marc-André Lureau
2018-11-30 10:55                 ` Igor Mammedov
2018-11-30 11:41                   ` Eduardo Habkost
2018-12-04 13:17                     ` Igor Mammedov
2018-12-04 18:43                       ` Eduardo Habkost
2018-11-30 11:37             ` Igor Mammedov
2018-11-29 16:09   ` Eduardo Habkost
2018-11-29 21:32     ` Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 17/28] hw: remove SET_MACHINE_COMPAT Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 18/28] qdev: all globals are now user-provided Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 19/28] qdev-props: convert global_props to GPtrArray Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 20/28] qdev-props: remove errp from GlobalProperty Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 21/28] qdev-props: call object_apply_global_props() Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 22/28] qom: teach interfaces to implement post-init Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 23/28] qom: add object_class_get_class_data() Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 24/28] arm: replace instance_post_init() Marc-André Lureau
2018-11-30 11:48   ` Igor Mammedov
2018-12-01 20:55     ` Marc-André Lureau
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 25/28] machine: add compat-props interface Marc-André Lureau
2018-11-29 17:49   ` Eduardo Habkost
2018-11-30 12:34     ` Igor Mammedov [this message]
2018-11-30 12:57       ` Eduardo Habkost
2018-11-30 12:39   ` Igor Mammedov
2018-11-27  9:27 ` [Qemu-devel] [PATCH for-3.2 v4 26/28] hw/i386: add pc-i440fx-3.2 & pc-q35-3.2 Marc-André Lureau
2018-11-27 13:01   ` Eduardo Habkost
2018-11-27  9:28 ` [Qemu-devel] [PATCH for-3.2 v4 27/28] hw/arm/virt: add virt-3.2 machine type Marc-André Lureau
2018-11-27  9:28 ` [Qemu-devel] [PATCH for-3.2 v4 28/28] hostmem: use object id for memory region name with >= 3.1 Marc-André Lureau
2018-11-27  9:53 ` [Qemu-devel] [PATCH for-3.2 v4 00/28] Generalize machine compatibility properties Greg Kurz
2018-11-27  9:58   ` Marc-André Lureau
2018-11-29  1:35 ` no-reply
2018-11-29  1:45 ` no-reply

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=20181130133456.727fe935@redhat.com \
    --to=imammedo@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --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).