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.

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<'a> VirtioDeviceBuilder for &'a ScsiConfig<'a>

source§

const NAME: &'static str = "scsi"

source§

impl<'a> VirtioDeviceBuilder for DiskConfig<'a>

source§

const NAME: &'static str = "block"