pub struct LayerStore { /* private fields */ }Expand description
A content-addressed store of layer blobs, unpacked layers and images:
<root>/blobs/sha256/<hex> verified blobs, one copy each
<root>/layers/<diff_id>/ one layer unpacked once, in overlayfs format
(whiteouts as 0/0 devices, opaque xattrs);
shared by every image that has it
<root>/images/<id>.json an image: its layers, bottom first; the
refcount of a layer is the images naming it
<root>/rootfs/<chain>/ optional flattened rootfs ([`LayerStore::rootfs`])
for tools that want one tree; not used by
overlays and not collected by gc
<root>/tmp/ downloads and unpacks in progressA container rootfs is an crate::Overlay over
LayerStore::image_layers; an updated image unpacks only its new layers.
Everything lands by rename, so a crash leaves only tmp/ debris.
Implementations§
Source§impl LayerStore
impl LayerStore
pub fn root(&self) -> &Path
pub fn blob_path(&self, digest: &Digest) -> PathBuf
pub fn has_blob(&self, digest: &Digest) -> bool
Sourcepub fn put_blob(&self, digest: &Digest, reader: impl Read) -> Result<PathBuf>
pub fn put_blob(&self, digest: &Digest, reader: impl Read) -> Result<PathBuf>
Store everything reader yields as digest; refused (and nothing
kept) if the bytes hash to something else.
Sourcepub fn blob_writer(&self) -> Result<BlobWriter>
pub fn blob_writer(&self) -> Result<BlobWriter>
A blob that arrives in chunks (a registry download).
Sourcepub fn rootfs(&self, layers: &[Digest], opts: &UnpackOptions) -> Result<PathBuf>
pub fn rootfs(&self, layers: &[Digest], opts: &UnpackOptions) -> Result<PathBuf>
The rootfs for layers (bottom first), unpacked on first use.
Sourcepub fn rootfs_path(&self, layers: &[Digest]) -> PathBuf
pub fn rootfs_path(&self, layers: &[Digest]) -> PathBuf
Where the rootfs for layers lives (whether or not it exists yet).
Source§impl LayerStore
impl LayerStore
Sourcepub fn layer_path(&self, diff_id: &Digest) -> PathBuf
pub fn layer_path(&self, diff_id: &Digest) -> PathBuf
Where the unpacked directory of a layer lives.
pub fn has_layer(&self, diff_id: &Digest) -> bool
Sourcepub fn missing_layers(&self, layers: &[ImageLayer]) -> Vec<ImageLayer>
pub fn missing_layers(&self, layers: &[ImageLayer]) -> Vec<ImageLayer>
The layers not yet unpacked: what a pull still has to fetch.
Sourcepub fn unpack_layer(
&self,
layer: &ImageLayer,
opts: &UnpackOptions,
) -> Result<PathBuf>
pub fn unpack_layer( &self, layer: &ImageLayer, opts: &UnpackOptions, ) -> Result<PathBuf>
Unpack one layer into its own directory (overlayfs format), once.
The uncompressed stream must hash to layer.diff_id.
Sourcepub fn add_image(
&self,
id: &Digest,
layers: &[ImageLayer],
opts: &UnpackOptions,
) -> Result<Vec<PathBuf>>
pub fn add_image( &self, id: &Digest, layers: &[ImageLayer], opts: &UnpackOptions, ) -> Result<Vec<PathBuf>>
Record image id as layers (bottom first), unpacking the layers
not in the store yet. Returns the layer directories, bottom first.
Sourcepub fn image_layers(&self, id: &Digest) -> Result<Vec<PathBuf>>
pub fn image_layers(&self, id: &Digest) -> Result<Vec<PathBuf>>
The layer directories of a recorded image, bottom first.
Sourcepub fn remove_image(&self, id: &Digest) -> Result<()>
pub fn remove_image(&self, id: &Digest) -> Result<()>
Forget image id; its layers stay until LayerStore::gc.
Sourcepub fn refcount(&self, diff_id: &Digest) -> Result<usize>
pub fn refcount(&self, diff_id: &Digest) -> Result<usize>
How many recorded images use the layer.
Sourcepub fn gc(&self) -> Result<GcStats>
pub fn gc(&self) -> Result<GcStats>
Remove layer directories and blobs that no recorded image uses, and
leftovers in tmp/. Run it while no pull is in progress.
Sourcepub fn holds_blob(&self, blob: &Digest) -> bool
pub fn holds_blob(&self, blob: &Digest) -> bool
Whether the store holds what blob is: the blob itself, or the layer
directory it unpacks to (its blob pruned by
LayerStore::prune_unpacked_blobs), as an image record names it. A
pull asks this to skip what it need not download.
Sourcepub fn prune_unpacked_blobs(&self) -> Result<usize>
pub fn prune_unpacked_blobs(&self) -> Result<usize>
Delete the blobs of layers that are unpacked (to save disk); a later pull of the same layers needs neither the blob nor a download.