]> git.proxmox.com Git - mirror_qemu.git/commitdiff
block/hmp: Allow info = NULL in print_block_info()
authorKevin Wolf <kwolf@redhat.com>
Mon, 15 Sep 2014 10:12:52 +0000 (12:12 +0200)
committerKevin Wolf <kwolf@redhat.com>
Wed, 10 Dec 2014 09:31:11 +0000 (10:31 +0100)
This allows printing infos of BlockDriverStates that aren't at the root
of the graph (and logically implementing a BlockBackend).

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
hmp.c

diff --git a/hmp.c b/hmp.c
index 2e2b91ba5003f863dbf55143a0f8d06a868d3aae..05ccf5faec44ecdf29c8f6b12d2faad894c178f0 100644 (file)
--- a/hmp.c
+++ b/hmp.c
@@ -295,7 +295,21 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
 {
     ImageInfo *image_info;
 
-    monitor_printf(mon, "%s", info->device);
+    assert(!info || !info->has_inserted || info->inserted == inserted);
+
+    if (info) {
+        monitor_printf(mon, "%s", info->device);
+        if (inserted && inserted->has_node_name) {
+            monitor_printf(mon, " (%s)", inserted->node_name);
+        }
+    } else {
+        assert(inserted);
+        monitor_printf(mon, "%s",
+                       inserted->has_node_name
+                       ? inserted->node_name
+                       : "<anonymous>");
+    }
+
     if (inserted) {
         monitor_printf(mon, ": %s (%s%s%s)\n",
                        inserted->file,
@@ -306,15 +320,17 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
         monitor_printf(mon, ": [not inserted]\n");
     }
 
-    if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
-        monitor_printf(mon, "    I/O status:       %s\n",
-                       BlockDeviceIoStatus_lookup[info->io_status]);
-    }
+    if (info) {
+        if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
+            monitor_printf(mon, "    I/O status:       %s\n",
+                           BlockDeviceIoStatus_lookup[info->io_status]);
+        }
 
-    if (info->removable) {
-        monitor_printf(mon, "    Removable device: %slocked, tray %s\n",
-                       info->locked ? "" : "not ",
-                       info->tray_open ? "open" : "closed");
+        if (info->removable) {
+            monitor_printf(mon, "    Removable device: %slocked, tray %s\n",
+                           info->locked ? "" : "not ",
+                           info->tray_open ? "open" : "closed");
+        }
     }