Struct virtio_device::ring::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> 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>,

§

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>,

§

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.