UsedRing

Struct UsedRing 

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

Used ring management structure.

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

  • The header (VirtQueueUsed structure)
  • The ring array of used elements (VirtqUsedElem structures)
  • The avail_event field (if VIRTIO_F_EVENT_IDX is negotiated)

Relationship with VirtQueueUsed and VirtqUsedElem:

  • VirtQueueUsed defines the memory layout of the used ring header
  • VirtqUsedElem defines the memory layout of each ring element
  • UsedRing uses both structures to access the complete used ring in guest memory
  • UsedRing manages the entire used ring structure and provides high-level operations

Memory Layout:

base_addr -> +-------------------+
             | VirtQueueUsed     |  (flags + idx)
             +-------------------+
             | ring[0]           |  (VirtqUsedElem: id + len)
             | ring[1]           |  (VirtqUsedElem: id + len)
             | ...               |
             | ring[queue_size-1]|  (VirtqUsedElem: id + len)
             +-------------------+
             | avail_event       |  (optional, if event_idx enabled)
             +-------------------+

Fields§

§base_addr: GuestPhysAddr

Base address of the used ring

§size: u16

Queue size

§used_idx: u16

Current used index

Implementations§

Source§

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

Source

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

Create a new used ring

Source

pub fn header_addr(&self) -> GuestPhysAddr

Get the address of the used 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 avail_event_addr(&self) -> GuestPhysAddr

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

Source

pub fn total_size(&self) -> usize

Calculate the total size of the used ring

Source

pub fn is_valid(&self) -> bool

Check if the used ring is valid

Source

pub fn add_used(&mut self, id: u32, len: u32) -> VirtioResult<()>

Add a used element to the ring

Source

pub fn write_used_idx(&self) -> VirtioResult<()>

Write the used index to the used ring header

Source

pub fn read_used_header(&self) -> VirtioResult<VirtQueueUsed>

Read the used ring header

Source

pub fn write_used_header(&self, header: &VirtQueueUsed) -> VirtioResult<()>

Write the used ring header

Source

pub fn get_used_idx(&self) -> u16

Get the current used index

Source

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

Set the used index

Source

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

Check if notifications should be suppressed

Source

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

Set notification suppression

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> UsedRing<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 UsedRing<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 UsedRing<T>

§

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

§

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

§

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

§

impl<T> Unpin for UsedRing<T>

§

impl<T> UnwindSafe for UsedRing<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.