From patchwork Sat May 22 08:18:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 53256 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5228CB7D1B for ; Sat, 22 May 2010 18:39:08 +1000 (EST) Received: from localhost ([127.0.0.1]:60426 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OFk4N-0001pM-AI for incoming@patchwork.ozlabs.org; Sat, 22 May 2010 04:28:31 -0400 Received: from [140.186.70.92] (port=58436 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OFjuf-0005Ny-Fv for qemu-devel@nongnu.org; Sat, 22 May 2010 04:18:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OFjuV-0000HM-5G for qemu-devel@nongnu.org; Sat, 22 May 2010 04:18:28 -0400 Received: from fmmailgate01.web.de ([217.72.192.221]:46889) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OFjuU-0000Gr-LE for qemu-devel@nongnu.org; Sat, 22 May 2010 04:18:19 -0400 Received: from smtp04.web.de ( [172.20.0.225]) by fmmailgate01.web.de (Postfix) with ESMTP id E042915AE0B10; Sat, 22 May 2010 10:18:17 +0200 (CEST) Received: from [88.65.39.229] (helo=localhost.localdomain) by smtp04.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #4) id 1OFjuO-00046n-02; Sat, 22 May 2010 10:18:12 +0200 From: Jan Kiszka To: qemu-devel@nongnu.org, Anthony Liguori Date: Sat, 22 May 2010 10:18:02 +0200 Message-Id: <818363ead9495baadb853a9385eb065703e72507.1274516288.git.jan.kiszka@web.de> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: References: In-Reply-To: References: X-Sender: jan.kiszka@web.de X-Provags-ID: V01U2FsdGVkX19l3cT24MqNdUX+XZzXhLjFEW+x2JI2LcsCf0YM 3mY5q38N5KNZJFYDnoJiHlR3F6mlkPwipDTatbqgX1phYBh96Z kJoPDSQ10= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Cc: Jan Kiszka , Avi Kivity , Juan Quintela , Markus Armbruster , Luiz Capitulino Subject: [Qemu-devel] [PATCH v2 05/15] qdev: Allow device specification by qtree path for device_del X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jan Kiszka Allow to specify the device to be removed via device_del not only by ID but also by its full or abbreviated qtree path. For this purpose, qdev_find is introduced which combines searching for device IDs with walking the qtree when required. Signed-off-by: Jan Kiszka --- hw/qdev.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- qemu-monitor.hx | 10 +++++----- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index 6d55e50..fa611a1 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -666,6 +666,44 @@ search_dev_bus: } } +static DeviceState *qdev_find(const char *path) +{ + const char *dev_name; + DeviceState *dev; + char *bus_path; + BusState *bus; + + dev_name = strrchr(path, '/'); + if (!dev_name) { + bus = main_system_bus; + dev = qdev_find_recursive(bus, path); + if (dev) { + return dev; + } + dev_name = path; + } else { + dev_name++; + bus_path = qemu_strdup(path); + bus_path[dev_name - path] = 0; + + bus = qbus_find(bus_path); + qemu_free(bus_path); + + if (!bus) { + /* qbus_find already reported the error */ + return NULL; + } + } + dev = qbus_find_dev(bus, dev_name); + if (!dev) { + qerror_report(QERR_DEVICE_NOT_FOUND, dev_name); + if (!monitor_cur_is_qmp()) { + qbus_list_dev(bus); + } + } + return dev; +} + void qbus_create_inplace(BusState *bus, BusInfo *info, DeviceState *parent, const char *name) { @@ -824,12 +862,12 @@ int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data) int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data) { - const char *id = qdict_get_str(qdict, "id"); + const char *path = qdict_get_str(qdict, "path"); DeviceState *dev; - dev = qdev_find_recursive(main_system_bus, id); - if (NULL == dev) { - qerror_report(QERR_DEVICE_NOT_FOUND, id); + dev = qdev_find(path); + if (!dev) { + qerror_report(QERR_DEVICE_NOT_FOUND, path); return -1; } return qdev_unplug(dev); diff --git a/qemu-monitor.hx b/qemu-monitor.hx index c8f1789..754d71e 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -703,7 +703,7 @@ EQMP { .name = "device_del", - .args_type = "id:s", + .args_type = "path:s", .params = "device", .help = "remove device", .user_print = monitor_user_noop, @@ -711,10 +711,10 @@ EQMP }, STEXI -@item device_del @var{id} +@item device_del @var{path} @findex device_del -Remove device @var{id}. +Remove device @var{path}. ETEXI SQMP device_del @@ -724,11 +724,11 @@ Remove a device. Arguments: -- "id": the device's ID (json-string) +- "path": the device's qtree path or unique ID (json-string) Example: --> { "execute": "device_del", "arguments": { "id": "net1" } } +-> { "execute": "device_del", "arguments": { "path": "net1" } } <- { "return": {} } EQMP