Architecture & Internals
qvm-ctl is implemented in Rust as a compiled native binary. It manages virtual machines as standalone background processes without hypervisor daemons or runtime interpreter dependencies.
Rust Module Design
The codebase is organized into clean, single-responsibility modules:
cli: Command-line argument parsing and validation powered byclap.qemu: Pure, testable QEMU command builder mapping VM configuration to Q35/KVM parameters.port: Subprocess-free dynamic TCP port allocation usingstd::net::TcpListener(starting at port 5900 for SPICE and 3389 for RDP).process: Subprocess management, PID file tracking, and graceful signal dispatch vianix.ovmf: Multi-distribution discovery for UEFIOVMF_CODEandOVMF_VARSfirmware templates across Arch, Debian/Ubuntu, and Fedora.tpm: Lifecycle supervisor forswtpmsoftware TPM 2.0 daemon and Unix control sockets.config: Strongly-typed parser and serializer forvm.confkey-value pairs and environment overrides.error: Comprehensive error domain modeled withthiserrorandanyhow.
Directory Layout
Each VM is self-contained in ~/vms/<name>/:
~/vms/<name>/
├── vm.conf # VM configuration and hardware parameters
├── disk.qcow2 # Primary QCOW2 sparse virtual disk
├── ovmf-vars.fd # Independent writable UEFI NVRAM
├── qemu.log # Process stdout & stderr log
├── spice.port # Currently allocated SPICE port
├── rdp.port # Currently allocated RDP port
├── <name>.pid # QEMU process ID
├── swtpm.pid # swtpm process ID
├── swtpm.sock # Unix control socket for swtpm
└── tpm/ # Persistent TPM 2.0 state directory
Hardware Configuration
When qvm launch runs, it executes qemu-system-x86_64 with:
- Chipset:
q35withaccel=kvmand host CPU passthrough (-cpu host). - Firmware: UEFI via read-only
OVMF_CODEand per-VM writableovmf-vars.fd. - Security: Hardware TPM 2.0 emulation via
swtpmon a dedicated Unix socket (-device tpm-crb). - Graphics:
virtio-gpu-pciwith SPICE server andvdagentfor clipboard synchronization and auto-resizing. - Input: USB tablet pointer device (
-device usb-tablet) for lag-free cursor tracking. - Storage: Paravirtualized VirtIO block device (
-drive file=$DISK,if=virtio,format=qcow2). - Networking: User-mode networking with VirtIO (
-nic user,model=virtio-net-pci) with host port-forwarding for RDP.
Port & Concurrency Management
- Port Allocation: Dynamic scanning with native
std::net::TcpListener::bindeliminates external subprocess overhead (such asss) while guaranteeing no port collisions. - Launch Locking: Uses cross-process advisory locking (
fd-lock) on.launch.lockto prevent accidental concurrent execution of the same VM.