aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHu Tao <hutao@cn.fujitsu.com>2014-06-16 18:05:41 +0800
committerMichael S. Tsirkin <mst@redhat.com>2014-06-19 18:44:21 +0300
commit76b5d8507d08db18bc0bd3c75349b357a82ff1a2 (patch)
treef6a8d8ddef7d83b15c760d47248b4fb631e8898a
parent4cf1b76bf1e2cbb91b1123d47505a6586195800c (diff)
downloadqemu-76b5d8507d08db18bc0bd3c75349b357a82ff1a2.zip
qemu-76b5d8507d08db18bc0bd3c75349b357a82ff1a2.tar.gz
qemu-76b5d8507d08db18bc0bd3c75349b357a82ff1a2.tar.bz2
qmp: add query-memdev
Add qmp command query-memdev to query for information of memory devices Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
-rw-r--r--numa.c84
-rw-r--r--qapi-schema.json40
-rw-r--r--qmp-commands.hx38
3 files changed, 162 insertions, 0 deletions
diff --git a/numa.c b/numa.c
index 711f682..eef0717 100644
--- a/numa.c
+++ b/numa.c
@@ -34,6 +34,7 @@
#include "qapi/qmp/qerror.h"
#include "hw/boards.h"
#include "sysemu/hostmem.h"
+#include "qmp-commands.h"
QemuOptsList qemu_numa_opts = {
.name = "numa",
@@ -283,3 +284,86 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
addr += size;
}
}
+
+static int query_memdev(Object *obj, void *opaque)
+{
+ MemdevList **list = opaque;
+ Error *err = NULL;
+
+ if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) {
+ MemdevList *m = g_malloc0(sizeof(*m));
+
+ m->value = g_malloc0(sizeof(*m->value));
+
+ m->value->size = object_property_get_int(obj, "size",
+ &err);
+ if (err) {
+ goto error;
+ }
+
+ m->value->merge = object_property_get_bool(obj, "merge",
+ &err);
+ if (err) {
+ goto error;
+ }
+
+ m->value->dump = object_property_get_bool(obj, "dump",
+ &err);
+ if (err) {
+ goto error;
+ }
+
+ m->value->prealloc = object_property_get_bool(obj,
+ "prealloc", &err);
+ if (err) {
+ goto error;
+ }
+
+ m->value->policy = object_property_get_enum(obj,
+ "policy",
+ HostMemPolicy_lookup,
+ &err);
+ if (err) {
+ goto error;
+ }
+
+ object_property_get_uint16List(obj, "host-nodes",
+ &m->value->host_nodes, &err);
+ if (err) {
+ goto error;
+ }
+
+ m->next = *list;
+ *list = m;
+ }
+
+ return 0;
+error:
+ return -1;
+}
+
+MemdevList *qmp_query_memdev(Error **errp)
+{
+ Object *obj;
+ MemdevList *list = NULL, *m;
+
+ obj = object_resolve_path("/objects", NULL);
+ if (obj == NULL) {
+ return NULL;
+ }
+
+ if (object_child_foreach(obj, query_memdev, &list) != 0) {
+ goto error;
+ }
+
+ return list;
+
+error:
+ while (list) {
+ m = list;
+ list = list->next;
+ g_free(m->value);
+ g_free(m);
+ }
+ return NULL;
+}
diff --git a/qapi-schema.json b/qapi-schema.json
index 10a324a..082bc3a 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3154,3 +3154,43 @@
##
{ 'enum': 'HostMemPolicy',
'data': [ 'default', 'preferred', 'bind', 'interleave' ] }
+
+##
+# @Memdev:
+#
+# Information of memory device
+#
+# @size: memory device size
+#
+# @merge: enables or disables memory merge support
+#
+# @dump: includes memory device's memory in a core dump or not
+#
+# @prealloc: enables or disables memory preallocation
+#
+# @host-nodes: host nodes for its memory policy
+#
+# @policy: memory policy of memory device
+#
+# Since: 2.1
+##
+
+{ 'type': 'Memdev',
+ 'data': {
+ 'size': 'size',
+ 'merge': 'bool',
+ 'dump': 'bool',
+ 'prealloc': 'bool',
+ 'host-nodes': ['uint16'],
+ 'policy': 'HostMemPolicy' }}
+
+##
+# @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 d6bb0f4..d99f235 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3574,3 +3574,41 @@ 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,
+ "merge": false,
+ "dump": true,
+ "prealloc": false,
+ "host-nodes": [0, 1],
+ "policy": "bind"
+ },
+ {
+ "size": 536870912,
+ "merge": false,
+ "dump": true,
+ "prealloc": true,
+ "host-nodes": [2, 3],
+ "policy": "preferred"
+ }
+ ]
+ }
+
+EQMP