pub trait VhostUserDevice {
Show 17 methods
// Required methods
fn max_queue_num(&self) -> usize;
fn features(&self) -> u64;
fn ack_features(&mut self, value: u64) -> Result<()>;
fn acked_features(&self) -> u64;
fn protocol_features(&self) -> VhostUserProtocolFeatures;
fn ack_protocol_features(&mut self, _value: u64) -> Result<()>;
fn acked_protocol_features(&self) -> u64;
fn read_config(&self, offset: u64, dst: &mut [u8]);
fn start_queue(
&mut self,
idx: usize,
queue: Queue,
mem: GuestMemory,
doorbell: Interrupt
) -> Result<()>;
fn stop_queue(&mut self, idx: usize) -> Result<Queue>;
fn reset(&mut self);
// Provided methods
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>
) { ... }
fn stop_non_queue_workers(&mut self) -> Result<()> { ... }
fn snapshot(&self) -> Result<Vec<u8>> { ... }
fn restore(&mut self, _data: Vec<u8>) -> Result<()> { ... }
}
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 ack_features(&mut self, value: u64) -> Result<()>
fn ack_features(&mut self, value: u64) -> Result<()>
Acknowledges that this set of features should be enabled.
sourcefn acked_features(&self) -> u64
fn acked_features(&self) -> u64
Returns the set of enabled features.
sourcefn protocol_features(&self) -> VhostUserProtocolFeatures
fn protocol_features(&self) -> VhostUserProtocolFeatures
The set of protocol feature bits that this backend supports.
sourcefn ack_protocol_features(&mut self, _value: u64) -> Result<()>
fn ack_protocol_features(&mut self, _value: u64) -> Result<()>
Acknowledges that this set of protocol features should be enabled.
sourcefn acked_protocol_features(&self) -> u64
fn acked_protocol_features(&self) -> u64
Returns the set of enabled protocol features.
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,
doorbell: Interrupt
) -> Result<()>
fn start_queue( &mut self, idx: usize, queue: Queue, mem: GuestMemory, doorbell: Interrupt ) -> 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
.
Provided Methods§
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: Arc<VhostBackendReqConnection>)
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.
sourcefn stop_non_queue_workers(&mut self) -> Result<()>
fn stop_non_queue_workers(&mut self) -> Result<()>
Used to stop non queue workers that VhostUserDevice::stop_queue
can’t stop. May or may
not also stop all queue workers.