qemu: Don't assume that /usr/libexec/qemu-kvm exists

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>
This commit is contained in:
Andrea Bolognani 2022-03-31 11:00:38 +02:00
parent c890c4962f
commit 0a301b1969

View 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);
}