pub struct Disk(/* private fields */);
Expand description
An asynchronous block device.
This type is cheap to clone, for sharing the disk among multiple concurrent users.
Implementations§
Source§impl Disk
impl Disk
Sourcepub fn new(disk: impl 'static + DiskIo) -> Result<Self, InvalidDisk>
pub fn new(disk: impl 'static + DiskIo) -> Result<Self, InvalidDisk>
Returns a new disk wrapping the given backing object.
Sourcepub fn sector_count(&self) -> u64
pub fn sector_count(&self) -> u64
Returns the current sector count.
For some backing stores, this may change at runtime. Use
wait_resize
to detect this change.
Sourcepub fn sector_size(&self) -> u32
pub fn sector_size(&self) -> u32
Returns the logical sector size of the backing store.
Sourcepub fn sector_shift(&self) -> u32
pub fn sector_shift(&self) -> u32
Returns log2 of the logical sector size of the backing store.
Sourcepub fn disk_id(&self) -> Option<[u8; 16]>
pub fn disk_id(&self) -> Option<[u8; 16]>
Optionally returns a 16-byte identifier for the disk, if there is a natural one for this backing store.
This may be exposed to the guest as a unique disk identifier.
Sourcepub fn physical_sector_size(&self) -> u32
pub fn physical_sector_size(&self) -> u32
Returns the physical sector size of the backing store.
Sourcepub fn is_fua_respected(&self) -> bool
pub fn is_fua_respected(&self) -> bool
Returns true if the fua
parameter to
write_vectored
is respected by the backing
store by ensuring that the IO is immediately committed to disk.
Sourcepub fn is_read_only(&self) -> bool
pub fn is_read_only(&self) -> bool
Returns true if the disk is read only.
Sourcepub fn unmap(
&self,
sector: u64,
count: u64,
block_level_only: bool,
) -> impl use<'_> + Future<Output = Result<(), DiskError>> + Send
pub fn unmap( &self, sector: u64, count: u64, block_level_only: bool, ) -> impl use<'_> + Future<Output = Result<(), DiskError>> + Send
Unmap sectors from the disk.
Sourcepub fn unmap_behavior(&self) -> UnmapBehavior
pub fn unmap_behavior(&self) -> UnmapBehavior
Returns the behavior of the unmap operation.
Sourcepub fn optimal_unmap_sectors(&self) -> u32
pub fn optimal_unmap_sectors(&self) -> u32
Returns the optimal granularity for unmaps, in sectors.
Sourcepub fn pr(&self) -> Option<&dyn PersistentReservation>
pub fn pr(&self) -> Option<&dyn PersistentReservation>
Optionally returns a trait object to issue persistent reservation requests.
Sourcepub fn eject(
&self,
) -> impl use<'_> + Future<Output = Result<(), DiskError>> + Send
pub fn eject( &self, ) -> impl use<'_> + Future<Output = Result<(), DiskError>> + Send
Issues an asynchronous eject media operation to the disk.
Sourcepub fn read_vectored<'a>(
&'a self,
buffers: &'a RequestBuffers<'_>,
sector: u64,
) -> impl use<'a> + Future<Output = Result<(), DiskError>> + Send
pub fn read_vectored<'a>( &'a self, buffers: &'a RequestBuffers<'_>, sector: u64, ) -> impl use<'a> + Future<Output = Result<(), DiskError>> + Send
Issues an asynchronous read-scatter operation to the disk.
§Arguments
buffers
- An object representing the data buffers into which the disk data will be transferred.sector
- The logical sector at which the read operation starts.
Sourcepub fn write_vectored<'a>(
&'a self,
buffers: &'a RequestBuffers<'_>,
sector: u64,
fua: bool,
) -> impl use<'a> + Future<Output = Result<(), DiskError>> + Send
pub fn write_vectored<'a>( &'a self, buffers: &'a RequestBuffers<'_>, sector: u64, fua: bool, ) -> impl use<'a> + Future<Output = Result<(), DiskError>> + Send
Issues an asynchronous write-gather operation to the disk.
§Arguments
buffers
- An object representing the data buffers containing the data to transfer to the disk.sector
- The logical sector at which the write operation starts.fua
- A flag indicates if FUA (force unit access) is requested.
§Panics
The caller must pass a buffer with an integer number of sectors.
Sourcepub fn sync_cache(
&self,
) -> impl use<'_> + Future<Output = Result<(), DiskError>> + Send
pub fn sync_cache( &self, ) -> impl use<'_> + Future<Output = Result<(), DiskError>> + Send
Issues an asynchronous flush operation to the disk.
Sourcepub fn wait_resize(
&self,
sector_count: u64,
) -> impl use<'_> + Future<Output = u64>
pub fn wait_resize( &self, sector_count: u64, ) -> impl use<'_> + Future<Output = u64>
Waits for the disk sector size to be different than the specified value.