]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
qemu: allow checking device availability with actually used flags
authorJoerg Behrmann <behrmann@physik.fu-berlin.de>
Wed, 1 Nov 2023 14:16:14 +0000 (15:16 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 2 Nov 2023 10:04:40 +0000 (11:04 +0100)
Also use an actual os.open instead of os.access, because os.access might fail
with certain flags in cases where os.open will not.

This works around the case where kernel modules after an upgrade cannot be
loaded anymore because it is no longer available for the running kernel.

mkosi/__init__.py
mkosi/qemu.py

index cde82ddf0b49161f894c4a7e83a0fd4183662dde..41ae721a439fa6217437a9d6015bc5a0ac51b7f8 100644 (file)
@@ -2579,7 +2579,7 @@ def run_verb(args: MkosiArgs, images: Sequence[MkosiConfig]) -> None:
     qemu_device_fds = {
         d: os.open(d.device(), os.O_RDWR|os.O_CLOEXEC|os.O_NONBLOCK)
         for d in QemuDeviceNode
-        if d.available(log=True)
+        if d.available(log=True, flags=os.O_RDWR|os.O_CLOEXEC|os.O_NONBLOCK)
     }
 
     # Get the user UID/GID either on the host or in the user namespace running the build
index 19ac314cd52f96ed1e15cd3e2a22294c320c36ba..0d718fd09e389fcf46b26274cc7db979a22f3323 100644 (file)
@@ -46,17 +46,21 @@ class QemuDeviceNode(StrEnum):
             QemuDeviceNode.vhost_vsock: "a VSock device",
         }[self]
 
-    def available(self, log: bool = False) -> bool:
+    def available(self, *, log: bool = False, flags: int = (os.R_OK | os.W_OK)) -> bool:
         if not os.access(self.device(), os.F_OK):
             if log:
                 logging.warning(f"{self.device()} not found. Not adding {self.description()} to the virtual machine.")
             return False
 
-        if not os.access(self.device(), os.R_OK|os.W_OK):
+        try:
+            fd = os.open(self.device(), flags)
+            os.close(fd)
+        except OSError:
             if log:
                 logging.warning(
                     f"Permission denied to access {self.device()}. "
-                    f"Not adding {self.description()} to the virtual machine."
+                    f"Not adding {self.description()} to the virtual machine. "
+                    "(Maybe a kernel module could not be loaded?)"
                 )
             return False