pub trait LayerSource: Send + 'static {
// Required methods
fn open(&self) -> Result<(Vec<OwnedFd>, Box<dyn Send + 'static>)>;
fn produce(
&self,
dirfd_index_map: &[u32],
out: Box<dyn Write + Send>,
) -> Result<()>;
}Expand description
A producer that can open the real diff-directory file descriptors for one
layer and stream the layer content as a splitdirfdstream.
Implementors supply two things:
- The set of real diff-directory fds (in chain order) plus an opaque
lifetime guard that must be held open until the consumer signals
completion (keepalive-pipe EOF). For the repo case the guard is
(); for containers-storage the guard is the sharedLayerStoreLock. - A function that, given the slot-index assignments from the sparse layout,
produces the
splitdirfdstreambytes into a writer.
The trait is object-safe so it can be stored in Box<dyn LayerSource>.
Required Methods§
Sourcefn open(&self) -> Result<(Vec<OwnedFd>, Box<dyn Send + 'static>)>
fn open(&self) -> Result<(Vec<OwnedFd>, Box<dyn Send + 'static>)>
Open the real diff-directory file descriptors for this layer, in chain order, AND acquire any lifetime-bound resources (e.g. a shared layer-store lock).
Returns (dirfds, guard) where:
dirfds— the real diff-dir fds, one per chain layer, in chain order.guard— an opaque object that must be held open until the consumer finishes processing (keepalive-pipe EOF). Dropping the guard signals that the layer’s storage may be released. For the repo source this isBox::new(())(no-op).
The lock is acquired BEFORE the fds are opened so that the lock →
open sequence is atomic (avoids a TOCTOU race where a concurrent
podman rmi could unlink a diff directory between lock and open).
Called once per GetLayer request, before the sparse layout is built.
Sourcefn produce(
&self,
dirfd_index_map: &[u32],
out: Box<dyn Write + Send>,
) -> Result<()>
fn produce( &self, dirfd_index_map: &[u32], out: Box<dyn Write + Send>, ) -> Result<()>
Write the layer content as a splitdirfdstream to out.
dirfd_index_map[i] is the slot index within the sparse dirfds region
where the i-th real diff-dir fd was placed. The producer must use
write_file_backed_data(dirfd_index_map[i], ...) for every file that
belongs to chain layer i.
This method is called from a spawn_blocking context so it MAY block.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".