Storage supplies the layers. A namespace owns the view.
LayerStack does not expose a writable checkout. The runtime takes one pinned lease, adds fresh per-session writable directories, and asks the kernel to attach exactly one merged workspace inside the holder's mount namespace.
Two inputs meet at one kernel object.
LayerStack contributes stable lower paths and a lease that keeps them alive. The namespace runtime contributes a holder, user and mount namespace file descriptors, and a pre-existing workspace root. A one-shot runner joins those namespaces and builds the overlay there.
Ownership handoff
No base tree is copied or materialized during this handoff.
LayerStack lease
[L42, S41, B1]
immutable · newest-first · pinned
One-shot runner
setns(user, mnt)
configure · attach · mask · exit
Mounted workspace
/workspace
private writes · shared reads
One visible root, four different roles.
The upperdir and lowerdirs participate in the merged view. The workdir does not: it is private kernel scratch and must remain a sibling of the upperdir on the same filesystem.
OverlayFS priority
Highest visible source first
/workspacemerged rootupper/ws-17rwprivate writes + whiteouts
L0000421 · newest published deltaS0000412 · compacted immutable historyB000001-base3 · oldest · shared basework/ws-17kernel scratch · not visible- Workspace root
- The pre-existing mountpoint that workloads see as the merged filesystem.
- Upperdir
- The session-private writable tree. New files, copy-ups, and deletion metadata land here.
- Workdir
- OverlayFS scratch space beside the upperdir. It supports kernel operations but is not part of the visible stack.
- Lowerdirs
- The leased immutable layers in newest-first priority order, with the shared base last.
Configure detached. Attach once.
The runtime calls the Linux new-mount API directly. It does not invoke the mount(8) binary, assemble a legacy option string, or attach a half-built filesystem to the daemon's namespace.
- 01
fsopenOpen a new overlay filesystem context.
- 02
fsconfig · lowerdir+Append each leased lower path, newest first.
- 03
fsconfig · userxattrEnable user-namespace-compatible overlay metadata.
- 04
fsconfig · upper / workAttach the session’s real writable paths.
- 05
fsconfig_createAsk the kernel to finish the filesystem configuration.
- 06
fsmountCreate the detached, read-write mount object.
- 07
move_mountAttach that object to the real workspace root.
Lowerdirs are pinned
Each leased lower directory is opened without following its final symlink and passed to the kernel through a /proc/self/fd/N path. Renaming its original path cannot redirect this mount build.
Writable paths stay real
Upperdir, workdir, and workspace root are validated and held open, but configured with real paths because common kernels do not accept the same FD-path treatment for these roles.
Array order becomes filesystem truth.
Publication prepends a layer. A lease copies manifest order into its paths. Workspace and runner messages preserve that array. Finally, the first lowerdir+ call receives highest priority. The plumbing does not sort or re-derive the order later.
- 01
Manifest
prepend newest L*
- 02
Lease
copy ordered paths
- 03
Runner request
serialize unchanged
- 04
Kernel
first lowerdir+ wins
Read
first visible path winsThe upperdir is checked first, then leased lower layers from newest to oldest.
First mutation
lower file → copy-upOverlayFS may copy the complete lower file into the upperdir before applying the write.
Delete
lower path → whiteoutA deletion marker hides the immutable lower path without changing shared history.
Copy-on-write is not byte-diff-on-write. A small edit to a lower-only file can require copying that whole file into the upperdir first.
The upperdir is both the write target and the change record.
Capture does not copy the merged workspace. It walks the private upperdir, preserves OverlayFS deletion and opacity semantics, and prepares a candidate immutable delta. Workspace coordination decides whether that candidate may become shared history.
- 01
Quiesce writes
The session gate stops lifecycle races around capture.
- 02
Walk upperdir
Read created files, copied-up entries, whiteouts, and opaque directories.
- 03
Stage delta
Build private immutable payload and path metadata outside the manifest.
- 04
Hand off
Conflict detection and merge determine whether publication can commit.
Overlay metadata is semantic. Dropping a whiteout or opaque-directory marker can resurrect an older lower-layer path. Capture must translate those markers, not treat them as disposable scratch.
The daemon coordinates the mount. It never owns the mount.
The one-shot runner joins only the holder's user and mount namespaces. After mounting and applying configured path masks, it deliberately gives up its userspace teardown guard. Kernel namespace references keep the overlay alive after the runner exits.
- 01
Daemon
spawn holder and open namespace FDs
- 02
Runner
join holder user + mount namespaces
- 03
Kernel
attach overlay; mask configured host paths
- 04
Holder
namespace pins the mount until teardown
Store paths are masked
Existing configured paths such as the runtime storage root receive a tiny, read-only, no-exec tmpfs cover inside the workload namespace after the overlay is attached.
Teardown follows ownership
Normal session destroy kills the holder. When its isolated mount namespace dies, the kernel drops the overlay; the runtime then removes the session scratch tree.
Reject ambiguity before attach. Preserve kernel errors after it.
Validation constrains path shape and directory identity. It does not promise that every Linux kernel accepts every layer chain; feature support and practical stack depth remain kernel limits.
- Linux kernel boundary
- Mount syscalls are Linux-only; non-Linux builds do not provide a real overlay workspace.
- Non-empty lease
- At least one lower layer is required. The workspace root and every lower layer must already exist.
- Directory integrity
- Root, lower, upper, and work paths are opened as directories without following a final symlink.
- Path hygiene
- Mount inputs reject comma, colon, backslash, control whitespace, and NUL before configuration.
- Kernel-sized stack
- The runtime sets no synthetic lower-layer cap; the kernel rejects an unsupported chain.
- No hidden fallback
- Syscall failures retain their operation context instead of silently changing mount semantics.
Before syscalls
Invalid input
No mount context is created. Session setup fails with the validation detail.
Before attachment
Kernel build failure
Owned file descriptors close; a detached mount that never moved to the root is discarded.
After attachment
Namespace lifetime
The holder namespace owns the live mount; ordinary teardown relies on namespace death, not lazy detach.
Live squash remount is the deliberate exception: it stages a second overlay, moves mountpoints through pre-opened FDs, and uses strict unmount so EBUSY remains visible instead of being hidden by lazy detach.
