Struct QueueSync

Source
pub struct QueueSync { /* private fields */ }
Expand description

Struct to maintain information and manipulate state of a virtio queue for multi-threaded context.

§Example

use virtio_queue::{Queue, QueueSync, QueueT};
use vm_memory::{Bytes, GuestAddress, GuestAddressSpace, GuestMemoryMmap};

let m = &GuestMemoryMmap::<()>::from_ranges(&[(GuestAddress(0), 0x10000)]).unwrap();
let mut queue = QueueSync::new(1024).unwrap();

// First, the driver sets up the queue; this set up is done via writes on the bus (PCI, MMIO).
queue.set_size(8);
queue.set_desc_table_address(Some(0x1000), None);
queue.set_avail_ring_address(Some(0x2000), None);
queue.set_used_ring_address(Some(0x3000), None);
queue.set_ready(true);
// The user should check if the queue is valid before starting to use it.
assert!(queue.is_valid(m.memory()));

// The memory object is not embedded in the `QueueSync`, so we have to pass it as a
// parameter to the methods that access the guest memory. Examples would be:
queue.add_used(m.memory(), 1, 0x100).unwrap();
queue.needs_notification(m.memory()).unwrap();

Trait Implementations§

Source§

impl Clone for QueueSync

Source§

fn clone(&self) -> QueueSync

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QueueSync

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> QueueGuard<'a> for QueueSync

Source§

type G = MutexGuard<'a, Queue>

Type for guard returned by Self::lock().
Source§

impl QueueT for QueueSync

Source§

fn new(max_size: u16) -> Result<Self, Error>

Construct an empty virtio queue state object with the given max_size. Read more
Source§

fn is_valid<M: GuestMemory>(&self, mem: &M) -> bool

Check whether the queue configuration is valid.
Source§

fn reset(&mut self)

Reset the queue to the initial state.
Source§

fn lock(&mut self) -> <Self as QueueGuard<'_>>::G

Get an exclusive reference to the underlying Queue object. Read more
Source§

fn max_size(&self) -> u16

Get the maximum size of the virtio queue.
Source§

fn size(&self) -> u16

Get the actual size configured by the guest.
Source§

fn set_size(&mut self, size: u16)

Configure the queue size for the virtio queue.
Source§

fn ready(&self) -> bool

Check whether the queue is ready to be processed.
Source§

fn set_ready(&mut self, ready: bool)

Configure the queue to ready for processing state.
Source§

fn set_desc_table_address(&mut self, low: Option<u32>, high: Option<u32>)

Set the descriptor table address for the queue. Read more
Source§

fn set_avail_ring_address(&mut self, low: Option<u32>, high: Option<u32>)

Set the available ring address for the queue. Read more
Source§

fn set_used_ring_address(&mut self, low: Option<u32>, high: Option<u32>)

Set the used ring address for the queue. Read more
Source§

fn set_event_idx(&mut self, enabled: bool)

Enable/disable the VIRTIO_F_RING_EVENT_IDX feature for interrupt coalescing.
Source§

fn avail_idx<M>(&self, mem: &M, order: Ordering) -> Result<Wrapping<u16>, Error>
where M: GuestMemory + ?Sized,

Read the idx field from the available ring. Read more
Source§

fn used_idx<M: GuestMemory>( &self, mem: &M, order: Ordering, ) -> Result<Wrapping<u16>, Error>

Read the idx field from the used ring. Read more
Source§

fn add_used<M: GuestMemory>( &mut self, mem: &M, head_index: u16, len: u32, ) -> Result<(), Error>

Put a used descriptor head into the used ring.
Source§

fn enable_notification<M: GuestMemory>( &mut self, mem: &M, ) -> Result<bool, Error>

Enable notification events from the guest driver. Read more
Source§

fn disable_notification<M: GuestMemory>(&mut self, mem: &M) -> Result<(), Error>

Disable notification events from the guest driver.
Source§

fn needs_notification<M: GuestMemory>(&mut self, mem: &M) -> Result<bool, Error>

Check whether a notification to the guest is needed. Read more
Source§

fn next_avail(&self) -> u16

Return the index of the next entry in the available ring.
Source§

fn set_next_avail(&mut self, next_avail: u16)

Set the index of the next entry in the available ring.
Source§

fn next_used(&self) -> u16

Return the index for the next descriptor in the used ring.
Source§

fn set_next_used(&mut self, next_used: u16)

Set the index for the next descriptor in the used ring.
Source§

fn desc_table(&self) -> u64

Return the address of the descriptor table.
Source§

fn avail_ring(&self) -> u64

Return the address of the available ring.
Source§

fn used_ring(&self) -> u64

Return the address of the used ring.
Source§

fn event_idx_enabled(&self) -> bool

Checks whether VIRTIO_F_RING_EVENT_IDX is negotiated. Read more
Source§

fn pop_descriptor_chain<M>(&mut self, mem: M) -> Option<DescriptorChain<M>>
where M: Clone + Deref, M::Target: GuestMemory,

Pop and return the next available descriptor chain, or None when there are no more descriptor chains available. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.