pub struct HookDisk { /* private fields */ }Expand description
A RAM disk or disk decorator with an optional operation hook.
Configure metadata and hooks before calling into_disk.
The resulting disk handle is cheap to clone and shares storage, capacity,
and hook state.
Implementations§
Source§impl HookDisk
impl HookDisk
Sourcepub fn new(size: u64, sector_size: u32) -> Self
pub fn new(size: u64, sector_size: u32) -> Self
Creates a sparse RAM disk of size bytes using [disklayer_ram].
Unwritten sectors read as zeroes. Storage is allocated only on writes.
Panics if the size is zero, the sector size is not a power of two
= 512, or the size is not a multiple of the sector size.
Sourcepub fn wrap(disk: Disk) -> Self
pub fn wrap(disk: Disk) -> Self
Wraps a disk, preserving its metadata, reservations, and resize support.
Sourcepub fn into_disk(self) -> Disk
pub fn into_disk(self) -> Disk
Converts this builder into a disk handle, preserving hooks and metadata.
The returned handle can be cheaply cloned to share storage and hook state.
Panics if the configured physical sector size is not a power of two or is smaller than the logical sector size.
Sourcepub fn with_physical_sector_size(self, sector_size: u32) -> Self
pub fn with_physical_sector_size(self, sector_size: u32) -> Self
Sets the physical sector size reported by the disk.
Sourcepub fn with_disk_id(self, disk_id: [u8; 16]) -> Self
pub fn with_disk_id(self, disk_id: [u8; 16]) -> Self
Sets the identifier reported by the disk.
Sourcepub fn with_read_only(self, read_only: bool) -> Self
pub fn with_read_only(self, read_only: bool) -> Self
Sets whether the disk rejects writes and unmaps that reach the backend.
Setting this to false does not make a read-only backing disk writable.
Sourcepub fn with_fua_respected(self, respected: bool) -> Self
pub fn with_fua_respected(self, respected: bool) -> Self
Sets whether the disk advertises FUA support.
Sourcepub fn with_unmap_behavior(self, behavior: UnmapBehavior) -> Self
pub fn with_unmap_behavior(self, behavior: UnmapBehavior) -> Self
Sets the advertised unmap behavior.
This does not change the backing disk’s behavior. Advertise Zeroes
only if it actually zeroes unmapped sectors. Disk does not forward
ignored unmaps, so they do not invoke the hook.
Sourcepub fn with_optimal_unmap_sectors(self, sectors: u32) -> Self
pub fn with_optimal_unmap_sectors(self, sectors: u32) -> Self
Sets the advertised optimal unmap granularity in sectors.
Sourcepub fn with_sync_hook<F>(self, hook: F) -> Self
pub fn with_sync_hook<F>(self, hook: F) -> Self
Installs a synchronous hook, replacing any existing hook.
The hook runs before each I/O operation and may fail it. Concurrent operations may invoke the hook concurrently.
Sourcepub fn with_async_hook<F, Fut>(self, hook: F) -> Self
pub fn with_async_hook<F, Fut>(self, hook: F) -> Self
Installs an async hook, replacing any existing hook.
The hook runs before each I/O operation and may fail or suspend it. Concurrent operations may invoke the hook concurrently.
Trait Implementations§
Source§impl DiskIo for HookDisk
impl DiskIo for HookDisk
Source§fn sector_count(&self) -> u64
fn sector_count(&self) -> u64
Source§fn sector_size(&self) -> u32
fn sector_size(&self) -> u32
Source§fn physical_sector_size(&self) -> u32
fn physical_sector_size(&self) -> u32
Source§fn disk_id(&self) -> Option<[u8; 16]>
fn disk_id(&self) -> Option<[u8; 16]>
Source§fn is_read_only(&self) -> bool
fn is_read_only(&self) -> bool
Source§fn is_fua_respected(&self) -> bool
fn is_fua_respected(&self) -> bool
fua parameter to [DiskIo::write_vectored] is
respected by the backing store by ensuring that the IO is immediately
committed to disk.