[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 05/15] qdev: Allow device specification by qtree
From: |
Jan Kiszka |
Subject: |
[Qemu-devel] [PATCH v2 05/15] qdev: Allow device specification by qtree path for device_del |
Date: |
Sat, 22 May 2010 10:18:02 +0200 |
From: Jan Kiszka <address@hidden>
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 <address@hidden>
---
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
address@hidden device_del @var{id}
address@hidden 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
--
1.6.0.2
[Qemu-devel] [PATCH v2 04/15] qdev: Convert device and bus lists to QTAILQ, Jan Kiszka, 2010/05/22
[Qemu-devel] [PATCH v2 05/15] qdev: Allow device specification by qtree path for device_del,
Jan Kiszka <=
[Qemu-devel] [PATCH v2 07/15] monitor: Add completion for qdev paths, Jan Kiszka, 2010/05/22
[Qemu-devel] [PATCH v2 11/15] monitor: return length of printed string via monitor_[v]printf, Jan Kiszka, 2010/05/22
[Qemu-devel] [PATCH v2 09/15] QMP: Reserve namespace for complex object classes, Jan Kiszka, 2010/05/22
[Qemu-devel] [PATCH v2 10/15] Add QBuffer, Jan Kiszka, 2010/05/22
[Qemu-devel] [PATCH v2 15/15] QMP: Add support for buffer class to qmp python helper, Jan Kiszka, 2010/05/22
[Qemu-devel] [PATCH v2 12/15] monitor: Add basic device state visualization, Jan Kiszka, 2010/05/22