Struct virtio_driver::virtqueue::Virtqueue
source · [−]pub struct Virtqueue<'a, R: Copy> { /* private fields */ }Expand description
A virtqueue of a virtio device.
R is used to store device-specific per-request data (like the request header or status byte)
in memory shared with the device and is copied on completion. Don’t put things there that the
device doesn’t have to access, in the interest of both security and performance.
Implementations
sourceimpl<'a, R: Copy> Virtqueue<'a, R>
impl<'a, R: Copy> Virtqueue<'a, R>
sourcepub fn new(
iova_translator: Box<dyn IovaTranslator>,
buf: &'a mut [u8],
queue_size: u16
) -> Result<Self, Error>
pub fn new(
iova_translator: Box<dyn IovaTranslator>,
buf: &'a mut [u8],
queue_size: u16
) -> Result<Self, Error>
Creates a new virtqueue in the passed memory buffer.
buf has to be memory that is visible for the device. It is used to store all descriptors,
rings and device-specific per-request data for the queue.
sourcepub fn queue_size(&self) -> u16
pub fn queue_size(&self) -> u16
Returns the number of entries in each of the descriptor table and rings.
sourcepub fn desc_table_ptr(&self) -> *const u8
pub fn desc_table_ptr(&self) -> *const u8
Returns a raw pointer to the start of the descriptor table.
sourcepub fn avail_ring_ptr(&self) -> *const u8
pub fn avail_ring_ptr(&self) -> *const u8
Returns a raw pointer to the start of the available ring.
sourcepub fn used_ring_ptr(&self) -> *const u8
pub fn used_ring_ptr(&self) -> *const u8
Returns a raw pointer to the start of the used ring.
sourcepub fn add_request<F>(&mut self, prepare: F) -> Result<u16, Error>where
F: FnOnce(&mut R, &mut dyn FnMut(iovec, bool) -> Result<(), Error>) -> Result<(), Error>,
pub fn add_request<F>(&mut self, prepare: F) -> Result<u16, Error>where
F: FnOnce(&mut R, &mut dyn FnMut(iovec, bool) -> Result<(), Error>) -> Result<(), Error>,
Enqueues a new request.
prepare is a function or closure that gets a reference to the device-specific per-request
data in its final location in the virtqueue memory and a FnMut to add virtio descriptors to
the request. It can set up the per-request data as necessary and must add all descriptors
needed for the request.
The parameters of the FnMut it received are the iovec describing the buffer to be added
and a boolean from_dev that is true if this buffer is written by the device and false
if it is read by the device.
sourcepub fn completions(&mut self) -> VirtqueueIter<'_, 'a, R>ⓘNotable traits for VirtqueueIter<'a, 'queue, R>impl<'a, 'queue, R: Copy> Iterator for VirtqueueIter<'a, 'queue, R> type Item = VirtqueueCompletion<R>;
pub fn completions(&mut self) -> VirtqueueIter<'_, 'a, R>ⓘNotable traits for VirtqueueIter<'a, 'queue, R>impl<'a, 'queue, R: Copy> Iterator for VirtqueueIter<'a, 'queue, R> type Item = VirtqueueCompletion<R>;
Returns an iterator that returns all completed requests.