pub trait VhostUserDevice {
Show 14 methods // Required methods fn max_queue_num(&self) -> usize; fn features(&self) -> u64; fn protocol_features(&self) -> VhostUserProtocolFeatures; fn read_config(&self, offset: u64, dst: &mut [u8]); fn start_queue( &mut self, idx: usize, queue: Queue, mem: GuestMemory ) -> Result<()>; fn stop_queue(&mut self, idx: usize) -> Result<Queue>; fn reset(&mut self); fn enter_suspended_state(&mut self) -> Result<()>; fn snapshot(&mut self) -> Result<Value>; fn restore(&mut self, data: Value) -> Result<()>; // Provided methods fn ack_features(&mut self, _value: u64) -> Result<()> { ... } fn write_config(&self, _offset: u64, _data: &[u8]) { ... } fn get_shared_memory_region(&self) -> Option<SharedMemoryRegion> { ... } fn set_backend_req_connection( &mut self, _conn: Arc<VhostBackendReqConnection> ) { ... }
}
Expand description

Trait for vhost-user devices. Analogous to the VirtioDevice trait.

In contrast with [vmm_vhost::Backend], which closely matches the vhost-user spec, this trait is designed to follow crosvm conventions for implementing devices.

Required Methods§

source

fn max_queue_num(&self) -> usize

The maximum number of queues that this backend can manage.

source

fn features(&self) -> u64

The set of feature bits that this backend supports.

source

fn protocol_features(&self) -> VhostUserProtocolFeatures

The set of protocol feature bits that this backend supports.

source

fn read_config(&self, offset: u64, dst: &mut [u8])

Reads this device configuration space at offset.

source

fn start_queue( &mut self, idx: usize, queue: Queue, mem: GuestMemory ) -> Result<()>

Indicates that the backend should start processing requests for virtio queue number idx. This method must not block the current thread so device backends should either spawn an async task or another thread to handle messages from the Queue.

source

fn stop_queue(&mut self, idx: usize) -> Result<Queue>

Indicates that the backend should stop processing requests for virtio queue number idx. This method should return the queue passed to start_queue for the corresponding idx. This method will only be called for queues that were previously started by start_queue.

source

fn reset(&mut self)

Resets the vhost-user backend.

source

fn enter_suspended_state(&mut self) -> Result<()>

Enter the “suspended device state” described in the vhost-user spec. See the spec for requirements.

One reasonably foolproof way to satisfy the requirements is to stop all worker threads.

Called after a stop_queue call if there are no running queues left. Also called soon after device creation to ensure the device is acting suspended immediately on construction.

The next start_queue call implicitly exits the “suspend device state”.

  • Ok(()) => device successfully suspended
  • Err(_) => unrecoverable error
source

fn snapshot(&mut self) -> Result<Value>

Snapshot device and return serialized state.

source

fn restore(&mut self, data: Value) -> Result<()>

Restore device state from a snapshot.

Provided Methods§

source

fn ack_features(&mut self, _value: u64) -> Result<()>

Acknowledges that this set of features should be enabled.

Implementations only need to handle device-specific feature bits; the DeviceRequestHandler framework will manage generic vhost and vring features.

DeviceRequestHandler checks for valid features before calling this function, so the features in value will always be a subset of those advertised by features().

source

fn write_config(&self, _offset: u64, _data: &[u8])

writes data to this device’s configuration space at offset.

source

fn get_shared_memory_region(&self) -> Option<SharedMemoryRegion>

Returns the device’s shared memory region if present.

source

fn set_backend_req_connection(&mut self, _conn: Arc<VhostBackendReqConnection>)

Accepts VhostBackendReqConnection to conduct Vhost backend to frontend message handling.

The backend is given an Arc instead of full ownership so that the framework can also use the connection.

This method will be called when VhostUserProtocolFeatures::BACKEND_REQ is negotiated.

Implementors§