Struct virtio_queue::Queue

source ·
pub struct Queue { /* private fields */ }
Expand description

Struct to maintain information and manipulate a virtio queue.

Example

use virtio_queue::{Queue, QueueOwnedT, QueueT};
use vm_memory::{Bytes, GuestAddress, GuestAddressSpace, GuestMemoryMmap};

let m = GuestMemoryMmap::<()>::from_ranges(&[(GuestAddress(0), 0x10000)]).unwrap();
let mut queue = Queue::new(1024).unwrap();

// First, the driver sets up the queue; this set up is done via writes on the bus (PCI, MMIO).
queue.set_size(8);
queue.set_desc_table_address(Some(0x1000), None);
queue.set_avail_ring_address(Some(0x2000), None);
queue.set_used_ring_address(Some(0x3000), None);
queue.set_event_idx(true);
queue.set_ready(true);
// The user should check if the queue is valid before starting to use it.
assert!(queue.is_valid(&m));

// Here the driver would add entries in the available ring and then update the `idx` field of
// the available ring (address = 0x2000 + 2).
m.write_obj(3, GuestAddress(0x2002));

loop {
    queue.disable_notification(&m).unwrap();

    // Consume entries from the available ring.
    while let Some(chain) = queue.iter(&m).unwrap().next() {
        // Process the descriptor chain, and then add an entry in the used ring and optionally
        // notify the driver.
        queue.add_used(&m, chain.head_index(), 0x100).unwrap();

        if queue.needs_notification(&m).unwrap() {
            // Here we would notify the driver it has new entries in the used ring to consume.
        }
    }
    if !queue.enable_notification(&m).unwrap() {
        break;
    }
}

// We can reset the queue at some point.
queue.reset();
// The queue should not be ready after reset.
assert!(!queue.ready());

Implementations

Equivalent of QueueT::set_size returning an error in case of invalid size.

This should not be directly used, as the preferred method is part of the QueueT interface. This is a convenience function for implementing save/restore capabilities.

Tries to set the descriptor table address. In case of an invalid value, the address is not updated.

This should not be directly used, as the preferred method is QueueT::set_desc_table_address. This is a convenience function for implementing save/restore capabilities.

Tries to update the available ring address. In case of an invalid value, the address is not updated.

This should not be directly used, as the preferred method is QueueT::set_avail_ring_address. This is a convenience function for implementing save/restore capabilities.

Tries to update the used ring address. In cae of an invalid value, the address is not updated.

This should not be directly used, as the preferred method is QueueT::set_used_ring_address. This is a convenience function for implementing save/restore capabilities.

Returns the state of the Queue.

This is useful for implementing save/restore capabilities. The state does not have support for serialization, but this can be added by VMMs locally through the use of a remote type.

Alternatively, a version aware and serializable/deserializable QueueState is available in the virtio-queue-ser crate.

Trait Implementations

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Type for guard returned by Self::lock().
Get a consuming iterator over all available descriptor chain heads offered by the driver. Read more
Undo the last advancement of the next available index field by decrementing its value by one. Read more
Construct an empty virtio queue state object with the given max_size. Read more
Check whether the queue configuration is valid.
Reset the queue to the initial state.
Get an exclusive reference to the underlying Queue object. Read more
Get the maximum size of the virtio queue.
Get the actual size configured by the guest.
Configure the queue size for the virtio queue.
Check whether the queue is ready to be processed.
Configure the queue to ready for processing state.
Set the descriptor table address for the queue. Read more
Set the available ring address for the queue. Read more
Set the used ring address for the queue. Read more
Enable/disable the VIRTIO_F_RING_EVENT_IDX feature for interrupt coalescing.
Read the idx field from the available ring. Read more
Read the idx field from the used ring. Read more
Put a used descriptor head into the used ring.
Enable notification events from the guest driver. Read more
Disable notification events from the guest driver.
Check whether a notification to the guest is needed. Read more
Return the index of the next entry in the available ring.
Set the index of the next entry in the available ring.
Return the index for the next descriptor in the used ring.
Set the index for the next descriptor in the used ring.
Return the address of the descriptor table.
Return the address of the available ring.
Return the address of the used ring.
Checks whether VIRTIO_F_RING_EVENT_IDX is negotiated. Read more
Pop and return the next available descriptor chain, or None when there are no more descriptor chains available. Read more
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.