On Thu, Jul 05, 2018 at 09:44:37 +0200, Michal Privoznik wrote:
This function fetches status of all pr-managers. So far, qemu
reports only a single attribute "connected" but that fits our
needs.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_monitor.c | 25 +++++++++++++
src/qemu/qemu_monitor.h | 9 +++++
src/qemu/qemu_monitor_json.c | 83 ++++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 4 +++
4 files changed, 121 insertions(+)
[...]
diff --git a/src/qemu/qemu_monitor_json.c
b/src/qemu/qemu_monitor_json.c
index 03c94cd88b..291a505d5d 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8065,3 +8065,86 @@ qemuMonitorJSONGetSEVMeasurement(qemuMonitorPtr mon)
virJSONValueFree(reply);
return measurement;
}
+
+
+/*
+ * Example return data
+ *
+ * "return": [
+ * { "connected": true, "id": "pr-helper0" }
+ * ]}
You are missing the opening curly bracket, so you need to drop the
closing one too
+ *
+ */
+static int
+qemuMonitorJSONExtractPRManagerInfo(virJSONValuePtr reply,
+ virHashTablePtr info)
+{
+ qemuMonitorPRManagerInfoPtr entry = NULL;
+ virJSONValuePtr data;
+ int ret = -1;
+ size_t i;
+
+ data = virJSONValueObjectGetArray(reply, "return");
+
+ for (i = 0; i < virJSONValueArraySize(data); i++) {
+ virJSONValuePtr prManager = virJSONValueArrayGet(data, i);
+ const char *alias;
+
+ if (!prManager)
+ goto malformed;
This should be impossible.
+
+ if (!(alias = virJSONValueObjectGetString(prManager, "id")))
+ goto malformed;
+
+ if (VIR_ALLOC(entry) < 0)
+ goto cleanup;
+
+ if (virJSONValueObjectGetBoolean(prManager,
+ "connected",
+ &entry->connected) < 0) {
+ goto malformed;
+ }
+
+ if (virHashAddEntry(info, alias, entry) < 0)
+ goto cleanup;
+
+ entry = NULL;
+ }
+
+ ret = 0;
+ cleanup:
+ VIR_FREE(entry);
+ return ret;
+
+ malformed:
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("malformed prManager reply"));
+ goto cleanup;
+}
ACK