pub trait VirtualMachine: Send + Sync {
type Vcpu: Vcpu;
type Memory: GuestMemory;
Show 13 methods
// Required methods
fn memory(&self) -> &Self::Memory;
fn create_vcpu(&mut self, id: u32) -> Result<Self::Vcpu, HypervisorError>;
fn add_virtio_device(
&mut self,
device: VirtioDeviceConfig,
) -> Result<(), HypervisorError>;
fn start(&mut self) -> Result<(), HypervisorError>;
fn pause(&mut self) -> Result<(), HypervisorError>;
fn resume(&mut self) -> Result<(), HypervisorError>;
fn stop(&mut self) -> Result<(), HypervisorError>;
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
fn vcpu_count(&self) -> u32;
fn snapshot_devices(&self) -> Result<Vec<DeviceSnapshot>, HypervisorError>;
fn restore_devices(
&mut self,
snapshots: &[DeviceSnapshot],
) -> Result<(), HypervisorError>;
// Provided method
fn is_managed_execution(&self) -> bool { ... }
}Expand description
Virtual machine trait for managing VM lifecycle and devices.
Required Associated Types§
Sourcetype Memory: GuestMemory
type Memory: GuestMemory
The guest memory type for this VM.
Required Methods§
Sourcefn create_vcpu(&mut self, id: u32) -> Result<Self::Vcpu, HypervisorError>
fn create_vcpu(&mut self, id: u32) -> Result<Self::Vcpu, HypervisorError>
Creates a new vCPU.
For managed execution VMs, this may return a placeholder vCPU.
§Errors
Returns an error if the vCPU cannot be created.
Sourcefn add_virtio_device(
&mut self,
device: VirtioDeviceConfig,
) -> Result<(), HypervisorError>
fn add_virtio_device( &mut self, device: VirtioDeviceConfig, ) -> Result<(), HypervisorError>
Sourcefn start(&mut self) -> Result<(), HypervisorError>
fn start(&mut self) -> Result<(), HypervisorError>
Sourcefn pause(&mut self) -> Result<(), HypervisorError>
fn pause(&mut self) -> Result<(), HypervisorError>
Sourcefn resume(&mut self) -> Result<(), HypervisorError>
fn resume(&mut self) -> Result<(), HypervisorError>
Sourcefn stop(&mut self) -> Result<(), HypervisorError>
fn stop(&mut self) -> Result<(), HypervisorError>
Sourcefn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
Returns the VM as a reference to Any for downcasting.
This allows the caller to downcast the VM to its concrete type for platform-specific operations like IRQ injection.
Sourcefn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Returns the VM as a mutable reference to Any for downcasting.
Sourcefn vcpu_count(&self) -> u32
fn vcpu_count(&self) -> u32
Returns the number of vCPUs in the VM.
Sourcefn snapshot_devices(&self) -> Result<Vec<DeviceSnapshot>, HypervisorError>
fn snapshot_devices(&self) -> Result<Vec<DeviceSnapshot>, HypervisorError>
Sourcefn restore_devices(
&mut self,
snapshots: &[DeviceSnapshot],
) -> Result<(), HypervisorError>
fn restore_devices( &mut self, snapshots: &[DeviceSnapshot], ) -> Result<(), HypervisorError>
Restores device states from snapshots.
§Errors
Returns an error if device states cannot be restored.
Provided Methods§
Sourcefn is_managed_execution(&self) -> bool
fn is_managed_execution(&self) -> bool
Returns whether this VM uses managed execution.
Managed execution (returns true):
- The hypervisor manages vCPU execution internally
start()begins VM execution,stop()ends itcreate_vcpu()is optional/placeholder- Examples: macOS Virtualization.framework
Manual execution (returns false):
- The caller must create vCPU threads and call
vcpu.run()in a loop start()andstop()are optional state markers- Examples: Linux KVM