[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 1/8] qdev: Allow device addressing via 'driver.insta
From: |
Jan Kiszka |
Subject: |
[Qemu-devel] [PATCH 1/8] qdev: Allow device addressing via 'driver.instance' |
Date: |
Fri, 14 May 2010 15:20:45 +0200 |
Extend qbus_find_dev to allow addressing of devices without an unique id
via an optional instance number. The new formats are 'driver.instance'
and 'alias.instance'.
Signed-off-by: Jan Kiszka <address@hidden>
---
hw/qdev.c | 23 ++++++++++++++++++-----
1 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index d3bf0fa..fe49e71 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -515,28 +515,41 @@ static BusState *qbus_find_bus(DeviceState *dev, char
*elem)
return NULL;
}
-static DeviceState *qbus_find_dev(BusState *bus, char *elem)
+static DeviceState *qbus_find_dev(BusState *bus, const char *elem)
{
DeviceState *dev;
+ int instance, n;
+ char buf[128];
/*
* try to match in order:
* (1) instance id, if present
- * (2) driver name
- * (3) driver alias, if present
+ * (2) driver name [.instance]
+ * (3) driver alias [.instance], if present
*/
QLIST_FOREACH(dev, &bus->children, sibling) {
if (dev->id && strcmp(dev->id, elem) == 0) {
return dev;
}
}
+
+ if (sscanf(elem, "%127[^.].%u", buf, &instance) == 2) {
+ elem = buf;
+ } else {
+ instance = 0;
+ }
+
+ n = 0;
QLIST_FOREACH(dev, &bus->children, sibling) {
- if (strcmp(dev->info->name, elem) == 0) {
+ if (strcmp(dev->info->name, elem) == 0 && n++ == instance) {
return dev;
}
}
+
+ n = 0;
QLIST_FOREACH(dev, &bus->children, sibling) {
- if (dev->info->alias && strcmp(dev->info->alias, elem) == 0) {
+ if (dev->info->alias && strcmp(dev->info->alias, elem) == 0 &&
+ n++ == instance) {
return dev;
}
}
--
1.6.0.2
[Qemu-devel] [PATCH 5/8] qmp: Teach basic capability negotiation to python example, Jan Kiszka, 2010/05/14
[Qemu-devel] [PATCH 4/8] monitor: Add basic device state visualization, Jan Kiszka, 2010/05/14