]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuConnectGetDomainCapabilities: Use wiser defaults
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 17 Jul 2014 09:06:09 +0000 (11:06 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 24 Jul 2014 07:19:09 +0000 (09:19 +0200)
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

index 539164fea3e059656e092f9ab5a552237fc95b26..ac7a65275ef2c4a878ecb564099f40af5e490d3c 100644 (file)
@@ -16900,15 +16900,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);
@@ -16931,9 +16936,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 "
@@ -16942,21 +16944,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) {