All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC PATCH 0/2] qom: custom link properties
@ 2014-06-05 11:23 Paolo Bonzini
  2014-06-05 11:23 ` [Qemu-devel] [PATCH 1/2] qom: add a generic mechanism to resolve paths Paolo Bonzini
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Paolo Bonzini @ 2014-06-05 11:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.crosthwaite, mtosatti, afaerber

Both Marcelo's rtc patches and Peter's MemoryRegion patches showed
the interest in having link properties with a custom representation
and/or a different way to store the property.

Such properties would still be link<>s for the outside world, but
the internal implementation in QEMU would be different.

This series proposes a way to introduce such custom link properties,
using a new property callback "resolve" that generalizes the if/else
ladder in object_resolve_path_component.

The second patch shows how the mechanism could be used to add a simple
immutable "alias" link.  Example:

    $ ./qom-list -s /tmp/m1 /machine
    @rtc/                              # this is an alias
    i440fx/
    fw_cfg/
    icc-bridge/
    unattached/
    peripheral/
    peripheral-anon/
    ...

    $ ./qom-get -s /tmp/m1 /machine.rtc
    /machine/unattached/device[8]      # later could become /machine/piix3/rtc
                                       # or /machine/ich9/rtc and so on

    $ ./qom-get -s /tmp/m1 /machine/rtc.date
    tm_sec: 58
    tm_hour: 11
    tm_mday: 5
    tm_year: 114
    tm_mon: 5
    tm_min: 16

Paolo

Paolo Bonzini (2):
  qom: add a generic mechanism to resolve paths
  qom: add object_property_add_alias

 include/qom/object.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 qom/object.c         | 68 +++++++++++++++++++++++++++++++++--------------
 2 files changed, 123 insertions(+), 19 deletions(-)

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 1/2] qom: add a generic mechanism to resolve paths
  2014-06-05 11:23 [Qemu-devel] [RFC PATCH 0/2] qom: custom link properties Paolo Bonzini
@ 2014-06-05 11:23 ` Paolo Bonzini
  2014-06-06  5:54   ` Peter Crosthwaite
  2014-06-05 11:23 ` [Qemu-devel] [PATCH 2/2] qom: add object_property_add_alias Paolo Bonzini
  2014-06-05 19:14 ` [Qemu-devel] [RFC PATCH 0/2] qom: custom link properties Marcelo Tosatti
  2 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2014-06-05 11:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.crosthwaite, mtosatti, afaerber

It may be desirable to have custom link<> properties that do more
than just store an object.  Even the addition of a "check"
function is not enough if setting the link has side effects
or if a non-standard reference counting is preferrable.

Avoid the assumption that the opaque field of a link<> is a
LinkProperty struct, by adding a generic "resolve" callback
to ObjectProperty.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/qom/object.h | 49 ++++++++++++++++++++++++++++++++++++++++++++++
 qom/object.c         | 55 ++++++++++++++++++++++++++++++++++------------------
 2 files changed, 85 insertions(+), 19 deletions(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index a641dcd..f8ab845 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -304,6 +304,23 @@ typedef void (ObjectPropertyAccessor)(Object *obj,
                                       Error **errp);
 
 /**
+ * ObjectPropertyResolve:
+ * @obj: the object that owns the property
+ * @opaque: the opaque registered with the property
+ * @part: the name of the property
+ *
+ * If @path is the path that led to @obj, the function should
+ * return the Object corresponding to "@path/@part".  If #NULL
+ * is returned, "@path/@part" is not a valid object path.
+ *
+ * The returned object can also be used as a starting point
+ * to resolve a relative path starting with "@part".
+ */
+typedef Object *(ObjectPropertyResolve)(Object *obj,
+                                        void *opaque,
+                                        const char *part);
+
+/**
  * ObjectPropertyRelease:
  * @obj: the object that owns the property
  * @name: the name of the property
@@ -321,6 +338,7 @@ typedef struct ObjectProperty
     gchar *type;
     ObjectPropertyAccessor *get;
     ObjectPropertyAccessor *set;
+    ObjectPropertyResolve *resolve;
     ObjectPropertyRelease *release;
     void *opaque;
 
@@ -769,6 +787,37 @@ void object_ref(Object *obj);
 void object_unref(Object *obj);
 
 /**
+ * object_property_add_full:
+ * @obj: the object to add a property to
+ * @name: the name of the property.  This can contain any character except for
+ *  a forward slash.  In general, you should use hyphens '-' instead of
+ *  underscores '_' when naming properties.
+ * @type: the type name of the property.  This namespace is pretty loosely
+ *   defined.  Sub namespaces are constructed by using a prefix and then
+ *   to angle brackets.  For instance, the type 'virtio-net-pci' in the
+ *   'link' namespace would be 'link<virtio-net-pci>'.
+ * @get: The getter to be called to read a property.  If this is NULL, then
+ *   the property cannot be read.
+ * @set: the setter to be called to write a property.  If this is NULL,
+ *   then the property cannot be written.
+ * @resolve: called when the property name is used as part of an object
+ *   path.  This is meant for cases when you want to have custom link
+ *   properties.  If it is NULL, the property name cannot be used as part
+ *   of a valid object path.
+ * @release: called when the property is removed from the object.  This is
+ *   meant to allow a property to free its opaque upon object
+ *   destruction.  This may be NULL.
+ * @opaque: an opaque pointer to pass to the callbacks for the property
+ * @errp: returns an error if this function fails
+ */
+void object_property_add_full(Object *obj, const char *name, const char *type,
+                         ObjectPropertyAccessor *get,
+                         ObjectPropertyAccessor *set,
+                         ObjectPropertyResolve *resolve,
+                         ObjectPropertyRelease *release,
+                         void *opaque, Error **errp);
+
+/**
  * object_property_add:
  * @obj: the object to add a property to
  * @name: the name of the property.  This can contain any character except for
diff --git a/qom/object.c b/qom/object.c
index e42b254..fcdd0da 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -355,11 +355,6 @@ static inline bool object_property_is_child(ObjectProperty *prop)
     return strstart(prop->type, "child<", NULL);
 }
 
-static inline bool object_property_is_link(ObjectProperty *prop)
-{
-    return strstart(prop->type, "link<", NULL);
-}
-
 static void object_property_del_all(Object *obj)
 {
     while (!QTAILQ_EMPTY(&obj->properties)) {
@@ -727,9 +722,10 @@ void object_unref(Object *obj)
     }
 }
 
-void object_property_add(Object *obj, const char *name, const char *type,
+void object_property_add_full(Object *obj, const char *name, const char *type,
                          ObjectPropertyAccessor *get,
                          ObjectPropertyAccessor *set,
+                         ObjectPropertyResolve *resolve,
                          ObjectPropertyRelease *release,
                          void *opaque, Error **errp)
 {
@@ -751,12 +747,23 @@ void object_property_add(Object *obj, const char *name, const char *type,
 
     prop->get = get;
     prop->set = set;
+    prop->resolve = resolve;
     prop->release = release;
     prop->opaque = opaque;
 
     QTAILQ_INSERT_TAIL(&obj->properties, prop, node);
 }
 
+void object_property_add(Object *obj, const char *name, const char *type,
+                         ObjectPropertyAccessor *get,
+                         ObjectPropertyAccessor *set,
+                         ObjectPropertyRelease *release,
+                         void *opaque, Error **errp)
+{
+    object_property_add_full(obj, name, type, get, set, NULL, release,
+                             opaque, errp);
+}
+
 ObjectProperty *object_property_find(Object *obj, const char *name,
                                      Error **errp)
 {
@@ -993,6 +1000,11 @@ static void object_get_child_property(Object *obj, Visitor *v, void *opaque,
     g_free(path);
 }
 
+static Object *object_resolve_child_property(Object *parent, void *opaque, const gchar *part)
+{
+    return opaque;
+}
+
 static void object_finalize_child_property(Object *obj, const char *name,
                                            void *opaque)
 {
@@ -1009,8 +1021,9 @@ void object_property_add_child(Object *obj, const char *name,
 
     type = g_strdup_printf("child<%s>", object_get_typename(OBJECT(child)));
 
-    object_property_add(obj, name, type, object_get_child_property, NULL,
-                        object_finalize_child_property, child, &local_err);
+    object_property_add_full(obj, name, type, object_get_child_property, NULL,
+                             object_resolve_child_property,
+                             object_finalize_child_property, child, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         goto out;
@@ -1128,6 +1141,12 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
     }
 }
 
+static Object *object_resolve_link_property(Object *parent, void *opaque, const gchar *part)
+{
+    LinkProperty *lprop = opaque;
+    return *lprop->child;
+}
+
 static void object_release_link_property(Object *obj, const char *name,
                                          void *opaque)
 {
@@ -1156,12 +1175,13 @@ void object_property_add_link(Object *obj, const char *name,
 
     full_type = g_strdup_printf("link<%s>", type);
 
-    object_property_add(obj, name, full_type,
-                        object_get_link_property,
-                        check ? object_set_link_property : NULL,
-                        object_release_link_property,
-                        prop,
-                        &local_err);
+    object_property_add_full(obj, name, full_type,
+                             object_get_link_property,
+                             check ? object_set_link_property : NULL,
+                             object_resolve_link_property,
+                             object_release_link_property,
+                             prop,
+                             &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         g_free(prop);
@@ -1225,11 +1245,8 @@ Object *object_resolve_path_component(Object *parent, const gchar *part)
         return NULL;
     }
 
-    if (object_property_is_link(prop)) {
-        LinkProperty *lprop = prop->opaque;
-        return *lprop->child;
-    } else if (object_property_is_child(prop)) {
-        return prop->opaque;
+    if (prop->resolve) {
+        return prop->resolve(parent, prop->opaque, part);
     } else {
         return NULL;
     }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 2/2] qom: add object_property_add_alias
  2014-06-05 11:23 [Qemu-devel] [RFC PATCH 0/2] qom: custom link properties Paolo Bonzini
  2014-06-05 11:23 ` [Qemu-devel] [PATCH 1/2] qom: add a generic mechanism to resolve paths Paolo Bonzini
