qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] hw/qdev-monitor: report error for -device <not-a-device-type>
@ 2012-11-28  8:54 Alon Levy
  2012-11-28 11:54 ` Luiz Capitulino
  2012-11-28 12:00 ` Markus Armbruster
  0 siblings, 2 replies; 10+ messages in thread
From: Alon Levy @ 2012-11-28  8:54 UTC (permalink / raw)
  To: qemu-devel, lcapitulino, armbru

Instead of aborting immediately after at DEVICE_CLASS(obj)

Signed-off-by: Alon Levy <alevy@redhat.com>
---
 hw/qdev-monitor.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index 479eecd..3b70cdb 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -426,6 +426,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         return NULL;
     }
 
+    if (!object_class_dynamic_cast(obj, "device")) {
+        qerror_report(QERR_INVALID_PARAMETER_TYPE, "driver", "device type");
+        return NULL;
+    }
+
     k = DEVICE_CLASS(obj);
 
     /* find bus */
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/qdev-monitor: report error for -device <not-a-device-type>
  2012-11-28  8:54 [Qemu-devel] [PATCH] hw/qdev-monitor: report error for -device <not-a-device-type> Alon Levy
@ 2012-11-28 11:54 ` Luiz Capitulino
  2012-11-28 12:02   ` Paolo Bonzini
                     ` (2 more replies)
  2012-11-28 12:00 ` Markus Armbruster
  1 sibling, 3 replies; 10+ messages in thread
From: Luiz Capitulino @ 2012-11-28 11:54 UTC (permalink / raw)
  To: Alon Levy; +Cc: pbonzini, qemu-devel, afaerber, armbru

On Wed, 28 Nov 2012 10:54:33 +0200
Alon Levy <alevy@redhat.com> wrote:

> Instead of aborting immediately after at DEVICE_CLASS(obj)
> 
> Signed-off-by: Alon Levy <alevy@redhat.com>
> ---
>  hw/qdev-monitor.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
> index 479eecd..3b70cdb 100644
> --- a/hw/qdev-monitor.c
> +++ b/hw/qdev-monitor.c
> @@ -426,6 +426,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
>          return NULL;
>      }
>  
> +    if (!object_class_dynamic_cast(obj, "device")) {
> +        qerror_report(QERR_INVALID_PARAMETER_TYPE, "driver", "device type");
> +        return NULL;
> +    }

