virQEMUCapsProbeQMPCommandLine: Rewrite using qemuMonitorGetCommandLineOptions

Use the new handler to fetch the required data and do the extraction
locally without conversion to string list.

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 18:05:23 +01:00
parent ebeff6cd57
commit bf8bd93df0

View File

@ -3226,28 +3226,32 @@ static int
virQEMUCapsProbeQMPCommandLine(virQEMUCapsPtr qemuCaps, virQEMUCapsProbeQMPCommandLine(virQEMUCapsPtr qemuCaps,
qemuMonitorPtr mon) qemuMonitorPtr mon)
{ {
bool found = false; g_autoptr(GHashTable) options = NULL;
int nvalues; size_t i;
char **values;
size_t i, j;
for (i = 0; i < G_N_ELEMENTS(virQEMUCapsCommandLine); i++) { if (!(options = qemuMonitorGetCommandLineOptions(mon)))
if ((nvalues = qemuMonitorGetCommandLineOptionParameters(mon,
virQEMUCapsCommandLine[i].option,
&values,
&found)) < 0)
return -1; return -1;
if (found && !virQEMUCapsCommandLine[i].param) for (i = 0; i < G_N_ELEMENTS(virQEMUCapsCommandLine); i++) {
virQEMUCapsSet(qemuCaps, virQEMUCapsCommandLine[i].flag); virJSONValuePtr option = g_hash_table_lookup(options, virQEMUCapsCommandLine[i].option);
size_t j;
for (j = 0; j < nvalues; j++) { if (!option)
if (STREQ_NULLABLE(virQEMUCapsCommandLine[i].param, values[j])) { continue;
/* not looking for a specific argument */
if (!virQEMUCapsCommandLine[i].param) {
virQEMUCapsSet(qemuCaps, virQEMUCapsCommandLine[i].flag); virQEMUCapsSet(qemuCaps, virQEMUCapsCommandLine[i].flag);
break; continue;
} }
for (j = 0; j < virJSONValueArraySize(option); j++) {
virJSONValuePtr param = virJSONValueArrayGet(option, j);
const char *paramname = virJSONValueObjectGetString(param, "name");
if (STREQ_NULLABLE(virQEMUCapsCommandLine[i].param, paramname))
virQEMUCapsSet(qemuCaps, virQEMUCapsCommandLine[i].flag);
} }
g_strfreev(values);
} }
return 0; return 0;