qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/7] qom: add object_property_add_alias()


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [PATCH 1/7] qom: add object_property_add_alias()
Date: Thu, 22 May 2014 12:23:16 +0200

On Thu, May 22, 2014 at 12:05 AM, Paolo Bonzini <address@hidden> wrote:
> Il 21/05/2014 22:22, Stefan Hajnoczi ha scritto:
>> +void object_property_add_alias(Object *obj, const char *name,
>> +                               Object *target_obj, const char
>> *target_name,
>> +                               Error **errp)
>> +{
>> +    AliasProperty *prop;
>> +    ObjectProperty *target_prop;
>> +
>> +    target_prop = object_property_find(target_obj, target_name, errp);
>> +    if (!target_prop) {
>> +        return;
>> +    }
>> +
>> +    prop = g_malloc(sizeof(*prop));
>> +    prop->target_obj = target_obj;
>> +    prop->target_name = target_name;
>> +
>> +    object_property_add(obj, name, target_prop->type,
>> +                        property_get_alias,
>> +                        property_set_alias,
>> +                        property_release_alias,
>> +                        prop, errp);
>> +}
>
>
> ref target_obj here, and unref in property_release_alias?

No.  I originally did this but realized it is probably not a good idea.

1. If you want to alias a property on the same object instance (foo.a
-> foo.b) this would create a refcount leak (unless someone explicitly
deletes this property to bring the refcount back to 1).
2. The virtio callers already have a child reference and I suspect
other callers would too.  Therefore we don't need to do extra
refcounting.

I had an intermediate version of this patch with a flag so you could
tell object_property_add_alias() whether or not to ref the target
object.  But in the end it seems like overengineering since the
refcount case is rare or non-existent.  The refcount is a convenience
feature just for the case where you want to alias to a random object
that you don't otherwise hold a refcount on (I couldn't think of an
example).

Do you see what I mean?

Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]