All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org, afaerber@suse.de
Subject: Re: [Qemu-devel] [PATCH 23/25] qom: add realized property
Date: Wed, 9 May 2012 22:01:28 +0200	[thread overview]
Message-ID: <20120509200128.GA30337@thinkpad.mammed.net> (raw)
In-Reply-To: <1333451753-3550-24-git-send-email-pbonzini@redhat.com>

Hi Paolo,

Are you plannig to respin this and related patches?
If yes, when?

On Tue, Apr 03, 2012 at 01:15:51PM +0200, Paolo Bonzini wrote:
> Since we had to move the state field from DeviceState to Object, we cannot
> delay the implementation of the "realized" property.  The property is
> a trigger for two actions that propagate through the composition tree.
> "Realize" is called when the property becomes true, and propagates in
> pre-order; realize can fail if the values of the properties are not valid.
> "Unrealize" is called when the property becomes false, and propagates in
> post-order; unrealize cannot fail.
> 
> Unrealize is also called by object_deinit, as a separate step before
> finalization.
> 
> Realize/unrealize is separate from reset.  Reset propagation is a thorny
> issue of its own.  We expect classes that care to implement a reset method
> and call it from realize or realize_children, depending on whether
> pre-order or post-order is more appropriate.
> 
> This patch adds four methods (realize, realize_children, unrealize,
> unrealize_children) to ObjectClass, together with a default implementation
> of realize_children and unrealize_children.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  include/qemu/object.h |   20 +++++++++++
>  qom/object.c          |   93 +++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 113 insertions(+)
> 
> diff --git a/include/qemu/object.h b/include/qemu/object.h
> index 6db376d..6bded2a 100644
> --- a/include/qemu/object.h
> +++ b/include/qemu/object.h
> @@ -245,6 +245,10 @@ struct ObjectClass
>  
>      /*< public >*/
>      Property *props;
> +    void (*realize)(Object *obj, struct Error **errp);
> +    void (*realize_children)(Object *obj, struct Error **errp);
> +    void (*unrealize)(Object *obj);
> +    void (*unrealize_children)(Object *obj);
>  };
>  
>  typedef enum ObjectState {
> @@ -463,6 +467,22 @@ Object *object_new_with_type(Type type);
>  void object_delete(Object *obj);
>  
>  /**
> + * object_realize_children:
> + * @obj: The object whose children should be realized.
> + *
> + * The default implementation of realize_children.
> + */
> +void object_realize_children(Object *obj, struct Error **errp);
> +
> +/**
> + * object_unrealize_children:
> + * @obj: The object whose children should be unrealize.
> + *
> + * The default implementation of unrealize_children.
> + */
> +void object_unrealize_children(Object *obj);
> +
> +/**
>   * object_initialize_with_type:
>   * @obj: A pointer to the memory to be used for the object.
>   * @type: The type of the object to instantiate.
> diff --git a/qom/object.c b/qom/object.c
> index 3a6b37b..2a3753a 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -259,6 +259,87 @@ static void object_interface_init(Object *obj, InterfaceImpl *iface)
>      obj->interfaces = g_slist_prepend(obj->interfaces, iface_obj);
>  }
>  
> +static void object_get_realized(Object *obj, Visitor *v, void *opaque,
> +                                const char *name, Error **errp)
> +{
> +    bool value = object_is_realized(obj);
> +
> +    visit_type_bool(v, &value, name, errp);
> +}
> +
> +static void object_unrealize(Object *obj)
> +{
> +    ObjectClass *klass = object_get_class(obj);
> +
> +    if (klass->unrealize_children) {
> +        klass->unrealize_children(obj);
> +    }
> +    if (obj->state != OBJECT_STATE_CREATED && klass->unrealize) {
> +        klass->unrealize(obj);
> +    }
> +    obj->state = OBJECT_STATE_CREATED;
> +}
> +
> +static int object_unrealize_1(Object *obj, void *unused)
> +{
> +    object_unrealize(obj);
> +    return 0;
> +}
> +
> +void object_unrealize_children(Object *obj)
> +{
> +    object_child_foreach(obj, object_unrealize_1, NULL);
> +}
> +
> +static void object_realize(Object *obj, Error **errp)
> +{
> +    ObjectClass *klass = object_get_class(obj);
> +
> +    if (obj->state != OBJECT_STATE_REALIZED && klass->realize) {
> +        klass->realize(obj, errp);
> +    }
> +    obj->state = OBJECT_STATE_REALIZED;
> +    if (klass->realize_children) {
> +        klass->realize_children(obj, errp);
> +    }
> +}
> +
> +static int object_realize_1(Object *obj, void *errp)
> +{
> +    Error *err = NULL;
> +    object_realize(obj, &err);
> +    if (err) {
> +        error_propagate((Error **)errp, err);
> +        return 1;
> +    }
> +
> +    return 0;
> +}
> +
> +void object_realize_children(Object *obj, Error **errp)
> +{
> +    object_child_foreach(obj, object_realize_1, errp);
> +}
> +
> +static void object_set_realized(Object *obj, Visitor *v, void *opaque,
> +                                const char *name, Error **errp)
> +{
> +    bool value;
> +    Error *err = NULL;
> +
> +    visit_type_bool(v, &value, name, &err);
> +    if (err) {
> +        error_propagate(errp, err);
> +        return;
> +    }
> +
> +    if (value) {
> +        object_realize(obj, errp);
> +    } else {
> +        object_unrealize(obj);
> +    }
> +}
> +
>  static void object_init_with_type(Object *obj, TypeImpl *ti)
>  {
>      int i;
> @@ -337,6 +418,8 @@ void object_unparent(Object *obj)
>  
>  static void object_deinit(Object *obj, TypeImpl *type)
>  {
> +    object_property_set_bool(obj, false, "realized", NULL);
> +
>      if (type->instance_finalize) {
>          type->instance_finalize(obj);
>      }
> @@ -1239,7 +1322,10 @@ static void object_instance_init(Object *obj)
>      Property *prop;
>  
>      object_property_add_str(obj, "type", qdev_get_type, NULL, NULL);
> +
>      obj->state = OBJECT_STATE_CREATED;
> +    object_property_add(obj, "realized", "bool", object_get_realized,
> +                        object_set_realized, NULL, NULL, NULL);
>  
>      class = object_get_class(obj);
>      do {
> @@ -1250,6 +1336,12 @@ static void object_instance_init(Object *obj)
>      } while (class != object_class_by_name(TYPE_OBJECT));
>  }
>  
> +static void object_class_init(ObjectClass *klass, void *class_data)
> +{
> +    klass->realize_children = object_realize_children;
> +    klass->unrealize_children = object_unrealize_children;
> +}
> +
>  static void register_types(void)
>  {
>      static TypeInfo interface_info = {
> @@ -1262,6 +1354,7 @@ static void register_types(void)
>          .name = TYPE_OBJECT,
>          .instance_size = sizeof(Object),
>          .class_base_init = object_class_base_init,
> +        .class_init = object_class_init,
>          .instance_init = object_instance_init,
>          .abstract = true,
>      };
> -- 
> 1.7.9.3
> 

  parent reply	other threads:[~2012-05-09 20:01 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-03 11:15 [Qemu-devel] [PATCH 00/25] qdev properties final installment: push, push! Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 01/25] qom: add object_class_get_parent Paolo Bonzini
2012-04-03 20:50   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 02/25] qom: add object_child_foreach Paolo Bonzini
2012-04-03 20:51   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 03/25] qom: add class_base_init Paolo Bonzini
2012-04-03 20:51   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 04/25] qom: make Object a type Paolo Bonzini
2012-04-03 12:30   ` Andreas Färber
2012-04-03 13:06     ` Paolo Bonzini
2012-04-03 20:52   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 05/25] qom: push type up to Object Paolo Bonzini
2012-04-03 12:33   ` Andreas Färber
2012-04-03 20:55   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 06/25] qdev: fix -device foo,? Paolo Bonzini
2012-04-03 20:59   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 07/25] qdev: use object_property_print in info qtree Paolo Bonzini
2012-04-03 12:28   ` Jan Kiszka
2012-04-03 13:05     ` Paolo Bonzini
2012-05-11 14:10       ` Andreas Färber
2012-05-16  7:40         ` Paolo Bonzini
2012-05-16  7:43           ` Paolo Bonzini
2012-04-03 21:06   ` Anthony Liguori
2012-05-10 20:58     ` Jan Kiszka
2012-05-11 11:28       ` Paolo Bonzini
2012-05-11 11:38         ` Andreas Färber
2012-04-03 11:15 ` [Qemu-devel] [PATCH 08/25] qdev: remove qdev_prop_set_defaults Paolo Bonzini
2012-04-03 21:09   ` Anthony Liguori
2012-04-03 21:43     ` Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 09/25] qdev: move bus properties to a separate global Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 10/25] qdev: do not propagate properties to subclasses Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 11/25] qdev: pick global properties from superclasses Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 12/25] qdev: factor setting of global properties Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 13/25] qdev: replace bus properties with superclass properties Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 14/25] qapi: add Visitor interfaces for uint*_t and int*_t Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 15/25] qdev: use int32_t container for devfn property Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 16/25] qdev: switch property accessors to fixed-width visitor interfaces Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 17/25] qdev: remove PropertyInfo range checking Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 18/25] qdev: remove qdev_prop_exists Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 19/25] qom: push state up to Object Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 20/25] qdev: generalize properties to Objects Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 21/25] qdev: move bulk of qdev-properties.c to qom/object.c Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 22/25] qom: push static properties to Object Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 23/25] qom: add realized property Paolo Bonzini
2012-04-03 12:11   ` Andreas Färber
2012-04-03 13:03     ` Paolo Bonzini
2012-04-05 12:04       ` Andreas Färber
2012-04-05 12:36         ` Paolo Bonzini
2012-04-05 13:31           ` Andreas Färber
2012-04-05 14:16             ` Paolo Bonzini
2012-04-05 15:13               ` Anthony Liguori
2012-05-09 20:01   ` Igor Mammedov [this message]
2012-05-10  7:05     ` Paolo Bonzini
2012-05-10 10:01       ` Andreas Färber
2012-05-10 12:19         ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 24/25] qdev: implement qdev_init on top of realize Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 25/25] qdev: split part of device_finalize to device_unrealize Paolo Bonzini

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=20120509200128.GA30337@thinkpad.mammed.net \
    --to=imammedo@redhat.com \
    --cc=afaerber@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=pbonzini@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 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.