Struct virtio_drivers::VirtIOBlk
source · [−]pub struct VirtIOBlk<'a> { /* private fields */ }
Expand description
The virtio block device is a simple virtual block device (ie. disk).
Read and write requests (and other exotic requests) are placed in the queue, and serviced (probably out of order) by the device except where noted.
Implementations
sourceimpl VirtIOBlk<'_>
impl VirtIOBlk<'_>
sourcepub fn new(header: &'static mut VirtIOHeader) -> Result<Self>
pub fn new(header: &'static mut VirtIOHeader) -> Result<Self>
Create a new VirtIO-Blk driver.
sourcepub fn ack_interrupt(&mut self) -> bool
pub fn ack_interrupt(&mut self) -> bool
Acknowledge interrupt.
sourcepub unsafe fn read_block_nb(
&mut self,
block_id: usize,
buf: &mut [u8],
resp: &mut BlkResp
) -> Result<u16>
pub unsafe fn read_block_nb(
&mut self,
block_id: usize,
buf: &mut [u8],
resp: &mut BlkResp
) -> Result<u16>
Read a block in a non-blocking way which means that it returns immediately.
Arguments
block_id
- The identifier of the block to read.buf
- The buffer in the memory which the block is read into.resp
- A mutable reference to a variable provided by the caller which contains the status of the requests. The caller can safely read the variable only after the request is ready.
Usage
It will submit request to the virtio block device and return a token identifying the position of the first Descriptor in the chain. If there are not enough Descriptors to allocate, then it returns Error::BufferTooSmall.
After the request is ready, resp
will be updated and the caller can get the
status of the request(e.g. succeed or failed) through it. However, the caller
must not spin on resp
to wait for it to change. A safe way is to read it
after the same token as this method returns is fetched through VirtIOBlk::pop_used(),
which means that the request has been ready.
Safety
buf
is still borrowed by the underlying virtio block device even if this
method returns. Thus, it is the caller’s responsibility to guarantee that
buf
is not accessed before the request is completed in order to avoid
data races.
sourcepub unsafe fn write_block_nb(
&mut self,
block_id: usize,
buf: &[u8],
resp: &mut BlkResp
) -> Result<u16>
pub unsafe fn write_block_nb(
&mut self,
block_id: usize,
buf: &[u8],
resp: &mut BlkResp
) -> Result<u16>
Arguments
block_id
- The identifier of the block to write.buf
- The buffer in the memory containing the data to write to the block.resp
- A mutable reference to a variable provided by the caller which contains the status of the requests. The caller can safely read the variable only after the request is ready.
Usage
See also VirtIOBlk::read_block_nb().
Safety
See also VirtIOBlk::read_block_nb().
sourcepub fn pop_used(&mut self) -> Result<u16>
pub fn pop_used(&mut self) -> Result<u16>
During an interrupt, it fetches a token of a completed request from the used ring and return it. If all completed requests have already been fetched, return Err(Error::NotReady).
sourcepub fn virt_queue_size(&self) -> u16
pub fn virt_queue_size(&self) -> u16
Return size of its VirtQueue. It can be used to tell the caller how many channels he should monitor on.
Auto Trait Implementations
impl<'a> RefUnwindSafe for VirtIOBlk<'a>
impl<'a> Send for VirtIOBlk<'a>
impl<'a> Sync for VirtIOBlk<'a>
impl<'a> Unpin for VirtIOBlk<'a>
impl<'a> !UnwindSafe for VirtIOBlk<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more