class VirtioChain
Defined at line 194 of file ../../src/virtualization/bin/vmm/device/virtio_queue.h
A |VirtioChain| is a linked list of buffer descriptors, read from the a
|VirtioQueue|.
When a chain is read out of a queue, there will be at least one
|VirtioDescriptor|, made availale by calling |NextDescriptor| on the chain.
If more descriptors are available (indicated by the VRING_DESC_F_NEXT flag),
then the subsequent descriptors will be made available further calls to
|NextDescriptor|.
When processing of the chain is completed, it must be returned back to the
driver by calling |Return|. Once a chain has been returned, there must not
be any further interactions with |VirtioDescriptor|s that have been read
from the chain.
If any bytes have been written to the chain, then the |Used| value must be
set the the exact number of bytes that have written to the chain. Reading
bytes from a chain does not impact the |Used| count.
Ex, to iterate over every descriptor in a |VirtioChain|:
void ProcessQueue(VirtioQueue* queue) {
VirtioChain chain;
VirtioDescriptor descriptor;
while (queue->NextChain(
&chain
)) {
// There was a descriptor chain in the queue. It was been read from the
// avail ring and written to |chain|.
while (chain.NextDescriptor(
&descriptor
)) {
// |descriptor| describes a single buffer in the chain.
if (descriptor.writable) {
uint32_t bytes_written =
WriteToDescriptor(descriptor.addr, descriptor.len);
// Increment the |Used| value by the number of bytes written.
*chain.Used() += bytes_written;
} else {
ReadFromDescriptor(descriptor.addr, descriptor.len);
}
}
// Write the chain to the used ring, passing ownership back to the
// driver.
chain.Return();
}
}
}
Public Methods
void VirtioChain (VirtioQueue * queue, uint16_t head)
Creates a new, valid descriptor chain rooted at descriptor |head| in
|queue|.
Defined at line 183 of file ../../src/virtualization/bin/vmm/device/virtio_queue.cc
void ~VirtioChain ()
Defined at line 186 of file ../../src/virtualization/bin/vmm/device/virtio_queue.cc
void VirtioChain (VirtioChain && )
When a |VirtioChain| is moved, the source becomes invalid. This ensures
only one instance will be responsible for returning the chain back to the
drivers.
Defined at line 188 of file ../../src/virtualization/bin/vmm/device/virtio_queue.cc
VirtioChain & operator= (VirtioChain && )
Defined at line 193 of file ../../src/virtualization/bin/vmm/device/virtio_queue.cc
void VirtioChain ()
Creates a new, invalid descriptor.
Defined at line 197 of file ../../src/virtualization/bin/vmm/device/virtio_queue.h
bool IsValid ()
Returns |true| iff this chain is valid. A valid chain must be returned
back to the driver before the VirtioChain destructor runs.
Defined at line 206 of file ../../src/virtualization/bin/vmm/device/virtio_queue.cc
bool HasDescriptor ()
Defined at line 208 of file ../../src/virtualization/bin/vmm/device/virtio_queue.cc
bool NextDescriptor (VirtioDescriptor * desc)
Defined at line 210 of file ../../src/virtualization/bin/vmm/device/virtio_queue.cc
void VirtioChain (const VirtioChain & )
Defined at line 211 of file ../../src/virtualization/bin/vmm/device/virtio_queue.h
VirtioChain & operator= (const VirtioChain & )
Defined at line 212 of file ../../src/virtualization/bin/vmm/device/virtio_queue.h
uint32_t * Used ()
Defined at line 224 of file ../../src/virtualization/bin/vmm/device/virtio_queue.cc
void Return (uint8_t actions)
Defined at line 226 of file ../../src/virtualization/bin/vmm/device/virtio_queue.cc