-
Notifications
You must be signed in to change notification settings - Fork 12
Orchestration of various Virtio devices (reopened) #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
cbd3f8f
9b45ce0
39a0ec2
fab5ab3
f3d06e1
acdfb89
2bc9aea
79eaede
5657b7b
afffb7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,43 @@ | |
| } | ||
| }, | ||
|
|
||
| "virtiocon" : { | ||
| "description" : "VirtioCON device. Only used for testing Virtio queues for now", | ||
| "type" : "object", | ||
| "properties" : { | ||
| "path" : { | ||
| "description" : "The path to redirect the guest output", | ||
| "type" : "string" | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| "virtiofs" : { | ||
| "description" : "VirtioFS device", | ||
| "type" : "object", | ||
| "properties" : { | ||
| "socket" : { "type" : "string" }, | ||
| "shared" : { | ||
| "description" : "Directory to be shared with guest", | ||
| "type" : "string" | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| "virtiopmem": { | ||
| "description" : "VirtioPMEM device", | ||
| "type" : "object", | ||
| "properties" : { | ||
| "image" : { | ||
| "description" : "Path to persistent image file", | ||
| "type" : "string" | ||
| }, | ||
| "size" : { | ||
| "description" : "Persistent memory size in megabytes", | ||
| "type" : "number" | ||
| } | ||
| } | ||
| }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So new device types for virtio console, fs and pmem - nice! |
||
|
|
||
| "mem" : { | ||
| "description" : "Amount of memory in megabytes", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import re | ||
| import traceback | ||
| import signal | ||
| import time | ||
| from enum import Enum | ||
| import platform | ||
| import psutil | ||
|
|
@@ -186,6 +187,7 @@ def __init__(self, config): | |
| self._enable_kvm = False # must be explicitly turned on at boot. | ||
| self._sudo = False # Set to true if sudo is available | ||
| self._proc = None # A running subprocess | ||
| self._virtiofsd_proc = None | ||
|
|
||
| # pylint: disable-next=unused-argument | ||
| def boot_in_hypervisor(self, multiboot=False, debug=False, kernel_args="", image_name="", allow_sudo = False, enable_kvm = False): | ||
|
|
@@ -516,6 +518,39 @@ def net_arg(self, backend, device, if_name = "net0", mac = None, bridge = None, | |
| return ["-device", device, | ||
| "-netdev", netdev] | ||
|
|
||
| def init_virtiocon(self, path): | ||
| """ creates a console device and redirects to the path given """ | ||
| qemu_args = ["-device", "virtio-serial-pci,disable-legacy=on,id=virtio-serial0"] | ||
| qemu_args += ["-device", "virtserialport,chardev=char0"] | ||
| qemu_args += ["-chardev", f"file,id=char0,path={path}"] | ||
|
|
||
| return qemu_args | ||
|
|
||
| def init_virtiofs(self, socket, shared, mem): | ||
| """ initializes virtiofs by launching virtiofsd and creating a virtiofs device """ | ||
| virtiofsd_args = ["virtiofsd", "--socket", socket, "--shared-dir", shared, "--sandbox", "none"] | ||
| self._virtiofsd_proc = subprocess.Popen(virtiofsd_args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # pylint: disable=consider-using-with | ||
|
|
||
| time.sleep(0.1) | ||
|
||
| if self._virtiofsd_proc.poll(): | ||
| raise Exception("VirtioFSD failed to start") | ||
|
|
||
| info("Successfully started VirtioFSD!") | ||
|
|
||
| qemu_args = ["-machine", "memory-backend=mem0"] | ||
| qemu_args += ["-chardev", f"socket,id=virtiofsd0,path={socket}"] | ||
| qemu_args += ["-device", "vhost-user-fs-pci,chardev=virtiofsd0,tag=virtiofs0"] | ||
| qemu_args += ["-object", f"memory-backend-memfd,id=mem0,size={mem}M,share=on"] | ||
|
|
||
| return qemu_args | ||
|
|
||
| def init_pmem(self, path, size): | ||
| """ creates a pmem device with image path as memory mapped backend """ | ||
| qemu_args = ["-object", f"memory-backend-file,id=pmemdev0,mem-path={path},size={size}M,share=on"] | ||
| qemu_args += ["-device", "virtio-pmem-pci,memdev=pmemdev0"] | ||
|
|
||
| return qemu_args | ||
|
|
||
| def kvm_present(self): | ||
| """ returns true if KVM is present and available """ | ||
| if not self._enable_kvm: | ||
|
|
@@ -660,7 +695,7 @@ def boot_in_hypervisor(self, multiboot=True, debug = False, kernel_args = "", im | |
|
|
||
| mem_arg = [] | ||
| if "mem" in self._config: | ||
| mem_arg = ["-m", str(self._config["mem"])] | ||
| mem_arg = ["-m", f"size={self._config["mem"]},maxmem={64}G"] | ||
|
||
|
|
||
| vga_arg = ["-nographic" ] | ||
| if "vga" in self._config: | ||
|
|
@@ -674,6 +709,36 @@ def boot_in_hypervisor(self, multiboot=True, debug = False, kernel_args = "", im | |
| if "vfio" in self._config: | ||
| pci_arg = ["-device", "vfio-pci,host=" + self._config["vfio"]] | ||
|
|
||
| virtiocon_args = [] | ||
| if "virtiocon" in self._config: | ||
| if "path" not in self._config["virtiocon"]: | ||
| raise Exception("Missing redirection path for guest output") | ||
| virtiocon_args = self.init_virtiocon(self._config["virtiocon"]["path"]) | ||
|
|
||
| virtiofs_args = [] | ||
| if "virtiofs" in self._config: | ||
| socket = "/tmp/virtiofsd.sock" | ||
|
||
| if "socket" in self._config["virtiofs"]: | ||
| socket = self._config["virtiofs"]["socket"] | ||
|
|
||
| if "shared" not in self._config["virtiofs"]: | ||
| raise Exception("Shared directory not specified for VirtioFS!") | ||
| shared = self._config["virtiofs"]["shared"] | ||
|
|
||
| virtiofs_args = self.init_virtiofs(socket, shared, self._config["mem"]) | ||
|
|
||
| virtiopmem_args = [] | ||
| if "virtiopmem" in self._config: | ||
| if "image" not in self._config["virtiopmem"]: | ||
| raise Exception("Missing path to persistent image file") | ||
| image = self._config["virtiopmem"]["image"] | ||
|
|
||
| if "size" not in self._config["virtiopmem"]: | ||
| raise Exception("Missing persistent memory size") | ||
| size = self._config["virtiopmem"]["size"] | ||
|
|
||
| virtiopmem_args = self.init_pmem(image, size) | ||
|
|
||
| # custom qemu binary/location | ||
| qemu_binary = "qemu-system-x86_64" | ||
| if "qemu" in self._config: | ||
|
|
@@ -703,7 +768,8 @@ def boot_in_hypervisor(self, multiboot=True, debug = False, kernel_args = "", im | |
|
|
||
| command += kernel_args | ||
| command += disk_args + debug_args + net_args + mem_arg + mod_args | ||
| command += vga_arg + trace_arg + pci_arg | ||
| command += vga_arg + trace_arg + pci_arg + virtiocon_args + virtiofs_args | ||
| command += virtiopmem_args | ||
|
|
||
| #command_str = " ".join(command) | ||
| #command_str.encode('ascii','ignore') | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this pin - we can inherit the toplevel pin, typically from IncldueOS' pinned.nix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can easily remove it. VirtioFSD should work with the latest nixpkgs. We need to check for breaking changes
when updating nixpkgs in the future.