diff mbox

[2.1,28/28] qmp: add query-memdev

Message ID 1393941656-29068-29-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini March 4, 2014, 2 p.m. UTC
From: Hu Tao <hutao@cn.fujitsu.com>

Add qmp command query-memdev to query for information
of memory devices

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
[Use QMP visitors instead of String visitors. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 numa.c           | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qapi-schema.json | 31 +++++++++++++++++++++++++++
 qmp-commands.hx  | 32 ++++++++++++++++++++++++++++
 3 files changed, 127 insertions(+)

Comments

Eric Blake March 4, 2014, 5:37 p.m. UTC | #1
On 03/04/2014 07:00 AM, Paolo Bonzini wrote:
> From: Hu Tao <hutao@cn.fujitsu.com>
> 
> Add qmp command query-memdev to query for information
> of memory devices
> 
> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> [Use QMP visitors instead of String visitors. - Paolo]
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  numa.c           | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  qapi-schema.json | 31 +++++++++++++++++++++++++++
>  qmp-commands.hx  | 32 ++++++++++++++++++++++++++++
>  3 files changed, 127 insertions(+)
> 

> +++ b/qapi-schema.json
> @@ -4576,3 +4576,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' }}

Why is policy 'str', when you just defined 'HostMemPolicy' as an enum in
the previous patch?  Should this be using the enum?


> +<- { "return": [
> +       {
> +         "size": 536870912,
> +         "host-nodes": [0, 1],
> +         "policy": "bind"

"bind" is not one of the values of HostMemPolicy - is that missing from
patch 27/28?
Paolo Bonzini March 4, 2014, 6:11 p.m. UTC | #2
Il 04/03/2014 18:37, Eric Blake ha scritto:
> On 03/04/2014 07:00 AM, Paolo Bonzini wrote:
>> From: Hu Tao <hutao@cn.fujitsu.com>
>>
>> Add qmp command query-memdev to query for information
>> of memory devices
>>
>> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
>> [Use QMP visitors instead of String visitors. - Paolo]
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>  numa.c           | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  qapi-schema.json | 31 +++++++++++++++++++++++++++
>>  qmp-commands.hx  | 32 ++++++++++++++++++++++++++++
>>  3 files changed, 127 insertions(+)
>>
>
>> +++ b/qapi-schema.json
>> @@ -4576,3 +4576,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' }}
>
> Why is policy 'str', when you just defined 'HostMemPolicy' as an enum in
> the previous patch?  Should this be using the enum?

Good catch.

>
>> +<- { "return": [
>> +       {
>> +         "size": 536870912,
>> +         "host-nodes": [0, 1],
>> +         "policy": "bind"
>
> "bind" is not one of the values of HostMemPolicy - is that missing from
> patch 27/28?

Should be membind.

Paolo
Hu Tao March 5, 2014, 3:48 a.m. UTC | #3
<...>

> +
> +MemdevList *qmp_query_memdev(Error **errp)
> +{
> +    QmpOutputVisitor *ov = qmp_output_visitor_new();
> +    QmpInputVisitor *iv;
> +    QObject *obj;
> +    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), qmp_output_get_visitor(ov),
> +                            "host-nodes", &err);
> +        if (err) {
> +            goto error;
> +        }
> +        obj = qmp_output_get_qobject(ov);

Unlike string output visitor, the internal state of qmp output visitor
retains, it should be cleaned up at the end of every loop.

> +        iv = qmp_input_visitor_new(obj);
> +        qobject_decref(obj);
> +
> +        visit_type_uint16List(qmp_input_get_visitor(iv),
> +                              &m->value->host_nodes, NULL, &err);
> +        if (err) {
> +            qmp_input_visitor_cleanup(iv);
> +            goto error;
> +        }
> +
> +        m->next = list;
> +        list = m;
> +        qmp_input_visitor_cleanup(iv);
> +    }
> +
> +    qmp_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);
> +    qmp_output_visitor_cleanup(ov);
> +    return NULL;
> +}
Hu Tao March 5, 2014, 3:50 a.m. UTC | #4
On Tue, Mar 04, 2014 at 07:11:53PM +0100, Paolo Bonzini wrote:
> Il 04/03/2014 18:37, Eric Blake ha scritto:
> >On 03/04/2014 07:00 AM, Paolo Bonzini wrote:
> >>From: Hu Tao <hutao@cn.fujitsu.com>
> >>
> >>Add qmp command query-memdev to query for information
> >>of memory devices
> >>
> >>Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> >>[Use QMP visitors instead of String visitors. - Paolo]
> >>Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> >>---
> >> numa.c           | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >> qapi-schema.json | 31 +++++++++++++++++++++++++++
> >> qmp-commands.hx  | 32 ++++++++++++++++++++++++++++
> >> 3 files changed, 127 insertions(+)
> >>
> >
> >>+++ b/qapi-schema.json
> >>@@ -4576,3 +4576,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' }}
> >
> >Why is policy 'str', when you just defined 'HostMemPolicy' as an enum in
> >the previous patch?  Should this be using the enum?
> 
> Good catch.
> 
> >
> >>+<- { "return": [
> >>+       {
> >>+         "size": 536870912,
> >>+         "host-nodes": [0, 1],
> >>+         "policy": "bind"
> >
> >"bind" is not one of the values of HostMemPolicy - is that missing from
> >patch 27/28?
> 
> Should be membind.

How about change it into bind to keep in line with MPOL_BIND?
Paolo Bonzini March 5, 2014, 8:17 a.m. UTC | #5
Il 05/03/2014 04:50, Hu Tao ha scritto:
>>> > >"bind" is not one of the values of HostMemPolicy - is that missing from
>>> > >patch 27/28?
>> >
>> > Should be membind.
> How about change it into bind to keep in line with MPOL_BIND?
>
>
>

Sure!

Paolo
diff mbox

Patch

diff --git a/numa.c b/numa.c
index 4a1ba0c..159f5af 100644
--- a/numa.c
+++ b/numa.c
@@ -30,9 +30,12 @@ 
 #include "qapi-visit.h"
 #include "qapi/opts-visitor.h"
 #include "qapi/dealloc-visitor.h"
+#include "qapi/qmp-output-visitor.h"
+#include "qapi/qmp-input-visitor.h"
 #include "qapi/qmp/qerror.h"
 #include "hw/boards.h"
 #include "sysemu/hostmem.h"
+#include "qmp-commands.h"
 
 QemuOptsList qemu_numa_opts = {
     .name = "numa",
@@ -281,3 +284,64 @@  void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
         addr += size;
     }
 }
+
+MemdevList *qmp_query_memdev(Error **errp)
+{
+    QmpOutputVisitor *ov = qmp_output_visitor_new();
+    QmpInputVisitor *iv;
+    QObject *obj;
+    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), qmp_output_get_visitor(ov),
+                            "host-nodes", &err);
+        if (err) {
+            goto error;
+        }
+        obj = qmp_output_get_qobject(ov);
+        iv = qmp_input_visitor_new(obj);
+        qobject_decref(obj);
+
+        visit_type_uint16List(qmp_input_get_visitor(iv),
+                              &m->value->host_nodes, NULL, &err);
+        if (err) {
+            qmp_input_visitor_cleanup(iv);
+            goto error;
+        }
+
+        m->next = list;
+        list = m;
+        qmp_input_visitor_cleanup(iv);
+    }
+
+    qmp_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);
+    qmp_output_visitor_cleanup(ov);
+    return NULL;
+}
diff --git a/qapi-schema.json b/qapi-schema.json
index b11b279..30d0d12 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4576,3 +4576,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