提交 bce3b080 编写于 作者: D Daniel P. Berrangé

qemu: cache host arch separately from virCapsPtr

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.
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 5c7cd74a
......@@ -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);
......
......@@ -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);
......
......@@ -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 "
......
......@@ -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;
......
......@@ -262,6 +262,9 @@ struct _virQEMUDriver {
*/
virCapsPtr caps;
/* Immutable value */
virArch hostarch;
/* Immutable pointer, Immutable object */
virDomainXMLOptionPtr xmlopt;
......
......@@ -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);
......
......@@ -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;
......@@ -13424,7 +13425,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);
}
......
......@@ -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++)
......@@ -7827,7 +7827,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;
......
......@@ -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)
......
......@@ -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;
......
......@@ -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);
......
......@@ -60,6 +60,15 @@ static virBitmapPtr testBitmap;
char *progname;
static char *python;
virArch virTestHostArch = VIR_ARCH_X86_64;
virArch
virArchFromHost(void)
{
return virTestHostArch;
}
static int virTestUseTerminalColors(void)
{
return isatty(STDOUT_FILENO);
......
......@@ -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);
......
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册