Message ID | 1401967435-17751-3-git-send-email-pbonzini@redhat.com |
---|---|
State | New |
Headers | show |
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) > { >
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) {
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(+)