[libvirt] [PATCH 3/8] qemu: agent: implement qemuAgentGetMemblocks

Zhang Bo oscar.zhangbo at huawei.com
Tue Jun 9 09:33:27 UTC 2015


implement function qemuAgentGetMemblocks().
behaviour example:
input: '{"execute":"guest-get-memory-blocks"}'
output:
{
    "return": [
        {
            "can-offline": false,
            "online": true,
            "phys-index": 0
        },
        {
            "can-offline": false,
            "online": true,
            "phys-index": 1
        },
..........
    ]
}
please refer to
http://git.qemu.org/?p=qemu.git;a=log;h=0dd38a03f5e1498aabf7d053a9fab792a5eeec5c
for more information.

Signed-off-by: Zhang Bo <oscar.zhangbo at huawei.com>
Signed-off-by: Li Bin <binlibin.li at huawei.com>
---
 src/qemu/qemu_agent.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_agent.h |  1 +
 2 files changed, 74 insertions(+)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 043695b..95daf7a 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1654,6 +1654,79 @@ qemuAgentUpdateCPUInfo(unsigned int nvcpus,
     return 0;
 }
 
+int
+qemuAgentGetMemblocks(qemuAgentPtr mon,
+                      qemuAgentMemblockInfoPtr *info)
+{
+    int ret = -1;
+    size_t i;
+    virJSONValuePtr cmd = NULL;
+    virJSONValuePtr reply = NULL;
+    virJSONValuePtr data = NULL;
+    int ndata;
+
+    if (!(cmd = qemuAgentMakeCommand("guest-get-memory-blocks", NULL)))
+        return -1;
+
+    if (qemuAgentCommand(mon, cmd, &reply, true,
+                         VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
+        goto cleanup;
+
+    if (!(data = virJSONValueObjectGet(reply, "return"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("guest-get-memory-blocks reply was missing return data"));
+        goto cleanup;
+    }
+
+    if (data->type != VIR_JSON_TYPE_ARRAY) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("guest-get-memory-blocks return information was not an array"));
+        goto cleanup;
+    }
+
+    ndata = virJSONValueArraySize(data);
+
+    if (VIR_ALLOC_N(*info, ndata) < 0)
+        goto cleanup;
+
+    for (i = 0; i < ndata; i++) {
+        virJSONValuePtr entry = virJSONValueArrayGet(data, i);
+        qemuAgentMemblockInfoPtr in = *info + i;
+
+        if (!entry) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("array element missing in guest-get-memory-blocks return "
+                             "value"));
+            goto cleanup;
+        }
+
+        if (virJSONValueObjectGetNumberUint(entry, "phys-index", &in->id) < 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("'phys-index' missing in reply of guest-get-memory-blocks"));
+            goto cleanup;
+        }
+
+        if (virJSONValueObjectGetBoolean(entry, "online", &in->online) < 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("'online' missing in reply of guest-get-memory-blocks"));
+            goto cleanup;
+        }
+
+        if (virJSONValueObjectGetBoolean(entry, "can-offline",
+                                         &in->offlinable) < 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("'can-offline' missing in reply of guest-get-memory-blocks"));
+            goto cleanup;
+        }
+    }
+
+    ret = ndata;
+
+ cleanup:
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
 
 int
 qemuAgentGetTime(qemuAgentPtr mon,
diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h
index 425ee87..61ba038 100644
--- a/src/qemu/qemu_agent.h
+++ b/src/qemu/qemu_agent.h
@@ -111,6 +111,7 @@ struct _qemuAgentMemblockInfo {
     bool offlinable;    /* true if the MEMORY BLOCK can be offlined */
 };
 
+int qemuAgentGetMemblocks(qemuAgentPtr mon, qemuAgentMemblockInfoPtr *info);
 
 int qemuAgentGetTime(qemuAgentPtr mon,
                      long long *seconds,
-- 
1.7.12.4





More information about the libvir-list mailing list