DescriptorTable

Struct DescriptorTable 

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

Descriptor table management structure.

This structure provides a high-level interface for managing the VirtIO descriptor table in guest memory. It wraps the guest memory accessor and provides methods to read/write individual descriptors and follow descriptor chains.

Relationship with VirtQueueDesc:

  • VirtQueueDesc defines the memory layout of a single descriptor
  • DescriptorTable uses VirtQueueDesc to access descriptors in guest memory
  • DescriptorTable manages the entire descriptor table and provides operations for descriptor chains, validation, and buffer management

Memory Layout:

base_addr -> +-------------------+
             | VirtQueueDesc[0]  |  (addr + len + flags + next)
             +-------------------+
             | VirtQueueDesc[1]  |  (addr + len + flags + next)
             +-------------------+
             | ...               |
             +-------------------+
             | VirtQueueDesc[n-1]|  (addr + len + flags + next)
             +-------------------+

Descriptor chains are formed by setting the NEXT flag and the next field to link descriptors together, allowing scatter-gather I/O operations.

Fields§

§base_addr: GuestPhysAddr

Base address of the descriptor table

§size: u16

Number of descriptors

Implementations§

Source§

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

Source

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

Create a new descriptor table

Source

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

Get the address of a specific descriptor

Source

pub fn total_size(&self) -> usize

Calculate the total size of the descriptor table

Source

pub fn is_valid(&self) -> bool

Check if the descriptor table is valid

Source

pub fn read_desc(&self, index: u16) -> VirtioResult<VirtQueueDesc>

Read a descriptor from the table

Source

pub fn write_desc(&self, index: u16, desc: &VirtQueueDesc) -> VirtioResult<()>

Write a descriptor to the table

Source

pub fn follow_chain(&self, head_index: u16) -> VirtioResult<Vec<VirtQueueDesc>>

Follow a descriptor chain starting from the given index

Source

pub fn chain_length(&self, head_index: u16) -> VirtioResult<u32>

Get the total length of a descriptor chain

Source

pub fn validate_chain(&self, head_index: u16) -> VirtioResult<bool>

Check if a descriptor chain is valid

Source

pub fn get_data_buffers( &self, head_index: u16, device_type: VirtioDeviceID, ) -> VirtioResult<Vec<(GuestPhysAddr, usize, bool)>>

Get data buffer descriptors (excluding first and last)

Source

pub fn get_status_addr(&self, head_index: u16) -> VirtioResult<GuestPhysAddr>

Get the status descriptor address (last descriptor)

Trait Implementations§

Source§

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

Source§

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

§

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

§

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

§

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

§

impl<T> Unpin for DescriptorTable<T>

§

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