Trait devices::virtio::vhost_user_backend::VhostUserDevice   
source · 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<AnySnapshot>;
    fn restore(&mut self, data: AnySnapshot) -> 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: 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§
sourcefn max_queue_num(&self) -> usize
 
fn max_queue_num(&self) -> usize
The maximum number of queues that this backend can manage.
sourcefn protocol_features(&self) -> VhostUserProtocolFeatures
 
fn protocol_features(&self) -> VhostUserProtocolFeatures
The set of protocol feature bits that this backend supports.
sourcefn read_config(&self, offset: u64, dst: &mut [u8])
 
fn read_config(&self, offset: u64, dst: &mut [u8])
Reads this device configuration space at offset.
sourcefn start_queue(
    &mut self,
    idx: usize,
    queue: Queue,
    mem: GuestMemory,
) -> Result<()>
 
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.
sourcefn stop_queue(&mut self, idx: usize) -> Result<Queue>
 
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.
sourcefn enter_suspended_state(&mut self) -> Result<()>
 
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
 
sourcefn snapshot(&mut self) -> Result<AnySnapshot>
 
fn snapshot(&mut self) -> Result<AnySnapshot>
Snapshot device and return serialized state.
sourcefn restore(&mut self, data: AnySnapshot) -> Result<()>
 
fn restore(&mut self, data: AnySnapshot) -> Result<()>
Restore device state from a snapshot.
Provided Methods§
sourcefn ack_features(&mut self, _value: u64) -> Result<()>
 
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().
sourcefn write_config(&self, _offset: u64, _data: &[u8])
 
fn write_config(&self, _offset: u64, _data: &[u8])
writes data to this device’s configuration space at offset.
Returns the device’s shared memory region if present.
sourcefn set_backend_req_connection(&mut self, _conn: VhostBackendReqConnection)
 
fn set_backend_req_connection(&mut self, _conn: VhostBackendReqConnection)
Accepts VhostBackendReqConnection to conduct Vhost backend to frontend message
handling.
This method will be called when VhostUserProtocolFeatures::BACKEND_REQ is
negotiated.