Skip to contentSkip to conversation

qdev: modify func qdev_build_hotpluggable_device_list

PATCH Superseded Jun Li 2 participants 2 messages Nov 2, 2014 – Nov 3, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jun Li

author
#0 lore raw

PATCH 1/1 qdev: modify func qdev_build_hotpluggable_device_list

Currently when *obj is not a TYPE_DEVICE, qemu will abort. This patch just fixed it. When *obj is not a TYPE_DEVICE, just do not add it to hotpluggable device list.

This patch also fixed the following issue:
1, boot qemu using cli:
virtio-scsi-pci,id=scsi0 -enable-kvm

2, device_del scsi0 via hmp using tab key(first input device_del, then press "Tab" key).
(qemu) device_del

After step2, qemu will abort.
(qemu) device_del hw/core/qdev.c:930:qdev_build_hotpluggable_device_list:
Object 0x5555563a2460 is not an instance of type device

---
 hw/core/qdev.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
hw/core/qdev.c +9 -4
index b3d5196..2282e95 100644
@@ -927,13 +927,18 @@ void qdev_alias_all_properties(DeviceState *target, Object *source)
 int qdev_build_hotpluggable_device_list(Object *obj, void *opaque)
 {
     GSList **list = opaque;
-    DeviceState *dev = DEVICE(obj);
+    DeviceState *dev = (DeviceState *)object_dynamic_cast(OBJECT(obj),
+                                                          "device");
+
+    if (dev) {
+        if (dev->realized &&
+            object_property_get_bool(obj, "hotpluggable", NULL)) {
+            *list = g_slist_append(*list, dev);
+        }
 
-    if (dev->realized && object_property_get_bool(obj, "hotpluggable", NULL)) {
-        *list = g_slist_append(*list, dev);
+        object_child_foreach(obj, qdev_build_hotpluggable_device_list, opaque);
     }
 
-    object_child_foreach(obj, qdev_build_hotpluggable_device_list, opaque);
     return 0;
 }
 
Signature · 1 line
1.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 35 lines · Jun Li

Currently when *obj is not a TYPE_DEVICE, qemu will abort. This patch just fixed it. When *obj is not a TYPE_DEVICE, just do not add it to hotpluggable device list.

This patch also fixed the following issue:
1, boot qemu using cli:
virtio-scsi-pci,id=scsi0 -enable-kvm

2, device_del scsi0 via hmp using tab key(first input device_del, then press "Tab" key).
(qemu) device_del

After step2, qemu will abort.
(qemu) device_del hw/core/qdev.c:930:qdev_build_hotpluggable_device_list:
Object 0x5555563a2460 is not an instance of type device

---
 hw/core/qdev.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
hw/core/qdev.c +5 -1
index b3d5196..2282e95 100644
@@ -927,13 +927,18 @@ void qdev_alias_all_properties(DeviceState *target, Object *source)
 int qdev_build_hotpluggable_device_list(Object *obj, void *opaque)
 {
     GSList **list = opaque;
-    DeviceState *dev = DEVICE(obj);
+    DeviceState *dev = (DeviceState *)object_dynamic_cast(OBJECT(obj),
+                                                          "device");
+
+    if (dev) {
+        if (dev->realized &&

hw/core/qdev.c void qdev_alias_all_properties(DeviceState *target, Object *source) · line 936

Quoted 10 lines
hw/core/qdev.c +4 -3
+            object_property_get_bool(obj, "hotpluggable", NULL)) {
+            *list = g_slist_append(*list, dev);
+        }
 
-    if (dev->realized && object_property_get_bool(obj, "hotpluggable", NULL)) {
-        *list = g_slist_append(*list, dev);
+        object_child_foreach(obj, qdev_build_hotpluggable_device_list, opaque);
     }
 
-    object_child_foreach(obj, qdev_build_hotpluggable_device_list, opaque);