1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-04-01 20:05:19 +00:00

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 <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2020-11-30 17:54:25 +01:00
parent 5dc28cc378
commit ebeff6cd57
4 changed files with 59 additions and 0 deletions

@ -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,

@ -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,

@ -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,

@ -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,