Struct virtio_drivers::VirtIOBlk
source · [−]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<H: Hal, T: Transport> VirtIOBlk<H, T>
impl<H: Hal, T: Transport> VirtIOBlk<H, T>
sourcepub fn ack_interrupt(&mut self) -> bool
pub fn ack_interrupt(&mut self) -> bool
Acknowledge interrupt.
sourcepub fn read_block(&mut self, block_id: usize, buf: &mut [u8]) -> Result
pub fn read_block(&mut self, block_id: usize, buf: &mut [u8]) -> Result
Read a block.
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 fn write_block(&mut self, block_id: usize, buf: &[u8]) -> Result
pub fn write_block(&mut self, block_id: usize, buf: &[u8]) -> Result
Write a block.
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.