Skip to contentSkip to conversation

hw/qdev-monitor: report error for -device <not-a-device-type>

PATCH In review Alon Levy 5 participants 10 messages Nov 28, 2012

lore
Share & tools
lore

Alon Levy

author
#0 lore raw

PATCH 1/1 hw/qdev-monitor: report error for -device <not-a-device-type>

Instead of aborting immediately after at DEVICE_CLASS(obj)

---
 hw/qdev-monitor.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/qdev-monitor.c +5 -0
index 479eecd..3b70cdb 100644
@@ -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 */
Signature · 1 line
1.8.0
#1 lore raw
Quoted 12 lines · On Wed, 28 Nov 2012 10:54:33 +0200 Alon Levy <[email protected]> wrote:

Instead of aborting immediately after at DEVICE_CLASS(obj)

---
 hw/qdev-monitor.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/qdev-monitor.c +0 -0
index 479eecd..3b70cdb 100644

hw/qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts) · line 432

Quoted 7 lines
hw/qdev-monitor.c +4 -0
@@ -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?

Quoted 4 lines
hw/qdev-monitor.c +1 -0
+
     k = DEVICE_CLASS(obj);
 
     /* find bus */
#2 lore raw

Il 28/11/2012 12:54, Luiz Capitulino ha scritto:

Quoted 18 lines
Quoted 15 lines · On Wed, 28 Nov 2012 10:54:33 +0200 Alon Levy <[email protected]> wrote:

Instead of aborting immediately after at DEVICE_CLASS(obj)

---
 hw/qdev-monitor.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/qdev-monitor.c +0 -0
index 479eecd..3b70cdb 100644
@@ -426,6 +426,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         return NULL;
     }
 
Quoted 7 lines

hw/qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts) · line 432

Quoted 4 lines
hw/qdev-monitor.c +4 -0
+    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.

Quoted 1 line

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

Quoted 5 lines
Quoted 4 lines
hw/qdev-monitor.c +1 -0
+
     k = DEVICE_CLASS(obj);
 
     /* find bus */
#3 lore raw
Quoted 27 lines · On Wed, 28 Nov 2012 13:02:26 +0100 Paolo Bonzini <[email protected]> wrote:

Il 28/11/2012 12:54, Luiz Capitulino ha scritto:

Quoted 18 lines
Quoted 15 lines · On Wed, 28 Nov 2012 10:54:33 +0200 Alon Levy <[email protected]> wrote:

Instead of aborting immediately after at DEVICE_CLASS(obj)

---
 hw/qdev-monitor.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/qdev-monitor.c +0 -0
index 479eecd..3b70cdb 100644
@@ -426,6 +426,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         return NULL;
     }
 
Quoted 7 lines

hw/qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts) · line 432

Quoted 4 lines
hw/qdev-monitor.c +4 -0
+    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).

Quoted 2 lines

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?

#4 lore raw

Am 28.11.2012 13:14, schrieb Luiz Capitulino:

Quoted 30 lines
Quoted 27 lines · On Wed, 28 Nov 2012 13:02:26 +0100 Paolo Bonzini <[email protected]> wrote:

Il 28/11/2012 12:54, Luiz Capitulino ha scritto:

Quoted 25 lines
Quoted 12 lines · On Wed, 28 Nov 2012 10:54:33 +0200 Alon Levy <[email protected]> wrote:

Instead of aborting immediately after at DEVICE_CLASS(obj)

---
 hw/qdev-monitor.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/qdev-monitor.c +0 -0
index 479eecd..3b70cdb 100644

hw/qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts) · line 432

Quoted 7 lines
hw/qdev-monitor.c +4 -0
@@ -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).

Quoted 6 lines
Quoted 2 lines

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

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#5 lore raw
Quoted 38 lines · On Wed, 28 Nov 2012 13:19:36 +0100 Andreas Färber <[email protected]> wrote:

Am 28.11.2012 13:14, schrieb Luiz Capitulino:

