AvailableRing

Struct AvailableRing 

Source
pub struct AvailableRing<T: GuestMemoryAccessor + Clone> {
    pub base_addr: GuestPhysAddr,
    pub size: u16,
    pub last_avail_idx: u16,
    /* private fields */
}
Expand description

Available ring management structure.

This structure provides a high-level interface for managing the VirtIO available ring in guest memory. It wraps the guest memory accessor and provides methods to read/write various parts of the available ring:

  • The header (VirtQueueAvail structure)
  • The ring array of descriptor indices
  • The used_event field (if VIRTIO_F_EVENT_IDX is negotiated)

Relationship with VirtQueueAvail:

  • VirtQueueAvail defines the memory layout of the available ring header
  • AvailableRing uses VirtQueueAvail to access the header in guest memory
  • AvailableRing manages the entire available ring structure, not just the header

Memory Layout:

base_addr -> +-------------------+
             | VirtQueueAvail    |  (flags + idx)
             +-------------------+
             | ring[0]           |  (descriptor index)
             | ring[1]           |
             | ...               |
             | ring[queue_size-1]|
             +-------------------+
             | used_event        |  (optional, if event_idx enabled)
             +-------------------+

Fields§

§base_addr: GuestPhysAddr

Base address of the available ring

§size: u16

Queue size

§last_avail_idx: u16

Last seen available index

Implementations§

Source§

impl<T: GuestMemoryAccessor + Clone> AvailableRing<T>

Source

pub fn new(base_addr: GuestPhysAddr, size: u16, accessor: Arc<T>) -> Self

Create a new available ring

Source

pub fn header_addr(&self) -> GuestPhysAddr

Get the address of the available ring header

Source

pub fn ring_addr(&self) -> GuestPhysAddr

Get the address of the ring array

Source

pub fn ring_entry_addr(&self, index: u16) -> Option<GuestPhysAddr>

Get the address of a specific ring entry

Source

pub fn used_event_addr(&self) -> GuestPhysAddr

Get the address of the used event field (if event_idx is enabled)

Source

pub fn total_size(&self) -> usize

Calculate the total size of the available ring

Source

pub fn is_valid(&self) -> bool

Check if the available ring is valid

Source

pub fn has_new_avail(&self, current_idx: u16) -> bool

Check if there are new available descriptors

Source

pub fn update_last_avail_idx(&mut self, idx: u16)

Update the last seen available index

Source

pub fn read_avail_header(&self) -> VirtioResult<VirtQueueAvail>

Read the available ring header

Source

pub fn write_avail_header(&self, header: &VirtQueueAvail) -> VirtioResult<()>

Write the available ring header

Source

pub fn read_avail_idx(&self) -> VirtioResult<u16>

Read the current available index from guest memory

Source

pub fn get_avail_idx(&self) -> VirtioResult<u16>

Get the available index for external access

Source

pub fn read_avail_ring_entry(&self, ring_index: u16) -> VirtioResult<u16>

Read a descriptor index from the available ring

Source

pub fn write_avail_ring_entry( &self, ring_index: u16, desc_index: u16, ) -> VirtioResult<()>

Write a descriptor index to the available ring

Source

pub fn get_available_count(&self) -> VirtioResult<u16>

Get the number of available descriptors since last check

Source

pub fn interrupts_suppressed(&self) -> VirtioResult<bool>

Check if interrupts are suppressed

Source

pub fn set_interrupt_suppression(&self, suppress: bool) -> VirtioResult<()>

Set interrupt suppression

Source

pub fn read_used_event(&self) -> VirtioResult<u16>

Read the used event field (for event_idx feature)

Source

pub fn write_used_event(&self, event: u16) -> VirtioResult<()>

Write the used event field (for event_idx feature)

Trait Implementations§

Source§

impl<T: Clone + GuestMemoryAccessor + Clone> Clone for AvailableRing<T>

Source§

fn clone(&self) -> AvailableRing<T>

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

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + GuestMemoryAccessor + Clone> Debug for AvailableRing<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for AvailableRing<T>

§

impl<T> RefUnwindSafe for AvailableRing<T>
where T: RefUnwindSafe,

§

impl<T> Send for AvailableRing<T>
where T: Sync + Send,

§

impl<T> Sync for AvailableRing<T>
where T: Sync + Send,

§

impl<T> Unpin for AvailableRing<T>

§

impl<T> UnwindSafe for AvailableRing<T>
where T: RefUnwindSafe,

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.