[libvirt] [PATCH] qemuConnectGetDomainCapabilities: Use wiser defaults

Michal Privoznik mprivozn at redhat.com
Thu Jul 17 09:12:05 UTC 2014


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 at 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




More information about the libvir-list mailing list