pub trait VhostUserBackend: Send + Sync {
    type Bitmap: Bitmap + 'static;
    type Vring: VringT<GuestMemoryAtomic<GuestMemoryMmap<Self::Bitmap>>>;

Show 13 methods // Required methods fn num_queues(&self) -> usize; fn max_queue_size(&self) -> usize; fn features(&self) -> u64; fn protocol_features(&self) -> VhostUserProtocolFeatures; fn set_event_idx(&self, enabled: bool); fn update_memory( &self, mem: GuestMemoryAtomic<GuestMemoryMmap<Self::Bitmap>> ) -> Result<()>; fn handle_event( &self, device_event: u16, evset: EventSet, vrings: &[Self::Vring], thread_id: usize ) -> Result<()>; // Provided methods fn acked_features(&self, _features: u64) { ... } fn get_config(&self, _offset: u32, _size: u32) -> Vec<u8> { ... } fn set_config(&self, _offset: u32, _buf: &[u8]) -> Result<()> { ... } fn set_backend_req_fd(&self, _backend: Backend) { ... } fn queues_per_thread(&self) -> Vec<u64> { ... } fn exit_event(&self, _thread_index: usize) -> Option<EventFd> { ... }
}
Expand description

Trait with interior mutability for vhost user backend servers to implement concrete services.

To support multi-threading and asynchronous IO, we enforce Send + Sync bound.

Required Associated Types§

Required Methods§

source

fn num_queues(&self) -> usize

Get number of queues supported.

source

fn max_queue_size(&self) -> usize

Get maximum queue size supported.

source

fn features(&self) -> u64

Get available virtio features.

source

fn protocol_features(&self) -> VhostUserProtocolFeatures

Get available vhost protocol features.

source

fn set_event_idx(&self, enabled: bool)

Enable or disable the virtio EVENT_IDX feature

source

fn update_memory( &self, mem: GuestMemoryAtomic<GuestMemoryMmap<Self::Bitmap>> ) -> Result<()>

Update guest memory regions.

source

fn handle_event( &self, device_event: u16, evset: EventSet, vrings: &[Self::Vring], thread_id: usize ) -> Result<()>

Handle IO events for backend registered file descriptors.

This function gets called if the backend registered some additional listeners onto specific file descriptors. The library can handle virtqueues on its own, but does not know what to do with events happening on custom listeners.

Provided Methods§

source

fn acked_features(&self, _features: u64)

Set acknowledged virtio features.

source

fn get_config(&self, _offset: u32, _size: u32) -> Vec<u8>

Get virtio device configuration.

A default implementation is provided as we cannot expect all backends to implement this function.

source

fn set_config(&self, _offset: u32, _buf: &[u8]) -> Result<()>

Set virtio device configuration.

A default implementation is provided as we cannot expect all backends to implement this function.

source

fn set_backend_req_fd(&self, _backend: Backend)

Set handler for communicating with the frontend by the backend communication channel.

A default implementation is provided as we cannot expect all backends to implement this function.

source

fn queues_per_thread(&self) -> Vec<u64>

Get the map to map queue index to worker thread index.

A return value of [2, 2, 4] means: the first two queues will be handled by worker thread 0, the following two queues will be handled by worker thread 1, and the last four queues will be handled by worker thread 2.

source

fn exit_event(&self, _thread_index: usize) -> Option<EventFd>

Provide an optional exit EventFd for the specified worker thread.

The returned EventFd will be monitored for IO events. When the returned EventFd is written to, the worker thread will exit.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T: VhostUserBackend> VhostUserBackend for Arc<T>

§

type Bitmap = <T as VhostUserBackend>::Bitmap

§

type Vring = <T as VhostUserBackend>::Vring

source§

fn num_queues(&self) -> usize

source§

fn max_queue_size(&self) -> usize

source§

fn features(&self) -> u64

source§

fn acked_features(&self, features: u64)

source§

fn protocol_features(&self) -> VhostUserProtocolFeatures

source§

fn set_event_idx(&self, enabled: bool)

source§

fn get_config(&self, offset: u32, size: u32) -> Vec<u8>

source§

fn set_config(&self, offset: u32, buf: &[u8]) -> Result<()>

source§

fn update_memory( &self, mem: GuestMemoryAtomic<GuestMemoryMmap<Self::Bitmap>> ) -> Result<()>

source§

fn set_backend_req_fd(&self, backend: Backend)

source§

fn queues_per_thread(&self) -> Vec<u64>

source§

fn exit_event(&self, thread_index: usize) -> Option<EventFd>

source§

fn handle_event( &self, device_event: u16, evset: EventSet, vrings: &[Self::Vring], thread_id: usize ) -> Result<()>

source§

impl<T: VhostUserBackendMut> VhostUserBackend for Mutex<T>

§

type Bitmap = <T as VhostUserBackendMut>::Bitmap

§

type Vring = <T as VhostUserBackendMut>::Vring

source§

fn num_queues(&self) -> usize

source§

fn max_queue_size(&self) -> usize

source§

fn features(&self) -> u64

source§

fn acked_features(&self, features: u64)

source§

fn protocol_features(&self) -> VhostUserProtocolFeatures

source§

fn set_event_idx(&self, enabled: bool)

source§

fn get_config(&self, offset: u32, size: u32) -> Vec<u8>

source§

fn set_config(&self, offset: u32, buf: &[u8]) -> Result<()>

source§

fn update_memory( &self, mem: GuestMemoryAtomic<GuestMemoryMmap<Self::Bitmap>> ) -> Result<()>

source§

fn set_backend_req_fd(&self, backend: Backend)

source§

fn queues_per_thread(&self) -> Vec<u64>

source§

fn exit_event(&self, thread_index: usize) -> Option<EventFd>

source§

fn handle_event( &self, device_event: u16, evset: EventSet, vrings: &[Self::Vring], thread_id: usize ) -> Result<()>

source§

impl<T: VhostUserBackendMut> VhostUserBackend for RwLock<T>

§

type Bitmap = <T as VhostUserBackendMut>::Bitmap

§

type Vring = <T as VhostUserBackendMut>::Vring

source§

fn num_queues(&self) -> usize

source§

fn max_queue_size(&self) -> usize

source§

fn features(&self) -> u64

source§

fn acked_features(&self, features: u64)

source§

fn protocol_features(&self) -> VhostUserProtocolFeatures

source§

fn set_event_idx(&self, enabled: bool)

source§

fn get_config(&self, offset: u32, size: u32) -> Vec<u8>

source§

fn set_config(&self, offset: u32, buf: &[u8]) -> Result<()>

source§

fn update_memory( &self, mem: GuestMemoryAtomic<GuestMemoryMmap<Self::Bitmap>> ) -> Result<()>

source§

fn set_backend_req_fd(&self, backend: Backend)

source§

fn queues_per_thread(&self) -> Vec<u64>

source§

fn exit_event(&self, thread_index: usize) -> Option<EventFd>

source§

fn handle_event( &self, device_event: u16, evset: EventSet, vrings: &[Self::Vring], thread_id: usize ) -> Result<()>

Implementors§