pub struct Queue {Show 13 fields
pub max_size: u16,
pub size: u16,
pub ready: bool,
pub desc_table_address: GuestAddress,
pub avail_ring_address: GuestAddress,
pub used_ring_address: GuestAddress,
pub desc_table_ptr: *const Descriptor,
pub avail_ring_ptr: *mut u16,
pub used_ring_ptr: *mut u8,
pub next_avail: Wrapping<u16>,
pub next_used: Wrapping<u16>,
pub uses_notif_suppression: bool,
pub num_added: Wrapping<u16>,
}Expand description
A virtio queue’s parameters.
Fields§
§max_size: u16The maximal size in elements offered by the device
size: u16The queue size in elements the driver selected
ready: boolIndicates if the queue is finished with configuration
desc_table_address: GuestAddressGuest physical address of the descriptor table
avail_ring_address: GuestAddressGuest physical address of the available ring
used_ring_address: GuestAddressGuest physical address of the used ring
desc_table_ptr: *const DescriptorHost virtual address pointer to the descriptor table
in the guest memory .
Getting access to the underling
data structure should only occur after the
struct is initialized with new.
Representation of in memory struct layout.
struct DescriptorTable = [Descriptor; <queue_size>]
avail_ring_ptr: *mut u16Host virtual address pointer to the available ring
in the guest memory .
Getting access to the underling
data structure should only occur after the
struct is initialized with new.
Representation of in memory struct layout.
struct AvailRing {
flags: u16,
idx: u16,
ring: [u16;
Because all types in the AvailRing are u16, we store pointer as *mut u16 for simplicity.
used_ring_ptr: *mut u8Host virtual address pointer to the used ring
in the guest memory .
Getting access to the underling
data structure should only occur after the
struct is initialized with new.
Representation of in memory struct layout. Because types in the UsedRing are different (u16 and u32) store pointer as *mut u8.
next_avail: Wrapping<u16>§next_used: Wrapping<u16>§uses_notif_suppression: boolVIRTIO_F_RING_EVENT_IDX negotiated (notification suppression enabled)
num_added: Wrapping<u16>The number of added used buffers since last guest kick
Implementations§
Source§impl Queue
impl Queue
Sourcepub fn initialize<M: GuestMemory>(&mut self, mem: &M) -> Result<(), QueueError>
pub fn initialize<M: GuestMemory>(&mut self, mem: &M) -> Result<(), QueueError>
Set up pointers to the queue objects in the guest memory and mark memory dirty for those objects
Sourcepub fn avail_ring_idx_get(&self) -> u16
pub fn avail_ring_idx_get(&self) -> u16
Get AvailRing.idx
Sourcepub fn avail_ring_used_event_get(&self) -> u16
pub fn avail_ring_used_event_get(&self) -> u16
Get AvailRing.used_event
Sourcepub fn used_ring_idx_set(&mut self, val: u16)
pub fn used_ring_idx_set(&mut self, val: u16)
Set UsedRing.idx
Sourcepub fn used_ring_avail_event_set(&mut self, val: u16)
pub fn used_ring_avail_event_set(&mut self, val: u16)
Set UsedRing.avail_event
Sourcepub fn len(&self) -> u16
pub fn len(&self) -> u16
Returns the number of yet-to-be-popped descriptor chains in the avail ring.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if the driver has made any descriptor chains available in the avail ring.
Sourcepub fn pop(&mut self) -> Result<Option<DescriptorChain>, InvalidAvailIdx>
pub fn pop(&mut self) -> Result<Option<DescriptorChain>, InvalidAvailIdx>
Pop the first available descriptor chain from the avail ring.
If this function returns an error at runtime, then the guest has requested Firecracker to process more virtio descriptors than there can possibly be given the queue’s size. This can be a malicious guest driver scenario, and hence a DoS attempt. If encountered and runtime, correct handling is to panic!
This function however is also called on paths that can (and should) just report the error to the user (e.g. loading a corrupt snapshot file), and hence cannot panic on its own.
Sourcepub fn pop_or_enable_notification(
&mut self,
) -> Result<Option<DescriptorChain>, InvalidAvailIdx>
pub fn pop_or_enable_notification( &mut self, ) -> Result<Option<DescriptorChain>, InvalidAvailIdx>
Try to pop the first available descriptor chain from the avail ring. If no descriptor is available, enable notifications.
If this function returns an error at runtime, then the guest has requested Firecracker to process more virtio descriptors than there can possibly be given the queue’s size. This can be a malicious guest driver scenario, and hence a DoS attempt. If encountered and runtime, correct handling is to panic!
This function however is also called on paths that can (and should) just report the error to the user (e.g. loading a corrupt snapshot file), and hence cannot panic on its own.
Sourcepub fn undo_pop(&mut self)
pub fn undo_pop(&mut self)
Undo the effects of the last self.pop() call.
The caller can use this, if it was unable to consume the last popped descriptor chain.
Sourcepub fn write_used_element(
&mut self,
ring_index_offset: u16,
desc_index: u16,
len: u32,
) -> Result<(), QueueError>
pub fn write_used_element( &mut self, ring_index_offset: u16, desc_index: u16, len: u32, ) -> Result<(), QueueError>
Write used element into used_ring ring.
- [
ring_index_offset] is an offset added to the current [self.next_used] to obtain actual index into used_ring.
Sourcepub fn advance_next_used(&mut self, n: u16)
pub fn advance_next_used(&mut self, n: u16)
Advance queue and used ring by n elements.
Sourcepub fn advance_used_ring_idx(&mut self)
pub fn advance_used_ring_idx(&mut self)
Set the used ring index to the current next_used value.
Should be called once after number of add_used calls.
Sourcepub fn add_used(&mut self, desc_index: u16, len: u32) -> Result<(), QueueError>
pub fn add_used(&mut self, desc_index: u16, len: u32) -> Result<(), QueueError>
Puts an available descriptor head into the used ring for use by the guest.
Sourcepub fn enable_notif_suppression(&mut self)
pub fn enable_notif_suppression(&mut self)
Enable notification suppression.
Sourcepub fn prepare_kick(&mut self) -> bool
pub fn prepare_kick(&mut self) -> bool
Check if we need to kick the guest.
Please note this method has side effects: once it returns true, it considers the
driver will actually be notified, and won’t return true again until the driver
updates used_event and/or the notification conditions hold once more.
This is similar to the vring_need_event() method implemented by the Linux kernel.
Trait Implementations§
Source§impl Persist<'_> for Queue
impl Persist<'_> for Queue
Source§type State = QueueState
type State = QueueState
Source§type ConstructorArgs = QueueConstructorArgs
type ConstructorArgs = QueueConstructorArgs
Source§type Error = QueueError
type Error = QueueError
impl Eq for Queue
impl Send for Queue
SAFETY: Queue is Send, because we use volatile memory accesses when working with pointers. These pointers are not copied or store anywhere else. We assume guest will not give different queues same guest memory addresses.
impl StructuralPartialEq for Queue
Auto Trait Implementations§
impl Freeze for Queue
impl RefUnwindSafe for Queue
impl !Sync for Queue
impl Unpin for Queue
impl UnwindSafe for Queue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.