Repository navigation
fs: copy up only the directory node for overlay metadata ops - #858
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.
Chmod, Chown, Chtimes, and Lchtimes on a lower-only directory cloned the whole raw lower subtree into the upper layer, resurrecting tombstoned children and copying every file. Copy up just the directory node (and any missing ancestors with their lower metadata); the merged ReadDir already unions both layers.
# Conflicts: # SPEC.md # fs/overlay.go
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.
Stacked on #856. This branch is built on
claude/interesting-pare-325ca4, so the diff againstmainincludes #856's commit until that PR merges. The change in this PR is commit 82e8ad3 only.Problem
In
OverlayFS,Chmod/Chown/Chtimes/Lchtimeson a directory that exists only in the lower layer calledclonePathWithInfo(ctx, o.lower, abs, info, o.upper, abs). That copied the whole subtree from the raw lower layer and ignored tombstones:It was also slow: a
chmodon a large lower directory copied every file into memory. And because the upperMkdirAllfilled in missing ancestors, their modes and owners were reset to the defaults (0755,1000:1000).Fix
OverlayFS.copyUpNode, used by the four metadata ops. A directory is copied up as a bare node with its mode (including the setuid/setgid/sticky bits), ownership and mtime, through the newcloneDirNodeinfs/clone.go. Its children stay in the lower layer. The mergedReadDiralready combines both layers, and tombstones keep deleted children hidden.visiblePrefixInfo, which also uses fs: resolve overlay symlinks across layers #856'slowerDirscache.clonePathWithInfo, as before.Rename(clones from the merged overlay) andLink(clones one lower file) are untouched; tests now cover both after a directory copy-up.SPEC
Added one bullet under the OverlayFS backend boundary describing metadata copy-up of directories.
Tests
New
fs/overlay_copyup_test.go, with each test run for all four ops:TestOverlayFSDirMetadataCopyUpKeepsTombstones: the repro above, plus a tombstoned grandchild.TestOverlayFSDirMetadataCopyUpCopiesOnlyDirectoryNode: children aren't put in the upper layer, untouched attributes keep their lower values, and the parent's lower mode0750is kept.TestOverlayFSRenameLowerDirRespectsTombstones,TestOverlayFSLinkAfterDirMetadataCopyUp.Before the fix, the tombstone, node-only and rename tests failed (
Lstat("/d/a") error = <nil>,upper Lstat("/p/d/a") error = <nil>,ReadDir(/e) = [a b]). With the ancestor copy-up turned off, the parent check fails (Stat(/p).Mode().Perm() = 755, want 750). All pass now.Not changed
OpenFile's write copy-up still creates missing upper ancestors with default metadata. The samecopyUpNodewould fix that, but that is left for a follow-up because it changes the write path.