It replaces hardcoded checks that select accelCPU/accelCPUModels
(formerly known as kvmCPU/kvmCPUModels) for KVM. It'll be cleaner to use
the function when multiple accelerators are supported in qemu driver.
Explicit KVM domain checks should be done only when a feature is
available only for KVM.
Signed-off-by: Roman Bolshakov <r.bolshakov(a)yadro.com>
---
src/qemu/qemu_capabilities.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 4dac040246..eb3148038a 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -630,6 +630,11 @@ static const char *virQEMUCapsArchToString(virArch arch)
return virArchToString(arch);
}
+static bool
+virQEMUCapsTypeIsAccelerated(virDomainVirtType type)
+{
+ return type == VIR_DOMAIN_VIRT_KVM;
+}
/* Checks whether a domain with @guest arch can run natively on @host.
*/
@@ -1772,7 +1777,7 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
size_t i;
virDomainCapsCPUModelsPtr cpus = NULL;
- if (type == VIR_DOMAIN_VIRT_KVM && qemuCaps->accelCPUModels)
+ if (virQEMUCapsTypeIsAccelerated(type) && qemuCaps->accelCPUModels)
cpus = qemuCaps->accelCPUModels;
else if (type == VIR_DOMAIN_VIRT_QEMU && qemuCaps->tcgCPUModels)
cpus = qemuCaps->tcgCPUModels;
@@ -1781,7 +1786,7 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
if (!(cpus = virDomainCapsCPUModelsNew(count)))
return -1;
- if (type == VIR_DOMAIN_VIRT_KVM)
+ if (virQEMUCapsTypeIsAccelerated(type))
qemuCaps->accelCPUModels = cpus;
else
qemuCaps->tcgCPUModels = cpus;
@@ -1800,7 +1805,7 @@ virDomainCapsCPUModelsPtr
virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
virDomainVirtType type)
{
- if (type == VIR_DOMAIN_VIRT_KVM)
+ if (virQEMUCapsTypeIsAccelerated(type))
return qemuCaps->accelCPUModels;
else
return qemuCaps->tcgCPUModels;
@@ -1811,7 +1816,7 @@ static virQEMUCapsHostCPUDataPtr
virQEMUCapsGetHostCPUData(virQEMUCapsPtr qemuCaps,
virDomainVirtType type)
{
- if (type == VIR_DOMAIN_VIRT_KVM)
+ if (virQEMUCapsTypeIsAccelerated(type))
return &qemuCaps->accelCPU;
else
return &qemuCaps->tcgCPU;
@@ -1867,7 +1872,7 @@ virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
switch (mode) {
case VIR_CPU_MODE_HOST_PASSTHROUGH:
- return type == VIR_DOMAIN_VIRT_KVM &&
+ return virQEMUCapsTypeIsAccelerated(type) &&
virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch);
case VIR_CPU_MODE_HOST_MODEL:
@@ -1875,7 +1880,7 @@ virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
VIR_QEMU_CAPS_HOST_CPU_REPORTED);
case VIR_CPU_MODE_CUSTOM:
- if (type == VIR_DOMAIN_VIRT_KVM)
+ if (virQEMUCapsTypeIsAccelerated(type))
cpus = qemuCaps->accelCPUModels;
else
cpus = qemuCaps->tcgCPUModels;
@@ -2976,7 +2981,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
virArchToString(qemuCaps->arch),
virDomainVirtTypeToString(type));
goto error;
- } else if (type == VIR_DOMAIN_VIRT_KVM &&
+ } else if (virQEMUCapsTypeIsAccelerated(type) &&
virCPUGetHostIsSupported(qemuCaps->arch)) {
if (!(fullCPU = virCPUGetHost(qemuCaps->arch, VIR_CPU_TYPE_GUEST,
NULL, NULL)))
@@ -3203,7 +3208,7 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
if (!(cpus = virDomainCapsCPUModelsNew(n)))
goto cleanup;
- if (type == VIR_DOMAIN_VIRT_KVM)
+ if (virQEMUCapsTypeIsAccelerated(type))
qemuCaps->accelCPUModels = cpus;
else
qemuCaps->tcgCPUModels = cpus;
@@ -3677,7 +3682,7 @@ virQEMUCapsFormatCPUModels(virQEMUCapsPtr qemuCaps,
const char *typeStr;
size_t i;
- if (type == VIR_DOMAIN_VIRT_KVM) {
+ if (virQEMUCapsTypeIsAccelerated(type))
typeStr = "kvm";
cpus = qemuCaps->accelCPUModels;
} else {
@@ -4932,7 +4937,8 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr cache,
if (virttype == VIR_DOMAIN_VIRT_NONE)
virttype = capsType;
- if (virttype == VIR_DOMAIN_VIRT_KVM && capsType == VIR_DOMAIN_VIRT_QEMU) {
+ if (virQEMUCapsTypeIsAccelerated(virttype) &&
+ !virQEMUCapsTypeIsAccelerated(capsType)) {
virReportError(VIR_ERR_INVALID_ARG,
_("KVM is not supported by '%s' on this host"),
binary);
@@ -5072,7 +5078,7 @@ virQEMUCapsFillDomainCPUCaps(virCapsPtr caps,
if (virCPUGetModels(domCaps->arch, &models) >= 0) {
virDomainCapsCPUModelsPtr cpus;
- if (domCaps->virttype == VIR_DOMAIN_VIRT_KVM)
+ if (virQEMUCapsTypeIsAccelerated(domCaps->virttype))
cpus = qemuCaps->accelCPUModels;
else
cpus = qemuCaps->tcgCPUModels;
--
2.17.1 (Apple Git-112)