[libvirt] [PATCH 04/11] qemu: Stop looking after finding the first binary

Andrea Bolognani abologna at redhat.com
Thu Sep 20 15:25:22 UTC 2018


When the guest is native, we are currently looking at
potential KVM binaries regardless of whether or not we have
already located a QEMU binary suitable to run the guest.

This made sense back when KVM support was not part of QEMU
proper, but these days the KVM binaries are in most cases
just trivial wrapper scripts around the native QEMU binary
so it doesn't make sense to poke at them unless they're
the only binaries on the system, such as when running on
RHEL.

This will allow us to simplify both virQEMUCapsInitGuest()
and virQEMUCapsInitGuestFromBinary().

Signed-off-by: Andrea Bolognani <abologna at redhat.com>
---
 src/qemu/qemu_capabilities.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 09d4af70ec..647fde4b6b 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -747,10 +747,8 @@ virQEMUCapsInitGuest(virCapsPtr caps,
                      virArch guestarch)
 {
     size_t i;
-    char *kvmbin = NULL;
     char *binary = NULL;
     virQEMUCapsPtr qemubinCaps = NULL;
-    virQEMUCapsPtr kvmbinCaps = NULL;
     int ret = -1;
 
     /* Check for existence of base emulator, or alternate base
@@ -766,7 +764,7 @@ virQEMUCapsInitGuest(virCapsPtr caps,
         }
     }
 
-    if (virQEMUCapsGuestIsNative(hostarch, guestarch)) {
+    if (virQEMUCapsGuestIsNative(hostarch, guestarch) && !binary) {
         const char *kvmbins[] = {
             "/usr/libexec/qemu-kvm", /* RHEL */
             "qemu-kvm", /* Fedora */
@@ -774,36 +772,28 @@ virQEMUCapsInitGuest(virCapsPtr caps,
         };
 
         for (i = 0; i < ARRAY_CARDINALITY(kvmbins); ++i) {
-            kvmbin = virFindFileInPath(kvmbins[i]);
+            binary = virFindFileInPath(kvmbins[i]);
 
-            if (!kvmbin)
+            if (!binary)
                 continue;
 
-            if (!(kvmbinCaps = virQEMUCapsCacheLookup(cache, kvmbin))) {
+            if (!(qemubinCaps = virQEMUCapsCacheLookup(cache, binary))) {
                 virResetLastError();
-                VIR_FREE(kvmbin);
+                VIR_FREE(binary);
                 continue;
             }
 
-            if (!binary) {
-                binary = kvmbin;
-                qemubinCaps = kvmbinCaps;
-                kvmbin = NULL;
-                kvmbinCaps = NULL;
-            }
             break;
         }
     }
 
     ret = virQEMUCapsInitGuestFromBinary(caps,
                                          binary, qemubinCaps,
-                                         kvmbin, kvmbinCaps,
+                                         NULL, NULL,
                                          guestarch);
 
     VIR_FREE(binary);
-    VIR_FREE(kvmbin);
     virObjectUnref(qemubinCaps);
-    virObjectUnref(kvmbinCaps);
 
     return ret;
 }
-- 
2.17.1




More information about the libvir-list mailing list