Repository navigation
fs: resolve overlay symlinks across layers - #856
Merged
Merged
Conversation
OverlayFS used Lstat semantics everywhere, so Stat did not follow links, MkdirAll rejected symlinked components, and writing through a lower symlink copied the target's bytes over the link instead of writing the target. Resolve every path through the merged upper/lower view, reading each link from the layer that provides it, and copy up the resolved target on write and metadata changes.
ewhauser
enabled auto-merge (squash)
October 19, 2026 04:05
This was referenced Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OverlayFS, the backend behind--rootsessions, treated every lookup asLstat, so symlinks in the read-only lower layer were never followed:Statbehaved likeLstat, so[ -d link ]and[ -f flink ]were false.mkdir -p link/subfailed with "Not a directory".echo new > flinkcopied the target's bytes into the upper layer at the link's path. That replaced the symlink with a 0777 regular file and left the real target unchanged.Paths are now resolved component by component through the merged upper+lower view. Each link is read from the layer that currently provides it, so a link in one layer can point at an entry that exists only in the other.
Stat,Open/OpenFile,ReadDir,Realpath,Chdir,Chmod,Chtimes,Chown(follow=true)Lstat,Readlink,Remove,Rename,Link,Symlink,Mkfifo,Lchtimes,Chown(follow=false)Writes and metadata changes through a link copy up and modify the resolved target, and the link stays a link.
MkdirAllfollows symlinked directory components.O_CREATE|O_EXCLfails on any existing link, including a dangling one. Parent resolution also fixesrm link/f(it used to tombstone the wrong path, soreal/fstayed visible) andecho x > link/new(it used to create alink/directory in the upper layer that hid the symlink).Performance
Walking each component made every lookup re-resolve all of its path prefixes in the lower layer. A new
lowerDirscache stores lower-layer directory prefixes. This is safe because the lower layer is never written through the overlay. DeepStatover a HostFS lower (ad-hoc benchmark, Apple M3 Max):With an in-memory lower layer, deep
Statgoes from 1.2µs to 4.3µs. The extra cost is per-component upperLstats, all in memory.SPEC
Added two bullets under the backend boundary section of
SPEC.mddescribing the overlay's symlink semantics.Tests
fs/overlay_symlink_test.go: Stat/Lstat, cross-layer links in both directions, Realpath/ReadDir/Chdir, MkdirAll, write-through, create-through (dir link, dangling link),O_EXCL, Chmod/Chtimes/Chown, and Remove through a symlinked parent. All 7 tests fail onmain.internal/runtime:TestOverlayFollowsLowerSymlinksForShellReadsAndWrites, an end-to-end shell script underSymlinkFollow. Onmainit fails withmkdir: cannot create directory "/w/link": Not a directoryandcat real/fprintsorig.go test ./fs/... ./internal/runtime/...passes, andmake lintreports 0 issues.make test: everything passes exceptscripts/bench-compareTestExpansionStressScenarioMatchesExpectedStdoutUnderBash, which also fails on unmodifiedmainon this machine (it runs host bash 3.2).Known pre-existing issue (not fixed here)
Chmod/Chown/Chtimeson a lower directory copy its whole subtree up from the raw lower layer and ignore tombstones. Afterrm d/a; chmod 700 d,d/ashows up again. This is a separate fix.