Patchwork [V10,16/17] hmp: show ImageInfo in 'info block'

login
register
mail settings
Submitter Wayne Xia
Date March 22, 2013, 2:19 p.m.
Message ID <1363961953-13561-17-git-send-email-xiawenc@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/230080/
State New
Headers show

Comments

Wayne Xia - March 22, 2013, 2:19 p.m.
Now human monitor can show image details include internal
snapshot info for every block device.

Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
---
 hmp.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
Kevin Wolf - March 28, 2013, 11:06 a.m.
Am 22.03.2013 um 15:19 hat Wenchao Xia geschrieben:
>   Now human monitor can show image details include internal
> snapshot info for every block device.
> 
> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>

I don't think we should do that unconditionally. 'info block' should be
a short summary of all block devices in use by the VM and this would
make it way too long.

We could either introduce an 'info block -v' to display everything, or
only do it for a single BlockDriverState with something like
'info block <blockdev-name>'. I'm not sure how easy those would be to
implement, though.

Kevin

Patch

diff --git a/hmp.c b/hmp.c
index c475d65..49f851b 100644
--- a/hmp.c
+++ b/hmp.c
@@ -22,6 +22,7 @@ 
 #include "qemu/sockets.h"
 #include "monitor/monitor.h"
 #include "ui/console.h"
+#include "block/qapi.h"
 
 static void hmp_handle_error(Monitor *mon, Error **errp)
 {
@@ -272,9 +273,12 @@  void hmp_info_cpus(Monitor *mon, const QDict *qdict)
     qapi_free_CpuInfoList(cpu_list);
 }
 
+#define IMAGE_INFO_BUF_SIZE (2048)
 void hmp_info_block(Monitor *mon, const QDict *qdict)
 {
     BlockInfoList *block_list, *info;
+    ImageInfo *image_info;
+    char *buf = NULL;
 
     block_list = qmp_query_block(NULL);
 
@@ -316,6 +320,22 @@  void hmp_info_block(Monitor *mon, const QDict *qdict)
                             info->value->inserted->iops,
                             info->value->inserted->iops_rd,
                             info->value->inserted->iops_wr);
+
+            if (!buf) {
+                buf = g_malloc0(IMAGE_INFO_BUF_SIZE);
+            }
+            monitor_printf(mon, " images:\n");
+            image_info = info->value->inserted->image;
+            while (1) {
+                bdrv_image_info_dump(buf, IMAGE_INFO_BUF_SIZE, image_info);
+                monitor_printf(mon, "%s", buf);
+                if (image_info->has_backing_image) {
+                    image_info = image_info->backing_image;
+                } else {
+                    break;
+                }
+            }
+
         } else {
             monitor_printf(mon, " [not inserted]");
         }
@@ -323,6 +343,7 @@  void hmp_info_block(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, "\n");
     }
 
+    g_free(buf);
     qapi_free_BlockInfoList(block_list);
 }