Struct virtio_queue::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
sourceimpl<'a> QueueGuard<'a> for QueueSync
impl<'a> QueueGuard<'a> for QueueSync
type G = MutexGuard<'a, Queue>
type G = MutexGuard<'a, Queue>
Type for guard returned by
Self::lock().sourceimpl QueueT for QueueSync
impl QueueT for QueueSync
sourcefn new(max_size: u16) -> Result<Self, Error>
fn new(max_size: u16) -> Result<Self, Error>
Construct an empty virtio queue state object with the given
max_size. Read moresourcefn is_valid<M: GuestMemory>(&self, mem: &M) -> bool
fn is_valid<M: GuestMemory>(&self, mem: &M) -> bool
Check whether the queue configuration is valid.
sourcefn lock(&mut self) -> <Self as QueueGuard<'_>>::G
fn lock(&mut self) -> <Self as QueueGuard<'_>>::G
Get an exclusive reference to the underlying
Queue object. Read moresourcefn set_desc_table_address(&mut self, low: Option<u32>, high: Option<u32>)
fn set_desc_table_address(&mut self, low: Option<u32>, high: Option<u32>)
Set the descriptor table address for the queue. Read more
sourcefn set_avail_ring_address(&mut self, low: Option<u32>, high: Option<u32>)
fn set_avail_ring_address(&mut self, low: Option<u32>, high: Option<u32>)
Set the available ring address for the queue. Read more
sourcefn set_used_ring_address(&mut self, low: Option<u32>, high: Option<u32>)
fn set_used_ring_address(&mut self, low: Option<u32>, high: Option<u32>)
Set the used ring address for the queue. Read more
sourcefn set_event_idx(&mut self, enabled: bool)
fn set_event_idx(&mut self, enabled: bool)
Enable/disable the VIRTIO_F_RING_EVENT_IDX feature for interrupt coalescing.
sourcefn avail_idx<M>(&self, mem: &M, order: Ordering) -> Result<Wrapping<u16>, Error>where
M: GuestMemory + ?Sized,
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 moresourcefn used_idx<M: GuestMemory>(
&self,
mem: &M,
order: Ordering
) -> Result<Wrapping<u16>, Error>
fn used_idx<M: GuestMemory>(
&self,
mem: &M,
order: Ordering
) -> Result<Wrapping<u16>, Error>
Read the
idx field from the used ring. Read moresourcefn add_used<M: GuestMemory>(
&mut self,
mem: &M,
head_index: u16,
len: u32
) -> Result<(), Error>
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.
sourcefn enable_notification<M: GuestMemory>(&mut self, mem: &M) -> Result<bool, Error>
fn enable_notification<M: GuestMemory>(&mut self, mem: &M) -> Result<bool, Error>
Enable notification events from the guest driver. Read more
sourcefn disable_notification<M: GuestMemory>(&mut self, mem: &M) -> Result<(), Error>
fn disable_notification<M: GuestMemory>(&mut self, mem: &M) -> Result<(), Error>
Disable notification events from the guest driver.
sourcefn needs_notification<M: GuestMemory>(&mut self, mem: &M) -> Result<bool, Error>
fn needs_notification<M: GuestMemory>(&mut self, mem: &M) -> Result<bool, Error>
Check whether a notification to the guest is needed. Read more
sourcefn next_avail(&self) -> u16
fn next_avail(&self) -> u16
Return the index of the next entry in the available ring.
sourcefn set_next_avail(&mut self, next_avail: u16)
fn set_next_avail(&mut self, next_avail: u16)
Set the index of the next entry in the available ring.
sourcefn set_next_used(&mut self, next_used: u16)
fn set_next_used(&mut self, next_used: u16)
Set the index for the next descriptor in the used ring.
sourcefn desc_table(&self) -> u64
fn desc_table(&self) -> u64
Return the address of the descriptor table.
sourcefn avail_ring(&self) -> u64
fn avail_ring(&self) -> u64
Return the address of the available ring.
sourcefn event_idx_enabled(&self) -> bool
fn event_idx_enabled(&self) -> bool
Checks whether
VIRTIO_F_RING_EVENT_IDX is negotiated. Read moresourcefn pop_descriptor_chain<M>(&mut self, mem: M) -> Option<DescriptorChain<M>>where
M: Clone + Deref,
M::Target: GuestMemory,
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 moreAuto Trait Implementations
impl RefUnwindSafe for QueueSync
impl Send for QueueSync
impl Sync for QueueSync
impl Unpin for QueueSync
impl UnwindSafe for QueueSync
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more