How openeuler-mirror/stratovirt works
Purpose and entry points
StratoVirt is a Rust virtualization platform for cloud datacenters, supporting standard VMs, lightweight microVMs, and container/Serverless-adjacent runtimes. The primary stratovirt process starts at src/main.rs, parses VM configuration, creates the selected machine model, and exposes management over QMP. Auxiliary executables include the image tool at image/src/main.rs, OCI-oriented ozonec/src/main.rs, and sandbox helper ozone/src/main.rs.
Startup, configuration, and management plane
CLI arguments and device definitions are parsed into machine configuration by machine_manager/src/cmdline.rs and machine_manager/src/config/mod.rs. machine_manager/src/machine.rs coordinates lifecycle creation and runtime operations; its event loop and notifier layer (machine_manager/src/event_loop.rs, machine_manager/src/notifier.rs) bridge host file descriptors/events to VM components. QMP is a Unix-socket control boundary implemented under machine_manager/src/qmp/qmp_socket.rs and machine_manager/src/qmp/qmp_schema.rs.
Machine construction and guest boot
The machine crate realizes architecture- and model-specific virtual hardware: x86 standard/micro machines live in machine/src/x86_64/standard.rs and machine/src/x86_64/micro.rs; AArch64 equivalents are in machine/src/aarch64/standard.rs and machine/src/aarch64/micro.rs. Boot loading is separated into boot_loader/src/x86_64/mod.rs and boot_loader/src/aarch64/mod.rs. Firmware-facing metadata is generated through ACPI for x86 (acpi/src/acpi_table.rs) or device trees for AArch64 (machine/src/aarch64/fdt.rs).
CPU, memory, and KVM boundary
Guest execution uses Linux KVM through hypervisor/src/kvm/mod.rs, with architecture-specific register/capability handling in hypervisor/src/kvm/x86_64/mod.rs and hypervisor/src/kvm/aarch64/mod.rs. Guest physical-memory layout, RAM regions, host mappings, and address-space listener notifications are owned by address_space/src/address_space.rs, address_space/src/region.rs, and address_space/src/host_mmap.rs. This is the primary boundary between VM abstractions and host kernel APIs, including userfaultfd support (address_space/src/uffd.rs).
Virtual devices and I/O data paths
The device model is divided by bus and protocol. PCI topology, configuration, interrupts, and hotplug are under devices/src/pci/bus.rs, devices/src/pci/config.rs, and devices/src/pci/hotplug.rs; platform/sysbus devices are rooted in devices/src/sysbus/mod.rs. Virtio supplies the main paravirtual I/O path: common queues/transports are in virtio/src/queue/split.rs and virtio/src/transport/virtio_pci.rs, while block and network devices are in virtio/src/device/block.rs and virtio/src/device/net.rs. Host-backed storage supports raw and qcow2 images via block_backend/src/raw.rs and block_backend/src/qcow2/mod.rs.
Host integrations and advanced lifecycle
Host I/O relies on Linux facilities including TAP networking (util/src/tap.rs), asynchronous I/O (util/src/aio/mod.rs), seccomp (util/src/seccomp.rs), VFIO passthrough (vfio/src/vfio_pci.rs), and vhost kernel/user backends (virtio/src/vhost/kernel/mod.rs, virtio/src/vhost/user/mod.rs). Migration and snapshots are centralized in migration/src/manager.rs, migration/src/protocol.rs, and migration/src/snapshot.rs; they form a lifecycle boundary requiring machine, memory, CPU, and device state coordination.
Observability and user-facing access
Tracing is generated from event definitions and emitted through trace/src/lib.rs, trace/src/ftrace.rs, and trace/src/hitrace.rs; system events use hisysevent/src/interface.rs. Guest display/input can use VNC (ui/src/vnc/mod.rs), GTK (ui/src/gtk/mod.rs), or OHUI server channels (ui/src/ohui_srv/mod.rs). These remain optional peripheral front ends rather than the core VM control path.
Main entry points: machine.rs Machine manager · standard.rs Standard and micro machines · manager.rs Migration and snapshots · block.rs Virtio block and net
Components 20
Entrypoints
- stratovirt process · Primary VM launcher.
src/main.rs - Auxiliary tools · Image and OCI/sandbox executables.
image/src/main.rs
Control Plane
- CLI and VM config
machine_manager/src/cmdline.rs - Machine manager
machine_manager/src/machine.rs - Event loop and notifiers
machine_manager/src/event_loop.rs - QMP control socket
machine_manager/src/qmp/qmp_socket.rs
Machine Construction
- Standard and micro machines · Architecture-specific x86 and AArch64 hardware realization.
machine/src/x86_64/standard.rs - Boot loader · Loads architecture-specific guest boot state.
boot_loader/src/x86_64/mod.rs - ACPI / device tree · Exposes virtual hardware to the guest.
acpi/src/acpi_table.rs
Execution Core
- KVM backend · CPU virtualization and KVM capability handling.
hypervisor/src/kvm/mod.rs - Guest address space · RAM regions, host mappings, listeners, and userfaultfd.
address_space/src/address_space.rs
I/O and Devices
- PCI and sysbus · PCI topology, interrupts, hotplug, and platform devices.
devices/src/pci/bus.rs - Virtio transport and queues · PCI transport and split virtqueues.
virtio/src/transport/virtio_pci.rs - Virtio block and net
virtio/src/device/block.rs - Block backends · Raw and qcow2 host-backed images.
block_backend/src/qcow2/mod.rs - Host I/O facilities · TAP networking, async I/O, and seccomp.
util/src/aio/mod.rs - VFIO and vhost · Passthrough and kernel/user vhost backends.
vfio/src/vfio_pci.rs
Lifecycle and Access
- Migration and snapshots · Coordinates machine, CPU, memory, and device state.
migration/src/manager.rs - Tracing and system events
trace/src/lib.rs - Display and input front ends · VNC, GTK, and OHUI access paths.
ui/src/vnc/mod.rs
Connections 26
- stratovirt process → CLI and VM config: parses
- stratovirt process → Machine manager: starts
- CLI and VM config → Machine manager: supplies VM definition
- QMP control socket → Machine manager: management commands
- Machine manager → Event loop and notifiers: drives
- Event loop and notifiers → QMP control socket: socket events
- Machine manager → Standard and micro machines: creates
- Standard and micro machines → Boot loader: boots guest
- Standard and micro machines → ACPI / device tree: publishes hardware metadata
- Standard and micro machines → KVM backend: creates vCPUs
- Standard and micro machines → Guest address space: maps guest RAM
- Standard and micro machines → PCI and sysbus: realizes buses
- PCI and sysbus → Virtio transport and queues: hosts PCI transport
- Virtio transport and queues → Virtio block and net: carries queues
- Virtio block and net → Block backends: block I/O
- Virtio block and net → Host I/O facilities: network and async I/O
- PCI and sysbus → VFIO and vhost: passthrough attachment
- Virtio transport and queues → VFIO and vhost: vhost acceleration
- Guest address space → KVM backend: memory slots
- Machine manager → Migration and snapshots: lifecycle operations
- Migration and snapshots → Standard and micro machines: machine state
- Migration and snapshots → Guest address space: memory state
- Migration and snapshots → KVM backend: CPU state
- Migration and snapshots → Virtio block and net: device state
- Machine manager → Tracing and system events: emits events
- Machine manager → Display and input front ends: optional guest access