Skip to main content

VirtioBlockDevice

Struct VirtioBlockDevice 

Source
pub struct VirtioBlockDevice {
    device: VirtioDevice,
    queue: SpinLock<Virtqueue>,
    capacity: u64,
    block_size: u32,
    bounce_pool: BouncePool,
    meta_pool: MetaPool,
}
Expand description

VirtIO Block Device driver

Fields§

§device: VirtioDevice§queue: SpinLock<Virtqueue>§capacity: u64§block_size: u32§bounce_pool: BouncePool

Pre-allocated DMA resources : no per-I/O alloc/free for common requests.

§meta_pool: MetaPool

Implementations§

Source§

impl VirtioBlockDevice

Source

pub unsafe fn new(pci_dev: PciDevice) -> Result<Self, &'static str>

Initialize a VirtIO block device from a PCI device

§Safety

The PCI device must be a valid VirtIO block device

Source

fn acquire_dma_buffer( &self, buf_size: usize, is_write: bool, src: Option<&[u8]>, ) -> Result<(u64, u64, Option<(PhysFrame, u8)>), BlockError>

Determine the DMA buffer strategy: use the pre-allocated pool when the request fits; fall back to a per-I/O allocation for large transfers.

Source

fn release_dma_buffer(&self, allocated: Option<(PhysFrame, u8)>)

Source

fn do_request( &self, request_type: RequestType, sector: u64, data_buf: Option<(&mut [u8], bool)>, ) -> Result<(), BlockError>

Submit a block request and wait for completion

Trait Implementations§

Source§

impl BlockDevice for VirtioBlockDevice

Source§

fn read_sector(&self, sector: u64, buf: &mut [u8]) -> Result<(), BlockError>

Reads sector.

Source§

fn write_sector(&self, sector: u64, buf: &[u8]) -> Result<(), BlockError>

Writes sector.

Source§

fn read_sectors( &self, sector: u64, count: u16, buf: &mut [u8], ) -> Result<(), BlockError>

Read multiple sectors in a single I/O.

VirtIO block uses a single descriptor whose length encodes the transfer size, so do_request naturally handles multi-sector transfers when given a large enough buffer.

Source§

fn write_sectors( &self, sector: u64, count: u16, buf: &[u8], ) -> Result<(), BlockError>

Write multiple sectors in a single I/O.

Source§

fn sector_count(&self) -> u64

Performs the sector count operation.

Source§

impl Send for VirtioBlockDevice

Source§

impl Sync for VirtioBlockDevice

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.