From 7bc1db5a1d83dd5838b8c502d74c73aa7ecc8b13 Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Tue, 17 Jun 2014 13:41:16 +0200 Subject: [PATCH] qemu: allow qmp probing for cmdline options without params That can be lately achieved with by having .param == NULL in the virQEMUCapsCommandLineProps struct. Signed-off-by: Martin Kletzander --- src/qemu/qemu_capabilities.c | 10 ++++++++-- src/qemu/qemu_monitor.c | 6 ++++-- src/qemu/qemu_monitor.h | 3 ++- src/qemu/qemu_monitor_json.c | 8 +++++++- src/qemu/qemu_monitor_json.h | 3 ++- tests/qemumonitorjsontest.c | 20 +++++++++++++++++--- 6 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index c5fef53249..a8d4648379 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2429,6 +2429,7 @@ static int virQEMUCapsProbeQMPCommandLine(virQEMUCapsPtr qemuCaps, qemuMonitorPtr mon) { + bool found = false; int nvalues; char **values; size_t i, j; @@ -2436,10 +2437,15 @@ virQEMUCapsProbeQMPCommandLine(virQEMUCapsPtr qemuCaps, for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsCommandLine); i++) { if ((nvalues = qemuMonitorGetCommandLineOptionParameters(mon, virQEMUCapsCommandLine[i].option, - &values)) < 0) + &values, + &found)) < 0) return -1; + + if (found && !virQEMUCapsCommandLine[i].param) + virQEMUCapsSet(qemuCaps, virQEMUCapsCommandLine[i].flag); + for (j = 0; j < nvalues; j++) { - if (STREQ(virQEMUCapsCommandLine[i].param, values[j])) { + if (STREQ_NULLABLE(virQEMUCapsCommandLine[i].param, values[j])) { virQEMUCapsSet(qemuCaps, virQEMUCapsCommandLine[i].flag); break; } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index db3dd730bc..3d9f87b63f 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3659,7 +3659,8 @@ int qemuMonitorGetEvents(qemuMonitorPtr mon, int qemuMonitorGetCommandLineOptionParameters(qemuMonitorPtr mon, const char *option, - char ***params) + char ***params, + bool *found) { VIR_DEBUG("mon=%p option=%s params=%p", mon, option, params); @@ -3675,7 +3676,8 @@ qemuMonitorGetCommandLineOptionParameters(qemuMonitorPtr mon, return -1; } - return qemuMonitorJSONGetCommandLineOptionParameters(mon, option, params); + return qemuMonitorJSONGetCommandLineOptionParameters(mon, option, + params, found); } diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 8a23267c1c..c3695f2487 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -748,7 +748,8 @@ int qemuMonitorGetEvents(qemuMonitorPtr mon, char ***events); int qemuMonitorGetCommandLineOptionParameters(qemuMonitorPtr mon, const char *option, - char ***params); + char ***params, + bool *found); int qemuMonitorGetKVMState(qemuMonitorPtr mon, bool *enabled, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index bef6a14144..a62c02f14c 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4504,7 +4504,8 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon, int qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon, const char *option, - char ***params) + char ***params, + bool *found) { int ret; virJSONValuePtr cmd = NULL; @@ -4516,6 +4517,8 @@ qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon, size_t i; *params = NULL; + if (found) + *found = false; /* query-command-line-options has fixed output for a given qemu * binary; but since callers want to query parameters for one @@ -4576,6 +4579,9 @@ qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon, goto cleanup; } + if (found) + *found = true; + if ((n = virJSONValueArraySize(data)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-command-line-options parameter data was not " diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 385211c421..5f6c846e7c 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -332,7 +332,8 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon, ATTRIBUTE_NONNULL(2); int qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon, const char *option, - char ***params) + char ***params, + bool *found) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); int qemuMonitorJSONGetKVMState(qemuMonitorPtr mon, diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 6debe13d50..baee80a7ac 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -583,6 +583,7 @@ testQemuMonitorJSONGetCommandLineOptionParameters(const void *data) int ret = -1; char **params = NULL; int nparams = 0; + bool found = false; if (!test) return -1; @@ -604,7 +605,8 @@ testQemuMonitorJSONGetCommandLineOptionParameters(const void *data) /* present with params */ if ((nparams = qemuMonitorGetCommandLineOptionParameters(qemuMonitorTestGetMonitor(test), "option-rom", - ¶ms)) < 0) + ¶ms, + NULL)) < 0) goto cleanup; if (nparams != 2) { @@ -634,7 +636,8 @@ testQemuMonitorJSONGetCommandLineOptionParameters(const void *data) /* present but empty */ if ((nparams = qemuMonitorGetCommandLineOptionParameters(qemuMonitorTestGetMonitor(test), "acpi", - ¶ms)) < 0) + ¶ms, + &found)) < 0) goto cleanup; if (nparams != 0) { @@ -642,6 +645,11 @@ testQemuMonitorJSONGetCommandLineOptionParameters(const void *data) "nparams was %d, expected 0", nparams); goto cleanup; } + if (!found) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "found was false, expected true"); + goto cleanup; + } if (params && params[0]) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "unexpected array contents"); @@ -654,7 +662,8 @@ testQemuMonitorJSONGetCommandLineOptionParameters(const void *data) /* no such option */ if ((nparams = qemuMonitorGetCommandLineOptionParameters(qemuMonitorTestGetMonitor(test), "foobar", - ¶ms)) < 0) + ¶ms, + &found)) < 0) goto cleanup; if (nparams != 0) { @@ -662,6 +671,11 @@ testQemuMonitorJSONGetCommandLineOptionParameters(const void *data) "nparams was %d, expected 0", nparams); goto cleanup; } + if (found) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "found was true, expected false"); + goto cleanup; + } if (params && params[0]) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "unexpected array contents");