qemuAgentGetMemblockGeneralInfo() is implememted, according to the qga command 'guest-get-memory-block-info'. the difference between this command and 'guest-get-memory-blocks' is that the latter one gets a list of infos for each memory block, and this command just returns general attributes for the guest memory blocks. Signed-off-by: Zhang Bo <oscar.zhangbo@xxxxxxxxxx> Signed-off-by: Li Bin <binlibin.li@xxxxxxxxxx> --- src/qemu/qemu_agent.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- src/qemu/qemu_agent.h | 7 +++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 95daf7a..3481354 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1700,7 +1700,7 @@ qemuAgentGetMemblocks(qemuAgentPtr mon, goto cleanup; } - if (virJSONValueObjectGetNumberUint(entry, "phys-index", &in->id) < 0) { + if (virJSONValueObjectGetNumberUlong(entry, "phys-index", &in->id) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("'phys-index' missing in reply of guest-get-memory-blocks")); goto cleanup; @@ -1729,6 +1729,54 @@ qemuAgentGetMemblocks(qemuAgentPtr mon, } int +qemuAgentGetMemblockGeneralInfo(qemuAgentPtr mon, + qemuAgentMemblockGeneralInfoPtr info) +{ + int ret = -1; + unsigned long long json_size = 0; + virJSONValuePtr cmd = NULL; + virJSONValuePtr reply = NULL; + virJSONValuePtr data = NULL; + + if (!info) { + VIR_ERROR(_("NULL info")); + return ret; + } + + cmd = qemuAgentMakeCommand("guest-get-memory-block-info", + NULL); + if (!cmd) + return ret; + + 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-block-info reply was missing return data")); + goto cleanup; + } + + if (virJSONValueObjectGetNumberUlong(data, "size", &json_size) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("'size' missing in reply of guest-get-memory-block-info")); + goto cleanup; + } + + /* guest agent returns the size in Bytes, + * we change it into MB here */ + info->blockSize = json_size >> 20; + ret = 0; + + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} + + +int qemuAgentGetTime(qemuAgentPtr mon, long long *seconds, unsigned int *nseconds) diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h index 61ba038..9a9b859 100644 --- a/src/qemu/qemu_agent.h +++ b/src/qemu/qemu_agent.h @@ -111,7 +111,14 @@ struct _qemuAgentMemblockInfo { bool offlinable; /* true if the MEMORY BLOCK can be offlined */ }; +typedef struct _qemuAgentMemblockGeneralInfo qemuAgentMemblockGeneralInfo; +typedef qemuAgentMemblockGeneralInfo *qemuAgentMemblockGeneralInfoPtr; +struct _qemuAgentMemblockGeneralInfo { + unsigned long long blockSize; +}; + int qemuAgentGetMemblocks(qemuAgentPtr mon, qemuAgentMemblockInfoPtr *info); +int qemuAgentGetMemblockGeneralInfo(qemuAgentPtr mon, qemuAgentMemblockGeneralInfoPtr info); int qemuAgentGetTime(qemuAgentPtr mon, long long *seconds, -- 1.7.12.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list