Patchwork [02/16] qom: store object with correct type in interface links

login
register
mail settings
Submitter Paolo Bonzini
Date Feb. 2, 2012, 4:45 p.m.
Message ID <1328201142-26145-3-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/139155/
State New
Headers show

Comments

Paolo Bonzini - Feb. 2, 2012, 4:45 p.m.
When a link property's type is an interface, the code expects the
implementation object (not the parent object) to be stored in the
variable.  The parent object does not contain the right vtable.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qom/object.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
Anthony Liguori - Feb. 2, 2012, 5:05 p.m.
On 02/02/2012 10:45 AM, Paolo Bonzini wrote:
> When a link property's type is an interface, the code expects the
> implementation object (not the parent object) to be stored in the
> variable.  The parent object does not contain the right vtable.
>
> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>
> ---
>   qom/object.c |    3 ++-
>   1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/qom/object.c b/qom/object.c
> index cd517f6..de6484d 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -749,7 +749,8 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
>               target_type = g_strdup(&type[5]);
>               target_type[strlen(target_type) - 2] = 0;
>
> -            if (object_dynamic_cast(target, target_type)) {
> +            target = object_dynamic_cast(target, target_type);
> +            if (target) {
>                   object_ref(target);
>                   *child = target;

Very good catch.

Regards,

Anthony Liguori

>               } else {
Paolo Bonzini - Feb. 3, 2012, 12:10 p.m.
On 02/02/2012 06:05 PM, Anthony Liguori wrote:
> On 02/02/2012 10:45 AM, Paolo Bonzini wrote:
>> When a link property's type is an interface, the code expects the
>> implementation object (not the parent object) to be stored in the
>> variable. The parent object does not contain the right vtable.
>>
>> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>
>> ---
>> qom/object.c | 3 ++-
>> 1 files changed, 2 insertions(+), 1 deletions(-)
>>
>> diff --git a/qom/object.c b/qom/object.c
>> index cd517f6..de6484d 100644
>> --- a/qom/object.c
>> +++ b/qom/object.c
>> @@ -749,7 +749,8 @@ static void object_set_link_property(Object *obj,
>> Visitor *v, void *opaque,
>> target_type = g_strdup(&type[5]);
>> target_type[strlen(target_type) - 2] = 0;
>>
>> - if (object_dynamic_cast(target, target_type)) {
>> + target = object_dynamic_cast(target, target_type);
>> + if (target) {
>> object_ref(target);
>> *child = target;
>
> Very good catch.

But when we implement type-based search for partial paths it will be 
fixed automatically (because object_resolve_path will have to do a 
dynamic cast on its own).  Let's do that instead.

I'll rebase the patch while travelling, since I have to convert 
LostTickPolicy as well.  Let's look at this after the weekend.

Paolo

Patch

diff --git a/qom/object.c b/qom/object.c
index cd517f6..de6484d 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -749,7 +749,8 @@  static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
             target_type = g_strdup(&type[5]);
             target_type[strlen(target_type) - 2] = 0;
 
-            if (object_dynamic_cast(target, target_type)) {
+            target = object_dynamic_cast(target, target_type);
+            if (target) {
                 object_ref(target);
                 *child = target;
             } else {