Trait VirtioDeviceBuilder

Source
pub trait VirtioDeviceBuilder: Sized {
    const NAME: &'static str;

    // Required method
    fn create_virtio_device(
        self,
        protection_type: ProtectionType,
    ) -> Result<Box<dyn VirtioDevice>>;

    // Provided methods
    fn create_vhost_user_device(
        self,
        _keep_rds: &mut Vec<RawDescriptor>,
    ) -> Result<Box<dyn VhostUserDeviceBuilder>> { ... }
    fn create_jail(
        &self,
        jail_config: Option<&JailConfig>,
        virtio_transport: VirtioDeviceType,
    ) -> Result<Option<Minijail>> { ... }
    fn create_virtio_device_and_jail(
        self,
        protection_type: ProtectionType,
        jail_config: Option<&JailConfig>,
    ) -> Result<VirtioDeviceStub> { ... }
}
Expand description

A trait for spawning virtio device instances and jails from their configuration structure.

Implementors become able to create virtio devices and jails following their own configuration. This trait also provides a few convenience methods for e.g. creating a virtio device and jail at once.

Required Associated Constants§

Source

const NAME: &'static str

Base name of the device, as it will appear in logs.

Required Methods§

Source

fn create_virtio_device( self, protection_type: ProtectionType, ) -> Result<Box<dyn VirtioDevice>>

Create a regular virtio device from the configuration and protection_type setting.

Provided Methods§

Source

fn create_vhost_user_device( self, _keep_rds: &mut Vec<RawDescriptor>, ) -> Result<Box<dyn VhostUserDeviceBuilder>>

Create a device suitable for being run as a vhost-user instance.

It is ok to leave this method unimplemented if the device is not intended to be used with vhost-user.

Source

fn create_jail( &self, jail_config: Option<&JailConfig>, virtio_transport: VirtioDeviceType, ) -> Result<Option<Minijail>>

Create a jail that is suitable to run a device.

The default implementation creates a simple jail with a seccomp policy derived from the base name of the device.

Source

fn create_virtio_device_and_jail( self, protection_type: ProtectionType, jail_config: Option<&JailConfig>, ) -> Result<VirtioDeviceStub>

Helper method to return a VirtioDeviceStub filled using create_virtio_device and create_jail.

This helper should cover the needs of most devices when run as regular virtio devices.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl VirtioDeviceBuilder for &SerialParameters

For creating console virtio devices.

Source§

const NAME: &'static str = "serial"

Source§

fn create_virtio_device( self, protection_type: ProtectionType, ) -> Result<Box<dyn VirtioDevice>>

Source§

fn create_vhost_user_device( self, keep_rds: &mut Vec<RawDescriptor>, ) -> Result<Box<dyn VhostUserDeviceBuilder>>

Source§

fn create_jail( &self, jail_config: Option<&JailConfig>, virtio_transport: VirtioDeviceType, ) -> Result<Option<Minijail>>

Source§

impl VirtioDeviceBuilder for &NetParameters

Source§

const NAME: &'static str = "net"

Source§

fn create_virtio_device( self, protection_type: ProtectionType, ) -> Result<Box<dyn VirtioDevice>>

Source§

fn create_jail( &self, jail_config: Option<&JailConfig>, virtio_transport: VirtioDeviceType, ) -> Result<Option<Minijail>>

Source§

fn create_vhost_user_device( self, keep_rds: &mut Vec<RawDescriptor>, ) -> Result<Box<dyn VhostUserDeviceBuilder>>

Source§

impl VirtioDeviceBuilder for &VsockConfig

Source§

const NAME: &'static str = "vhost_vsock"

Source§

fn create_virtio_device( self, protection_type: ProtectionType, ) -> Result<Box<dyn VirtioDevice>>

Source§

fn create_vhost_user_device( self, keep_rds: &mut Vec<RawDescriptor>, ) -> Result<Box<dyn VhostUserDeviceBuilder>>

Implementors§

Source§

impl VirtioDeviceBuilder for DiskConfig<'_>

Source§

const NAME: &'static str = "block"

Source§

impl<'a> VirtioDeviceBuilder for &'a ScsiConfig<'a>

Source§

const NAME: &'static str = "scsi"