@ 2014-06-05 11:23 ` Paolo Bonzini
  2014-06-10 18:31   ` Paolo Bonzini
  2014-06-05 19:14 ` [Qemu-devel] [RFC PATCH 0/2] qom: custom link properties Marcelo Tosatti
  2 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2014-06-05 11:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.crosthwaite, mtosatti, afaerber

Similar to object_property_add_link, alias properties provide an
alternative, non-canonical path to an object.  In fact, external
observers cannot distinguish alias properties from other links.

Aliases differ from links in that they are immutable and typically
managed by the target of the alias  in order to add a link to itself
at a well-known location.  For example, a real-time clock device might
add a link to itself at "/machine/rtc".  Such well-known locations can
then expose a standard set of properties that can be accessed via the
"qom-get" and "qom-set" commands.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/qom/object.h | 25 +++++++++++++++++++++++++
 qom/object.c         | 13 +++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index f8ab845..fc80078 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1116,6 +1116,31 @@ Object *object_resolve_path_component(Object *parent, const gchar *part);
 void object_property_add_child(Object *obj, const char *name,
                                Object *child, Error **errp);
 
+/**
+ * object_property_add_alias:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @dest: the destination of the alias
+ * @errp: if an error occurs, a pointer to an area to store the area
+ *
+ * Similar to @object_property_add_link, alias properties provide an
+ * alternative, non-canonical path to an object.  In fact, external
+ * observers cannot distinguish alias properties from other links.
+ *
+ * Aliases differ from links in that they are immutable and typically
+ * managed by the target of the alias (@dest) in order to add a link to
+ * itself at a well-known location.  For example, a real-time clock device
+ * might add a link to itself at "/machine/rtc".  Such well-known locations
+ * can then expose a standard set of properties that can be accessed via
+ * the "qom-get" and "qom-set" commands.
+ *
+ * @object_property_add_alias does not add a reference to @dest.
+ * It is @dest's responsibility to remove the alias in its
+ * @instance_finalize function.
+ */
+void object_property_add_alias(Object *obj, const char *name,
+                               Object *dest, Error **errp);
+
 typedef enum {
     /* Unref the link pointer when the property is deleted */
     OBJ_PROP_LINK_UNREF_ON_RELEASE = 0x1,
diff --git a/qom/object.c b/qom/object.c
index fcdd0da..46d60c8 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1036,6 +1036,19 @@ out:
     g_free(type);
 }
 
+void object_property_add_alias(Object *obj, const char *name,
+                               Object *dest, Error **errp)
+{
+    gchar *type;
+
+    type = g_strdup_printf("link<%s>", object_get_typename(OBJECT(dest)));
+
+    object_property_add_full(obj, name, type, object_get_child_property, NULL,
+                             object_resolve_child_property,
+                             NULL, dest, errp);
+    g_free(type);
+}
+
 void object_property_allow_set_link(Object *obj, const char *name,
                                     Object *val, Error **errp)
 {
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [RFC PATCH 0/2] qom: custom link properties
  2014-06-05 11:23 [Qemu-devel] [RFC PATCH 0/2] qom: custom link properties Paolo Bonzini
  2014-06-05 11:23 ` [Qemu-devel] [PATCH 1/2] qom: add a generic mechanism to resolve paths Paolo Bonzini
  2014-06-05 11:23 ` [Qemu-devel] [PATCH 2/2] qom: add object_property_add_alias Paolo Bonzini
@ 2014-06-05 19:14 ` Marcelo Tosatti
  2 siblings, 0 replies; 6+ messages in thread
