[libvirt PATCH 2/3] qemu: Don't assume that /usr/libexec/qemu-kvm exists

Andrea Bolognani abologna at redhat.com
Thu Mar 31 09:24:05 UTC 2022


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 at suse.com>
Signed-off-by: Andrea Bolognani <abologna at redhat.com>
---
 src/qemu/qemu_capabilities.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 68edf94ba5..41e9a3a3f5 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -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);
 }
 
 
-- 
2.35.1



More information about the libvir-list mailing list