From: Anthony Liguori <anthony@codemonkey.ws>
To: "Andreas Färber" <afaerber@suse.de>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH qom-next 6/7] qom: Add "realized" property
Date: Fri, 08 Jun 2012 09:26:48 +0800 [thread overview]
Message-ID: <4FD154D8.3000105@codemonkey.ws> (raw)
In-Reply-To: <1339097465-22977-7-git-send-email-afaerber@suse.de>
On 06/08/2012 03:31 AM, Andreas Färber wrote:
> From: Paolo Bonzini<pbonzini@redhat.com>
>
> 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.
>
> 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>
> Signed-off-by: Andreas Färber<afaerber@suse.de>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Regards,
Anthony Liguori
> ---
> include/qemu/object.h | 20 +++++++++++
> qom/object.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 109 insertions(+), 0 deletions(-)
>
> diff --git a/include/qemu/object.h b/include/qemu/object.h
> index 4ea1187..05ea711 100644
> --- a/include/qemu/object.h
> +++ b/include/qemu/object.h
> @@ -246,6 +246,10 @@ struct ObjectClass
> /*< public>*/
> Property *props;
> const char *(*get_id)(Object *);
> + 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 {
> @@ -464,6 +468,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 a639348..40bc23a 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -265,6 +265,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_INITIALIZED&& klass->unrealize) {
> + klass->unrealize(obj);
> + }
> + obj->state = OBJECT_STATE_INITIALIZED;
> +}
> +
> +static int object_unrealize_one(Object *obj, void *unused)
> +{
> + object_unrealize(obj);
> + return 0;
> +}
> +
> +void object_unrealize_children(Object *obj)
> +{
> + object_child_foreach(obj, object_unrealize_one, 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_one(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_one, 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;
> @@ -373,6 +454,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);
> }
> @@ -1277,6 +1360,9 @@ static void object_instance_init(Object *obj)
>
> object_property_add_str(obj, "type", qdev_get_type, NULL, NULL);
>
> + object_property_add(obj, "realized", "bool", object_get_realized,
> + object_set_realized, NULL, NULL, NULL);
> +
> class = object_get_class(obj);
> do {
> for (prop = OBJECT_CLASS(class)->props; prop&& prop->name; prop++) {
> @@ -1289,6 +1375,8 @@ static void object_instance_init(Object *obj)
> static void object_class_init(ObjectClass *klass, void *class_data)
> {
> klass->get_id = object_instance_get_id;
> + klass->realize_children = object_realize_children;
> + klass->unrealize_children = object_unrealize_children;
> }
>
> static void register_types(void)
> @@ -1303,6 +1391,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,
> .class_init = object_class_init,
> .abstract = true,
next prev parent reply other threads:[~2012-06-08 1:27 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-07 19:30 [Qemu-devel] [PATCH qom-next 0/7] QOM realize, revised Andreas Färber
2012-06-07 19:30 ` [Qemu-devel] [PATCH qom-next 1/7] qdev: Push state up to Object Andreas Färber
2012-06-08 1:19 ` Anthony Liguori
2012-06-10 15:49 ` Paolo Bonzini
2012-06-10 17:35 ` Anthony Liguori
2012-06-10 17:38 ` Andreas Färber
2012-06-11 8:25 ` Kevin Wolf
2012-06-11 13:21 ` Anthony Liguori
2012-06-11 14:38 ` Kevin Wolf
2012-06-11 21:31 ` Andreas Färber
2012-06-11 21:43 ` Andreas Färber
2012-06-11 21:48 ` Anthony Liguori
2012-06-12 0:14 ` Andreas Färber
2012-06-07 19:31 ` [Qemu-devel] [PATCH qom-next 2/7] qom: Add get_id Andreas Färber
2012-06-08 1:22 ` Anthony Liguori
2012-06-08 7:11 ` Andreas Färber
2012-06-08 7:44 ` Anthony Liguori
2012-06-08 8:17 ` Andreas Färber
2012-06-08 10:59 ` [Qemu-devel] [libvirt] " Daniel P. Berrange
2012-06-08 11:58 ` [Qemu-devel] " Eric Blake
2012-06-07 19:31 ` [Qemu-devel] [PATCH qom-next 3/7] qdev: Generalize properties to Objects Andreas Färber
2012-06-08 1:23 ` Anthony Liguori
2012-06-07 19:31 ` [Qemu-devel] [PATCH qom-next 4/7] qdev: Move bulk of qdev-properties.c to qom/object-properties.c Andreas Färber
2012-06-07 23:23 ` Paolo Bonzini
2012-06-08 1:26 ` Anthony Liguori
2012-06-07 19:31 ` [Qemu-devel] [PATCH qom-next 5/7] qom: Push static properties to Object Andreas Färber
2012-06-08 1:26 ` Anthony Liguori
2012-06-07 19:31 ` [Qemu-devel] [PATCH qom-next 6/7] qom: Add "realized" property Andreas Färber
2012-06-08 1:26 ` Anthony Liguori [this message]
2012-06-07 19:31 ` [Qemu-devel] [PATCH qom-next 7/7] qom: Add QERR_PROPERTY_SET_AFTER_REALIZE Andreas Färber
2012-06-07 19:56 ` Andreas Färber
2012-06-07 23:22 ` [Qemu-devel] [PATCH qom-next 0/7] QOM realize, revised 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=4FD154D8.3000105@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=afaerber@suse.de \
--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 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).