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. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- 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..c828ac6365 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 non is present + */ +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 0ac201de4c..956adfb050 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1964,6 +1964,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; +} + + void object_property_allow_set_link(const Object *obj, const char *name, Object *val, Error **errp) { -- 2.54.0