From: Marcelo Tosatti @ 2014-06-05 19:14 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: peter.crosthwaite, qemu-devel, afaerber

On Thu, Jun 05, 2014 at 01:23:53PM +0200, Paolo Bonzini wrote:
> Both Marcelo's rtc patches and Peter's MemoryRegion patches showed
> the interest in having link properties with a custom representation
> and/or a different way to store the property.
> 
> Such properties would still be link<>s for the outside world, but
> the internal implementation in QEMU would be different.
> 
> This series proposes a way to introduce such custom link properties,
> using a new property callback "resolve" that generalizes the if/else
> ladder in object_resolve_path_component.
> 
> The second patch shows how the mechanism could be used to add a simple
> immutable "alias" link.  Example:
> 
>     $ ./qom-list -s /tmp/m1 /machine
>     @rtc/                              # this is an alias
>     i440fx/
>     fw_cfg/
>     icc-bridge/
>     unattached/
>     peripheral/
>     peripheral-anon/
>     ...
> 
>     $ ./qom-get -s /tmp/m1 /machine.rtc
>     /machine/unattached/device[8]      # later could become /machine/piix3/rtc
>                                        # or /machine/ich9/rtc and so on
> 
>     $ ./qom-get -s /tmp/m1 /machine/rtc.date
>     tm_sec: 58
>     tm_hour: 11
>     tm_mday: 5
>     tm_year: 114
>     tm_mon: 5
>     tm_min: 16
> 
> Paolo
> 
> Paolo Bonzini (2):
>   qom: add a generic mechanism to resolve paths
>   qom: add object_property_add_alias
> 
>  include/qom/object.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  qom/object.c         | 68 +++++++++++++++++++++++++++++++++--------------
>  2 files changed, 123 insertions(+), 19 deletions(-)
> 
> -- 
> 1.8.3.1

