virtio_device::ring

Struct Device

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

Represents the device owned data.

Contents of this struct are expected to be modified by the device and so are mutable. Provided methods allow for safely publishing data to the driver using appropriate memory barriers.

Although only the device is supposed to be modifying this data it is designed to account for a malicious guest performing modifications in parallel.

Implementations§

Source§

impl<'a> Device<'a>

Source

pub const fn used_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 slice for passing to new

Source

pub fn new<'b: 'a>(used: DeviceRange<'b>) -> Option<Self>

Construct a Device using the provided memory for the used ring.

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

Source

pub fn queue_size(&self) -> u16

Returns the size of the used ring.

Source

pub fn insert_used(&mut self, used: Used, index: u16)

Add a descriptor chain to the used ring.

After calling this the descriptor is not yet visible to the driver. To make it visible publish_used must be called. Chains are not implicitly published to allow for batching the return of chains.

To allow for passing the same index between this and publish_used, index here will automatically be wrapped to the queue length.

Source

pub fn publish_used(&mut self, index: u16)

Publish the avail ring up to the provided index to the driver.

This updates the driver visible index and performs appropriate memory barriers for the driver to see any returned descriptors. It does not perform any kind of asynchronous notification, such as an interrupt injection, to the guest or driver as that is a virtio transport specific detail and is the responsibility of the caller to know how to do.

Note that indices should not be wrapped by the caller to the queue length as they are supposed to be free running and only wrap at the u16 limit.

Auto Trait Implementations§

§

impl<'a> Freeze for Device<'a>

§

impl<'a> RefUnwindSafe for Device<'a>

§

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

§

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

§

impl<'a> Unpin for Device<'a>

§

impl<'a> UnwindSafe for Device<'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.