Queue

Struct Queue 

Source
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: u16

The maximal size in elements offered by the device

§size: u16

The queue size in elements the driver selected

§ready: bool

Indicates if the queue is finished with configuration

§desc_table_address: GuestAddress

Guest physical address of the descriptor table

§avail_ring_address: GuestAddress

Guest physical address of the available ring

§used_ring_address: GuestAddress

Guest physical address of the used ring

§desc_table_ptr: *const Descriptor

Host 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 u16

Host 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; ], used_event: u16, }

Because all types in the AvailRing are u16, we store pointer as *mut u16 for simplicity.

§used_ring_ptr: *mut u8

Host 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: bool

VIRTIO_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

Source

pub fn new(max_size: u16) -> Queue

Constructs an empty virtio queue with the given max_size.

Source

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

Source

pub fn avail_ring_idx_get(&self) -> u16

Get AvailRing.idx

Source

pub fn avail_ring_used_event_get(&self) -> u16

Get AvailRing.used_event

Source

pub fn used_ring_idx_set(&mut self, val: u16)

Set UsedRing.idx

Source

pub fn used_ring_avail_event_set(&mut self, val: u16)

Set UsedRing.avail_event

Source

pub fn len(&self) -> u16

Returns the number of yet-to-be-popped descriptor chains in the avail ring.

Source

pub fn is_empty(&self) -> bool

Checks if the driver has made any descriptor chains available in the avail ring.

Source

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.

Source

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.

Source

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.

Source

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.
Source

pub fn advance_next_used(&mut self, n: u16)

Advance queue and used ring by n elements.

Source

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.

Source

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.

Source

pub fn enable_notif_suppression(&mut self)

Enable notification suppression.

Source

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 Clone for Queue

Source§

fn clone(&self) -> Queue

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 Debug for Queue

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Queue

Source§

fn eq(&self, other: &Queue) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Persist<'_> for Queue

Source§

type State = QueueState

The type of the object representing the state of the component.
Source§

type ConstructorArgs = QueueConstructorArgs

The type of the object holding the constructor arguments.
Source§

type Error = QueueError

The type of the error that can occur while constructing the object.
Source§

fn save(&self) -> Self::State

Returns the current state of the component.
Source§

fn restore( constructor_args: Self::ConstructorArgs, state: &Self::State, ) -> Result<Self, Self::Error>

Constructs a component from a specified state.
Source§

impl Eq for Queue

Source§

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.

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Return the immutable any encapsulated object.
Source§

fn as_mut_any(&mut self) -> &mut (dyn Any + 'static)

Return the mutable encapsulated any object.
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
§

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. 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.

§

impl<T> Pipe for T
where T: ?Sized,

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows 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) -> R
where R: 'a,

Mutably borrows 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
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows 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
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows 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
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .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
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .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
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
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
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V