From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36120) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZdJq-0006Ie-6n for qemu-devel@nongnu.org; Thu, 02 Oct 2014 06:09:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XZdJh-0000SO-7z for qemu-devel@nongnu.org; Thu, 02 Oct 2014 06:09:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11955) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZdJh-0000SI-07 for qemu-devel@nongnu.org; Thu, 02 Oct 2014 06:08:57 -0400 From: Igor Mammedov Date: Thu, 2 Oct 2014 10:08:45 +0000 Message-Id: <1412244525-7153-1-git-send-email-imammedo@redhat.com> In-Reply-To: <1411723721-20484-1-git-send-email-imammedo@redhat.com> References: <1411723721-20484-1-git-send-email-imammedo@redhat.com> Subject: [Qemu-devel] [PATCH v2 37/36] qdev: device_del: search for to be unplugged device in 'peripheral' container List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, Peter Crosthwaite , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Bharata B Rao 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 --- qdev-monitor.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/qdev-monitor.c b/qdev-monitor.c index c721451..754437b 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -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) -- 1.8.3.1