Trait vhost_user_backend::VhostUserBackend
source · pub trait VhostUserBackend<V, B = ()>: Send + Syncwhere
V: VringT<GuestMemoryAtomic<GuestMemoryMmap<B>>>,
B: Bitmap + 'static,{
Show 13 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<B>>
) -> Result<()>;
fn handle_event(
&self,
device_event: u16,
evset: EventSet,
vrings: &[V],
thread_id: usize
) -> Result<bool>;
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_slave_req_fd(&self, _vu_req: SlaveFsCacheReq) { ... }
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 Methods§
sourcefn num_queues(&self) -> usize
fn num_queues(&self) -> usize
Get number of queues supported.
sourcefn max_queue_size(&self) -> usize
fn max_queue_size(&self) -> usize
Get maximum queue size supported.
sourcefn protocol_features(&self) -> VhostUserProtocolFeatures
fn protocol_features(&self) -> VhostUserProtocolFeatures
Get available vhost protocol features.
sourcefn set_event_idx(&self, enabled: bool)
fn set_event_idx(&self, enabled: bool)
Enable or disable the virtio EVENT_IDX feature
sourcefn update_memory(&self, mem: GuestMemoryAtomic<GuestMemoryMmap<B>>) -> Result<()>
fn update_memory(&self, mem: GuestMemoryAtomic<GuestMemoryMmap<B>>) -> Result<()>
Update guest memory regions.
sourcefn handle_event(
&self,
device_event: u16,
evset: EventSet,
vrings: &[V],
thread_id: usize
) -> Result<bool>
fn handle_event(
&self,
device_event: u16,
evset: EventSet,
vrings: &[V],
thread_id: usize
) -> Result<bool>
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§
sourcefn acked_features(&self, _features: u64)
fn acked_features(&self, _features: u64)
Set acknowledged virtio features.
sourcefn get_config(&self, _offset: u32, _size: u32) -> Vec<u8>
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.
sourcefn set_config(&self, _offset: u32, _buf: &[u8]) -> Result<()>
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.
sourcefn set_slave_req_fd(&self, _vu_req: SlaveFsCacheReq)
fn set_slave_req_fd(&self, _vu_req: SlaveFsCacheReq)
Set handler for communicating with the master by the slave communication channel.
A default implementation is provided as we cannot expect all backends to implement this function.
TODO: this interface is designed only for vhost-user-fs, it should be refined.
sourcefn queues_per_thread(&self) -> Vec<u64>
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.
sourcefn exit_event(&self, _thread_index: usize) -> Option<EventFd>
fn exit_event(&self, _thread_index: usize) -> Option<EventFd>
Provide an optional exit EventFd for the specified worker thread.
If an (EventFd
, token
) pair is returned, the returned EventFd
will be monitored for IO
events by using epoll with the specified token
. When the returned EventFd is written to,
the worker thread will exit.