Quoted 30 lines
Quoted 27 lines · On Wed, 28 Nov 2012 13:02:26 +0100 Paolo Bonzini <[email protected]> wrote:

Il 28/11/2012 12:54, Luiz Capitulino ha scritto:

Quoted 25 lines
Quoted 12 lines · On Wed, 28 Nov 2012 10:54:33 +0200 Alon Levy <[email protected]> wrote:

Instead of aborting immediately after at DEVICE_CLASS(obj)

---
 hw/qdev-monitor.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/qdev-monitor.c +0 -0
index 479eecd..3b70cdb 100644

hw/qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts) · line 432

Quoted 7 lines
hw/qdev-monitor.c +4 -0
@@ -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).

Quoted 6 lines
Quoted 2 lines

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.

Quoted 7 lines

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 :)

Quoted 6 lines

/* find bus */
...

Andreas

author
#6 lore raw
In reply to Paolo Bonzini
Quoted 41 lines

Il 28/11/2012 12:54, Luiz Capitulino ha scritto:

Quoted 18 lines
Quoted 15 lines · On Wed, 28 Nov 2012 10:54:33 +0200 Alon Levy <[email protected]> wrote:

Instead of aborting immediately after at DEVICE_CLASS(obj)

---
 hw/qdev-monitor.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/qdev-monitor.c +0 -0
index 479eecd..3b70cdb 100644
@@ -426,6 +426,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         return NULL;
     }
 
Quoted 9 lines

hw/qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts) · line 432

Quoted 5 lines
hw/qdev-monitor.c +4 -0
+    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.

Quoted 1 line

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:

Quoted 7 lines
$ 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.

Quoted 11 lines

Paolo

Quoted 5 lines
Quoted 4 lines
hw/qdev-monitor.c +1 -0
+
     k = DEVICE_CLASS(obj);
 
     /* find bus */
#7 lore raw
In reply to Luiz Capitulino

Am 28.11.2012 12:54, schrieb Luiz Capitulino:

Quoted 18 lines
Quoted 15 lines · On Wed, 28 Nov 2012 10:54:33 +0200 Alon Levy <[email protected]> wrote:

Instead of aborting immediately after at DEVICE_CLASS(obj)

---
 hw/qdev-monitor.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/qdev-monitor.c +0 -0
index 479eecd..3b70cdb 100644
@@ -426,6 +426,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         return NULL;
     }
 
Quoted 1 line

hw/qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts) · line 429

Quoted 1 line
hw/qdev-monitor.c +1 -0
+    if (!object_class_dynamic_cast(obj, "device")) {

"device" should be TYPE_DEVICE.

Quoted 6 lines

hw/qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts) · line 432

Quoted 3 lines
hw/qdev-monitor.c +3 -0
+        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.

Quoted 2 lines

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

Quoted 6 lines
Quoted 5 lines
hw/qdev-monitor.c +1 -0
+
     k = DEVICE_CLASS(obj);
 
     /* find bus */
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
author
#8 lore raw
In reply to Luiz Capitulino
Quoted 27 lines
Quoted 12 lines · On Wed, 28 Nov 2012 10:54:33 +0200 Alon Levy <[email protected]> wrote:

Instead of aborting immediately after at DEVICE_CLASS(obj)

---
 hw/qdev-monitor.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/qdev-monitor.c +0 -0
index 479eecd..3b70cdb 100644

hw/qdev-monitor.c DeviceState *qdev_device_add(QemuOpts *opts) · line 433

Quoted 8 lines
hw/qdev-monitor.c +4 -0
@@ -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).

Quoted 1 line

How do you reproduce it btw?

-device virtio-serial-bus

which is the incorrect way of saying

-device virtio-serial-pci

Quoted 7 lines
Quoted 5 lines
hw/qdev-monitor.c +1 -0
+
     k = DEVICE_CLASS(obj);
 
     /* find bus */