Gives me the impression that something is wrong before this, but it's
better to ask a QOM guy (CC'ing them).

How do you reproduce it btw?

> +
>      k = DEVICE_CLASS(obj);
>  
>      /* find bus */

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/qdev-monitor: report error for -device <not-a-device-type>
  2012-11-28  8:54 [Qemu-devel] [PATCH] hw/qdev-monitor: report error for -device <not-a-device-type> Alon Levy
  2012-11-28 11:54 ` Luiz Capitulino
@ 2012-11-28 12:00 ` Markus Armbruster
  1 sibling, 0 replies; 10+ messages in thread
From: Markus Armbruster @ 2012-11-28 12:00 UTC (permalink / raw)
  To: Alon Levy; +Cc: qemu-devel, lcapitulino

Alon Levy <alevy@redhat.com> writes:

> Instead of aborting immediately after at DEVICE_CLASS(obj)

Reproducer?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/qdev-monitor: report error for -device <not-a-device-type>
  2012-11-28 11:54 ` Luiz Capitulino
@ 2012-11-28 12:02   ` Paolo Bonzini
  2012-11-28 12:14     ` Luiz Capitulino
  2012-11-28 12:18     ` Alon Levy
  2012-11-28 12:15   ` Andreas Färber
  2012-11-28 12:17   ` Alon Levy
  2 siblings, 2 replies; 10+ messages in thread
From: Paolo Bonzini @ 2012-11-28 12:02 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: Alon Levy, qemu-devel, afaerber, armbru

Il 28/11/2012 12:54, Luiz Capitulino ha scritto:
> On Wed, 28 Nov 2012 10:54:33 +0200
> Alon Levy <alevy@redhat.com> wrote:
> 
>> Instead of aborting immediately after at DEVICE_CLASS(obj)
>>
>> Signed-off-by: Alon Levy <alevy@redhat.com>
>> ---
>>  hw/qdev-monitor.c | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
>> index 479eecd..3b70cdb 100644
>> --- a/hw/qdev-monitor.c
>> +++ b/hw/qdev-monitor.c
>> @@ -426,6 +426,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
>>          return NULL;
>>      }
>>  
>> +    if (!object_class_dynamic_cast(obj, "device")) {
>> +        qerror_report(QERR_INVALID_PARAMETER_TYPE, "driver", "device type");
>> +        return NULL;
>> +    }
> 
> Gives me the impression that something is wrong before this, but it's
> better to ask a QOM guy (CC'ing them).

I would reuse the same error message as for "if (!obj)", and also use
TYPE_DEVICE instead of the hardcoded string, but the patch is ok.

> How do you reproduce it btw?

$ x86_64-softmmu/qemu-system-x86_64 -device SCSI
Object 0x7f56872248b0 is not an instance of type device
Aborted

However, we also need an object_class_is_abstract method to fix this
similar failure:

$ x86_64-softmmu/qemu-system-x86_64 -device pci-device
**
ERROR:/home/pbonzini/work/upstream/qemu/qom/object.c:306:object_initialize_with_type:
assertion failed: (type->abstract == false)
Aborted

All in all, it makes sense to me that we delay this post-1.3.

Paolo

>> +
>>      k = DEVICE_CLASS(obj);
>>  
>>      /* find bus */
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/qdev-monitor: report error for -device <not-a-device-type>
  2012-11-28 12:02   ` Paolo Bonzini
@ 2012-11-28 12:14     ` Luiz Capitulino
  2012-11-28 12:19       ` Andreas Färber
  2012-11-28 12:18     ` Alon Levy
  1 sibling, 1 reply; 10+ messages in thread
From: Luiz Capitulino @ 2012-11-28 12:14 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Alon Levy, qemu-devel, afaerber, armbru

On Wed, 28 Nov 2012 13:02:26 +0100
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Il 28/11/2012 12:54, Luiz Capitulino ha scritto:
> > On Wed, 28 Nov 2012 10:54:33 +0200
> > Alon Levy <alevy@redhat.com> wrote:
> > 
> >> Instead of aborting immediately after at DEVICE_CLASS(obj)
> >>
> >> Signed-off-by: Alon Levy <alevy@redhat.com>
> >> ---
> >>  hw/qdev-monitor.c | 5 +++++
> >>  1 file changed, 5 insertions(+)
> >>
> >> diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
> >> index 479eecd..3b70cdb 100644
> >> --- a/hw/qdev-monitor.c
> >> +++ b/hw/qdev-monitor.c
> >> @@ -426,6 +426,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
> >>          return NULL;
> >>      }
> >>  
> >> +    if (!object_class_dynamic_cast(obj, "device")) {
> >> +        qerror_report(QERR_INVALID_PARAMETER_TYPE, "driver", "device type");
> >> +        return NULL;
> >> +    }
> > 
> > Gives me the impression that something is wrong before this, but it's
> > better to ask a QOM guy (CC'ing them).
> 
> I would reuse the same error message as for "if (!obj)", and also use
> TYPE_DEVICE instead of the hardcoded string, but the patch is ok.

It's a bit weird to me that you check for a condition and right next
you also assert it (it's what DEVICE_CLASS() will do). But I'm not familiar
with QOM, so I'll just trust you.

If the patch is good, why should we wait post-1.3 giving that it fixes a
real bug?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/qdev-monitor: report error for -device <not-a-device-type>
  2012-11-28 11:54 ` Luiz Capitulino
  2012-11-28 12:02   ` Paolo Bonzini
@ 2012-11-28 12:15   ` Andreas Färber
  2012-11-28 12:17   ` Alon Levy
  2 siblings, 0 replies; 10+ messages in thread
From: Andreas Färber @ 2012-11-28 12:15 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: pbonzini, Alon Levy, qemu-devel, armbru

Am 28.11.2012 12:54, schrieb Luiz Capitulino:
> On Wed, 28 Nov 2012 10:54:33 +0200
> Alon Levy <alevy@redhat.com> wrote:
> 
>> Instead of aborting immediately after at DEVICE_CLASS(obj)
>>
>> Signed-off-by: Alon Levy <alevy@redhat.com>
>> ---
>>  hw/qdev-monitor.c | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
>> index 479eecd..3b70cdb 100644
>> --- a/hw/qdev-monitor.c
>> +++ b/hw/qdev-monitor.c
>> @@ -426,6 +426,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
>>          return NULL;
>>      }
>>  
>> +    if (!object_class_dynamic_cast(obj, "device")) {

"device" should be TYPE_DEVICE.

>> +        qerror_report(QERR_INVALID_PARAMETER_TYPE, "driver", "device type");
>> +        return NULL;
>> +    }
> 
> Gives me the impression that something is wrong before this, but it's
> better to ask a QOM guy (CC'ing them).

What is definitely wrong here is the naming: "obj" is used for
ObjectClass rather than Object.
Therefore the use of object_class_dynamic_cast() is correct. I don't see
an earlier place to error out.

> 
> How do you reproduce it btw?

My guess is that trying to instantiate a non-device type needs to be
caught before using the mentioned asserting DEVICE_CLASS() macro below.

I.e. something like -device x86_64-cpu (non-abstract non-device type
currently) on qemu-system-x86_64, or easier -device container.

Regards,
Andreas

> 
>> +
>>      k = DEVICE_CLASS(obj);
>>  
>>      /* find bus */
> 

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/qdev-monitor: report error for -device <not-a-device-type>
  2012-11-28 11:54 ` Luiz Capitulino
  2012-11-28 12:02   ` Paolo Bonzini
  2012-11-28 12:15   ` Andreas Färber
@ 2012-11-28 12:17   ` Alon Levy
  2 siblings, 0 replies; 10+ messages in thread
From: Alon Levy @ 2012-11-28 12:17 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: pbonzini, qemu-devel, afaerber, armbru

> On Wed, 28 Nov 2012 10:54:33 +0200
> Alon Levy <alevy@redhat.com> wrote:
> 
> > Instead of aborting immediately after at DEVICE_CLASS(obj)
> > 
> > Signed-off-by: Alon Levy <alevy@redhat.com>
> > ---
> >  hw/qdev-monitor.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> > 
> > diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
> > index 479eecd..3b70cdb 100644
> > --- a/hw/qdev-monitor.c
> > +++ b/hw/qdev-monitor.c
> > @@ -426,6 +426,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
> >          return NULL;
> >      }
> >  
> > +    if (!object_class_dynamic_cast(obj, "device")) {
> > +        qerror_report(QERR_INVALID_PARAMETER_TYPE, "driver",
> > "device type");
> > +        return NULL;
> > +    }
> 
> Gives me the impression that something is wrong before this, but it's
> better to ask a QOM guy (CC'ing them).
> 
> How do you reproduce it btw?

-device virtio-serial-bus

which is the incorrect way of saying

-device virtio-serial-pci

> 
> > +
> >      k = DEVICE_CLASS(obj);
> >  
> >      /* find bus */
> 
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/qdev-monitor: report error for -device <not-a-device-type>
  2012-11-28 12:02   ` Paolo Bonzini
  2012-11-28 12:14     ` Luiz Capitulino
@ 2012-11-28 12:18     ` Alon Levy
  1 sibling, 0 replies; 10+ messages in thread
From: Alon Levy @ 2012-11-28 12:18 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: armbru, Luiz Capitulino, qemu-devel, afaerber

> Il 28/11/2012 12:54, Luiz Capitulino ha scritto:
> > On Wed, 28 Nov 2012 10:54:33 +0200
> > Alon Levy <alevy@redhat.com> wrote:
> > 
> >> Instead of aborting immediately after at DEVICE_CLASS(obj)
> >>
> >> Signed-off-by: Alon Levy <alevy@redhat.com>
> >> ---
> >>  hw/qdev-monitor.c | 5 +++++
> >>  1 file changed, 5 insertions(+)
> >>
> >> diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
> >> index 479eecd..3b70cdb 100644
> >> --- a/hw/qdev-monitor.c
> >> +++ b/hw/qdev-monitor.c
> >> @@ -426,6 +426,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
> >>          return NULL;
> >>      }
> >>  
> >> +    if (!object_class_dynamic_cast(obj, "device")) {
> >> +        qerror_report(QERR_INVALID_PARAMETER_TYPE, "driver",
> >> "device type");
> >> +        return NULL;
> >> +    }
> > 
> > Gives me the impression that something is wrong before this, but
> > it's
> > better to ask a QOM guy (CC'ing them).
> 
> I would reuse the same error message as for "if (!obj)", and also use
> TYPE_DEVICE instead of the hardcoded string, but the patch is ok.
> 
> > How do you reproduce it btw?
> 
> $ x86_64-softmmu/qemu-system-x86_64 -device SCSI
> Object 0x7f56872248b0 is not an instance of type device
> Aborted
> 
> However, we also need an object_class_is_abstract method to fix this
> similar failure:
> 
> $ x86_64-softmmu/qemu-system-x86_64 -device pci-device
> **
> ERROR:/home/pbonzini/work/upstream/qemu/qom/object.c:306:object_initialize_with_type:
> assertion failed: (type->abstract == false)
> Aborted
> 
> All in all, it makes sense to me that we delay this post-1.3.

I agree, I'll keep it until then.

> 
> Paolo
> 
> >> +
> >>      k = DEVICE_CLASS(obj);
> >>  
> >>      /* find bus */
> > 
> 
> 
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/qdev-monitor: report error for -device <not-a-device-type>
  2012-11-28 12:14     ` Luiz Capitulino
@ 2012-11-28 12:19       ` Andreas Färber
  2012-11-28 12:21         ` Luiz Capitulino
  0 siblings, 1 reply; 10+ messages in thread
From: Andreas Färber @ 2012-11-28 12:19 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: Paolo Bonzini, Alon Levy, qemu-devel, armbru

Am 28.11.2012 13:14, schrieb Luiz Capitulino:
> On Wed, 28 Nov 2012 13:02:26 +0100
> Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
>> Il 28/11/2012 12:54, Luiz Capitulino ha scritto:
>>> On Wed, 28 Nov 2012 10:54:33 +0200
>>> Alon Levy <alevy@redhat.com> wrote:
>>>
>>>> Instead of aborting immediately after at DEVICE_CLASS(obj)
>>>>
>>>> Signed-off-by: Alon Levy <alevy@redhat.com>
>>>> ---
>>>>  hw/qdev-monitor.c | 5 +++++
>>>>  1 file changed, 5 insertions(+)
>>>>
>>>> diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
>>>> index 479eecd..3b70cdb 100644
>>>> --- a/hw/qdev-monitor.c
>>>> +++ b/hw/qdev-monitor.c
>>>> @@ -426,6 +426,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
>>>>          return NULL;
>>>>      }
>>>>  
>>>> +    if (!object_class_dynamic_cast(obj, "device")) {
>>>> +        qerror_report(QERR_INVALID_PARAMETER_TYPE, "driver", "device type");
>>>> +        return NULL;
>>>> +    }
>>>
>>> Gives me the impression that something is wrong before this, but it's
>>> better to ask a QOM guy (CC'ing them).
>>
>> I would reuse the same error message as for "if (!obj)", and also use
>> TYPE_DEVICE instead of the hardcoded string, but the patch is ok.
> 
> It's a bit weird to me that you check for a condition and right next
> you also assert it (it's what DEVICE_CLASS() will do). But I'm not familiar
> with QOM, so I'll just trust you.

We could just as well do:

k = object_class_dynamic_cast(obj, TYPE_DEVICE);
if (k == NULL) {
    // do the error reporting
    return ...;
}

/* find bus */
...

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/qdev-monitor: report error for -device <not-a-device-type>
  2012-11-28 12:19       ` Andreas Färber
@ 2012-11-28 12:21         ` Luiz Capitulino
  0 siblings, 0 replies; 10+ messages in thread
From: Luiz Capitulino @ 2012-11-28 12:21 UTC (permalink / raw)
  To: Andreas Färber; +Cc: Paolo Bonzini, Alon Levy, qemu-devel, armbru

On Wed, 28 Nov 2012 13:19:36 +0100
Andreas Färber <afaerber@suse.de> wrote:

> Am 28.11.2012 13:14, schrieb Luiz Capitulino:
> > On Wed, 28 Nov 2012 13:02:26 +0100
> > Paolo Bonzini <pbonzini@redhat.com> wrote:
> > 
> >> Il 28/11/2012 12:54, Luiz Capitulino ha scritto:
> >>> On Wed, 28 Nov 2012 10:54:33 +0200
> >>> Alon Levy <alevy@redhat.com> wrote:
> >>>
> >>>> Instead of aborting immediately after at DEVICE_CLASS(obj)
> >>>>
> >>>> Signed-off-by: Alon Levy <alevy@redhat.com>
> >>>> ---
> >>>>  hw/qdev-monitor.c | 5 +++++
> >>>>  1 file changed, 5 insertions(+)
> >>>>
> >>>> diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
> >>>> index 479eecd..3b70cdb 100644
> >>>> --- a/hw/qdev-monitor.c
> >>>> +++ b/hw/qdev-monitor.c
> >>>> @@ -426,6 +426,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
> >>>>          return NULL;
> >>>>      }
> >>>>  
> >>>> +    if (!object_class_dynamic_cast(obj, "device")) {
> >>>> +        qerror_report(QERR_INVALID_PARAMETER_TYPE, "driver", "device type");
> >>>> +        return NULL;
> >>>> +    }
> >>>
> >>> Gives me the impression that something is wrong before this, but it's
> >>> better to ask a QOM guy (CC'ing them).
> >>
> >> I would reuse the same error message as for "if (!obj)", and also use
> >> TYPE_DEVICE instead of the hardcoded string, but the patch is ok.
> > 
> > It's a bit weird to me that you check for a condition and right next
> > you also assert it (it's what DEVICE_CLASS() will do). But I'm not familiar
> > with QOM, so I'll just trust you.
> 
> We could just as well do:
> 
> k = object_class_dynamic_cast(obj, TYPE_DEVICE);
> if (k == NULL) {
>     // do the error reporting
>     return ...;
> }

Yeah, was reaching this solution after some code reading :)

> 
> /* find bus */
> ...
> 
> Andreas
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-11-28 12:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-28  8:54 [Qemu-devel] [PATCH] hw/qdev-monitor: report error for -device <not-a-device-type> Alon Levy
2012-11-28 11:54 ` Luiz Capitulino
2012-11-28 12:02   ` Paolo Bonzini
2012-11-28 12:14     ` Luiz Capitulino
2012-11-28 12:19       ` Andreas Färber
2012-11-28 12:21         ` Luiz Capitulino
2012-11-28 12:18     ` Alon Levy
2012-11-28 12:15   ` Andreas Färber
2012-11-28 12:17   ` Alon Levy
2012-11-28 12:00 ` Markus Armbruster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).