render / rpms / libvirt

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