Skip to main content

HookDisk

Struct HookDisk 

Source
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

Source

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.

Source

pub fn wrap(disk: Disk) -> Self

Wraps a disk, preserving its metadata, reservations, and resize support.

Source

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.

Source

pub fn with_physical_sector_size(self, sector_size: u32) -> Self

Sets the physical sector size reported by the disk.

Source

pub fn with_disk_id(self, disk_id: [u8; 16]) -> Self

Sets the identifier reported by the disk.

Source

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.

Source

pub fn with_fua_respected(self, respected: bool) -> Self

Sets whether the disk advertises FUA support.

Source

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.

Source

pub fn with_optimal_unmap_sectors(self, sectors: u32) -> Self

Sets the advertised optimal unmap granularity in sectors.

Source

pub fn with_sync_hook<F>(self, hook: F) -> Self
where F: Fn(DiskOperation) -> Result<(), DiskError> + Send + Sync + 'static,

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.

Source

pub fn with_async_hook<F, Fut>(self, hook: F) -> Self
where F: Fn(DiskOperation) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), DiskError>> + Send + 'static,

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

Source§

fn disk_type(&self) -> &str

Returns the disk type name as a string. Read more
Source§

fn sector_count(&self) -> u64

Returns the current sector count. Read more
Source§

fn sector_size(&self) -> u32

Returns the logical sector size of the backing store. Read more
Source§

fn physical_sector_size(&self) -> u32

Returns the physical sector size of the backing store. Read more
Source§

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. Read more
Source§

fn is_read_only(&self) -> bool

Returns true if the disk is read only.
Source§

fn is_fua_respected(&self) -> bool

Returns true if the fua parameter to [DiskIo::write_vectored] is respected by the backing store by ensuring that the IO is immediately committed to disk.
Source§

fn unmap_behavior(&self) -> UnmapBehavior

Returns the behavior of the unmap operation. Read more
Source§

fn optimal_unmap_sectors(&self) -> u32

Returns the optimal granularity for unmaps, in sectors.
Source§

fn pr(&self) -> Option<&dyn PersistentReservation>

Optionally returns a trait object to issue persistent reservation requests.
Source§

async fn read_vectored( &self, buffers: &RequestBuffers<'_>, sector: u64, ) -> Result<(), DiskError>

Issues an asynchronous read-scatter operation to the disk. Read more
Source§

async fn write_vectored( &self, buffers: &RequestBuffers<'_>, sector: u64, fua: bool, ) -> Result<(), DiskError>

Issues an asynchronous write-gather operation to the disk. Read more
Source§

async fn sync_cache(&self) -> Result<(), DiskError>

Issues an asynchronous flush operation to the disk.
Source§

async fn unmap( &self, sector: u64, count: u64, block_level_only: bool, ) -> Result<(), DiskError>

Unmap sectors from the layer. Read more
Source§

async fn eject(&self) -> Result<(), DiskError>

Issues an asynchronous eject media operation to the disk. Read more
Source§

async fn wait_resize(&self, sector_count: u64) -> u64

Waits for the disk sector count to change from the specified value. Read more
Source§

impl Inspect for HookDisk

Source§

fn inspect(&self, req: Request<'_>)

Inspects the object.

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more