Struct 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§

Source§

impl<'a, R: Copy> Virtqueue<'a, R>

Source

pub fn new( iova_translator: Box<dyn IovaTranslator>, buf: &'a mut [u8], queue_size: u16, features: VirtioFeatureFlags, ) -> 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.

Source

pub fn queue_size(&self) -> u16

Returns the number of entries in each of the descriptor table and rings.

Source

pub fn layout(&self) -> &VirtqueueLayout

Returns the virtqueue memory layout.

Source

pub fn desc_table_ptr(&self) -> *const u8

Returns a raw pointer to the start of the descriptor table.

Source

pub fn driver_area_ptr(&self) -> *const u8

Returns a raw pointer to the start of the driver area.

Source

pub fn device_area_ptr(&self) -> *const u8

Returns a raw pointer to the start of the device area.

Source

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.

Source

pub fn completions(&mut self) -> VirtqueueIter<'_, 'a, R>

Returns an iterator that returns all completed requests.

Source

pub fn avail_notif_needed(&mut self) -> bool

Source

pub fn set_used_notif_enabled(&mut self, enabled: bool)

Trait Implementations§

Source§

impl<R: Copy> Send for Virtqueue<'_, R>

Source§

impl<R: Copy> Sync for Virtqueue<'_, R>

Auto Trait Implementations§

§

impl<'a, R> Freeze for Virtqueue<'a, R>

§

impl<'a, R> !RefUnwindSafe for Virtqueue<'a, R>

§

impl<'a, R> Unpin for Virtqueue<'a, R>

§

impl<'a, R> !UnwindSafe for Virtqueue<'a, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.