virtio_device::ring

Struct Driver

Source
pub struct Driver<'a> { /* private fields */ }
Expand description

Representation of driver owned data.

Provides methods for safely querying, using appropriate memory barriers, items published by the driver.

Contents of this struct are not expected to be being modified in parallel by a driver in a guest, but as there is no way to guarantee guest behavior it is designed under the assumption of parallel modifications by a malicious guest.

Implementations§

Source§

impl<'a> Driver<'a>

Source

pub const fn avail_len_for_queue_size(queue_size: u16) -> usize

How many bytes the avail ring should be for the given queue_size.

Provides an easy way to calculate the correct size of the range for passing to new

Source

pub fn new<'b: 'a, 'c: 'a>( desc: DeviceRange<'b>, avail: DeviceRange<'c>, ) -> Option<Self>

Construct a Driver using the provided memory for descriptor and available rings.

Provided ranges must be correctly sized and aligned to represent the same power of two queue size, otherwise a None is returned.

Source

pub fn get_avail(&self, next_index: u16) -> Option<u16>

Query if a descriptor chain has been published with the given index.

If a chain has been published by the driver then returns the index of the first descriptor in the chain. Otherwise returns a None.

Source

pub fn get_desc(&self, index: u16) -> Option<Desc>

Request a descriptor by index.

Returns a none if the requested index is not within the range of the ring. Beyond this check this method has no way to validate if the requested descriptor is valid and it is the responsibility of the caller to know this.

Source

pub fn needs_notification( &self, feature_event_idx: bool, submitted: u16, ) -> bool

Determines if the driver has requested a notification for the given descriptor submission.

Queries the information published by the driver to determine whether or not it would like a notification for the given submitted descriptor by the Device. As the Driver holds no host state whether the VIRTIO_F_EVENT_IDX feature was negotiated must be passed in.

Source

pub fn queue_size(&self) -> u16

Returns the size of the descriptor and available rings.

The descriptor and available rings are, by definition, the same size. This is just returning the size that was calculated during new

Auto Trait Implementations§

§

impl<'a> Freeze for Driver<'a>

§

impl<'a> RefUnwindSafe for Driver<'a>

§

impl<'a> !Send for Driver<'a>

§

impl<'a> !Sync for Driver<'a>

§

impl<'a> Unpin for Driver<'a>

§

impl<'a> UnwindSafe for Driver<'a>

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.