block/qdev: Let 'drive' property fall back to node name
authorKevin Wolf <kwolf@redhat.com>
Thu, 4 Aug 2016 12:09:07 +0000 (14:09 +0200)
committerKevin Wolf <kwolf@redhat.com>
Mon, 8 Aug 2016 11:05:43 +0000 (13:05 +0200)
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.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
hw/core/qdev-properties-system.c

index 2ba2504ea06eef29b1b5d06bc3718b27ede0a910..e55afe6bf272f9534bf0fd811d5a8cc79fc02b4b 100644 (file)
@@ -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,