qemu: Make virQEMUCapsProbeHostCPUForEmulator more generic

The function is renamed as virQEMUCapsProbeHostCPU and it does not get
the list of allowed CPU models from qemuCaps anymore. This is
responsibility is moved to the caller. The result is just a very thin
wrapper around virCPUGetHost mostly required mocking in tests.

The generic function is used in place of a direct call to virCPUGetHost
in virQEMUCapsInitHostCPUModel to make sure tests don't accidentally
probe host CPU.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Jiri Denemark 2019-06-03 13:13:38 +02:00
parent ec6ce6363a
commit dd3fc650de
3 changed files with 10 additions and 14 deletions

View File

@ -881,12 +881,10 @@ virQEMUCapsInitGuestFromBinary(virCapsPtr caps,
virCPUDefPtr virCPUDefPtr
virQEMUCapsProbeHostCPUForEmulator(virArch hostArch, virQEMUCapsProbeHostCPU(virArch hostArch,
virQEMUCapsPtr qemuCaps, virDomainCapsCPUModelsPtr models)
virDomainVirtType type)
{ {
return virCPUGetHost(hostArch, VIR_CPU_TYPE_GUEST, NULL, return virCPUGetHost(hostArch, VIR_CPU_TYPE_GUEST, NULL, models);
virQEMUCapsGetCPUDefinitions(qemuCaps, type));
} }
@ -3057,7 +3055,8 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
} else if (rc == 1) { } else if (rc == 1) {
VIR_DEBUG("No host CPU model info from QEMU; probing host CPU directly"); VIR_DEBUG("No host CPU model info from QEMU; probing host CPU directly");
hostCPU = virQEMUCapsProbeHostCPUForEmulator(hostArch, qemuCaps, type); hostCPU = virQEMUCapsProbeHostCPU(hostArch,
virQEMUCapsGetCPUDefinitions(qemuCaps, type));
if (!hostCPU || if (!hostCPU ||
virCPUDefCopyModelFilter(cpu, hostCPU, true, virCPUDefCopyModelFilter(cpu, hostCPU, true,
virQEMUCapsCPUFilterFeatures, virQEMUCapsCPUFilterFeatures,
@ -3070,8 +3069,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
goto error; goto error;
} else if (type == VIR_DOMAIN_VIRT_KVM && } else if (type == VIR_DOMAIN_VIRT_KVM &&
virCPUGetHostIsSupported(qemuCaps->arch)) { virCPUGetHostIsSupported(qemuCaps->arch)) {
if (!(fullCPU = virCPUGetHost(qemuCaps->arch, VIR_CPU_TYPE_GUEST, if (!(fullCPU = virQEMUCapsProbeHostCPU(qemuCaps->arch, NULL)))
NULL, NULL)))
goto error; goto error;
if (!(cpuExpanded = virCPUDefCopy(cpu)) || if (!(cpuExpanded = virCPUDefCopy(cpu)) ||

View File

@ -82,9 +82,8 @@ virQEMUCapsGetCPUModelX86Data(qemuMonitorCPUModelInfoPtr model,
bool migratable); bool migratable);
virCPUDefPtr virCPUDefPtr
virQEMUCapsProbeHostCPUForEmulator(virArch hostArch, virQEMUCapsProbeHostCPU(virArch hostArch,
virQEMUCapsPtr qemuCaps, virDomainCapsCPUModelsPtr models) ATTRIBUTE_NOINLINE;
virDomainVirtType type) ATTRIBUTE_NOINLINE;
void void
virQEMUCapsSetGICCapabilities(virQEMUCapsPtr qemuCaps, virQEMUCapsSetGICCapabilities(virQEMUCapsPtr qemuCaps,

View File

@ -27,9 +27,8 @@
virCPUDefPtr virCPUDefPtr
virQEMUCapsProbeHostCPUForEmulator(virArch hostArch ATTRIBUTE_UNUSED, virQEMUCapsProbeHostCPU(virArch hostArch ATTRIBUTE_UNUSED,
virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSED, virDomainCapsCPUModelsPtr models ATTRIBUTE_UNUSED)
virDomainVirtType type ATTRIBUTE_UNUSED)
{ {
const char *model = getenv("VIR_TEST_MOCK_FAKE_HOST_CPU"); const char *model = getenv("VIR_TEST_MOCK_FAKE_HOST_CPU");