|
|
edecca |
From 968116c9fb74569a6ea61e7eef6a87b6e766a61b Mon Sep 17 00:00:00 2001
|
|
|
edecca |
Message-Id: <968116c9fb74569a6ea61e7eef6a87b6e766a61b@dist-git>
|
|
|
edecca |
From: Michal Privoznik <mprivozn@redhat.com>
|
|
|
edecca |
Date: Wed, 11 Jul 2018 17:27:27 +0200
|
|
|
edecca |
Subject: [PATCH] qemu_monitor: Introduce qemuMonitorJSONGetPRManagerInfo
|
|
|
edecca |
MIME-Version: 1.0
|
|
|
edecca |
Content-Type: text/plain; charset=UTF-8
|
|
|
edecca |
Content-Transfer-Encoding: 8bit
|
|
|
edecca |
|
|
|
edecca |
https://bugzilla.redhat.com/show_bug.cgi?id=1470007
|
|
|
edecca |
|
|
|
edecca |
This function fetches status of all pr-managers. So far, qemu
|
|
|
edecca |
reports only a single attribute "connected" but that fits our
|
|
|
edecca |
needs.
|
|
|
edecca |
|
|
|
edecca |
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
edecca |
(cherry picked from commit 5f085862e87668e77333cc369bf66ff3b6c19ae8)
|
|
|
edecca |
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
edecca |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
edecca |
---
|
|
|
edecca |
src/qemu/qemu_monitor.c | 25 ++++++++++++
|
|
|
edecca |
src/qemu/qemu_monitor.h | 9 ++++
|
|
|
edecca |
src/qemu/qemu_monitor_json.c | 79 ++++++++++++++++++++++++++++++++++++
|
|
|
edecca |
src/qemu/qemu_monitor_json.h | 4 ++
|
|
|
edecca |
4 files changed, 117 insertions(+)
|
|
|
edecca |
|
|
|
edecca |
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
|
|
|
edecca |
index 86b2b6e985..bc116e4e2d 100644
|
|
|
edecca |
--- a/src/qemu/qemu_monitor.c
|
|
|
edecca |
+++ b/src/qemu/qemu_monitor.c
|
|
|
edecca |
@@ -4346,3 +4346,28 @@ qemuMonitorGetSEVMeasurement(qemuMonitorPtr mon)
|
|
|
edecca |
|
|
|
edecca |
return qemuMonitorJSONGetSEVMeasurement(mon);
|
|
|
edecca |
}
|
|
|
edecca |
+
|
|
|
edecca |
+
|
|
|
edecca |
+int
|
|
|
edecca |
+qemuMonitorGetPRManagerInfo(qemuMonitorPtr mon,
|
|
|
edecca |
+ virHashTablePtr *retinfo)
|
|
|
edecca |
+{
|
|
|
edecca |
+ int ret = -1;
|
|
|
edecca |
+ virHashTablePtr info = NULL;
|
|
|
edecca |
+
|
|
|
edecca |
+ *retinfo = NULL;
|
|
|
edecca |
+
|
|
|
edecca |
+ QEMU_CHECK_MONITOR(mon);
|
|
|
edecca |
+
|
|
|
edecca |
+ if (!(info = virHashCreate(10, virHashValueFree)))
|
|
|
edecca |
+ goto cleanup;
|
|
|
edecca |
+
|
|
|
edecca |
+ if (qemuMonitorJSONGetPRManagerInfo(mon, info) < 0)
|
|
|
edecca |
+ goto cleanup;
|
|
|
edecca |
+
|
|
|
edecca |
+ VIR_STEAL_PTR(*retinfo, info);
|
|
|
edecca |
+ ret = 0;
|
|
|
edecca |
+ cleanup:
|
|
|
edecca |
+ virHashFree(info);
|
|
|
edecca |
+ return ret;
|
|
|
edecca |
+}
|
|
|
edecca |
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
|
|
|
edecca |
index a906bc8410..e8ed2d044c 100644
|
|
|
edecca |
--- a/src/qemu/qemu_monitor.h
|
|
|
edecca |
+++ b/src/qemu/qemu_monitor.h
|
|
|
edecca |
@@ -1157,4 +1157,13 @@ int qemuMonitorBlockdevDel(qemuMonitorPtr mon,
|
|
|
edecca |
char *
|
|
|
edecca |
qemuMonitorGetSEVMeasurement(qemuMonitorPtr mon);
|
|
|
edecca |
|
|
|
edecca |
+typedef struct _qemuMonitorPRManagerInfo qemuMonitorPRManagerInfo;
|
|
|
edecca |
+typedef qemuMonitorPRManagerInfo *qemuMonitorPRManagerInfoPtr;
|
|
|
edecca |
+struct _qemuMonitorPRManagerInfo {
|
|
|
edecca |
+ bool connected;
|
|
|
edecca |
+};
|
|
|
edecca |
+
|
|
|
edecca |
+int qemuMonitorGetPRManagerInfo(qemuMonitorPtr mon,
|
|
|
edecca |
+ virHashTablePtr *retinfo);
|
|
|
edecca |
+
|
|
|
edecca |
#endif /* QEMU_MONITOR_H */
|
|
|
edecca |
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
|
|
|
edecca |
index 03c94cd88b..66c525ed0c 100644
|
|
|
edecca |
--- a/src/qemu/qemu_monitor_json.c
|
|
|
edecca |
+++ b/src/qemu/qemu_monitor_json.c
|
|
|
edecca |
@@ -8065,3 +8065,82 @@ qemuMonitorJSONGetSEVMeasurement(qemuMonitorPtr mon)
|
|
|
edecca |
virJSONValueFree(reply);
|
|
|
edecca |
return measurement;
|
|
|
edecca |
}
|
|
|
edecca |
+
|
|
|
edecca |
+
|
|
|
edecca |
+/*
|
|
|
edecca |
+ * Example return data
|
|
|
edecca |
+ *
|
|
|
edecca |
+ * "return": [
|
|
|
edecca |
+ * { "connected": true, "id": "pr-helper0" }
|
|
|
edecca |
+ * ]
|
|
|
edecca |
+ */
|
|
|
edecca |
+static int
|
|
|
edecca |
+qemuMonitorJSONExtractPRManagerInfo(virJSONValuePtr reply,
|
|
|
edecca |
+ virHashTablePtr info)
|
|
|
edecca |
+{
|
|
|
edecca |
+ qemuMonitorPRManagerInfoPtr entry = NULL;
|
|
|
edecca |
+ virJSONValuePtr data;
|
|
|
edecca |
+ int ret = -1;
|
|
|
edecca |
+ size_t i;
|
|
|
edecca |
+
|
|
|
edecca |
+ data = virJSONValueObjectGetArray(reply, "return");
|
|
|
edecca |
+
|
|
|
edecca |
+ for (i = 0; i < virJSONValueArraySize(data); i++) {
|
|
|
edecca |
+ virJSONValuePtr prManager = virJSONValueArrayGet(data, i);
|
|
|
edecca |
+ const char *alias;
|
|
|
edecca |
+
|
|
|
edecca |
+ if (!(alias = virJSONValueObjectGetString(prManager, "id")))
|
|
|
edecca |
+ goto malformed;
|
|
|
edecca |
+
|
|
|
edecca |
+ if (VIR_ALLOC(entry) < 0)
|
|
|
edecca |
+ goto cleanup;
|
|
|
edecca |
+
|
|
|
edecca |
+ if (virJSONValueObjectGetBoolean(prManager,
|
|
|
edecca |
+ "connected",
|
|
|
edecca |
+ &entry->connected) < 0) {
|
|
|
edecca |
+ goto malformed;
|
|
|
edecca |
+ }
|
|
|
edecca |
+
|
|
|
edecca |
+ if (virHashAddEntry(info, alias, entry) < 0)
|
|
|
edecca |
+ goto cleanup;
|
|
|
edecca |
+
|
|
|
edecca |
+ entry = NULL;
|
|
|
edecca |
+ }
|
|
|
edecca |
+
|
|
|
edecca |
+ ret = 0;
|
|
|
edecca |
+ cleanup:
|
|
|
edecca |
+ VIR_FREE(entry);
|
|
|
edecca |
+ return ret;
|
|
|
edecca |
+
|
|
|
edecca |
+ malformed:
|
|
|
edecca |
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
edecca |
+ _("malformed prManager reply"));
|
|
|
edecca |
+ goto cleanup;
|
|
|
edecca |
+}
|
|
|
edecca |
+
|
|
|
edecca |
+
|
|
|
edecca |
+int
|
|
|
edecca |
+qemuMonitorJSONGetPRManagerInfo(qemuMonitorPtr mon,
|
|
|
edecca |
+ virHashTablePtr info)
|
|
|
edecca |
+{
|
|
|
edecca |
+ int ret = -1;
|
|
|
edecca |
+ virJSONValuePtr cmd;
|
|
|
edecca |
+ virJSONValuePtr reply = NULL;
|
|
|
edecca |
+
|
|
|
edecca |
+ if (!(cmd = qemuMonitorJSONMakeCommand("query-pr-managers",
|
|
|
edecca |
+ NULL)))
|
|
|
edecca |
+ return -1;
|
|
|
edecca |
+
|
|
|
edecca |
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
edecca |
+ goto cleanup;
|
|
|
edecca |
+
|
|
|
edecca |
+ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
|
|
|
edecca |
+ goto cleanup;
|
|
|
edecca |
+
|
|
|
edecca |
+ ret = qemuMonitorJSONExtractPRManagerInfo(reply, info);
|
|
|
edecca |
+ cleanup:
|
|
|
edecca |
+ virJSONValueFree(cmd);
|
|
|
edecca |
+ virJSONValueFree(reply);
|
|
|
edecca |
+ return ret;
|
|
|
edecca |
+
|
|
|
edecca |
+}
|
|
|
edecca |
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
|
|
|
edecca |
index 6bc0dd3ad2..66536ceb97 100644
|
|
|
edecca |
--- a/src/qemu/qemu_monitor_json.h
|
|
|
edecca |
+++ b/src/qemu/qemu_monitor_json.h
|
|
|
edecca |
@@ -550,4 +550,8 @@ int qemuMonitorJSONBlockdevDel(qemuMonitorPtr mon,
|
|
|
edecca |
const char *nodename)
|
|
|
edecca |
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
edecca |
|
|
|
edecca |
+int qemuMonitorJSONGetPRManagerInfo(qemuMonitorPtr mon,
|
|
|
edecca |
+ virHashTablePtr info)
|
|
|
edecca |
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
edecca |
+
|
|
|
edecca |
#endif /* QEMU_MONITOR_JSON_H */
|
|
|
edecca |
--
|
|
|
edecca |
2.18.0
|
|
|
edecca |
|