As part of a goal to eliminate the need to use virCapsPtr for anything
other than the virConnectGetCapabilies() API impl, cache the host arch
against the QEMU driver struct and use that field directly.
In the tests we move virArchFromHost() globally in testutils.c so that
every test runs with a fixed default architecture reported.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
src/qemu/qemu_capabilities.c | 20 ++++++++++----------
src/qemu/qemu_capabilities.h | 6 +++---
src/qemu/qemu_command.c | 6 +-----
src/qemu/qemu_conf.c | 6 +-----
src/qemu/qemu_conf.h | 3 +++
src/qemu/qemu_domain.c | 8 ++++----
src/qemu/qemu_driver.c | 3 ++-
src/qemu/qemu_process.c | 14 +++++++-------
tests/domaincapstest.c | 2 +-
tests/qemumemlocktest.c | 4 ++--
tests/qemuxml2argvtest.c | 16 ++++++++--------
tests/testutils.c | 9 +++++++++
tests/testutils.h | 2 ++
tests/testutilsqemu.c | 11 ++++++++---
tests/testutilsqemu.h | 4 ++--
15 files changed, 63 insertions(+), 51 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index edb128c881..cfc16ba63e 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2096,7 +2096,7 @@ virQEMUCapsSetHostModel(virQEMUCapsPtr qemuCaps,
bool
virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
- virCapsPtr caps,
+ virArch hostarch,
virDomainVirtType type,
virCPUMode mode)
{
@@ -2105,7 +2105,7 @@ virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
switch (mode) {
case VIR_CPU_MODE_HOST_PASSTHROUGH:
return type == VIR_DOMAIN_VIRT_KVM &&
- virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch);
+ virQEMUCapsGuestIsNative(hostarch, qemuCaps->arch);
case VIR_CPU_MODE_HOST_MODEL:
return !!virQEMUCapsGetHostModel(qemuCaps, type,
@@ -5412,22 +5412,22 @@ virQEMUCapsFillDomainOSCaps(virDomainCapsOSPtr os,
static void
-virQEMUCapsFillDomainCPUCaps(virCapsPtr caps,
- virQEMUCapsPtr qemuCaps,
+virQEMUCapsFillDomainCPUCaps(virQEMUCapsPtr qemuCaps,
+ virArch hostarch,
virDomainCapsPtr domCaps)
{
- if (virQEMUCapsIsCPUModeSupported(qemuCaps, caps, domCaps->virttype,
+ if (virQEMUCapsIsCPUModeSupported(qemuCaps, hostarch, domCaps->virttype,
VIR_CPU_MODE_HOST_PASSTHROUGH))
domCaps->cpu.hostPassthrough = true;
- if (virQEMUCapsIsCPUModeSupported(qemuCaps, caps, domCaps->virttype,
+ if (virQEMUCapsIsCPUModeSupported(qemuCaps, hostarch, domCaps->virttype,
VIR_CPU_MODE_HOST_MODEL)) {
virCPUDefPtr cpu = virQEMUCapsGetHostModel(qemuCaps, domCaps->virttype,
VIR_QEMU_CAPS_HOST_CPU_REPORTED);
domCaps->cpu.hostModel = virCPUDefCopy(cpu);
}
- if (virQEMUCapsIsCPUModeSupported(qemuCaps, caps, domCaps->virttype,
+ if (virQEMUCapsIsCPUModeSupported(qemuCaps, hostarch, domCaps->virttype,
VIR_CPU_MODE_CUSTOM)) {
const char *blacklist[] = { "host", NULL };
VIR_AUTOSTRINGLIST models = NULL;
@@ -5746,9 +5746,9 @@ virQEMUCapsFillDomainFeatureSEVCaps(virQEMUCapsPtr qemuCaps,
int
-virQEMUCapsFillDomainCaps(virCapsPtr caps,
+virQEMUCapsFillDomainCaps(virQEMUCapsPtr qemuCaps,
+ virArch hostarch,
virDomainCapsPtr domCaps,
- virQEMUCapsPtr qemuCaps,
bool privileged,
virFirmwarePtr *firmwares,
size_t nfirmwares)
@@ -5781,7 +5781,7 @@ virQEMUCapsFillDomainCaps(virCapsPtr caps,
firmwares, nfirmwares) < 0)
return -1;
- virQEMUCapsFillDomainCPUCaps(caps, qemuCaps, domCaps);
+ virQEMUCapsFillDomainCPUCaps(qemuCaps, hostarch, domCaps);
virQEMUCapsFillDomainDeviceDiskCaps(qemuCaps, domCaps->machine, disk);
virQEMUCapsFillDomainDeviceGraphicsCaps(qemuCaps, graphics);
virQEMUCapsFillDomainDeviceVideoCaps(qemuCaps, video);
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 4d7d836e8c..399496796d 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -604,7 +604,7 @@ int virQEMUCapsGetCPUFeatures(virQEMUCapsPtr qemuCaps,
char ***features);
bool virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
- virCapsPtr caps,
+ virArch hostarch,
virDomainVirtType type,
virCPUMode mode);
const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
@@ -665,9 +665,9 @@ int virQEMUCapsInitGuestFromBinary(virCapsPtr caps,
virQEMUCapsPtr qemuCaps,
virArch guestarch);
-int virQEMUCapsFillDomainCaps(virCapsPtr caps,
+int virQEMUCapsFillDomainCaps(virQEMUCapsPtr qemuCaps,
+ virArch hostarch,
virDomainCapsPtr domCaps,
- virQEMUCapsPtr qemuCaps,
bool privileged,
virFirmwarePtr *firmwares,
size_t nfirmwares);
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3465d28b84..49a0dad8d4 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6657,18 +6657,14 @@ qemuBuildCpuModelArgStr(virQEMUDriverPtr driver,
virQEMUCapsPtr qemuCaps)
{
size_t i;
- g_autoptr(virCaps) caps = NULL;
virCPUDefPtr cpu = def->cpu;
- if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
- return -1;
-
switch ((virCPUMode) cpu->mode) {
case VIR_CPU_MODE_HOST_PASSTHROUGH:
virBufferAddLit(buf, "host");
if (def->os.arch == VIR_ARCH_ARMV7L &&
- caps->host.arch == VIR_ARCH_AARCH64) {
+ driver->hostarch == VIR_ARCH_AARCH64) {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_AARCH64_OFF)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("QEMU binary does not support CPU "
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 30637b21ac..53658c80e8 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1341,7 +1341,6 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver,
virDomainVirtType virttype)
{
g_autoptr(virDomainCaps) domCaps = NULL;
- g_autoptr(virCaps) caps = NULL;
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
virHashTablePtr domCapsCache = virQEMUCapsGetDomainCapsCache(qemuCaps);
struct virQEMUDriverSearchDomcapsData data = {
@@ -1351,9 +1350,6 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver,
.virttype = virttype,
};
- if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
- return NULL;
-
domCaps = virHashSearch(domCapsCache,
virQEMUDriverSearchDomcaps, &data, NULL);
if (!domCaps) {
@@ -1364,7 +1360,7 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver,
data.arch, data.virttype)))
return NULL;
- if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps,
+ if (virQEMUCapsFillDomainCaps(qemuCaps, driver->hostarch, domCaps,
driver->privileged,
cfg->firmwares, cfg->nfirmwares) < 0)
return NULL;
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 95b33a1093..7c56226b8c 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -262,6 +262,9 @@ struct _virQEMUDriver {
*/
virCapsPtr caps;
+ /* Immutable value */
+ virArch hostarch;
+
/* Immutable pointer, Immutable object */
virDomainXMLOptionPtr xmlopt;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 470d342afc..939e6fc01c 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4446,7 +4446,7 @@ qemuDomainDefVcpusPostParse(virDomainDefPtr def)
static int
qemuDomainDefSetDefaultCPU(virDomainDefPtr def,
- virCapsPtr caps,
+ virArch hostarch,
virQEMUCapsPtr qemuCaps)
{
const char *model;
@@ -4484,7 +4484,7 @@ qemuDomainDefSetDefaultCPU(virDomainDefPtr def,
if (STREQ(model, "host")) {
if (ARCH_IS_S390(def->os.arch) &&
- virQEMUCapsIsCPUModeSupported(qemuCaps, caps, def->virtType,
+ virQEMUCapsIsCPUModeSupported(qemuCaps, hostarch, def->virtType,
VIR_CPU_MODE_HOST_MODEL)) {
def->cpu->mode = VIR_CPU_MODE_HOST_MODEL;
} else {
@@ -4691,7 +4691,7 @@ qemuDomainDefPostParseBasic(virDomainDefPtr def,
static int
qemuDomainDefPostParse(virDomainDefPtr def,
- virCapsPtr caps,
+ virCapsPtr caps G_GNUC_UNUSED,
unsigned int parseFlags,
void *opaque,
void *parseOpaque)
@@ -4723,7 +4723,7 @@ qemuDomainDefPostParse(virDomainDefPtr def,
if (qemuCanonicalizeMachine(def, qemuCaps) < 0)
return -1;
- if (qemuDomainDefSetDefaultCPU(def, caps, qemuCaps) < 0)
+ if (qemuDomainDefSetDefaultCPU(def, driver->hostarch, qemuCaps) < 0)
return -1;
qemuDomainDefEnableDefaultFeatures(def, qemuCaps);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1911073f3e..594b683b80 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -673,6 +673,7 @@ qemuStateInitialize(bool privileged,
qemu_driver->inhibitOpaque = opaque;
qemu_driver->privileged = privileged;
+ qemu_driver->hostarch = virArchFromHost();
if (!(qemu_driver->domains = virDomainObjListNew()))
goto error;
@@ -13418,7 +13419,7 @@ qemuConnectCompareCPU(virConnectPtr conn,
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
return VIR_CPU_COMPARE_ERROR;
- return virCPUCompareXML(caps->host.arch, caps->host.cpu,
+ return virCPUCompareXML(driver->hostarch, caps->host.cpu,
xmlDesc, failIncompatible);
}
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 75ee3893c6..480fcd075d 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6047,7 +6047,7 @@ qemuProcessDropUnknownCPUFeatures(const char *name,
static int
qemuProcessUpdateGuestCPU(virDomainDefPtr def,
virQEMUCapsPtr qemuCaps,
- virCapsPtr caps,
+ virArch hostarch,
unsigned int flags)
{
if (!def->cpu)
@@ -6069,7 +6069,7 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
def->cpu->mode = VIR_CPU_MODE_CUSTOM;
}
- if (!virQEMUCapsIsCPUModeSupported(qemuCaps, caps, def->virtType,
+ if (!virQEMUCapsIsCPUModeSupported(qemuCaps, hostarch, def->virtType,
def->cpu->mode)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("CPU mode '%s' for %s %s domain on %s host is not
"
@@ -6077,11 +6077,11 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
virCPUModeTypeToString(def->cpu->mode),
virArchToString(def->os.arch),
virDomainVirtTypeToString(def->virtType),
- virArchToString(caps->host.arch));
+ virArchToString(hostarch));
return -1;
}
- if (virCPUConvertLegacy(caps->host.arch, def->cpu) < 0)
+ if (virCPUConvertLegacy(hostarch, def->cpu) < 0)
return -1;
/* nothing to update for host-passthrough */
@@ -6089,7 +6089,7 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
g_autoptr(virDomainCapsCPUModels) cpuModels = NULL;
if (def->cpu->check == VIR_CPU_CHECK_PARTIAL &&
- virCPUCompare(caps->host.arch,
+ virCPUCompare(hostarch,
virQEMUCapsGetHostModel(qemuCaps, def->virtType,
VIR_QEMU_CAPS_HOST_CPU_FULL),
def->cpu, true) < 0)
@@ -6351,7 +6351,7 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver,
priv->pausedReason = VIR_DOMAIN_PAUSED_UNKNOWN;
VIR_DEBUG("Updating guest CPU definition");
- if (qemuProcessUpdateGuestCPU(vm->def, priv->qemuCaps, caps, flags) < 0)
+ if (qemuProcessUpdateGuestCPU(vm->def, priv->qemuCaps, driver->hostarch,
flags) < 0)
goto cleanup;
for (i = 0; i < vm->def->nshmems; i++)
@@ -7825,7 +7825,7 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver,
if (!caps)
return -1;
- if (!virQEMUCapsGuestIsNative(caps->host.arch, vm->def->os.arch) ||
+ if (!virQEMUCapsGuestIsNative(driver->hostarch, vm->def->os.arch) ||
!caps->host.cpu ||
!vm->def->cpu) {
ret = 0;
diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
index c6700f7e78..94e5831706 100644
--- a/tests/domaincapstest.c
+++ b/tests/domaincapstest.c
@@ -106,7 +106,7 @@ fillQemuCaps(virDomainCapsPtr domCaps,
if (!domCaps->machine)
domCaps->machine = g_strdup(virQEMUCapsGetPreferredMachine(qemuCaps,
virtType));
- if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps,
+ if (virQEMUCapsFillDomainCaps(qemuCaps, caps->host.arch, domCaps,
false,
cfg->firmwares,
cfg->nfirmwares) < 0)
diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c
index ef3bfa0345..55f65dcb6a 100644
--- a/tests/qemumemlocktest.c
+++ b/tests/qemumemlocktest.c
@@ -101,7 +101,7 @@ mymain(void)
* ensure settings are prioritized as expected.
*/
- qemuTestSetHostArch(driver.caps, VIR_ARCH_X86_64);
+ qemuTestSetHostArch(&driver, VIR_ARCH_X86_64);
DO_TEST("pc-kvm", 0);
DO_TEST("pc-tcg", 0);
@@ -115,7 +115,7 @@ mymain(void)
DO_TEST("pc-hardlimit+locked+hostdev", 2147483648);
DO_TEST("pc-locked+hostdev", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
- qemuTestSetHostArch(driver.caps, VIR_ARCH_PPC64);
+ qemuTestSetHostArch(&driver, VIR_ARCH_PPC64);
if (!(qemuCaps = virQEMUCapsNew())) {
ret = -1;
goto cleanup;
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 86b8899921..546cdae245 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -413,7 +413,7 @@ testCompareXMLToArgv(const void *data)
qemuDomainObjPrivatePtr priv = NULL;
if (info->arch != VIR_ARCH_NONE && info->arch != VIR_ARCH_X86_64)
- qemuTestSetHostArch(driver.caps, info->arch);
+ qemuTestSetHostArch(&driver, info->arch);
memset(&monitor_chr, 0, sizeof(monitor_chr));
@@ -584,7 +584,7 @@ testCompareXMLToArgv(const void *data)
virObjectUnref(conn);
VIR_FREE(migrateURI);
if (info->arch != VIR_ARCH_NONE && info->arch != VIR_ARCH_X86_64)
- qemuTestSetHostArch(driver.caps, VIR_ARCH_NONE);
+ qemuTestSetHostArch(&driver, VIR_ARCH_NONE);
return ret;
}
@@ -1724,11 +1724,11 @@ mymain(void)
DO_TEST("cpu-host-passthrough", QEMU_CAPS_KVM);
DO_TEST_FAILURE("cpu-qemu-host-passthrough", QEMU_CAPS_KVM);
- qemuTestSetHostArch(driver.caps, VIR_ARCH_S390X);
+ qemuTestSetHostArch(&driver, VIR_ARCH_S390X);
DO_TEST("cpu-s390-zEC12", QEMU_CAPS_KVM, QEMU_CAPS_CCW,
QEMU_CAPS_VIRTIO_S390);
DO_TEST("cpu-s390-features", QEMU_CAPS_KVM,
QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION);
DO_TEST_FAILURE("cpu-s390-features", QEMU_CAPS_KVM);
- qemuTestSetHostArch(driver.caps, VIR_ARCH_NONE);
+ qemuTestSetHostArch(&driver, VIR_ARCH_NONE);
qemuTestSetHostCPU(driver.caps, cpuHaswell);
DO_TEST("cpu-Haswell", QEMU_CAPS_KVM);
@@ -1855,7 +1855,7 @@ mymain(void)
QEMU_CAPS_DEVICE_SPAPR_VTY);
DO_TEST_PARSE_ERROR("pseries-no-parallel", NONE);
- qemuTestSetHostArch(driver.caps, VIR_ARCH_PPC64);
+ qemuTestSetHostArch(&driver, VIR_ARCH_PPC64);
DO_TEST("pseries-cpu-compat", QEMU_CAPS_KVM,
QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE,
QEMU_CAPS_DEVICE_SPAPR_VTY);
@@ -1877,7 +1877,7 @@ mymain(void)
QEMU_CAPS_DEVICE_SPAPR_VTY);
qemuTestSetHostCPU(driver.caps, NULL);
- qemuTestSetHostArch(driver.caps, VIR_ARCH_NONE);
+ qemuTestSetHostArch(&driver, VIR_ARCH_NONE);
DO_TEST("pseries-panic-missing",
QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE,
@@ -2552,7 +2552,7 @@ mymain(void)
QEMU_CAPS_DEVICE_VIRTIO_RNG, QEMU_CAPS_OBJECT_RNG_RANDOM);
DO_TEST("aarch64-virt-default-nic",
QEMU_CAPS_DEVICE_VIRTIO_MMIO);
- qemuTestSetHostArch(driver.caps, VIR_ARCH_AARCH64);
+ qemuTestSetHostArch(&driver, VIR_ARCH_AARCH64);
DO_TEST("aarch64-cpu-passthrough",
QEMU_CAPS_DEVICE_VIRTIO_MMIO,
QEMU_CAPS_KVM);
@@ -2668,7 +2668,7 @@ mymain(void)
/* SVE aarch64 CPU features work on modern QEMU */
DO_TEST_CAPS_ARCH_LATEST("aarch64-features-sve", "aarch64");
- qemuTestSetHostArch(driver.caps, VIR_ARCH_NONE);
+ qemuTestSetHostArch(&driver, VIR_ARCH_NONE);
DO_TEST("kvm-pit-delay", QEMU_CAPS_KVM_PIT_TICK_POLICY);
DO_TEST("kvm-pit-discard", QEMU_CAPS_KVM_PIT_TICK_POLICY);
diff --git a/tests/testutils.c b/tests/testutils.c
index d9c0d5abbe..387ba55908 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -60,6 +60,15 @@ static virBitmapPtr testBitmap;
char *progname;
static char *perl;
+virArch virTestHostArch = VIR_ARCH_X86_64;
+
+virArch
+virArchFromHost(void)
+{
+ return virTestHostArch;
+}
+
+
static int virTestUseTerminalColors(void)
{
return isatty(STDOUT_FILENO);
diff --git a/tests/testutils.h b/tests/testutils.h
index 76090c5522..c3f2cee85f 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -43,6 +43,8 @@ extern char *progname;
# error Fix Makefile.am
#endif
+extern virArch virTestHostArch;
+
int virTestRun(const char *title,
int (*body)(const void *data),
const void *data);
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 4cb128559a..97f63e7d5d 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -576,13 +576,16 @@ virCapsPtr testQemuCapsInit(void)
void
-qemuTestSetHostArch(virCapsPtr caps,
+qemuTestSetHostArch(virQEMUDriverPtr driver,
virArch arch)
{
if (arch == VIR_ARCH_NONE)
arch = VIR_ARCH_X86_64;
- caps->host.arch = arch;
- qemuTestSetHostCPU(caps, NULL);
+
+ virTestHostArch = arch;
+ driver->hostarch = virArchFromHost();
+ driver->caps->host.arch = virArchFromHost();
+ qemuTestSetHostCPU(driver->caps, NULL);
}
@@ -694,6 +697,8 @@ int qemuTestDriverInit(virQEMUDriver *driver)
if (virMutexInit(&driver->lock) < 0)
return -1;
+ driver->hostarch = virArchFromHost();
+
driver->config = virQEMUDriverConfigNew(false);
if (!driver->config)
goto error;
diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h
index da3bf3ab7a..8dcc930ac3 100644
--- a/tests/testutilsqemu.h
+++ b/tests/testutilsqemu.h
@@ -80,8 +80,8 @@ extern virCPUDefPtr cpuHaswell;
extern virCPUDefPtr cpuPower8;
extern virCPUDefPtr cpuPower9;
-void qemuTestSetHostArch(virCapsPtr caps,
- virArch arch);
+void qemuTestSetHostArch(virQEMUDriverPtr driver,
+ virArch arch);
void qemuTestSetHostCPU(virCapsPtr caps,
virCPUDefPtr cpu);
--
2.23.0