Skip to main content

VirtualDisk

Struct VirtualDisk 

Source
pub struct VirtualDisk { /* private fields */ }
Expand description

A crashable virtual disk with two-stage durability and fault knobs.

Implementations§

Source§

impl VirtualDisk

Source

pub fn new() -> Self

An empty disk with no faults armed.

Source

pub fn set_write_failures(&mut self, enabled: bool)

Fails every write while enabled is true.

Source

pub fn set_fsync_failures(&mut self, enabled: bool)

Fails every fsync while enabled is true.

Source

pub fn fail_next_write(&mut self)

Fails only the next write.

Source

pub fn fail_next_fsync(&mut self)

Fails only the next fsync.

Source

pub fn set_torn_write_limit(&mut self, limit: Option<usize>)

Truncates every write to at most limit bytes (a torn write). None disables truncation.

Source

pub fn append(&mut self, path: &str, bytes: &[u8]) -> Result<usize, DiskError>

Appends bytes to the pending stage. Returns the number of bytes accepted, which a torn write may shorten. The bytes are not durable until VirtualDisk::fsync.

Source

pub fn fsync(&mut self, path: &str) -> Result<(), DiskError>

Moves all pending bytes of path to the durable stage.

Source

pub fn read(&self, path: &str) -> Vec<u8>

Live view: durable bytes followed by not-yet-fsynced bytes.

Source

pub fn read_durable(&self, path: &str) -> Vec<u8>

Crash-recovery view: exactly the fsynced prefix.

Source

pub fn durable_len(&self, path: &str) -> usize

Number of fsynced bytes for path.

Source

pub fn pending_len(&self, path: &str) -> usize

Number of written-but-not-fsynced bytes for path.

Source

pub fn crash(&mut self)

Simulates power loss: every pending (un-fsynced) byte is lost, on every file.

Trait Implementations§

Source§

impl Debug for VirtualDisk

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VirtualDisk

Source§

fn default() -> VirtualDisk

Returns the “default value” for a type. Read more

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.

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.