]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: monitor: Implement new handlers for 'query-command-line-options'
authorPeter Krempa <pkrempa@redhat.com>
Mon, 30 Nov 2020 16:54:25 +0000 (17:54 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 2 Dec 2020 08:14:28 +0000 (09:14 +0100)
Add a new set hander for getting the data for
'query-command-line-options' which returns everything at once and lets
the caller extract the data. This way we don't need to cache the output
of the monitor command for repeated calls.

Note that we will have enough testing of this code path via
qemucapabilitiestest.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h

index f2ed165b227fb56811871ff9835106e5c267fb6d..a60d04f78a28e1a2b875665c5646d0c7664e4186 100644 (file)
@@ -3873,6 +3873,15 @@ qemuMonitorGetCommandLineOptionParameters(qemuMonitorPtr mon,
 }
 
 
+GHashTable *
+qemuMonitorGetCommandLineOptions(qemuMonitorPtr mon)
+{
+    QEMU_CHECK_MONITOR_NULL(mon);
+
+    return qemuMonitorJSONGetCommandLineOptions(mon);
+}
+
+
 int
 qemuMonitorGetKVMState(qemuMonitorPtr mon,
                        bool *enabled,
index d301568e407f1c735f182b6f1eb48e97c2f3061e..6b2e435f709fd4c7c6fef2921a3c782bd9d4d276 100644 (file)
@@ -1288,6 +1288,7 @@ int qemuMonitorGetCommandLineOptionParameters(qemuMonitorPtr mon,
                                               const char *option,
                                               char ***params,
                                               bool *found);
+GHashTable *qemuMonitorGetCommandLineOptions(qemuMonitorPtr mon);
 
 int qemuMonitorGetKVMState(qemuMonitorPtr mon,
                            bool *enabled,
index 49751570a5003d2d433718d6aaf921b411b593f6..92701974e4ebaa332d317bdc66633104fae84922 100644 (file)
@@ -6378,6 +6378,54 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon,
 }
 
 
+static int
+qemuMonitorJSONGetCommandLineOptionsWorker(size_t pos G_GNUC_UNUSED,
+                                           virJSONValuePtr item,
+                                           void *opaque)
+{
+    const char *name = virJSONValueObjectGetString(item, "option");
+    g_autoptr(virJSONValue) parameters = NULL;
+    GHashTable *options = opaque;
+
+    if (!name ||
+        virJSONValueObjectRemoveKey(item, "parameters", &parameters) <= 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("reply data was missing 'option' name or parameters"));
+        return -1;
+    }
+
+    g_hash_table_insert(options, g_strdup(name), parameters);
+    parameters = NULL;
+
+    return 0;
+}
+
+
+GHashTable *
+qemuMonitorJSONGetCommandLineOptions(qemuMonitorPtr mon)
+{
+    g_autoptr(GHashTable) ret = virHashNew(virJSONValueHashFree);
+    g_autoptr(virJSONValue) cmd = NULL;
+    g_autoptr(virJSONValue) reply = NULL;
+
+    if (!(cmd = qemuMonitorJSONMakeCommand("query-command-line-options", NULL)))
+        return NULL;
+
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        return NULL;
+
+    if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
+        return NULL;
+
+    if (virJSONValueArrayForeachSteal(virJSONValueObjectGetArray(reply, "return"),
+                                      qemuMonitorJSONGetCommandLineOptionsWorker,
+                                      ret) < 0)
+        return NULL;
+
+    return g_steal_pointer(&ret);
+}
+
+
 int
 qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon,
                                               const char *option,
index b588722d90544353d21649082f9893a2a04bb8d2..53445b97bb14228f775e90caec0cb00975d37463 100644 (file)
@@ -430,6 +430,7 @@ int qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon,
                                                   char ***params,
                                                   bool *found)
     ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
+GHashTable *qemuMonitorJSONGetCommandLineOptions(qemuMonitorPtr mon);
 
 int qemuMonitorJSONGetKVMState(qemuMonitorPtr mon,
                                bool *enabled,