Crate disk_layered

Crate disk_layered 

Source
Expand description

A layered disk implementation, LayeredDisk.

A layered disk is a disk composed of multiple layers. Each layer is a block device made up of sectors, but with the added per-sector state of whether the sector is present or not. When reading a sector, the layered disk will read from the topmost layer that has the sector present. When writing, the disk will write to the topmost layer.

A layer can also have caching behavior. If a layer is configured to cache reads, then sectors that are read from lower layers are written back to the layer. If a layer is configured to write through, then writes are written to the layer and the next layer. These can be useful to implement simple persistent and non-persistent caches, primarily designed for lazily populating local backing stores from remote sources.

Missing from this implementation is write-back caching and cache eviction, which would be needed for caches that are smaller than the disk. These require potentially complicated cache management policies and are probably best implemented in a separate disk implementation.

§Layer types

Each layer implements LayerIo, which is similar to [DiskIo] but adds per-sector presence tracking via SectorMarker. Two concrete layer implementations exist:

  • RamDiskLayer (disklayer_ram) — ephemeral, in-memory.
  • SqliteDiskLayer (disklayer_sqlite) — persistent, file-backed (dev/test only).

A full [Disk] can appear at the bottom of the stack as a fully-present layer via DiskLayer::from_disk, which wraps it in DiskAsLayer — a layer that marks all sectors as present on every read.

§Construction and validation

LayeredDisk::new validates the layer stack at construction time:

  • All layers must have matching sector sizes.
  • Write-through layers must be contiguous from the top.
  • The last layer must not be write-through.
  • Layers used as read caches must support WriteNoOverwrite.
  • If the disk is writable, all layers in the write path must be writable.

Modules§

resolve
Resolver-related definitions for disk layer resources.
resolver
Resolvers for layered disks.

Structs§

DiskLayer
A single layer which can be attached to a LayeredDisk.
DiskLayerMetadata
Metadata of a particular layer, collected from various LayerIo APIs.
LayerConfiguration
A configuration for a layer in a LayeredDisk.
LayeredDisk
A disk composed of multiple layers.
SectorMarker
A type to mark sectors that have been read by a layer as part of a LayerIo::read operation.

Enums§

InvalidLayer
An error returned when creating a DiskLayer.
InvalidLayeredDisk
An error returned when creating a LayeredDisk.

Traits§

LayerAttach
Transition a layer from an unattached type-state, into an attached type-state, capable of performing LayerIo.
LayerIo
Metadata and IO for disk layers.
WriteNoOverwrite
Writes to the layer without overwriting existing data.