Skip to main content

build_layer_fd_layout

Function build_layer_fd_layout 

Source
pub fn build_layer_fd_layout(
    pipe_read: OwnedFd,
    real_fds: Vec<OwnedFd>,
    seed: u64,
) -> Result<LayerFdLayout>
Expand description

Build the complete wire fd layout for a producer serving n_real real diff directories.

This pure-ish (only I/O: pipe, /dev/null, memfd) function:

  1. Calls [sparse_dir_slots] to compute the sparse placement.
  2. Opens dummy fds (/dev/null alternating with memfd) for gap slots.
  3. Builds the dirfds region by interleaving real and dummy fds in slot order.
  4. Creates a keepalive pipe; the write end goes into fds_all, the read end is returned in LayerFdLayout::keepalive_read.
  5. Adds n_extra_lifetime_fds(seed) extra dummy lifetime fds.
  6. Prepends the pipe_read fd so fds_all[0] is always the data pipe.

The caller is responsible for:

  • Passing the correct real_fds (in chain order) — the first real_fd gets slot real_indices[0], the second gets real_indices[1], etc.
  • Spawning the producer with write_fd (not returned here; the caller opens the pipe and passes write_fd to the producer separately).

§Arguments

  • pipe_read — Read end of the data pipe (will become fds_all[0]).
  • real_fds — Pre-opened real diff-directory file descriptors, one per chain layer, in chain order.
  • seed — Deterministic seed (see seed_from_id).

§Errors

Returns io::Error if any dummy-fd or keepalive-pipe creation fails.