Thats nicer, thanks. 

Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] qom: add a generic mechanism to resolve paths
  2014-06-05 11:23 ` [Qemu-devel] [PATCH 1/2] qom: add a generic mechanism to resolve paths Paolo Bonzini
@ 2014-06-06  5:54   ` Peter Crosthwaite
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Crosthwaite @ 2014-06-06  5:54 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Marcelo Tosatti, qemu-devel@nongnu.org Developers, Andreas Färber

On Thu, Jun 5, 2014 at 9:23 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> It may be desirable to have custom link<> properties that do more
> than just store an object.  Even the addition of a "check"
> function is not enough if setting the link has side effects
> or if a non-standard reference counting is preferrable.
>
> Avoid the assumption that the opaque field of a link<> is a
> LinkProperty struct, by adding a generic "resolve" callback
> to ObjectProperty.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  include/qom/object.h | 49 ++++++++++++++++++++++++++++++++++++++++++++++
>  qom/object.c         | 55 ++++++++++++++++++++++++++++++++++------------------
>  2 files changed, 85 insertions(+), 19 deletions(-)
>
> diff --git a/include/qom/object.h b/include/qom/object.h
> index a641dcd..f8ab845 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -304,6 +304,23 @@ typedef void (ObjectPropertyAccessor)(Object *obj,
>                                        Error **errp);
>
>  /**
> + * ObjectPropertyResolve:
> + * @obj: the object that owns the property
> + * @opaque: the opaque registered with the property
> + * @part: the name of the property
> + *
> + * If @path is the path that led to @obj, the function should
> + * return the Object corresponding to "@path/@part".  If #NULL
> + * is returned, "@path/@part" is not a valid object path.
> + *
> + * The returned object can also be used as a starting point
> + * to resolve a relative path starting with "@part".
> + */
> +typedef Object *(ObjectPropertyResolve)(Object *obj,
> +                                        void *opaque,
> +                                        const char *part);
> +
> +/**
>   * ObjectPropertyRelease:
>   * @obj: the object that owns the property
>   * @name: the name of the property
> @@ -321,6 +338,7 @@ typedef struct ObjectProperty
>      gchar *type;
>      ObjectPropertyAccessor *get;
>      ObjectPropertyAccessor *set;
> +    ObjectPropertyResolve *resolve;
>      ObjectPropertyRelease *release;
>      void *opaque;
>
> @@ -769,6 +787,37 @@ void object_ref(Object *obj);
>  void object_unref(Object *obj);
>
>  /**
> + * object_property_add_full:
> + * @obj: the object to add a property to
> + * @name: the name of the property.  This can contain any character except for
> + *  a forward slash.  In general, you should use hyphens '-' instead of
> + *  underscores '_' when naming properties.
> + * @type: the type name of the property.  This namespace is pretty loosely
> + *   defined.  Sub namespaces are constructed by using a prefix and then
> + *   to angle brackets.  For instance, the type 'virtio-net-pci' in the
> + *   'link' namespace would be 'link<virtio-net-pci>'.
> + * @get: The getter to be called to read a property.  If this is NULL, then
> + *   the property cannot be read.
> + * @set: the setter to be called to write a property.  If this is NULL,
> + *   then the property cannot be written.
> + * @resolve: called when the property name is used as part of an object
> + *   path.  This is meant for cases when you want to have custom link
> + *   properties.  If it is NULL, the property name cannot be used as part
> + *   of a valid object path.
> + * @release: called when the property is removed from the object.  This is
> + *   meant to allow a property to free its opaque upon object
> + *   destruction.  This may be NULL.
> + * @opaque: an opaque pointer to pass to the callbacks for the property
> + * @errp: returns an error if this function fails
> + */
> +void object_property_add_full(Object *obj, const char *name, const char *type,
> +                         ObjectPropertyAccessor *get,
> +                         ObjectPropertyAccessor *set,
> +                         ObjectPropertyResolve *resolve,
> +                         ObjectPropertyRelease *release,
> +                         void *opaque, Error **errp);
> +
> +/**
>   * object_property_add:
>   * @obj: the object to add a property to
>   * @name: the name of the property.  This can contain any character except for
> diff --git a/qom/object.c b/qom/object.c
> index e42b254..fcdd0da 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -355,11 +355,6 @@ static inline bool object_property_is_child(ObjectProperty *prop)
>      return strstart(prop->type, "child<", NULL);
>  }
>
> -static inline bool object_property_is_link(ObjectProperty *prop)
> -{
> -    return strstart(prop->type, "link<", NULL);
> -}
> -
>  static void object_property_del_all(Object *obj)
>  {
>      while (!QTAILQ_EMPTY(&obj->properties)) {
> @@ -727,9 +722,10 @@ void object_unref(Object *obj)
>      }
>  }
>
> -void object_property_add(Object *obj, const char *name, const char *type,
> +void object_property_add_full(Object *obj, const char *name, const char *type,
>                           ObjectPropertyAccessor *get,
>                           ObjectPropertyAccessor *set,
> +                         ObjectPropertyResolve *resolve,
>                           ObjectPropertyRelease *release,
>                           void *opaque, Error **errp)
>  {
> @@ -751,12 +747,23 @@ void object_property_add(Object *obj, const char *name, const char *type,
>
>      prop->get = get;
>      prop->set = set;
> +    prop->resolve = resolve;
>      prop->release = release;
>      prop->opaque = opaque;
>
>      QTAILQ_INSERT_TAIL(&obj->properties, prop, node);
>  }
>
> +void object_property_add(Object *obj, const char *name, const char *type,
> +                         ObjectPropertyAccessor *get,
> +                         ObjectPropertyAccessor *set,
> +                         ObjectPropertyRelease *release,
> +                         void *opaque, Error **errp)
> +{
> +    object_property_add_full(obj, name, type, get, set, NULL, release,
> +                             opaque, errp);
> +}
> +
>  ObjectProperty *object_property_find(Object *obj, const char *name,
>                                       Error **errp)
>  {
> @@ -993,6 +1000,11 @@ static void object_get_child_property(Object *obj, Visitor *v, void *opaque,
>      g_free(path);
>  }
>
> +static Object *object_resolve_child_property(Object *parent, void *opaque, const gchar *part)
> +{
> +    return opaque;
> +}
> +
>  static void object_finalize_child_property(Object *obj, const char *name,
>                                             void *opaque)
>  {
> @@ -1009,8 +1021,9 @@ void object_property_add_child(Object *obj, const char *name,
>
>      type = g_strdup_printf("child<%s>", object_get_typename(OBJECT(child)));
>
> -    object_property_add(obj, name, type, object_get_child_property, NULL,
> -                        object_finalize_child_property, child, &local_err);
> +    object_property_add_full(obj, name, type, object_get_child_property, NULL,
> +                             object_resolve_child_property,
> +                             object_finalize_child_property, child, &local_err);
>      if (local_err) {
>          error_propagate(errp, local_err);
>          goto out;
> @@ -1128,6 +1141,12 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
>      }
>  }
>
> +static Object *object_resolve_link_property(Object *parent, void *opaque, const gchar *part)

80 Char issue here and one more below.

Otherwise,

Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

Respinning my Memory work based on this. Thanks for the help.

Regards,
Peter

> +{
> +    LinkProperty *lprop = opaque;
> +    return *lprop->child;
> +}
> +
>  static void object_release_link_property(Object *obj, const char *name,
>                                           void *opaque)
>  {
> @@ -1156,12 +1175,13 @@ void object_property_add_link(Object *obj, const char *name,
>
>      full_type = g_strdup_printf("link<%s>", type);
>
> -    object_property_add(obj, name, full_type,
> -                        object_get_link_property,
> -                        check ? object_set_link_property : NULL,
> -                        object_release_link_property,
> -                        prop,
> -                        &local_err);
> +    object_property_add_full(obj, name, full_type,
> +                             object_get_link_property,
> +                             check ? object_set_link_property : NULL,
> +                             object_resolve_link_property,
> +                             object_release_link_property,
> +                             prop,
> +                             &local_err);
>      if (local_err) {
>          error_propagate(errp, local_err);
>          g_free(prop);
> @@ -1225,11 +1245,8 @@ Object *object_resolve_path_component(Object *parent, const gchar *part)
>          return NULL;
>      }
>
> -    if (object_property_is_link(prop)) {
> -        LinkProperty *lprop = prop->opaque;
> -        return *lprop->child;
> -    } else if (object_property_is_child(prop)) {
> -        return prop->opaque;
> +    if (prop->resolve) {
> +        return prop->resolve(parent, prop->opaque, part);
>      } else {
>          return NULL;
>      }
> --
> 1.8.3.1
>
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] qom: add object_property_add_alias
  2014-06-05 11:23 ` [Qemu-devel] [PATCH 2/2] qom: add object_property_add_alias Paolo Bonzini
@ 2014-06-10 18:31   ` Paolo Bonzini
  0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2014-06-10 18:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.crosthwaite, mtosatti, afaerber

Il 05/06/2014 13:23, Paolo Bonzini ha scritto:
> Similar to object_property_add_link, alias properties provide an
> alternative, non-canonical path to an object.  In fact, external
> observers cannot distinguish alias properties from other links.
>
> Aliases differ from links in that they are immutable and typically
> managed by the target of the alias  in order to add a link to itself
> at a well-known location.  For example, a real-time clock device might
> add a link to itself at "/machine/rtc".  Such well-known locations can
> then expose a standard set of properties that can be accessed via the
> "qom-get" and "qom-set" commands.

Heh, another object_property_add_alias is in flight (from Stefan, for 
dataplane).  Luckily it is possible to share the more generic alias 
property implementation for object aliases too, with just an extra NULL 
argument before the Error**.  I'll post the patches as soon as Andreas 
comes back.

Paolo

> +void object_property_add_alias(Object *obj, const char *name,
> +                               Object *dest, Error **errp);
> +
>  typedef enum {
>      /* Unref the link pointer when the property is deleted */
>      OBJ_PROP_LINK_UNREF_ON_RELEASE = 0x1,
> diff --git a/qom/object.c b/qom/object.c
> index fcdd0da..46d60c8 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -1036,6 +1036,19 @@ out:
>      g_free(type);
>  }
>
> +void object_property_add_alias(Object *obj, const char *name,
> +                               Object *dest, Error **errp)
> +{
> +    gchar *type;
> +
> +    type = g_strdup_printf("link<%s>", object_get_typename(OBJECT(dest)));
> +
> +    object_property_add_full(obj, name, type, object_get_child_property, NULL,
> +                             object_resolve_child_property,
> +                             NULL, dest, errp);
> +    g_free(type);
> +}
> +
>  void object_property_allow_set_link(Object *obj, const char *name,
>                                      Object *val, Error **errp)
>  {
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-06-10 18:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-05 11:23 [Qemu-devel] [RFC PATCH 0/2] qom: custom link properties Paolo Bonzini
2014-06-05 11:23 ` [Qemu-devel] [PATCH 1/2] qom: add a generic mechanism to resolve paths Paolo Bonzini
2014-06-06  5:54   ` Peter Crosthwaite
2014-06-05 11:23 ` [Qemu-devel] [PATCH 2/2] qom: add object_property_add_alias Paolo Bonzini
2014-06-10 18:31   ` Paolo Bonzini
2014-06-05 19:14 ` [Qemu-devel] [RFC PATCH 0/2] qom: custom link properties Marcelo Tosatti

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.