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

qemu: fixing auto-detecting binary in domain capabilities

The virConnectGetDomainCapabilities API accepts either a binary path
to the emulator, or desired guest arch. If guest arch is not given,
then the host arch is assumed.

In the case where the binary is not given, the code tried to find the
emulator binary in the existing list of cached emulator capabilities.
This is not valid since we switched to lazy population of the cache in:

  commit 3dd91af0
  Author: Daniel P. Berrangé <berrange@redhat.com>
  Date:   Mon Dec 2 13:04:26 2019 +0000

    qemu: stop creating capabilities at driver startup

As a result of this change, if there are no persistent guests defined
using the requested guest architecture, virConnectGetDomainCapabilities
will fail to find an emulator binary.

The solution is to stop relying on the cached capabilities to find the
binary and instead use the same logic we use to pick default a binary
per arch when populating capabilities.
Tested-by: NBoris Fiuczynski <fiuczy@linux.ibm.com>
Tested-by: NRichard W.M. Jones <rjones@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 e7a65484
...@@ -5284,10 +5284,13 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr cache, ...@@ -5284,10 +5284,13 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr cache,
const char **retMachine) const char **retMachine)
{ {
int virttype = VIR_DOMAIN_VIRT_NONE; int virttype = VIR_DOMAIN_VIRT_NONE;
int arch = virArchFromHost(); virArch hostarch = virArchFromHost();
virArch arch = hostarch;
virDomainVirtType capsType; virDomainVirtType capsType;
virQEMUCapsPtr qemuCaps = NULL; virQEMUCapsPtr qemuCaps = NULL;
virQEMUCapsPtr ret = NULL; virQEMUCapsPtr ret = NULL;
virArch arch_from_caps;
g_autofree char *probedbinary = NULL;
if (virttypeStr && if (virttypeStr &&
(virttype = virDomainVirtTypeFromString(virttypeStr)) < 0) { (virttype = virDomainVirtTypeFromString(virttypeStr)) < 0) {
...@@ -5303,31 +5306,27 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr cache, ...@@ -5303,31 +5306,27 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr cache,
goto cleanup; goto cleanup;
} }
if (binary) { if (!binary) {
virArch arch_from_caps; probedbinary = virQEMUCapsGetDefaultEmulator(hostarch, arch);
binary = probedbinary;
}
if (!(qemuCaps = virQEMUCapsCacheLookup(cache, binary))) if (!(qemuCaps = virQEMUCapsCacheLookup(cache, binary)))
goto cleanup; goto cleanup;
arch_from_caps = virQEMUCapsGetArch(qemuCaps); arch_from_caps = virQEMUCapsGetArch(qemuCaps);
if (arch_from_caps != arch && if (arch_from_caps != arch &&
!((ARCH_IS_X86(arch) && ARCH_IS_X86(arch_from_caps)) || !((ARCH_IS_X86(arch) && ARCH_IS_X86(arch_from_caps)) ||
(ARCH_IS_PPC(arch) && ARCH_IS_PPC(arch_from_caps)) || (ARCH_IS_PPC(arch) && ARCH_IS_PPC(arch_from_caps)) ||
(ARCH_IS_ARM(arch) && ARCH_IS_ARM(arch_from_caps)) || (ARCH_IS_ARM(arch) && ARCH_IS_ARM(arch_from_caps)) ||
(ARCH_IS_S390(arch) && ARCH_IS_S390(arch_from_caps)))) { (ARCH_IS_S390(arch) && ARCH_IS_S390(arch_from_caps)))) {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("architecture from emulator '%s' doesn't " _("architecture from emulator '%s' doesn't "
"match given architecture '%s'"), "match given architecture '%s'"),
virArchToString(arch_from_caps), virArchToString(arch_from_caps),
virArchToString(arch)); virArchToString(arch));
goto cleanup; goto cleanup;
}
} else {
if (!(qemuCaps = virQEMUCapsCacheLookupByArch(cache, arch)))
goto cleanup;
binary = virQEMUCapsGetBinary(qemuCaps);
} }
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册