diff mbox

[for-2.7] block/qdev: Let 'drive' property fall back to node name

Message ID 1470312212-3005-1-git-send-email-kwolf@redhat.com
State New
Headers show

Commit Message

Kevin Wolf Aug. 4, 2016, 12:03 p.m. UTC
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>
---
 hw/core/qdev-properties-system.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Kevin Wolf Aug. 4, 2016, 12:11 p.m. UTC | #1
Am 04.08.2016 um 14:03 hat Kevin Wolf geschrieben:
> 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>

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

> diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
> index 2ba2504..25b24aa 100644
> --- a/hw/core/qdev-properties-system.c
> +++ b/hw/core/qdev-properties-system.c
> @@ -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.

> +    }
> +    return g_strdup(name);
>  }

Kevin
diff mbox

Patch

diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 2ba2504..25b24aa 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -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,