From ebeff6cd57d07c89d42e191ed0085a9dd89835c5 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 30 Nov 2020 17:54:25 +0100 Subject: [PATCH] qemu: monitor: Implement new handlers for 'query-command-line-options' 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 Reviewed-by: Michal Privoznik --- src/qemu/qemu_monitor.c | 9 +++++++ src/qemu/qemu_monitor.h | 1 + src/qemu/qemu_monitor_json.c | 48 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 1 + 4 files changed, 59 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index f2ed165b22..a60d04f78a 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -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, diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index d301568e40..6b2e435f70 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -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, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 49751570a5..92701974e4 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -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", ¶meters) <= 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, diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index b588722d90..53445b97bb 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -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,