Skip to contentSkip to conversation

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

PATCH Applied Kevin Wolf 2 participants 3 messages Aug 4, 2016 – Aug 5, 2016

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH v2 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.

---
v2:
- Check whether the BB has even a BDS inserted. Fixes a segfault with empty anonymous BlockBackends.

 hw/core/qdev-properties-system.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
hw/core/qdev-properties-system.c +10 -1
index 2ba2504..e55afe6 100644
@@ -126,7 +126,16 @@ 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) {
+        BlockDriverState *bs = blk_bs(ptr);
+        if (bs) {
+            name = bdrv_get_node_name(bs);
+        }
+    }
+    return g_strdup(name);
 }
 
 static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque,
Signature · 1 line
1.8.3.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Kevin Wolf

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.

---
v2:
- Check whether the BB has even a BDS inserted. Fixes a segfault with empty anonymous BlockBackends.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author Applied
#2 lore raw
In reply to Kevin Wolf

Am 04.08.2016 um 14:09 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.

Applied to the block branch.

Kevin