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>
This commit is contained in:
Hu Tao 2014-06-16 18:05:41 +08:00 committed by Michael S. Tsirkin
parent 4cf1b76bf1
commit 76b5d8507d
3 changed files with 162 additions and 0 deletions

84
numa.c
View File

@ -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;
}

View File

@ -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'] }

View File

@ -3573,4 +3573,42 @@ 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