Patchwork [V8,16/20] hmp: add command info images

login
register
mail settings
Submitter Wayne Xia
Date March 7, 2013, 6:07 a.m.
Message ID <1362636445-7188-17-git-send-email-xiawenc@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/225750/
State New
Headers show

Comments

Wayne Xia - March 7, 2013, 6:07 a.m.
This command will show block image's information, including
internal snapshots.

Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
---
 hmp.c     |   38 ++++++++++++++++++++++++++++++++++++++
 hmp.h     |    1 +
 monitor.c |    7 +++++++
 3 files changed, 46 insertions(+), 0 deletions(-)

Patch

diff --git a/hmp.c b/hmp.c
index 34f0691..05d9b3b 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)
 {
@@ -649,6 +650,43 @@  void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
     qapi_free_SnapshotInfoList(list);
 }
 
+#define IMAGE_INFO_BUF_SIZE (2048)
+static void mon_dump_device_image_info_list(Monitor *mon,
+                                            DeviceImageInfoList *list)
+{
+    char *buf = g_malloc0(IMAGE_INFO_BUF_SIZE);
+    DeviceImageInfoList *p = list;
+    DeviceImageInfo *dii;
+    while (p) {
+        dii = p->value;
+        monitor_printf(mon, "Device : %s\n", dii->device);
+        if (dii->has_image) {
+            bdrv_image_info_dump(buf, IMAGE_INFO_BUF_SIZE, dii->image);
+            monitor_printf(mon, "%s", buf);
+        }
+        monitor_printf(mon, "\n");
+
+        p = p->next;
+    }
+    g_free(buf);
+}
+
+void hmp_info_images(Monitor *mon, const QDict *qdict)
+{
+    const char *device = qdict_get_try_str(qdict, "device");
+    int backing = qdict_get_try_bool(qdict, "backing", 0);
+    Error *err = NULL;
+    DeviceImageInfoList *list = NULL;
+
+    list = qmp_query_images(!!device, device, true, backing, &err);
+    if (!error_is_set(&err) && list) {
+        mon_dump_device_image_info_list(mon, list);
+    }
+
+    hmp_handle_error(mon, &err);
+    qapi_free_DeviceImageInfoList(list);
+}
+
 void hmp_quit(Monitor *mon, const QDict *qdict)
 {
     monitor_suspend(mon);
diff --git a/hmp.h b/hmp.h
index 0b0ae13..9d9ada3 100644
--- a/hmp.h
+++ b/hmp.h
@@ -37,6 +37,7 @@  void hmp_info_balloon(Monitor *mon, const QDict *qdict);
 void hmp_info_pci(Monitor *mon, const QDict *qdict);
 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict);
 void hmp_info_snapshots(Monitor *mon, const QDict *qdict);
+void hmp_info_images(Monitor *mon, const QDict *qdict);
 void hmp_quit(Monitor *mon, const QDict *qdict);
 void hmp_stop(Monitor *mon, const QDict *qdict);
 void hmp_system_reset(Monitor *mon, const QDict *qdict);
diff --git a/monitor.c b/monitor.c
index 5112375..b470963 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2597,6 +2597,13 @@  static mon_cmd_t info_cmds[] = {
         .mhandler.cmd = hmp_info_snapshots,
     },
     {
+        .name       = "images",
+        .args_type  = "backing:-b,device:B?",
+        .params     = "[-b] [device]",
+        .help       = "show the image info",
+        .mhandler.cmd = hmp_info_images,
+    },
+    {
         .name       = "status",
         .args_type  = "",
         .params     = "",