Skip to contentSkip to conversation

block/qdev: Let 'drive' property fall back to node name

PATCH Superseded Kevin Wolf 1 participant 2 messages Aug 4, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 block/qdev: Let 'drive' property fall back to node name

If a qdev block device is created with an anonymous BlockBackend (i.e. a node name rather than a BB name was given for the drive property), qdev used to return an empty string when the property was read. This patch fixes it to return the node name instead.

---
 hw/core/qdev-properties-system.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
hw/core/qdev-properties-system.c +7 -1
index 2ba2504..25b24aa 100644
@@ -126,7 +126,13 @@ static void release_drive(Object *obj, const char *name, void *opaque)
 
 static char *print_drive(void *ptr)
 {
-    return g_strdup(blk_name(ptr));
+    const char *name;
+
+    name = blk_name(ptr);
+    if (!*name) {
+        name = bdrv_get_node_name(blk_bs(ptr));
+    }
+    return g_strdup(name);
 }
 
 static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque,
Signature · 1 line
1.8.3.1
author
#1 lore raw

Am 04.08.2016 um 14:03 hat Kevin Wolf geschrieben:

Quoted 6 lines

If a qdev block device is created with an anonymous BlockBackend (i.e. a node name rather than a BB name was given for the drive property), qdev used to return an empty string when the property was read. This patch fixes it to return the node name instead.

As always, the moment you send out a patch, you notice that it's broken.

Quoted 5 lines
hw/core/qdev-properties-system.c +0 -0
index 2ba2504..25b24aa 100644

hw/core/qdev-properties-system.c static void release_drive(Object *obj, const char *name, void *opaque) · line 133

Quoted 9 lines
hw/core/qdev-properties-system.c +5 -1
@@ -126,7 +126,13 @@ static void release_drive(Object *obj, const char *name, void *opaque)
 
 static char *print_drive(void *ptr)
 {
-    return g_strdup(blk_name(ptr));
+    const char *name;
+
+    name = blk_name(ptr);
+    if (!*name) {
+        name = bdrv_get_node_name(blk_bs(ptr));

blk_bs(ptr) can be NULL. Self-NACK, v2 is coming.

hw/core/qdev-properties-system.c static void release_drive(Object *obj, const char *name, void *opaque) · line 136

Quoted 3 lines
hw/core/qdev-properties-system.c +2 -0
+    }
+    return g_strdup(name);
 }

Kevin