Daniel P. Berrangé <[email protected]> writes:

> The 'user_creatable_del' method doesn't want the 'Object *', but
> instead the "id" of the object to be deleted. While most of its
> work could be done with the "Object *" alone, purging the QemuOpts
> values needs the "id".
>
> The "id" is not recorded against an Object though, it is indirectly
> stored as a property linking the parent and child objects together.
> Add an accessor that can fetch this property name.
>
> Reviewed-by: Marc-André Lureau <[email protected]>
> Tested-by: Peter Krempa <[email protected]>
> Signed-off-by: Daniel P. Berrangé <[email protected]>
> ---
>  include/qom/object.h | 10 ++++++++++
>  qom/object.c         | 17 +++++++++++++++++
>  2 files changed, 27 insertions(+)
>
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 11f55613fc..216d2a30f6 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -1759,6 +1759,16 @@ ObjectProperty *object_property_try_add_child(Object 
> *obj, const char *name,
>  ObjectProperty *object_property_add_child(Object *obj, const char *name,
>                                            Object *child);
>  
> +/**
> + * object_property_get_child_name:
> + * @obj: the object that owns the property
> + * @child: the object referenced by the child property
> + *
> + * Return the property name against which @child is registered
> + * with @obj, or NULL if @obj is not a parent of @child.
> + */
> +char *object_property_get_child_name(Object *obj, Object *child);
> +
>  typedef enum {
>      /* Unref the link pointer when the property is deleted */
>      OBJ_PROP_LINK_STRONG = 0x1,
> diff --git a/qom/object.c b/qom/object.c
> index f79b2cf361..66bbd1488b 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -1952,6 +1952,23 @@ object_property_add_child(Object *obj, const char 
> *name,
>      return object_property_try_add_child(obj, name, child, &error_abort);
>  }
>  
> +char *object_property_get_child_name(Object *obj, Object *child)
> +{
> +    ObjectProperty *prop;
> +    GHashTableIter iter;
> +    gpointer key, value;
> +
> +    g_hash_table_iter_init(&iter, obj->properties);
> +    while (g_hash_table_iter_next(&iter, &key, &value)) {
> +        prop = value;
> +        if (object_property_is_child(prop) && prop->opaque == child) {
> +            return g_strdup(prop->name);
> +        }
> +    }
> +    return NULL;
> +}

Isn't this a slight variation of object_get_canonical_path_component()?

> +
> +
>  void object_property_allow_set_link(const Object *obj, const char *name,
>                                      Object *val, Error **errp)
>  {

Reply via email to