[PATCH v2 02/15] qemu: monitor: Add code to retrieve and store QMP schema data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Call 'query-qmp-schema' and store the returned types in a hash table
keyed by the 'name' field so that the capabilities code can traverse it.
---
 src/qemu/qemu_monitor.c      | 11 ++++++++
 src/qemu/qemu_monitor.h      |  2 ++
 src/qemu/qemu_monitor_json.c | 67 ++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |  3 ++
 4 files changed, 83 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index a5e14b2..0bfc1a8 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4033,3 +4033,14 @@ qemuMonitorGetRTCTime(qemuMonitorPtr mon,

     return qemuMonitorJSONGetRTCTime(mon, tm);
 }
+
+
+virHashTablePtr
+qemuMonitorQueryQMPSchema(qemuMonitorPtr mon)
+{
+    VIR_DEBUG("mon=%p", mon);
+
+    QEMU_CHECK_MONITOR_JSON_NULL(mon);
+
+    return qemuMonitorJSONQueryQMPSchema(mon);
+}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index c3133c4..a0e5075 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1008,4 +1008,6 @@ int qemuMonitorMigrateStartPostCopy(qemuMonitorPtr mon);
 int qemuMonitorGetRTCTime(qemuMonitorPtr mon,
                           struct tm *tm);

+virHashTablePtr qemuMonitorQueryQMPSchema(qemuMonitorPtr mon);
+
 #endif /* QEMU_MONITOR_H */
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 6c13832..9e06a4d 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -7278,3 +7278,70 @@ qemuMonitorJSONGetHotpluggableCPUs(qemuMonitorPtr mon,
     virJSONValueFree(reply);
     return ret;
 }
+
+
+static int
+qemuMonitorJSONFillQMPSchema(size_t pos ATTRIBUTE_UNUSED,
+                             virJSONValuePtr item,
+                             void *opaque)
+{
+    const char *name;
+    virHashTablePtr schema = opaque;
+
+    if (!(name = virJSONValueObjectGetString(item, "name"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("malformed QMP schema"));
+        return -1;
+    }
+
+    if (virHashAddEntry(schema, name, item) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+static void
+qemuMonitorJSONFreeSchemaEntry(void *opaque,
+                               const void *name ATTRIBUTE_UNUSED)
+{
+    virJSONValueFree(opaque);
+}
+
+
+virHashTablePtr
+qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)
+{
+    virJSONValuePtr cmd;
+    virJSONValuePtr reply = NULL;
+    virJSONValuePtr arr;
+    virHashTablePtr schema = NULL;
+    virHashTablePtr ret = NULL;
+
+    if (!(cmd = qemuMonitorJSONMakeCommand("query-qmp-schema", NULL)))
+        return NULL;
+
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        goto cleanup;
+
+    if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+        goto cleanup;
+
+    arr = virJSONValueObjectGet(reply, "return");
+
+    if (!(schema = virHashCreate(512, qemuMonitorJSONFreeSchemaEntry)))
+        goto cleanup;
+
+    if (virJSONValueArrayForeachSteal(arr, qemuMonitorJSONFillQMPSchema,
+                                      schema) < 0)
+        goto cleanup;
+
+    VIR_STEAL_PTR(ret, schema);
+
+ cleanup:
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    virHashFree(schema);
+
+    return ret;
+}
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 77b2e02..4780d53 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -500,4 +500,7 @@ int qemuMonitorJSONGetHotpluggableCPUs(qemuMonitorPtr mon,
                                        struct qemuMonitorQueryHotpluggableCpusEntry **entries,
                                        size_t *nentries)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
+
+virHashTablePtr qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)
+    ATTRIBUTE_NONNULL(1);
 #endif /* QEMU_MONITOR_JSON_H */
-- 
2.10.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]