Skip to main content

MachineBuilder

Struct MachineBuilder 

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

Builder for machine configuration (vCPUs, memory, etc.).

§Example

VmBuilder::new()
    .machine(|m| {
        m.vcpus(4)
            .memory_mib(2048)
            .hyperthreading(true)
            .nested_virt(true)
    });

Implementations§

Source§

impl MachineBuilder

Source

pub fn new() -> Self

Create a new machine builder with defaults.

Source

pub fn vcpus(self, count: u8) -> Self

Set the number of virtual CPUs.

Source

pub fn memory_mib(self, mib: usize) -> Self

Set the memory size in MiB.

Source

pub fn max_vcpus(self, count: u8) -> Self

Set the maximum possible virtual CPUs.

The VM boots with this full topology described to the guest but only vcpus online (maxcpus= boot parameter); the guest can online the remaining CPUs later through CPU hotplug. Defaults to the effective vCPU count, which reserves no extra capacity.

Source

pub fn max_memory_mib(self, mib: usize) -> Self

Set the maximum guest memory in MiB reserved for future memory hotplug.

Currently configuration plumbing only: capacity above memory_mib is validated and recorded but not yet consumed until the virtio-mem device lands. Defaults to the effective memory size, which reserves no extra capacity.

Source

pub fn hyperthreading(self, enabled: bool) -> Self

Enable or disable hyperthreading.

Source

pub fn nested_virt(self, enabled: bool) -> Self

Enable or disable nested virtualization.

Source

pub fn split_irqchip(self, enabled: bool) -> Self

Enable the userspace split irqchip on x86_64.

The default in-kernel IOAPIC is hardcoded by KVM to 24 pins, leaving only 11 IRQs for virtio-mmio devices. The userspace split irqchip emulates a larger IOAPIC (256 pins) and raises the usable range to 219 IRQs, which is needed for VMs with many virtio-mmio devices (e.g. lots of virtio-fs mounts or block devices). No effect on aarch64 or riscv64.

Source

pub fn vsock(self, enabled: bool) -> Self

Force-attach a virtio-vsock device to the guest.

By default, vsock is only attached when needed as a TSI transport (no virtio-net → HIJACK_INET, or single root virtio-fs on Linux → HIJACK_UNIX). Set this to true when the guest needs a vsock for its own purposes even though TSI would not otherwise require one.

Source

pub fn balloon(self, enabled: bool) -> Self

Enable or disable the virtio-balloon device.

The device is enabled by default for general-purpose VMs. Latency-sensitive guests that never resize memory can disable it to avoid one virtio-mmio device and its guest-side probe.

Source

pub fn balloon_stats_interval(self, interval: Option<Duration>) -> Self

Set the virtio-balloon guest memory statistics polling interval.

Some(interval) advertises and drives the stats queue at the requested cadence. None disables balloon stats polling while still allowing the balloon device itself to be attached.

Source

pub fn rng(self, enabled: bool) -> Self

Enable or disable the virtio-rng device.

The device is enabled by default. Guests with a known nonblocking boot path can disable it to remove one virtio-mmio device from cold start.

Source

pub fn msb_metrics(self, enabled: bool) -> Self

Enable or disable the private microsandbox metrics virtio device.

The device is enabled by default so protected guest filesystem metrics are available for bundled microsandbox kernels.

Source

pub fn enable_inet_hijack(self, enabled: bool) -> Self

Enable the automatic TSI INET hijack fallback.

When set to true and no virtio-net device is configured, TsiFlags::HIJACK_INET is enabled so the guest’s INET socket calls are transparently bridged to the host through vsock. This is useful for guests that need outbound connectivity without the caller setting up a virtio-net backend.

Defaults to false — guests with no virtio-net are air-gapped by default. Callers must opt in to TSI when they want host network access without an explicit network device.

Note: HIJACK_UNIX (used by virtio-fs on Linux for AF_UNIX hijack) is gated on HIJACK_INET already being set, so leaving INET hijack off also leaves the UNIX hijack auto-enable path off.

Trait Implementations§

Source§

impl Clone for MachineBuilder

Source§

fn clone(&self) -> MachineBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MachineBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MachineBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn as_mut_any(&mut self) -> &mut (dyn Any + 'static)

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V