diff mbox

[v3,04/17] qdev: Give qtree names precedence over user-assigned IDs

Message ID 3715da16813f7cdcb7ec023167a84a94e8a37089.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 the user may specify ambiguous device IDs, let's search for their
official names first before considering the user-supplied identifiers.

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

Comments

Markus Armbruster May 29, 2010, 8:01 a.m. UTC | #1
Jan Kiszka <jan.kiszka@web.de> writes:

> From: Jan Kiszka <jan.kiszka@siemens.com>
>
> As the user may specify ambiguous device IDs, let's search for their
> official names first before considering the user-supplied identifiers.
>
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>

The problem is letting the user specify ambiguous device IDs in the
first place!  That way is madness...
Avi Kivity May 30, 2010, 8:16 a.m. UTC | #2
On 05/29/2010 11:01 AM, Markus Armbruster wrote:
> Jan Kiszka<jan.kiszka@web.de>  writes:
>
>    
>> From: Jan Kiszka<jan.kiszka@siemens.com>
>>
>> As the user may specify ambiguous device IDs, let's search for their
>> official names first before considering the user-supplied identifiers.
>>
>> Signed-off-by: Jan Kiszka<jan.kiszka@siemens.com>
>>      
> The problem is letting the user specify ambiguous device IDs in the
> first place!  That way is madness...
>    

Agreed, we're sowing the seeds for future problems.
diff mbox

Patch

diff --git a/docs/qdev-device-use.txt b/docs/qdev-device-use.txt
index 74d4960..0160191 100644
--- a/docs/qdev-device-use.txt
+++ b/docs/qdev-device-use.txt
@@ -25,7 +25,9 @@  omitted in the path.  Example: /i440FX-pcihost/PIIX3 abbreviates
 /i440FX-pcihost/pci.0/PIIX3/isa.0 as none of the buses has siblings.
 
 Existing devices can be addressed either via a unique ID if it was
-assigned during creation or via the device tree path:
+assigned during creation or via the device tree path. In conflicts,
+the latter has precedence. A device tree path has the following
+structure:
 
 /full_bus_address/driver_name[.instance_number]
     or
diff --git a/hw/qdev.c b/hw/qdev.c
index 6b4a629..eeadf4a 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -535,16 +535,10 @@  static DeviceState *qbus_find_dev(BusState *bus, const char *elem)
 
     /*
      * try to match in order:
-     *   (1) instance id, if present
-     *   (2) driver name [.instance]
-     *   (3) driver alias [.instance], if present
+     *   (1) driver name [.instance]
+     *   (2) driver alias [.instance], if present
+     *   (3) instance id, 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 {
@@ -565,6 +559,12 @@  static DeviceState *qbus_find_dev(BusState *bus, const char *elem)
             return dev;
         }
     }
+
+    QLIST_FOREACH(dev, &bus->children, sibling) {
+        if (dev->id && strcmp(dev->id, elem) == 0) {
+            return dev;
+        }
+    }
     return NULL;
 }