import contextlib
import copy
import enum
-import errno
import fcntl
import functools
import importlib
def qemu_check_kvm_support(log: bool) -> bool:
# some CI runners may present a non-working KVM device
- try:
- os.close(os.open("/dev/kvm", os.O_RDWR|os.O_CLOEXEC))
- except OSError as e:
- if e.errno == errno.ENOENT:
- if log:
- logging.warning("/dev/kvm not found. Not using KVM acceleration.")
- return False
- elif e.errno in (errno.EPERM, errno.EACCES):
- if log:
- logging.warning("Permission denied to access /dev/kvm. Not using KVM acceleration")
- return False
-
- raise e
+
+ if not os.access("/dev/kvm", os.F_OK):
+ if log:
+ logging.warning("/dev/kvm not found. Not using KVM acceleration.")
+ return False
+
+ if not os.access("/dev/kvm", os.R_OK|os.W_OK):
+ if log:
+ logging.warning("Permission denied to access /dev/kvm. Not using KVM acceleration")
+ return False
return True
def qemu_check_vsock_support(log: bool) -> bool:
- try:
- os.close(os.open("/dev/vhost-vsock", os.O_RDWR|os.O_CLOEXEC))
- except OSError as e:
- if e.errno == errno.ENOENT:
- if log:
- logging.warning("/dev/vhost-vsock not found. Not adding a vsock device to the virtual machine.")
- return False
- elif e.errno in (errno.EPERM, errno.EACCES):
- if log:
- logging.warning(
- "Permission denied to access /dev/vhost-vsock. "
- "Not adding a vsock device to the virtual machine."
- )
- return False
-
- raise e
+ if not os.access("/dev/vhost-vsock", os.F_OK):
+ if log:
+ logging.warning("/dev/vhost-vsock not found. Not adding a vsock device to the virtual machine.")
+ return False
+
+ if not os.access("/dev/vhost-vsock", os.R_OK|os.W_OK):
+ if log:
+ logging.warning(
+ "Permission denied to access /dev/vhost-vsock. "
+ "Not adding a vsock device to the virtual machine."
+ )
+ return False
return True