[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v19 10/11] qmp: add query-memdev
From: |
Hu Tao |
Subject: |
[Qemu-devel] [PATCH v19 10/11] qmp: add query-memdev |
Date: |
Tue, 4 Mar 2014 15:28:24 +0800 |
Add qmp command query-memdev to query for information
of memory devices
Signed-off-by: Hu Tao <address@hidden>
---
backends/hostmem.c | 1 +
numa.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
qapi-schema.json | 31 +++++++++++++++++++++++++++
qmp-commands.hx | 32 ++++++++++++++++++++++++++++
4 files changed, 125 insertions(+)
diff --git a/backends/hostmem.c b/backends/hostmem.c
index 077e8cc..0d4f863 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -18,6 +18,7 @@
#ifdef CONFIG_NUMA
#include <numaif.h>
#endif
+#include "qmp-commands.h"
static void
hostmemory_backend_get_size(Object *obj, Visitor *v, void *opaque,
diff --git a/numa.c b/numa.c
index 8d05078..933f6b8 100644
--- a/numa.c
+++ b/numa.c
@@ -28,7 +28,11 @@
#include "qapi-visit.h"
#include "qapi/opts-visitor.h"
#include "qapi/dealloc-visitor.h"
+#include "qapi/string-output-visitor.h"
+#include "qapi/string-input-visitor.h"
#include "qapi/qmp/qerror.h"
+#include "qmp-commands.h"
+
QemuOptsList qemu_numa_opts = {
.name = "numa",
@@ -259,3 +263,60 @@ void memory_region_allocate_system_memory(MemoryRegion
*mr, Object *owner,
addr += size;
}
}
+
+MemdevList *qmp_query_memdev(Error **errp)
+{
+ StringOutputVisitor *ov = string_output_visitor_new(false);
+ StringInputVisitor *iv;
+ MemdevList *list = NULL, *m;
+ HostMemoryBackend *backend;
+ Error *err = NULL;
+ int i;
+
+ for (i = 0; i < nb_numa_nodes; i++) {
+ backend = numa_info[i].node_memdev;
+
+ m = g_malloc0(sizeof(*m));
+ m->value = g_malloc0(sizeof(*m->value));
+ m->value->size = object_property_get_int(OBJECT(backend), "size",
+ &err);
+ if (err) {
+ goto error;
+ }
+ m->value->policy = object_property_get_str(OBJECT(backend), "policy",
+ &err);
+ if (err) {
+ goto error;
+ }
+ object_property_get(OBJECT(backend), string_output_get_visitor(ov),
+ "host-nodes", &err);
+ if (err) {
+ goto error;
+ }
+ iv = string_input_visitor_new(string_output_get_string(ov));
+ visit_type_uint16List(string_input_get_visitor(iv),
+ &m->value->host_nodes, NULL, &err);
+ if (err) {
+ string_input_visitor_cleanup(iv);
+ goto error;
+ }
+
+ m->next = list;
+ list = m;
+ string_input_visitor_cleanup(iv);
+ }
+
+ string_output_visitor_cleanup(ov);
+
+ return list;
+error:
+ while (list) {
+ m = list;
+ list = list->next;
+ g_free(m->value);
+ g_free(m);
+ }
+ qerror_report_err(err);
+ return NULL;
+}
+
diff --git a/qapi-schema.json b/qapi-schema.json
index 86b78a5..b5dccfa 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4574,3 +4574,34 @@
##
{ 'enum': 'HostMemPolicy',
'data': [ 'default', 'preferred', 'membind', 'interleave' ] }
+
+##
+# @Memdev:
+#
+# Information of memory device
+#
+# @size: memory device size
+#
+# @host-nodes: host nodes for its memory policy
+#
+# @policy: memory policy of memory device
+#
+# Since: 2.1
+##
+
+{ 'type': 'Memdev',
+ 'data': {
+ 'size': 'size',
+ 'host-nodes': ['uint16'],
+ 'policy': 'str' }}
+
+##
+# @query-memdev:
+#
+# Returns information for all memory devices.
+#
+# Returns: a list of @Memdev.
+#
+# Since: 2.1
+##
+{ 'command': 'query-memdev', 'returns': ['Memdev'] }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 8a0e832..903a48a 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3498,3 +3498,35 @@ Example:
} } ] }
EQMP
+
+ {
+ .name = "query-memdev",
+ .args_type = "",
+ .mhandler.cmd_new = qmp_marshal_input_query_memdev,
+ },
+
+SQMP
+query-memdev
+------------
+
+Show memory devices information.
+
+
+Example (1):
+
+-> { "execute": "query-memdev" }
+<- { "return": [
+ {
+ "size": 536870912,
+ "host-nodes": [0, 1],
+ "policy": "bind"
+ },
+ {
+ "size": 536870912,
+ "host-nodes": [2, 3],
+ "policy": "preferred"
+ }
+ ]
+ }
+
+EQMP
--
1.8.5.2.229.g4448466
- [Qemu-devel] [PATCH v19 00/11] Add support for binding guest numa nodes to host numa nodes, Hu Tao, 2014/03/04
- [Qemu-devel] [PATCH v19 05/11] numa: add -numa node, memdev= option, Hu Tao, 2014/03/04
- [Qemu-devel] [PATCH v19 11/11] hmp: add info memdev, Hu Tao, 2014/03/04
- [Qemu-devel] [PATCH v19 02/11] add memdev backend infrastructure, Hu Tao, 2014/03/04
- [Qemu-devel] [PATCH v19 01/11] object_add: allow completion handler to get canonical path, Hu Tao, 2014/03/04
- [Qemu-devel] [PATCH v19 08/11] Add Linux libnuma detection, Hu Tao, 2014/03/04
- [Qemu-devel] [PATCH v19 03/11] pc: pass QEMUMachineInitArgs to pc_memory_init, Hu Tao, 2014/03/04
- [Qemu-devel] [PATCH v19 06/11] qapi: make string input visitor parse int list, Hu Tao, 2014/03/04
- [Qemu-devel] [PATCH v19 09/11] hostmem backend: implement memory policy, Hu Tao, 2014/03/04
- [Qemu-devel] [PATCH v19 10/11] qmp: add query-memdev,
Hu Tao <=
- [Qemu-devel] [PATCH v19 04/11] numa: introduce memory_region_allocate_system_memory, Hu Tao, 2014/03/04
- [Qemu-devel] [PATCH v19 07/11] qapi: make string output visitor parse int list, Hu Tao, 2014/03/04