The code for transforming qemuMonitorCPUModelInfo data from QEMU into virCPUDefPtr consumable by virCPU* APIs was hidden inside virQEMUCapsInitCPUModelX86. This patch moves it into a new function to make it usable in tests. Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx> Reviewed-by: Ján Tomko <jtomko@xxxxxxxxxx> --- Notes: Version 2: - no change src/qemu/qemu_capabilities.c | 50 ++++++++++++++++++++++++------------ src/qemu/qemu_capspriv.h | 4 +++ 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d435bf17ae..9ef63f8cbf 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2839,28 +2839,17 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps, } -/** - * Returns 0 when host CPU model provided by QEMU was filled in qemuCaps, - * 1 when the caller should fall back to using virCapsPtr->host.cpu, - * -1 on error. - */ -static int -virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps, - virDomainVirtType type, - qemuMonitorCPUModelInfoPtr model, - virCPUDefPtr cpu, - bool migratable) +virCPUDataPtr +virQEMUCapsGetCPUModelX86Data(qemuMonitorCPUModelInfoPtr model, + bool migratable) { - virCPUDataPtr data = NULL; unsigned long long sigFamily = 0; unsigned long long sigModel = 0; unsigned long long sigStepping = 0; - int ret = -1; + virCPUDataPtr data = NULL; + virCPUDataPtr ret = NULL; size_t i; - if (!model) - return 1; - if (!(data = virCPUDataNew(VIR_ARCH_X86_64))) goto cleanup; @@ -2901,6 +2890,35 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps, if (virCPUx86DataSetSignature(data, sigFamily, sigModel, sigStepping) < 0) goto cleanup; + VIR_STEAL_PTR(ret, data); + + cleanup: + virCPUDataFree(data); + return ret; +} + + +/** + * Returns 0 when host CPU model provided by QEMU was filled in qemuCaps, + * 1 when the caller should fall back to using virCapsPtr->host.cpu, + * -1 on error. + */ +static int +virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps, + virDomainVirtType type, + qemuMonitorCPUModelInfoPtr model, + virCPUDefPtr cpu, + bool migratable) +{ + virCPUDataPtr data = NULL; + int ret = -1; + + if (!model) + return 1; + + if (!(data = virQEMUCapsGetCPUModelX86Data(model, migratable))) + goto cleanup; + if (cpuDecode(cpu, data, virQEMUCapsGetCPUDefinitions(qemuCaps, type)) < 0) goto cleanup; diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h index b995e4d5d3..c8d45d699b 100644 --- a/src/qemu/qemu_capspriv.h +++ b/src/qemu/qemu_capspriv.h @@ -73,6 +73,10 @@ virQEMUCapsSetCPUModelInfo(virQEMUCapsPtr qemuCaps, virDomainVirtType type, qemuMonitorCPUModelInfoPtr modelInfo); +virCPUDataPtr +virQEMUCapsGetCPUModelX86Data(qemuMonitorCPUModelInfoPtr model, + bool migratable); + virCPUDefPtr virQEMUCapsProbeHostCPUForEmulator(virArch hostArch, virQEMUCapsPtr qemuCaps, -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list