Trait VhostUserBackend

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

Show 18 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 reset_device(&self) { ... } 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 get_shared_object(&self, _uuid: VhostUserSharedMsg) -> Result<File> { ... } fn set_gpu_socket(&self, _gpu_backend: GpuBackend) -> Result<()> { ... } fn queues_per_thread(&self) -> Vec<u64> { ... } fn exit_event(&self, _thread_index: usize) -> Option<EventFd> { ... } fn set_device_state_fd( &self, _direction: VhostTransferStateDirection, _phase: VhostTransferStatePhase, _file: File, ) -> Result<Option<File>> { ... } fn check_device_state(&self) -> Result<()> { ... }
}
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 reset_device(&self)

Reset the emulated device state.

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

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 get_shared_object(&self, _uuid: VhostUserSharedMsg) -> Result<File>

This method retrieves a file descriptor for a shared object, identified by a unique UUID, which can be used by the front-end for DMA. If the shared object is found, it must return a File that the frontend can use. If the shared object does not exist the function returns None (indicating no file descriptor is available).

This function returns a Result, returning an error if the backend does not implement this function.

Source

fn set_gpu_socket(&self, _gpu_backend: GpuBackend) -> Result<()>

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

This function returns a Result, returning an error if the backend does not 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.

Source

fn set_device_state_fd( &self, _direction: VhostTransferStateDirection, _phase: VhostTransferStatePhase, _file: File, ) -> Result<Option<File>>

Initiate transfer of internal state for the purpose of migration to/from the back-end.

Depending on direction, the state should either be saved (i.e. serialized and written to file) or loaded (i.e. read from file and deserialized). The back-end can choose to use a different channel than file. If so, it must return a File that the front-end can use. Note that this function must not block during transfer, i.e. I/O to/from file must be done outside of this function.

Source

fn check_device_state(&self) -> Result<()>

After transferring internal state, check for any resulting errors, including potential deserialization errors when loading state.

Although this function return a Result, the front-end will not receive any details about this error.

Implementations on Foreign Types§

Source§

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

Source§

type Bitmap = <T as VhostUserBackend>::Bitmap

Source§

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 reset_device(&self)

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 get_shared_object(&self, uuid: VhostUserSharedMsg) -> Result<File>

Source§

fn set_gpu_socket(&self, gpu_backend: GpuBackend) -> Result<()>

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§

fn set_device_state_fd( &self, direction: VhostTransferStateDirection, phase: VhostTransferStatePhase, file: File, ) -> Result<Option<File>>

Source§

fn check_device_state(&self) -> Result<()>

Source§

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

Source§

type Bitmap = <T as VhostUserBackendMut>::Bitmap

Source§

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 reset_device(&self)

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 get_shared_object(&self, uuid: VhostUserSharedMsg) -> Result<File>

Source§

fn set_gpu_socket(&self, gpu_backend: GpuBackend) -> Result<()>

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§

fn set_device_state_fd( &self, direction: VhostTransferStateDirection, phase: VhostTransferStatePhase, file: File, ) -> Result<Option<File>>

Source§

fn check_device_state(&self) -> Result<()>

Source§

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

Source§

type Bitmap = <T as VhostUserBackendMut>::Bitmap

Source§

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 reset_device(&self)

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 get_shared_object(&self, uuid: VhostUserSharedMsg) -> Result<File>

Source§

fn set_gpu_socket(&self, gpu_backend: GpuBackend) -> Result<()>

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§

fn set_device_state_fd( &self, direction: VhostTransferStateDirection, phase: VhostTransferStatePhase, file: File, ) -> Result<Option<File>>

Source§

fn check_device_state(&self) -> Result<()>

Implementors§