]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add a feature for enabling/disabling qemu vsock usage 1557/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 11 May 2023 13:26:52 +0000 (15:26 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 12 May 2023 05:42:03 +0000 (07:42 +0200)
mkosi.md
mkosi/config.py
mkosi/qemu.py

index fdb2aa10366170a497aa0bfecc84a381306f32ed..9c67a3315c31af5533f6d5b05a6c3e319decd840 100644 (file)
--- a/mkosi.md
+++ b/mkosi.md
@@ -978,6 +978,11 @@ a boolean argument: either "1", "yes", or "true" to enable, or "0",
 : When used with the `qemu` verb, this option specifies whether QEMU should use KVM acceleration. Takes a
   boolean value or `auto`. Defaults to `auto`.
 
+`QemuVsock=`, `--qemu-vsock=`
+
+: When used with the `qemu` verb, this option specifies whether QEMU should be configured with a vsock. Takes
+  a boolean value or `auto`. Defaults to `auto`.
+
 `QemuArgs=`
 
 : Space-delimited list of additional arguments to pass when invoking
index c79b0b8a8b394c1ff5583ed75aed762d5eab7c5d..0c8a426f7823e0e4288c6683f6536f1c7f7698e7 100644 (file)
@@ -37,6 +37,7 @@ from mkosi.util import (
     is_dnf_distribution,
     prepend_to_environ_path,
     qemu_check_kvm_support,
+    qemu_check_vsock_support,
 )
 
 __version__ = "14"
@@ -643,6 +644,7 @@ class MkosiConfig:
     qemu_smp: str
     qemu_mem: str
     qemu_kvm: ConfigFeature
+    qemu_vsock: ConfigFeature
     qemu_args: Sequence[str]
 
     passphrase: Optional[Path]
@@ -1163,6 +1165,11 @@ class MkosiConfigParser:
             section="Host",
             parse=config_parse_feature,
         ),
+        MkosiConfigSetting(
+            dest="qemu_vsock",
+            section="Host",
+            parse=config_parse_feature,
+        ),
         MkosiConfigSetting(
             dest="qemu_args",
             section="Host",
@@ -1879,6 +1886,13 @@ class MkosiConfigParser:
             nargs="?",
             action=action,
         )
+        group.add_argument(
+            "--qemu-vsock",
+            metavar="FEATURE",
+            help="Configure whether to use qemu with a vsock or not",
+            nargs="?",
+            action=action,
+        )
         group.add_argument(
             "--qemu-args",
             metavar="ARGS",
@@ -2211,6 +2225,9 @@ def load_config(args: argparse.Namespace) -> MkosiConfig:
     if args.qemu_kvm == ConfigFeature.enabled and not qemu_check_kvm_support():
         die("Sorry, the host machine does not support KVM acceleration.")
 
+    if args.qemu_vsock == ConfigFeature.enabled and not qemu_check_vsock_support(log=False):
+        die("Sorry, the host machine does not support vsock")
+
     if args.repositories and not (is_dnf_distribution(args.distribution) or is_apt_distribution(args.distribution)):
         die("Sorry, the --repositories option is only supported on DNF/Debian based distributions")
 
index c7e5afa8f7916e65a5cb4f2b4721dccc20470246..bc6c1738b4735f3e9bab89aa2ee7b7ef3c6f65ec 100644 (file)
@@ -214,7 +214,9 @@ def run_qemu(args: MkosiArgs, config: MkosiConfig) -> None:
         "-nic", "user,model=virtio-net-pci",
     ]
 
-    if qemu_check_vsock_support(log=True):
+    use_vsock = (config.qemu_vsock == ConfigFeature.enabled or
+                (config.qemu_vsock == ConfigFeature.auto and qemu_check_vsock_support(log=True)))
+    if use_vsock:
         cmdline += ["-device", f"vhost-vsock-pci,guest-cid={machine_cid(config)}"]
 
     cmdline += ["-cpu", "max"]
@@ -292,8 +294,9 @@ def run_qemu(args: MkosiArgs, config: MkosiConfig) -> None:
             elif config.architecture == "aarch64":
                 cmdline += ["-device", "tpm-tis-device,tpmdev=tpm0"]
 
-        addr, notifications = stack.enter_context(vsock_notify_handler())
-        cmdline += ["-smbios", f"type=11,value=io.systemd.credential:vmm.notify_socket={addr}"]
+        if use_vsock:
+            addr, notifications = stack.enter_context(vsock_notify_handler())
+            cmdline += ["-smbios", f"type=11,value=io.systemd.credential:vmm.notify_socket={addr}"]
 
         cmdline += config.qemu_args
         cmdline += args.cmdline