From: Joerg Behrmann Date: Wed, 23 Feb 2022 08:16:47 +0000 (+0100) Subject: Check /dev/kvm more thoroughly. X-Git-Tag: v13~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aaedc44a152dac356433b5b6d76868d6990cbdb1;p=thirdparty%2Fmkosi.git Check /dev/kvm more thoroughly. Some CI runners, among them apparently GA, present non-working KVM devices. Let's try to open it, to see whether we can. Fixes: #914 --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 0164fa727..9eea3907c 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -7555,9 +7555,21 @@ def find_ovmf_vars() -> Path: die("Couldn't find OVMF UEFI variables file.") +def qemu_check_kvm_support() -> bool: + kvm = Path("/dev/kvm") + if not kvm.is_char_device(): + return False + # some CI runners may present a non-working KVM device + try: + with kvm.open("r+b"): + return True + except OSError: + return False + + @contextlib.contextmanager def run_qemu_cmdline(args: MkosiArgs) -> Iterator[List[str]]: - has_kvm = os.path.exists("/dev/kvm") + has_kvm = qemu_check_kvm_support() accel = "kvm" if has_kvm else "tcg" firmware, fw_supports_sb = find_qemu_firmware()