On Tue, Sep 25, 2012 at 19:00:09 +0100, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange(a)redhat.com>
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(a)redhat.com>
---
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 6da4ecf..ca5380b 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3161,3 +3161,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 88ff15a..3e69f64 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -604,7 +604,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 bd4da23..70afd91 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -4322,3 +4322,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"));
s/query-status/query-target/
+ goto cleanup;
+ }
+
+ if (!(arch = virJSONValueObjectGetString(data, "arch"))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-status reply was missing arch data"));
s/query-status/query-target/
+ 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 16a3a8f..83773d2 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -309,5 +309,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 */
ACK with the two copy&paste issues fixed.
Jirka