diff mbox

[v3,02/17] qdev: Fix scanning across single-bus devices

Message ID 6a034099416bccaf10e56861896ae98239c19aa6.1274612367.git.jan.kiszka@web.de
State New
Headers show

Commit Message

Jan Kiszka May 23, 2010, 10:59 a.m. UTC
From: Jan Kiszka <jan.kiszka@siemens.com>

As long as we allow /dev.1 as shortcut for /dev1/bus1, we also have to
make sure that /dev1/dev2 works for /dev1/bus1/dev2/bus2 - as long as
there is only one child bus per device.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 docs/qdev-device-use.txt |    4 ++++
 hw/qdev.c                |   12 +++++++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)

Comments

Paul Brook June 3, 2010, 5:58 a.m. UTC | #1
> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> As long as we allow /dev.1 as shortcut for /dev1/bus1, we also have to
> make sure that /dev1/dev2 works for /dev1/bus1/dev2/bus2 - as long as
> there is only one child bus per device.

How about we make this explicit in the syntax by having a different separator 
for bus names. e.g. /dev1:bus1/dev2:bus1. Omitting the :bus is then 
unambiguous.

Paul
Jan Kiszka June 3, 2010, 6:12 a.m. UTC | #2
Paul Brook wrote:
>> From: Jan Kiszka <jan.kiszka@siemens.com>
>>
>> As long as we allow /dev.1 as shortcut for /dev1/bus1, we also have to
>> make sure that /dev1/dev2 works for /dev1/bus1/dev2/bus2 - as long as
>> there is only one child bus per device.
> 
> How about we make this explicit in the syntax by having a different separator 
> for bus names. e.g. /dev1:bus1/dev2:bus1. Omitting the :bus is then 
> unambiguous.

...as long as there will always be only one bus at dev1 and/or only one
dev2 on dev1's buses.

I think we should stick with the consensus of dropping these abbreviations.

Jan
diff mbox

Patch

diff --git a/docs/qdev-device-use.txt b/docs/qdev-device-use.txt
index f252c8e..9ac1fa1 100644
--- a/docs/qdev-device-use.txt
+++ b/docs/qdev-device-use.txt
@@ -20,6 +20,10 @@  bus named pci.0.  To put a FOO device into its slot 4, use -device
 FOO,bus=/i440FX-pcihost/pci.0,addr=4.  The abbreviated form bus=pci.0
 also works as long as the bus name is unique.
 
+Furthermore, if a device only hosts a single bus, the bus name can be
+omitted in the path.  Example: /i440FX-pcihost/PIIX3 abbreviates
+/i440FX-pcihost/pci.0/PIIX3/isa.0 as none of the buses has siblings.
+
 Note: the USB device address can't be controlled at this time.
 
 === Block Devices ===
diff --git a/hw/qdev.c b/hw/qdev.c
index aa2ce01..2e50531 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -557,7 +557,7 @@  static DeviceState *qbus_find_dev(BusState *bus, char *elem)
 
 static BusState *qbus_find(const char *path)
 {
-    DeviceState *dev;
+    DeviceState *dev, *next_dev;
     BusState *bus;
     char elem[128];
     int pos, len;
@@ -603,6 +603,7 @@  static BusState *qbus_find(const char *path)
             return NULL;
         }
 
+search_dev_bus:
         assert(path[pos] == '/' || !path[pos]);
         while (path[pos] == '/') {
             pos++;
@@ -633,6 +634,15 @@  static BusState *qbus_find(const char *path)
         pos += len;
         bus = qbus_find_bus(dev, elem);
         if (!bus) {
+            if (dev->num_child_bus == 1) {
+                /* Last element might have been a short-cut to a device on
+                 * the single child bus of the parent device. */
+                next_dev = qbus_find_dev(QTAILQ_FIRST(&dev->child_bus), elem);
+                if (next_dev) {
+                    dev = next_dev;
+                    goto search_dev_bus;
+                }
+            }
             qerror_report(QERR_BUS_NOT_FOUND, elem);
             if (!monitor_cur_is_qmp()) {
                 qbus_list_bus(dev);