From: "Daniel P. Berrange" <berrange@xxxxxxxxxx> Add a new qemuMonitorGetTargetArch() method to support invocation of the 'query-target' JSON monitor command. No HMP equivalent is required, since this will only be present for QEMU >= 1.2 Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx> --- src/qemu/qemu_monitor.c | 21 +++++++++++++++++++++ src/qemu/qemu_monitor.h | 2 +- src/qemu/qemu_monitor_json.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 1 + 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 27aa625..f45a225 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3165,3 +3165,24 @@ int qemuMonitorGetObjectProps(qemuMonitorPtr mon, return qemuMonitorJSONGetObjectProps(mon, type, props); } + + +char *qemuMonitorGetTargetArch(qemuMonitorPtr mon) +{ + VIR_DEBUG("mon=%p", + mon); + + if (!mon) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("monitor must not be NULL")); + return NULL; + } + + if (!mon->json) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("JSON monitor is required")); + return NULL; + } + + return qemuMonitorJSONGetTargetArch(mon); +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 8307a52..8453e44 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -613,7 +613,7 @@ int qemuMonitorGetObjectTypes(qemuMonitorPtr mon, int qemuMonitorGetObjectProps(qemuMonitorPtr mon, const char *type, char ***props); - +char *qemuMonitorGetTargetArch(qemuMonitorPtr mon); /** * When running two dd process and using <> redirection, we need a diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 823cffd..6a1c507 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4332,3 +4332,48 @@ cleanup: virJSONValueFree(reply); return ret; } + + +char * +qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon) +{ + char *ret = NULL; + int rv; + const char *arch; + virJSONValuePtr cmd; + virJSONValuePtr reply = NULL; + virJSONValuePtr data; + + if (!(cmd = qemuMonitorJSONMakeCommand("query-target", NULL))) + return NULL; + + rv = qemuMonitorJSONCommand(mon, cmd, &reply); + + if (rv == 0) + rv = qemuMonitorJSONCheckError(cmd, reply); + + if (rv < 0) + goto cleanup; + + if (!(data = virJSONValueObjectGet(reply, "return"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("query-status reply was missing return data")); + goto cleanup; + } + + if (!(arch = virJSONValueObjectGetString(data, "arch"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("query-status reply was missing arch data")); + goto cleanup; + } + + if (!(ret = strdup(arch))) { + virReportOOMError(); + goto cleanup; + } + +cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 9e81284..6fc3ce7 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -312,5 +312,6 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon, const char *type, char ***props) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); +char *qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon); #endif /* QEMU_MONITOR_JSON_H */ -- 1.7.11.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list