Skip to main content

VmManager

Struct VmManager 

Source
pub struct VmManager { /* private fields */ }
Expand description

VM manager - orchestrates VM lifecycle.

Implementations§

Source§

impl VmManager

Source

pub fn new(config: BoxConfig, event_emitter: EventEmitter) -> Self

Create a new VM manager.

Source

pub fn with_box_id( config: BoxConfig, event_emitter: EventEmitter, box_id: String, ) -> Self

Create a new VM manager with a specific box ID.

Source

pub fn with_provider( config: BoxConfig, event_emitter: EventEmitter, provider: Box<dyn VmmProvider>, ) -> Self

Create a new VM manager with a custom VMM provider.

Source

pub fn box_id(&self) -> &str

Get the box ID.

Source

pub async fn state(&self) -> BoxState

Get current state.

Source

pub fn exec_client(&self) -> Option<&ExecClient>

Get the exec client, if connected.

Source

pub async fn attach_running_process( &mut self, pid: u32, exec_socket_path: PathBuf, pty_socket_path: Option<PathBuf>, ) -> Result<()>

Attach this manager to an already-running shim process.

This is useful for crash recovery or control-plane restart flows where the workload VM is still alive and only the host-side manager state needs to be reconstructed.

Source

pub fn exec_socket_path(&self) -> Option<&Path>

Get the exec socket path, if the VM has been booted.

Source

pub fn pty_socket_path(&self) -> Option<&Path>

Get the PTY socket path, if the VM has been booted.

Source

pub fn port_forward_socket_path(&self) -> Option<&Path>

Get the CRI port-forward socket path, if the VM has been booted.

Source

pub fn set_provider(&mut self, provider: Box<dyn VmmProvider>)

Inject a custom VMM provider (e.g., a VmController with a known shim path).

If set before boot(), the injected provider is used instead of the default VmController::find_shim() fallback.

Source

pub fn set_rootfs_provider(&mut self, provider: Box<dyn RootfsProvider>)

Override the rootfs provider (overlay or copy).

By default, default_provider() auto-detects the best available provider. Call this before boot() to force a specific provider.

Source

pub fn rootfs_provider_name(&self) -> &str

Get the name of the active rootfs provider.

Source

pub fn set_pull_progress_fn( &mut self, f: Arc<dyn Fn(usize, usize, &str, i64) + Send + Sync>, )

Set a progress callback for image pulls: (current, total, digest, size_bytes). Called once per layer when run pulls an image that is not yet cached.

Source

pub fn set_metrics(&mut self, metrics: RuntimeMetrics)

Attach Prometheus metrics to this VM manager.

Source

pub fn set_log_config(&mut self, log_config: LogConfig)

Set the logging driver config. Threaded into the InstanceSpec so the shim runs the log processor for the box’s lifetime.

Source

pub fn metrics_prom(&self) -> Option<&RuntimeMetrics>

Get the attached Prometheus metrics (if any).

Source

pub fn anonymous_volumes(&self) -> &[String]

Get the names of anonymous volumes created during boot.

These are auto-created from OCI VOLUME directives and should be tracked for cleanup when the box is removed.

Source

pub fn image_config(&self) -> Option<&OciImageConfig>

Get the OCI image config resolved during boot.

Source

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

Get the exit code of the container, if it has exited.

Returns Some(code) after destroy() has been called and the shim process exited naturally (not killed). Returns None if the VM has not yet stopped or the exit code could not be determined.

Source

pub async fn try_wait_exit(&mut self) -> Result<Option<i32>>

Poll the owned VM process for natural exit without sending a signal.

This is used by foreground CLI flows where the container command may finish on its own and the CLI should clean up instead of waiting for a Ctrl-C.

Source

pub async fn run_deferred_main( &mut self, spec_json: &[u8], timeout: Duration, ) -> Result<ExecOutput>

Run a command as the container MAIN in an IDLE-booted (deferred-main) VM.

Sends the spawn-main control frame carrying spec_json (the command), waits for the main to exit (which halts the VM), and returns its real exit code + the box’s json-file console logs split by stream. This is the full- box-semantics counterpart to Self::exec_command (whose output is piped over the exec stream, not the json-file logs).

Source

pub async fn exec_request(&self, request: &ExecRequest) -> Result<ExecOutput>

Execute a command in the guest VM.

Requires the VM to be in Ready, Busy, or Compacting state.

Source

pub async fn exec_command( &self, cmd: Vec<String>, timeout_ns: u64, ) -> Result<ExecOutput>

Execute a command in the guest VM.

Requires the VM to be in Ready, Busy, or Compacting state.

Source

pub async fn boot(&mut self) -> Result<()>

Boot the VM.

Source

pub async fn destroy(&mut self) -> Result<()>

Destroy the VM with the default shutdown timeout and SIGTERM.

Source

pub async fn destroy_with_timeout(&mut self, timeout_ms: u64) -> Result<()>

Destroy the VM with a custom shutdown timeout and SIGTERM.

Source

pub async fn destroy_with_options( &mut self, signal: i32, timeout_ms: u64, ) -> Result<()>

Destroy the VM with a specific stop signal and timeout.

Sends signal to the shim process and waits up to timeout_ms for it to exit gracefully before sending SIGKILL.

Source

pub async fn set_busy(&self) -> Result<()>

Transition to busy state.

Source

pub async fn set_ready(&self) -> Result<()>

Transition back to ready state.

Source

pub async fn set_compacting(&self) -> Result<()>

Transition to compacting state.

Source

pub async fn pause(&self) -> Result<()>

Pause the VM by sending SIGSTOP to the shim process.

The VM must be in Ready, Busy, or Compacting state.

Source

pub async fn resume(&self) -> Result<()>

Resume the VM by sending SIGCONT to the shim process.

Can be called on a paused VM to resume execution.

Source

pub async fn health_check(&self) -> Result<bool>

Check if VM is healthy.

Source

pub async fn metrics(&self) -> Option<VmMetrics>

Get VM metrics.

Source

pub async fn pid(&self) -> Option<u32>

Get the PID of the VM shim process.

Source

pub fn tee(&self) -> Option<&dyn TeeExtension>

Get the TEE extension, if TEE is configured and VM is booted.

Source

pub fn require_tee(&self) -> Result<&dyn TeeExtension>

Get the TEE extension or return an error.

Source

pub async fn update_resources( &self, update: &ResourceUpdate, ) -> Result<ResizeResult>

Apply a live resource update to the running VM.

Tier 1 changes (vCPU count, memory size) are rejected with a clear error because libkrun does not expose a hot-resize API.

Tier 2 changes (cgroup-based limits) are applied by executing shell commands inside the guest that write to cgroup v2 control files.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more