]> xenbits.xensource.com Git - qemu-upstream-4.6-testing.git/commitdiff
qdev: device_del: Search for to be unplugged device in 'peripheral' container
authorIgor Mammedov <imammedo@redhat.com>
Thu, 2 Oct 2014 10:08:45 +0000 (10:08 +0000)
committerAndreas Färber <afaerber@suse.de>
Wed, 15 Oct 2014 03:03:15 +0000 (05:03 +0200)
device_add puts every device with 'id' inside of 'peripheral'
container using id's value as the last component name.
Use it by replacing recursive search on sysbus with path
lookup in 'peripheral' container, which could handle both
BUS and BUS-less device cases.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
qdev-monitor.c

index c72145127e673927a1735833e5507be18cfe1be8..754437b777837b21a06f0e45fb0dd12beea92133 100644 (file)
@@ -686,15 +686,20 @@ int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
 
 void qmp_device_del(const char *id, Error **errp)
 {
-    DeviceState *dev;
+    Object *obj;
+    char *root_path = object_get_canonical_path(qdev_get_peripheral());
+    char *path = g_strdup_printf("%s/%s", root_path, id);
 
-    dev = qdev_find_recursive(sysbus_get_default(), id);
-    if (!dev) {
+    g_free(root_path);
+    obj = object_resolve_path_type(path, TYPE_DEVICE, NULL);
+    g_free(path);
+
+    if (!obj) {
         error_set(errp, QERR_DEVICE_NOT_FOUND, id);
         return;
     }
 
-    qdev_unplug(dev, errp);
+    qdev_unplug(DEVICE(obj), errp);
 }
 
 void qdev_machine_init(void)