Skip to main content

VmHandler

Trait VmHandler 

Source
pub trait VmHandler: Send + Sync {
    // Required methods
    fn stop(&mut self, signal: i32, timeout_ms: u64) -> Result<(), BoxError>;
    fn metrics(&self) -> VmMetrics;
    fn is_running(&self) -> bool;
    fn pid(&self) -> u32;

    // Provided methods
    fn has_exited(&self) -> bool { ... }
    fn exit_code(&self) -> Option<i32> { ... }
    fn try_wait_exit(&mut self) -> Result<Option<i32>, BoxError> { ... }
}
Expand description

Lifecycle operations on a running VM.

Separates runtime operations (stop, metrics) from spawning (VmmProvider). Allows reconnecting to existing VMs by constructing a handler from a PID.

Required Methods§

Source

fn stop(&mut self, signal: i32, timeout_ms: u64) -> Result<(), BoxError>

Stop the VM. Sends signal first, then SIGKILL after timeout_ms.

Source

fn metrics(&self) -> VmMetrics

Get current CPU and memory metrics.

Source

fn is_running(&self) -> bool

Check if the VM process is still alive.

Source

fn pid(&self) -> u32

Return the OS process ID of the VM.

Provided Methods§

Source

fn has_exited(&self) -> bool

Whether the VM process has exited, treating a zombie (an exited child not yet reaped by its parent) as exited.

Distinct from !is_running(): shim handlers implement is_running with kill(pid, 0), which still succeeds for a zombie, so a freshly-exited shim looks alive until its parent reaps it. Boot-readiness waits use this so a short-lived container’s exit does not stall the wait for the full timeout. On Linux it inspects /proc/<pid> process state; elsewhere it falls back to !is_running().

Source

fn exit_code(&self) -> Option<i32>

Return the exit code of the VM process, if it has exited.

Returns None until stop() has been called and the process has exited. Backends that do not track exit codes may leave this as the default None.

Source

fn try_wait_exit(&mut self) -> Result<Option<i32>, BoxError>

Poll the VM process for natural exit without sending any signal.

Implementations that own a child process handle can use this to reap short-lived foreground workloads. Backends that cannot poll should return Ok(None).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§