qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	fred.konrad@greensocs.com
Subject: Re: [Qemu-devel] [RFC 1/5] qdev: add child alias properties
Date: Wed, 14 May 2014 15:27:32 +0200	[thread overview]
Message-ID: <53736F44.5040400@suse.de> (raw)
In-Reply-To: <1395244138-8834-2-git-send-email-stefanha@redhat.com>

Am 19.03.2014 16:48, schrieb Stefan Hajnoczi:
> Child alias properties allow a parent object to expose child object
> properties.  This makes it possible for a parent object to forward all
> or a subset of a child's properties.
> 
> Currently we achieve similar behavior by duplicating property
> definitions and copying the fields around.  It turns out virtio has
> several double-frees since we didn't get the memory management right.
> 
> Using child alias properties it will be much easier for a parent object
> to set a child's properties without fragile memory management issues
> since the actual field only exists once in the child object.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  hw/core/qdev-properties.c    | 28 ++++++++++++++++++++++++++++
>  include/hw/qdev-properties.h | 28 ++++++++++++++++++++++++++++
>  2 files changed, 56 insertions(+)
> 
> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
> index 77d0c66..e62a4fd 100644
> --- a/hw/core/qdev-properties.c
> +++ b/hw/core/qdev-properties.c
> @@ -1002,3 +1002,31 @@ PropertyInfo qdev_prop_size = {
>      .get = get_size,
>      .set = set_size,
>  };
> +
> +/* --- alias that forwards to a child object's property --- */
> +
> +static void get_child_alias(Object *obj, Visitor *v, void *opaque,
> +                            const char *name, Error **errp)
> +{
> +    DeviceState *dev = DEVICE(obj);
> +    Property *prop = opaque;
> +    Object *child = OBJECT(qdev_get_prop_ptr(dev, prop));
> +
> +    object_property_get(child, v, name, errp);
> +}
> +
> +static void set_child_alias(Object *obj, Visitor *v, void *opaque,
> +                            const char *name, Error **errp)
> +{
> +    DeviceState *dev = DEVICE(obj);
> +    Property *prop = opaque;
> +    Object *child = OBJECT(qdev_get_prop_ptr(dev, prop));
> +
> +    object_property_set(child, v, name, errp);
> +}
> +
> +PropertyInfo qdev_prop_child_alias = {
> +    .name  = "ChildAlias",

Won't this turn into the QMP-exposed type of the property? That would be
wrong then, requiring per-type alias property types. They could be
macro-automated of course, if we need them.

Paolo had cleaned up type names to match QAPI schema for 2.0, CC'ing.

Regards,
Andreas

> +    .get = get_child_alias,
> +    .set = set_child_alias,
> +};
> diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
> index 3c000ee..5ab1cac 100644
> --- a/include/hw/qdev-properties.h
> +++ b/include/hw/qdev-properties.h
> @@ -13,6 +13,7 @@ extern PropertyInfo qdev_prop_uint32;
>  extern PropertyInfo qdev_prop_int32;
>  extern PropertyInfo qdev_prop_uint64;
>  extern PropertyInfo qdev_prop_size;
> +extern PropertyInfo qdev_prop_child_alias;
>  extern PropertyInfo qdev_prop_string;
>  extern PropertyInfo qdev_prop_chr;
>  extern PropertyInfo qdev_prop_ptr;
> @@ -61,6 +62,33 @@ extern PropertyInfo qdev_prop_arraylen;
>          .defval    = (bool)_defval,                              \
>          }
>  
> +/**
> + * DEFINE_PROP_CHILD_ALIAS:
> + * @_name: property name
> + * @_state: name of the device state structure type
> + * @_field: name of field in @_state, must be Object subclass
> + *
> + * Define device properties that alias a child object's property.  For example,
> + * use the following to forward the 'baz' property where Foo embeds a Bar
> + * object:
> + *
> + *   typedef struct {
> + *       Object parent_obj;
> + *
> + *       Bar bar_obj;
> + *   } Foo;
> + *
> + *   DEFINE_PROP_CHILD_ALIAS("baz", Foo, bar_obj)
> + *
> + * Any access to Foo's 'baz' property actually accesses bar_obj's 'baz'
> + * property.
> + */
> +#define DEFINE_PROP_CHILD_ALIAS(_name, _state, _field) {         \
> +        .name      = (_name),                                    \
> +        .info      = &(qdev_prop_child_alias),                   \
> +        .offset    = offsetof(_state, _field),                   \
> +        }
> +
>  #define PROP_ARRAY_LEN_PREFIX "len-"
>  
>  /**

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

  reply	other threads:[~2014-05-14 13:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-19 15:48 [Qemu-devel] [RFC 0/5] virtio: use alias properties in transport devices Stefan Hajnoczi
2014-03-19 15:48 ` [Qemu-devel] [RFC 1/5] qdev: add child alias properties Stefan Hajnoczi
2014-05-14 13:27   ` Andreas Färber [this message]
2014-05-14 13:31     ` Paolo Bonzini
2014-05-14 14:13   ` Peter Crosthwaite
2014-05-14 14:17     ` Andreas Färber
2014-05-14 14:26       ` Peter Crosthwaite
2014-03-19 15:48 ` [Qemu-devel] [RFC 2/5] virtio: add child alias properties for virtio-blk Stefan Hajnoczi
2014-05-14 14:04   ` Peter Crosthwaite
2014-05-14 14:33     ` Stefan Hajnoczi
2014-05-14 14:38       ` Peter Crosthwaite
2014-03-19 15:48 ` [Qemu-devel] [RFC 3/5] virtio: use child aliases for virtio-blk transport properties Stefan Hajnoczi
2014-03-19 15:48 ` [Qemu-devel] [RFC 4/5] virtio-blk: drop virtio_blk_set_conf() Stefan Hajnoczi
2014-03-19 15:48 ` [Qemu-devel] [RFC 5/5] virtio: fix virtio-blk child refcount in transports Stefan Hajnoczi
2014-05-14 13:21 ` [Qemu-devel] [RFC 0/5] virtio: use alias properties in transport devices Stefan Hajnoczi
2014-05-16 15:08 ` Frederic Konrad
2014-05-19 14:21   ` Stefan Hajnoczi

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=53736F44.5040400@suse.de \
    --to=afaerber@suse.de \
    --cc=fred.konrad@greensocs.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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 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).