pub struct RequestBuffers<'a> { /* private fields */ }Expand description
An accessor for guest memory associated with a storage IO request.
Wraps a single [PagedRange] — a contiguous byte range scattered
across guest pages — together with a GuestMemory reference and a
read/write direction flag.
§One range per RequestBuffers
Because PagedRange requires interior pages to be fully covered,
a RequestBuffers can only describe memory regions where every
page boundary between the first and last page is fully spanned.
Two guest memory regions with arbitrary starting GPAs generally
cannot be combined into one RequestBuffers.
When a device has multiple disjoint memory regions for a single IO (e.g., a virtio descriptor chain whose descriptors don’t align to page boundaries), options include:
- Issue separate IOs per region (only valid if each region is sector-aligned)
- Use a
BounceBufferto coalesce into one contiguous buffer - Use multiple
RequestBufferswith a multi-range disk backend API (not currently available)
Implementations§
Source§impl<'a> RequestBuffers<'a>
impl<'a> RequestBuffers<'a>
Sourcepub fn new(
guest_memory: &'a GuestMemory,
range: PagedRange<'a>,
is_write: bool,
) -> Self
pub fn new( guest_memory: &'a GuestMemory, range: PagedRange<'a>, is_write: bool, ) -> Self
Creates a new request buffer from the given memory ranges.
Sourcepub fn guest_memory(&self) -> &GuestMemory
pub fn guest_memory(&self) -> &GuestMemory
Returns the guest memory accessor.
Sourcepub fn is_aligned(&self, alignment: usize) -> bool
pub fn is_aligned(&self, alignment: usize) -> bool
Returns whether the buffer is aligned to at least alignment bytes.
Checks three things (all must be multiples of alignment):
- The byte offset into the first page (
range.offset()) - The total byte length (
range.len()) - The page size (4096) — always true for alignment ≤ 4096
When this returns false, disk backends that require aligned
buffers (e.g., those using O_DIRECT or io_uring) must use a
BounceBuffer to perform the IO.
§Panics
Panics if alignment is not a power of two.
Sourcepub fn writer(&self) -> impl MemoryWrite + '_
pub fn writer(&self) -> impl MemoryWrite + '_
Gets a memory writer for the buffers.
Returns an empty writer if the buffers are only available for read access.
Trait Implementations§
Source§impl<'a> Clone for RequestBuffers<'a>
impl<'a> Clone for RequestBuffers<'a>
Source§fn clone(&self) -> RequestBuffers<'a>
fn clone(&self) -> RequestBuffers<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more