Patchwork [v3,34/34] hmp: add info memdev

login
register
mail settings
Submitter Hu Tao
Date March 26, 2014, 10:37 a.m.
Message ID <d96dc238b6a3e891f6063545fc40f18204b3ce63.1395825871.git.hutao@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/333822/
State New
Headers show

Comments

Hu Tao - March 26, 2014, 10:37 a.m.
This is the hmp counterpart of qmp query-memdev.

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 hmp.c     | 36 ++++++++++++++++++++++++++++++++++++
 hmp.h     |  1 +
 monitor.c |  7 +++++++
 3 files changed, 44 insertions(+)

Patch

diff --git a/hmp.c b/hmp.c
index 2f279c4..b500856 100644
--- a/hmp.c
+++ b/hmp.c
@@ -22,6 +22,8 @@ 
 #include "qemu/sockets.h"
 #include "monitor/monitor.h"
 #include "qapi/opts-visitor.h"
+#include "qapi/string-output-visitor.h"
+#include "qapi-visit.h"
 #include "ui/console.h"
 #include "block/qapi.h"
 #include "qemu-io.h"
@@ -1647,3 +1649,37 @@  void hmp_object_del(Monitor *mon, const QDict *qdict)
     qmp_object_del(id, &err);
     hmp_handle_error(mon, &err);
 }
+
+void hmp_info_memdev(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    MemdevList *memdev_list = qmp_query_memdev(&err);
+    MemdevList *m = memdev_list;
+    StringOutputVisitor *ov;
+    int i = 0;
+
+
+    while (m) {
+        ov = string_output_visitor_new(false);
+        visit_type_uint16List(string_output_get_visitor(ov),
+                              &m->value->host_nodes, NULL, NULL);
+        monitor_printf(mon, "memory device %d\n", i);
+        monitor_printf(mon, "  size: %ld\n", m->value->size);
+        monitor_printf(mon, "  merge: %s\n",
+                       m->value->merge ? "true" : "false");
+        monitor_printf(mon, "  dump: %s\n",
+                       m->value->dump ? "true" : "false");
+        monitor_printf(mon, "  prealloc: %s\n",
+                       m->value->prealloc ? "true" : "false");
+        monitor_printf(mon, "  policy: %s\n",
+                       HostMemPolicy_lookup[m->value->policy]);
+        monitor_printf(mon, "  host nodes: %s\n",
+                       string_output_get_string(ov));
+
+        string_output_visitor_cleanup(ov);
+        m = m->next;
+        i++;
+    }
+
+    monitor_printf(mon, "\n");
+}
diff --git a/hmp.h b/hmp.h
index ed58f0e..b6f5d02 100644
--- a/hmp.h
+++ b/hmp.h
@@ -92,5 +92,6 @@  void hmp_qemu_io(Monitor *mon, const QDict *qdict);
 void hmp_cpu_add(Monitor *mon, const QDict *qdict);
 void hmp_object_add(Monitor *mon, const QDict *qdict);
 void hmp_object_del(Monitor *mon, const QDict *qdict);
+void hmp_info_memdev(Monitor *mon, const QDict *qdict);
 
 #endif
diff --git a/monitor.c b/monitor.c
index 39f2518..408daca 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2966,6 +2966,13 @@  static mon_cmd_t info_cmds[] = {
         .mhandler.cmd = hmp_info_tpm,
     },
     {
+        .name       = "memdev",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show the memory device",
+        .mhandler.cmd = hmp_info_memdev,
+    },
+    {
         .name       = NULL,
     },
 };