qemu: Do not hardcode Hyper-V feature names on command line

When constructing the command line for QEMU, some Hyper-V features were
hardcoded, probably due to the fact that they could not have been
automatically translated from the libvirt feature name to QEMU CPU
feature name.

Well now they can be, thanks to their additions to the
virQEMUCapsCPUFeaturesX86 translation table.

Translate all such features the same way when constructing the command
line.  This way any future feature that is not translated will be caught
by tests (if a test is added for it) which was not the case when it was
just hardcoded.  Hopefully this avoids at least some possible future
issues.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Martin Kletzander 2024-10-16 14:31:50 +02:00
parent ca8c0862ac
commit f7c89763b1

View File

@ -6315,9 +6315,15 @@ qemuBuildCpuCommandLine(virCommand *cmd,
case VIR_DOMAIN_HYPERV_IPI: case VIR_DOMAIN_HYPERV_IPI:
case VIR_DOMAIN_HYPERV_EVMCS: case VIR_DOMAIN_HYPERV_EVMCS:
case VIR_DOMAIN_HYPERV_AVIC: case VIR_DOMAIN_HYPERV_AVIC:
if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON) case VIR_DOMAIN_HYPERV_EMSR_BITMAP:
virBufferAsprintf(&buf, ",hv-%s=on", case VIR_DOMAIN_HYPERV_XMM_INPUT:
virDomainHypervTypeToString(i)); if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON) {
const char *name = virDomainHypervTypeToString(i);
g_autofree char *full_name = g_strdup_printf("hv-%s", name);
const char *qemu_name = virQEMUCapsCPUFeatureToQEMU(def->os.arch,
full_name);
virBufferAsprintf(&buf, ",%s=on", qemu_name);
}
if ((i == VIR_DOMAIN_HYPERV_STIMER) && if ((i == VIR_DOMAIN_HYPERV_STIMER) &&
(def->hyperv_stimer_direct == VIR_TRISTATE_SWITCH_ON)) (def->hyperv_stimer_direct == VIR_TRISTATE_SWITCH_ON))
virBufferAsprintf(&buf, ",%s=on", VIR_CPU_x86_HV_STIMER_DIRECT); virBufferAsprintf(&buf, ",%s=on", VIR_CPU_x86_HV_STIMER_DIRECT);
@ -6336,16 +6342,6 @@ qemuBuildCpuCommandLine(virCommand *cmd,
def->hyperv_vendor_id); def->hyperv_vendor_id);
break; break;
case VIR_DOMAIN_HYPERV_EMSR_BITMAP:
if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON)
virBufferAsprintf(&buf, ",%s=on", "hv-emsr-bitmap");
break;
case VIR_DOMAIN_HYPERV_XMM_INPUT:
if (def->hyperv_features[i] == VIR_TRISTATE_SWITCH_ON)
virBufferAsprintf(&buf, ",%s=on", "hv-xmm-input");
break;
case VIR_DOMAIN_HYPERV_LAST: case VIR_DOMAIN_HYPERV_LAST:
break; break;
} }