]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Don't assume that /usr/libexec/qemu-kvm exists
authorAndrea Bolognani <abologna@redhat.com>
Thu, 31 Mar 2022 09:00:38 +0000 (11:00 +0200)
committerAndrea Bolognani <abologna@redhat.com>
Fri, 1 Apr 2022 16:35:21 +0000 (18:35 +0200)
On a machine where no QEMU binary is installed, we end up logging

  libvirtd: Cannot check QEMU binary /usr/libexec/qemu-kvm:
  No such file or directory

which is not very useful in general, and downright misleading in
the case of operating systems that are not derived from RHEL.

This is a consequence of treating that specific path in a different
way from all other possible QEMU binary paths, and specifically of
not checking whether the file actually exists but sort of assuming
that it must do if we haven't found another QEMU binary earlier.

Address the issue by trying this path out in
virQEMUCapsFindBinaryForArch(), along with all the other possible
ones, and making sure it exists before returning it.

Reported-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Tested-by: Jim Fehlig <jfehlig@suse.com>
src/qemu/qemu_capabilities.c

index 68edf94ba553831932b7eacadee8e17d043a705b..41e9a3a3f51153c43ee6cf177ce6a4ef49fdc62f 100644 (file)
@@ -945,6 +945,13 @@ virQEMUCapsFindBinaryForArch(virArch hostarch,
             return binary;
     }
 
+    /* RHEL doesn't follow the usual naming for QEMU binaries and ships
+     * a single binary named qemu-kvm outside of $PATH instead */
+    if (virQEMUCapsGuestIsNative(hostarch, guestarch)) {
+        if ((binary = virFindFileInPath("/usr/libexec/qemu-kvm")))
+            return binary;
+    }
+
     return NULL;
 }
 
@@ -953,18 +960,7 @@ char *
 virQEMUCapsGetDefaultEmulator(virArch hostarch,
                               virArch guestarch)
 {
-    char *binary = NULL;
-    /* Check for existence of base emulator, or alternate base
-     * which can be used with magic cpu choice
-     */
-    binary = virQEMUCapsFindBinaryForArch(hostarch, guestarch);
-
-    /* RHEL doesn't follow the usual naming for QEMU binaries and ships
-     * a single binary named qemu-kvm outside of $PATH instead */
-    if (virQEMUCapsGuestIsNative(hostarch, guestarch) && !binary)
-        binary = g_strdup("/usr/libexec/qemu-kvm");
-
-    return binary;
+    return virQEMUCapsFindBinaryForArch(hostarch, guestarch);
 }