On Tue, Oct 15, 2019 at 05:34:54PM +0200, Jiri Denemark wrote:
We will need to keep some QEMU-specific data for each CPU model
supported by a QEMU binary. Instead of complicating the generic
virDomainCapsCPUModelsPtr, we can just directly store
qemuMonitorCPUDefsPtr returned by the capabilities probing code.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
Notes:
Version 2:
- adapted to changes made by the new patches
src/qemu/qemu_capabilities.c | 109 +++++++++++++++++------------------
1 file changed, 53 insertions(+), 56 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 436d65f578..a274cef120 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -607,8 +607,8 @@ struct _virQEMUCaps {
virArch arch;
virHashTablePtr domCapsCache;
- virDomainCapsCPUModelsPtr kvmCPUModels;
- virDomainCapsCPUModelsPtr tcgCPUModels;
+ qemuMonitorCPUDefsPtr kvmCPUModels;
+ qemuMonitorCPUDefsPtr tcgCPUModels;
size_t nmachineTypes;
struct virQEMUCapsMachineType *machineTypes;
@@ -1625,17 +1625,9 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
ret->arch = qemuCaps->arch;
- if (qemuCaps->kvmCPUModels) {
- ret->kvmCPUModels = virDomainCapsCPUModelsCopy(qemuCaps->kvmCPUModels);
- if (!ret->kvmCPUModels)
- goto error;
- }
-
- if (qemuCaps->tcgCPUModels) {
- ret->tcgCPUModels = virDomainCapsCPUModelsCopy(qemuCaps->tcgCPUModels);
- if (!ret->tcgCPUModels)
- goto error;
- }
+ if (qemuMonitorCPUDefsCopy(&ret->kvmCPUModels, qemuCaps->kvmCPUModels) <
0 ||
+ qemuMonitorCPUDefsCopy(&ret->tcgCPUModels, qemuCaps->tcgCPUModels) <
0)
+ goto error;
if (virQEMUCapsHostCPUDataCopy(&ret->kvmCPU, &qemuCaps->kvmCPU) < 0
||
virQEMUCapsHostCPUDataCopy(&ret->tcgCPU, &qemuCaps->tcgCPU) <
0)
@@ -1861,25 +1853,36 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
virDomainCapsCPUUsable usable)
{
size_t i;
- virDomainCapsCPUModelsPtr cpus = NULL;
+ size_t start;
+ qemuMonitorCPUDefsPtr defs = NULL;
if (type == VIR_DOMAIN_VIRT_KVM && qemuCaps->kvmCPUModels)
- cpus = qemuCaps->kvmCPUModels;
+ defs = qemuCaps->kvmCPUModels;
else if (type == VIR_DOMAIN_VIRT_QEMU && qemuCaps->tcgCPUModels)
- cpus = qemuCaps->tcgCPUModels;
+ defs = qemuCaps->tcgCPUModels;
+
+ if (defs) {
+ start = defs->ncpus;
- if (!cpus) {
- if (!(cpus = virDomainCapsCPUModelsNew(count)))
+ if (VIR_EXPAND_N(defs->cpus, defs->ncpus, count) < 0)
+ return -1;
+ } else {
+ start = 0;
+
+ if (!(defs = qemuMonitorCPUDefsNew(count)))
return -1;
if (type == VIR_DOMAIN_VIRT_KVM)
- qemuCaps->kvmCPUModels = cpus;
+ qemuCaps->kvmCPUModels = defs;
else
- qemuCaps->tcgCPUModels = cpus;
+ qemuCaps->tcgCPUModels = defs;
}
for (i = 0; i < count; i++) {
- if (virDomainCapsCPUModelsAdd(cpus, name[i], usable, NULL) < 0)
+ qemuMonitorCPUDefInfoPtr cpu = defs->cpus + start + i;
+
+ cpu->usable = usable;
This fails to compile with my CLang:
qemu/qemu_capabilities.c:1884:23: error: implicit conversion from enumeration type
'virDomainCapsCPUUsable' to different enumeration type 'virTristateBool'
[-Werror,-Wenum-conversion]
cpu->usable = usable;
~ ^~~~~~
An explicit cast works:
cpu->usable = (virTristateBool)usable;
but I forgot what is our preferred spacing for casts again.
+ if (VIR_STRDUP(cpu->name, name[i]) < 0)
consider g_strdup
return -1;
}
@@ -3503,7 +3503,7 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
xmlXPathContextPtr ctxt,
virDomainVirtType type)
{
- virDomainCapsCPUModelsPtr cpus = NULL;
+ VIR_AUTOPTR(qemuMonitorCPUDefs) defs = NULL;
g_autoptr
VIR_AUTOFREE(xmlNodePtr *) nodes = NULL;
size_t i;
int n;
@@ -3579,11 +3574,13 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
}
}
}
-
- if (virDomainCapsCPUModelsAddSteal(cpus, &name, usable, &blockers) <
0)
- return -1;
}
+ if (type == VIR_DOMAIN_VIRT_KVM)
+ VIR_STEAL_PTR(qemuCaps->kvmCPUModels, defs);
+ else
+ VIR_STEAL_PTR(qemuCaps->tcgCPUModels, defs);
g_steal_pointer
+
return 0;
}
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
Jano