Skip to main content

Queue

Struct Queue 

Source
pub struct Queue {
    pub max_size: u16,
    pub size: u16,
    pub ready: bool,
    pub desc_table_addr: GuestAddress,
    pub avail_ring_addr: GuestAddress,
    pub used_ring_addr: GuestAddress,
    pub next_avail_idx: u16,
    pub next_used_idx: u16,
}
Expand description

Per-queue setup state and runtime cursor.

The transport mutates size, *_addr, and ready in response to guest MMIO writes during driver init. The device handler mutates next_avail_idx as it consumes descriptor heads.

Fields§

§max_size: u16

Maximum descriptor count negotiated at boot (the device exposes this as QueueNumMax).

§size: u16

Active descriptor count. Bounded by max_size. Set by the driver writing QueueNum.

§ready: bool

true once the driver writes QueueReady = 1.

§desc_table_addr: GuestAddress

Guest-physical address of the descriptor table.

§avail_ring_addr: GuestAddress

Guest-physical address of the available ring.

§used_ring_addr: GuestAddress

Guest-physical address of the used ring.

§next_avail_idx: u16

Device-side cursor into the available ring.

§next_used_idx: u16

Device-side cursor into the used ring (the next slot to write to).

Implementations§

Source§

impl Queue

Source

pub fn new(max_size: u16) -> Self

Build a fresh queue with the given maximum descriptor count.

Source

pub fn set_size(&mut self, requested: u16)

Set the negotiated descriptor count, clamping to max_size and to a power of two as the spec requires.

Source

pub fn is_valid(&self) -> bool

true when every required address is set and ready = 1.

Source

pub fn reset(&mut self)

Reset the queue cursors and clear the ready flag. Called when the driver writes Status = INIT.

Source

pub fn pop_avail<M: GuestMemory + ?Sized>( &mut self, mem: &M, ) -> Result<Option<DescriptorChain>, QueueError>

Pop the next descriptor head from the available ring.

Returns Ok(None) if the driver has not made any new descriptors available since the last call.

§Errors

QueueError for any underlying memory access failure.

Source

pub fn push_used<M: GuestMemory + ?Sized>( &mut self, mem: &M, head_index: u16, bytes_written: u32, ) -> Result<(), QueueError>

Push a completed descriptor chain into the used ring.

head_index is the descriptor index returned by pop_avail; bytes_written is the total bytes the device wrote into device-write descriptors of the chain (zero for purely device-read chains).

§Errors

QueueError for any underlying memory access failure.

Trait Implementations§

Source§

impl Clone for Queue

Source§

fn clone(&self) -> Queue

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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

Auto Trait Implementations§

§

impl Freeze for Queue

§

impl RefUnwindSafe for Queue

§

impl Send for Queue

§

impl Sync for Queue

§

impl Unpin for Queue

§

impl UnsafeUnpin 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> 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more