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: GuestPhysAddrBase address of the descriptor table
size: u16Number of descriptors
Implementations§
Source§impl<T: GuestMemoryAccessor + Clone> DescriptorTable<T>
impl<T: GuestMemoryAccessor + Clone> DescriptorTable<T>
Sourcepub fn new(base_addr: GuestPhysAddr, size: u16, accessor: Arc<T>) -> Self
pub fn new(base_addr: GuestPhysAddr, size: u16, accessor: Arc<T>) -> Self
Create a new descriptor table
Sourcepub fn desc_addr(&self, index: u16) -> Option<GuestPhysAddr>
pub fn desc_addr(&self, index: u16) -> Option<GuestPhysAddr>
Get the address of a specific descriptor
Sourcepub fn total_size(&self) -> usize
pub fn total_size(&self) -> usize
Calculate the total size of the descriptor table
Sourcepub fn read_desc(&self, index: u16) -> VirtioResult<VirtQueueDesc>
pub fn read_desc(&self, index: u16) -> VirtioResult<VirtQueueDesc>
Read a descriptor from the table
Sourcepub fn write_desc(&self, index: u16, desc: &VirtQueueDesc) -> VirtioResult<()>
pub fn write_desc(&self, index: u16, desc: &VirtQueueDesc) -> VirtioResult<()>
Write a descriptor to the table
Sourcepub fn follow_chain(&self, head_index: u16) -> VirtioResult<Vec<VirtQueueDesc>>
pub fn follow_chain(&self, head_index: u16) -> VirtioResult<Vec<VirtQueueDesc>>
Follow a descriptor chain starting from the given index
Sourcepub fn chain_length(&self, head_index: u16) -> VirtioResult<u32>
pub fn chain_length(&self, head_index: u16) -> VirtioResult<u32>
Get the total length of a descriptor chain
Sourcepub fn validate_chain(&self, head_index: u16) -> VirtioResult<bool>
pub fn validate_chain(&self, head_index: u16) -> VirtioResult<bool>
Check if a descriptor chain is valid
Sourcepub fn get_data_buffers(
&self,
head_index: u16,
device_type: VirtioDeviceID,
) -> VirtioResult<Vec<(GuestPhysAddr, usize, bool)>>
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)
Sourcepub fn get_status_addr(&self, head_index: u16) -> VirtioResult<GuestPhysAddr>
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>
impl<T: Clone + GuestMemoryAccessor + Clone> Clone for DescriptorTable<T>
Source§fn clone(&self) -> DescriptorTable<T>
fn clone(&self) -> DescriptorTable<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more