On Tue, Oct 20, 2026 at 00:15:00 -0400, Rorie Reyes wrote:
> Replace the char **result output parameter with a virCPUCompareResult
> return value in qemuMonitorJSONGetCPUModelComparison() and its public
> wrapper qemuMonitorGetCPUModelComparison(). Move the result string to
> enum mapping (identical/superset/subset/incompatible) into the monitor
> layer and remove it from qemuConnectCPUModelComparison() in
> qemu_driver.c. Unknown result strings are reported as errors.
>
> The existing unit test is updated to use the new return value and
> extended with cases for all four result strings (identical, superset,
> subset, incompatible).
>
> Signed-off-by: Rorie Reyes <[email protected]>
> ---
> src/qemu/qemu_driver.c | 16 ++++-----
> src/qemu/qemu_monitor.c | 9 +++--
> src/qemu/qemu_monitor.h | 5 ++-
> src/qemu/qemu_monitor_json.c | 34 +++++++++++-------
> src/qemu/qemu_monitor_json.h | 5 ++-
> tests/qemumonitorjsontest.c | 67 +++++++++++++++++++++++++++++-------
> 6 files changed, 90 insertions(+), 46 deletions(-)
>
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 5922065897..2500b6fb50 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -12128,7 +12128,7 @@ qemuConnectCPUModelComparison(virQEMUCaps *qemuCaps,
> bool failIncompatible)
> {
> g_autoptr(qemuProcessQMP) proc = NULL;
> - g_autofree char *result = NULL;
> + virCPUCompareResult result;
>
> if (!(proc = qemuProcessQMPNew(virQEMUCapsGetBinary(qemuCaps),
> libDir, runUid, runGid, false)))
> @@ -12137,21 +12137,17 @@ qemuConnectCPUModelComparison(virQEMUCaps *qemuCaps,
> if (qemuProcessQMPStart(proc) < 0)
> return VIR_CPU_COMPARE_ERROR;
>
> - if (qemuMonitorGetCPUModelComparison(proc->mon, cpu_a, cpu_b, &result) <
> 0)
> - return VIR_CPU_COMPARE_ERROR;
> -
> - if (STREQ(result, "identical"))
> - return VIR_CPU_COMPARE_IDENTICAL;
> + result = qemuMonitorGetCPUModelComparison(proc->mon, cpu_a, cpu_b);
>
> - if (STREQ(result, "superset"))
> - return VIR_CPU_COMPARE_SUPERSET;
> + if (result == VIR_CPU_COMPARE_ERROR)
> + return VIR_CPU_COMPARE_ERROR;
This check is quite redundant here as we mostly just return the result
directly. The only exception is covered by the following if statement:
>
> - if (failIncompatible) {
> + if (failIncompatible && result == VIR_CPU_COMPARE_INCOMPATIBLE) {
> virReportError(VIR_ERR_CPU_INCOMPATIBLE, NULL);
> return VIR_CPU_COMPARE_ERROR;
> }
>
> - return VIR_CPU_COMPARE_INCOMPATIBLE;
> + return result;
> }
>
>
Reviewed-by: Jiri Denemark <[email protected]>