Skip to main content

LayerStore

Struct LayerStore 

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

A 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

Source

pub fn open(root: &Path) -> Result<Self>

Open (and create) a store at root.

Source

pub fn root(&self) -> &Path

Source

pub fn blob_path(&self, digest: &Digest) -> PathBuf

Source

pub fn has_blob(&self, digest: &Digest) -> bool

Source

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.

Source

pub fn blob_writer(&self) -> Result<BlobWriter>

A blob that arrives in chunks (a registry download).

Source

pub fn rootfs(&self, layers: &[Digest], opts: &UnpackOptions) -> Result<PathBuf>

The rootfs for layers (bottom first), unpacked on first use.

Source

pub fn rootfs_path(&self, layers: &[Digest]) -> PathBuf

Where the rootfs for layers lives (whether or not it exists yet).

Source§

impl LayerStore

Source

pub fn layer_path(&self, diff_id: &Digest) -> PathBuf

Where the unpacked directory of a layer lives.

Source

pub fn has_layer(&self, diff_id: &Digest) -> bool

Source

pub fn missing_layers(&self, layers: &[ImageLayer]) -> Vec<ImageLayer>

The layers not yet unpacked: what a pull still has to fetch.

Source

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.

Source

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.

Source

pub fn image_layers(&self, id: &Digest) -> Result<Vec<PathBuf>>

The layer directories of a recorded image, bottom first.

Source

pub fn remove_image(&self, id: &Digest) -> Result<()>

Forget image id; its layers stay until LayerStore::gc.

Source

pub fn refcount(&self, diff_id: &Digest) -> Result<usize>

How many recorded images use the layer.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for LayerStore

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LayerStore

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.