[libvirt] [PATCH] qemuConnectGetDomainCapabilities: Use wiser defaults

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@redhat.com> --- src/qemu/qemu_driver.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 33541d3..7d99435 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16849,17 +16849,17 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn, char *ret = NULL; virQEMUDriverPtr driver = conn->privateData; virQEMUCapsPtr qemuCaps = NULL; - int virttype; /* virDomainVirtType */ + int virttype = VIR_DOMAIN_VIRT_KVM; /* 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 (virttype_str && + (virttype = virDomainVirtTypeFromString(virttype_str)) < 0) { virReportError(VIR_ERR_INVALID_ARG, _("unknown virttype: %s"), virttype_str); @@ -16882,9 +16882,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 " @@ -16893,21 +16890,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

On Thu, Jul 17, 2014 at 11:12:05AM +0200, Michal Privoznik wrote:
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 33541d3..7d99435 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16849,17 +16849,17 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn, char *ret = NULL; virQEMUDriverPtr driver = conn->privateData; virQEMUCapsPtr qemuCaps = NULL; - int virttype; /* virDomainVirtType */ + int virttype = VIR_DOMAIN_VIRT_KVM; /* virDomainVirtType */
Isn't this going to always fail when we run inside a guest which does not have nested virt? When we know the QEMU binary, we probe to see whether it can do KVM or not, so could we postpone this decision about virt type until after we've checked if KVM was available ? Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 17.07.2014 11:28, Daniel P. Berrange wrote:
On Thu, Jul 17, 2014 at 11:12:05AM +0200, Michal Privoznik wrote:
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 33541d3..7d99435 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16849,17 +16849,17 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn, char *ret = NULL; virQEMUDriverPtr driver = conn->privateData; virQEMUCapsPtr qemuCaps = NULL; - int virttype; /* virDomainVirtType */ + int virttype = VIR_DOMAIN_VIRT_KVM; /* virDomainVirtType */
Isn't this going to always fail when we run inside a guest which does not have nested virt? When we know the QEMU binary, we probe to see whether it can do KVM or not, so could we postpone this decision about virt type until after we've checked if KVM was available ?
I don't think we can. I mean, in order to construct virDomainCaps object we need to know the virttype. The KVM is checked later in the process when the object exits already. What we can do, however, is check for KVM twice. How about this squashed in? diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7d99435..33d6e47 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16849,7 +16849,7 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn, char *ret = NULL; virQEMUDriverPtr driver = conn->privateData; virQEMUCapsPtr qemuCaps = NULL; - int virttype = VIR_DOMAIN_VIRT_KVM; /* virDomainVirtType */ + int virttype; /* virDomainVirtType */ virDomainCapsPtr domCaps = NULL; int arch = virArchFromHost(); /* virArch */ @@ -16858,6 +16858,11 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn, if (virConnectGetDomainCapabilitiesEnsureACL(conn) < 0) return ret; + 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, Michal
participants (2)
-
Daniel P. Berrange
-
Michal Privoznik