[PATCH 04/11] qemu: monitor: Move processing of QMP schema to the new file

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

 



The JSON array was processed to the hash table used by the query apis in
the monitor code. Move it to a new helper in qemu_qapi.c.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c |  9 ++++++--
 src/qemu/qemu_monitor.c      |  2 +-
 src/qemu/qemu_monitor.h      |  2 +-
 src/qemu/qemu_monitor_json.c | 41 +++++-------------------------------
 src/qemu/qemu_monitor_json.h |  2 +-
 src/qemu/qemu_qapi.c         | 50 ++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_qapi.h         |  4 ++++
 7 files changed, 69 insertions(+), 41 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index a6170c66f2..16f7c7d6c9 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4570,12 +4570,17 @@ virQEMUCapsProbeQMPSchemaCapabilities(virQEMUCapsPtr qemuCaps,
                                       qemuMonitorPtr mon)
 {
     struct virQEMUCapsStringFlags *entry;
-    virHashTablePtr schema;
+    virJSONValuePtr schemareply;
+    virHashTablePtr schema = NULL;
     size_t i;

-    if (!(schema = qemuMonitorQueryQMPSchema(mon)))
+    if (!(schemareply = qemuMonitorQueryQMPSchema(mon)))
         return -1;

+    if (!(schema = virQEMUQapiSchemaConvert(schemareply)))
+        return -1;
+    schemareply = NULL;
+
     for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsQMPSchemaQueries); i++) {
         entry = virQEMUCapsQMPSchemaQueries + i;

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 1d67a97789..e169553b7e 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4316,7 +4316,7 @@ qemuMonitorGetRTCTime(qemuMonitorPtr mon,
 }


-virHashTablePtr
+virJSONValuePtr
 qemuMonitorQueryQMPSchema(qemuMonitorPtr mon)
 {
     QEMU_CHECK_MONITOR_JSON_NULL(mon);
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index adfa87aba9..7a22323504 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1175,7 +1175,7 @@ int qemuMonitorMigrateContinue(qemuMonitorPtr mon,
 int qemuMonitorGetRTCTime(qemuMonitorPtr mon,
                           struct tm *tm);

-virHashTablePtr qemuMonitorQueryQMPSchema(qemuMonitorPtr mon);
+virJSONValuePtr qemuMonitorQueryQMPSchema(qemuMonitorPtr mon);

 int qemuMonitorSetBlockThreshold(qemuMonitorPtr mon,
                                  const char *nodename,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 08dfffdf64..d80c4f18d1 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -7776,35 +7776,12 @@ qemuMonitorJSONGetHotpluggableCPUs(qemuMonitorPtr mon,
 }


-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;
-}
-
-
-virHashTablePtr
+virJSONValuePtr
 qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)
 {
     virJSONValuePtr cmd;
     virJSONValuePtr reply = NULL;
-    virJSONValuePtr arr;
-    virHashTablePtr schema = NULL;
-    virHashTablePtr ret = NULL;
+    virJSONValuePtr ret = NULL;

     if (!(cmd = qemuMonitorJSONMakeCommand("query-qmp-schema", NULL)))
         return NULL;
@@ -7815,21 +7792,13 @@ qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)
     if (qemuMonitorJSONCheckError(cmd, reply) < 0)
         goto cleanup;

-    arr = virJSONValueObjectGet(reply, "return");
-
-    if (!(schema = virHashCreate(512, virJSONValueHashFree)))
-        goto cleanup;
-
-    if (virJSONValueArrayForeachSteal(arr, qemuMonitorJSONFillQMPSchema,
-                                      schema) < 0)
-        goto cleanup;
-
-    VIR_STEAL_PTR(ret, schema);
+    if (!(ret = virJSONValueObjectStealArray(reply, "return")))
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("query-qmp-schema reply is not an array"));

  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 ec243becc4..846d366b27 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -516,7 +516,7 @@ int qemuMonitorJSONGetHotpluggableCPUs(qemuMonitorPtr mon,
                                        size_t *nentries)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);

-virHashTablePtr qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)
+virJSONValuePtr qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)
     ATTRIBUTE_NONNULL(1);

 int qemuMonitorJSONSetBlockThreshold(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_qapi.c b/src/qemu/qemu_qapi.c
index 0a18764ac1..e63896397f 100644
--- a/src/qemu/qemu_qapi.c
+++ b/src/qemu/qemu_qapi.c
@@ -185,3 +185,53 @@ virQEMUQapiSchemaPathExists(const char *query,

     return !!entry;
 }
+
+static int
+virQEMUQapiSchemaEntryProcess(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;
+}
+
+
+/**
+ * virQEMUQapiSchemaConvert:
+ * @schemareply: Schema data as returned by the qemu monitor
+ *
+ * Converts the schema into the hash-table used by the functions working with
+ * the schema. @schemareply is consumed and freed.
+ */
+virHashTablePtr
+virQEMUQapiSchemaConvert(virJSONValuePtr schemareply)
+{
+    virHashTablePtr schema;
+    virHashTablePtr ret = NULL;
+
+    if (!(schema = virHashCreate(512, virJSONValueHashFree)))
+        goto cleanup;
+
+    if (virJSONValueArrayForeachSteal(schemareply,
+                                      virQEMUQapiSchemaEntryProcess,
+                                      schema) < 0)
+        goto cleanup;
+
+    VIR_STEAL_PTR(ret, schema);
+
+ cleanup:
+    virJSONValueFree(schemareply);
+    virHashFree(schema);
+    return ret;
+}
diff --git a/src/qemu/qemu_qapi.h b/src/qemu/qemu_qapi.h
index 7b5546eefe..b0a68bec12 100644
--- a/src/qemu/qemu_qapi.h
+++ b/src/qemu/qemu_qapi.h
@@ -33,4 +33,8 @@ bool
 virQEMUQapiSchemaPathExists(const char *query,
                             virHashTablePtr schema);

+virHashTablePtr
+virQEMUQapiSchemaConvert(virJSONValuePtr schemareply);
+
+
 #endif /* __QEMU_QAPI_H__ */
-- 
2.16.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]

  Powered by Linux