Create utility function encapsulating code to calculate hypervisor baseline cpu using the local libvirt utility functions.
Similar function encapsulating code to calculating hypervisor baseline using QEMU QMP messages will be introduced in later commit. Patch is a cut and paste of existing code into a utility function wrapper. s/cpu/*baseline/ (change output variable name ) and initialize variable "rc" are the only code changes. Signed-off-by: Chris Venteicher <cvent...@redhat.com> --- src/qemu/qemu_driver.c | 78 ++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 161b82d229..2a030bed2f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13696,6 +13696,55 @@ qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED, } +static int +qemuConnectBaselineHypervisorCPUViaLibvirt( + virQEMUCapsPtr qemuCaps, + bool migratable, + virDomainVirtType virttype, + virArch arch, + virCPUDefPtr *cpus, + unsigned int ncpus, + virCPUDefPtr *baseline) +{ + char **features = NULL; + int ret = -1; + int rc = -1; + virDomainCapsCPUModelsPtr cpuModels; + + *baseline = NULL; + + if (!(cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, virttype)) || + cpuModels->nmodels == 0) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("QEMU '%s' does not support any CPU models for " + "virttype '%s'"), + virQEMUCapsGetBinary(qemuCaps), + virDomainVirtTypeToString(virttype)); + goto cleanup; + } + + rc = virQEMUCapsGetCPUFeatures(qemuCaps, virttype, + migratable, &features); + if (rc < 0) + goto cleanup; + if (features && rc == 0) { + /* We got only migratable features from QEMU if we asked for them, + * no further filtering in virCPUBaseline is desired. */ + migratable = false; + } + + if (!(*baseline = virCPUBaseline(arch, cpus, ncpus, cpuModels, + (const char **)features, migratable))) + goto cleanup; + + ret = 0; + + cleanup: + virStringListFree(features); + return ret; +} + + static char * qemuConnectBaselineHypervisorCPU(virConnectPtr conn, const char *emulator, @@ -13714,7 +13763,6 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn, bool migratable; virCPUDefPtr cpu = NULL; char *cpustr = NULL; - char **features = NULL; virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES | VIR_CONNECT_BASELINE_CPU_MIGRATABLE, NULL); @@ -13737,30 +13785,9 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn, if (ARCH_IS_X86(arch)) { migratable = !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE); - virDomainCapsCPUModelsPtr cpuModels; - - if (!(cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, virttype)) || - cpuModels->nmodels == 0) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, - _("QEMU '%s' does not support any CPU models for " - "virttype '%s'"), - virQEMUCapsGetBinary(qemuCaps), - virDomainVirtTypeToString(virttype)); - goto cleanup; - } - - int rc = virQEMUCapsGetCPUFeatures(qemuCaps, virttype, - migratable, &features); - if (rc < 0) - goto cleanup; - if (features && rc == 0) { - /* We got only migratable features from QEMU if we asked for them, - * no further filtering in virCPUBaseline is desired. */ - migratable = false; - } - - if (!(cpu = virCPUBaseline(arch, cpus, ncpus, cpuModels, - (const char **)features, migratable))) + if (qemuConnectBaselineHypervisorCPUViaLibvirt(qemuCaps, migratable, + virttype, arch, + cpus, ncpus, &cpu) < 0) goto cleanup; } else { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, @@ -13781,7 +13808,6 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn, virCPUDefListFree(cpus); virCPUDefFree(cpu); virObjectUnref(qemuCaps); - virStringListFree(features); return cpustr; } -- 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list