Up to now, users have to pass two arguments at least: domain virt type
('qemu' vs 'kvm') and one of emulatorbin or architecture. This is not
much user friendly. Nowadays users mostly use KVM and share the host
architecture with the guest. So now, the API (and subsequently virsh
command) can be called with all NULLs (without any arguments).
Before this patch:
# virsh domcapabilities
error: failed to get emulator capabilities
error: virttype_str in qemuConnectGetDomainCapabilities must not be NULL
# virsh domcapabilities kvm
error: failed to get emulator capabilities
error: invalid argument: at least one of emulatorbin or architecture fields must be
present
After:
# virsh domcapabilities
<domainCapabilities>
<path>/usr/bin/qemu-system-x86_64</path>
<domain>kvm</domain>
<machine>pc-i440fx-2.1</machine>
<arch>x86_64</arch>
<vcpu max='255'/>
</domainCapabilities>
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
Notes:
It would be nice to have this in the same release as the new API it's fixing.
So please, review.
src/qemu/qemu_driver.c | 27 ++++++++++-----------------
1 file changed, 10 insertions(+), 17 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b85d909..008f101 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16893,15 +16893,20 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,
virQEMUCapsPtr qemuCaps = NULL;
int virttype; /* virDomainVirtType */
virDomainCapsPtr domCaps = NULL;
- int arch = VIR_ARCH_NONE; /* virArch */
+ int arch = virArchFromHost(); /* virArch */
virCheckFlags(0, ret);
- virCheckNonNullArgReturn(virttype_str, ret);
if (virConnectGetDomainCapabilitiesEnsureACL(conn) < 0)
return ret;
- if ((virttype = virDomainVirtTypeFromString(virttype_str)) < 0) {
+ if (qemuHostdevHostSupportsPassthroughLegacy())
+ virttype = VIR_DOMAIN_VIRT_KVM;
+ else
+ virttype = VIR_DOMAIN_VIRT_QEMU;
+
+ if (virttype_str &&
+ (virttype = virDomainVirtTypeFromString(virttype_str)) < 0) {
virReportError(VIR_ERR_INVALID_ARG,
_("unknown virttype: %s"),
virttype_str);
@@ -16924,9 +16929,6 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,
arch_from_caps = virQEMUCapsGetArch(qemuCaps);
- if (arch == VIR_ARCH_NONE)
- arch = arch_from_caps;
-
if (arch_from_caps != arch) {
virReportError(VIR_ERR_INVALID_ARG,
_("architecture from emulator '%s' doesn't
"
@@ -16935,21 +16937,12 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,
virArchToString(arch));
goto cleanup;
}
- } else if (arch_str) {
+ } else {
if (!(qemuCaps = virQEMUCapsCacheLookupByArch(driver->qemuCapsCache,
arch)))
goto cleanup;
- if (!emulatorbin)
- emulatorbin = virQEMUCapsGetBinary(qemuCaps);
- /* Deliberately not checking if provided @emulatorbin matches @arch,
- * since if @emulatorbin was specified the match has been checked a few
- * lines above. */
- } else {
- virReportError(VIR_ERR_INVALID_ARG, "%s",
- _("at least one of emulatorbin or "
- "architecture fields must be present"));
- goto cleanup;
+ emulatorbin = virQEMUCapsGetBinary(qemuCaps);
}
if (machine) {
--
1.8.5.5