Skip to content

fs: copy up only the directory node for overlay metadata ops - #858

Merged
ewhauser merged 3 commits into
mainfrom
fix/overlay-metadata-copyup
Oct 19, 2026
Merged

ewhauser merged 3 commits into
mainfrom
fix/overlay-metadata-copyup

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Stacked on #856. This branch is built on claude/interesting-pare-325ca4, so the diff against main includes #856's commit until that PR merges. The change in this PR is commit 82e8ad3 only.

Problem

In OverlayFS, Chmod/Chown/Chtimes/Lchtimes on a directory that exists only in the lower layer called clonePathWithInfo(ctx, o.lower, abs, info, o.upper, abs). That copied the whole subtree from the raw lower layer and ignored tombstones:

lower: /d/a, /d/b
overlay.Remove("/d/a")
overlay.Chmod("/d", 0o700)
overlay.Lstat("/d/a")   // succeeded again: the deleted file came back

It was also slow: a chmod on a large lower directory copied every file into memory. And because the upper MkdirAll filled in missing ancestors, their modes and owners were reset to the defaults (0755, 1000:1000).

Fix

  • New 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 new cloneDirNode in fs/clone.go. Its children stay in the lower layer. The merged ReadDir already combines both layers, and tombstones keep deleted children hidden.
  • Ancestors missing from the upper layer are copied up the same way, using lower metadata from visiblePrefixInfo, which also uses fs: resolve overlay symlinks across layers #856's lowerDirs cache.
  • Non-directories still go through clonePathWithInfo, as before.
  • Rename (clones from the merged overlay) and Link (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 mode 0750 is 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.

go test ./fs/... ./internal/runtime/...   # ok
make lint                                 # 0 issues

Not changed

OpenFile's write copy-up still creates missing upper ancestors with default metadata. The same copyUpNode would fix that, but that is left for a follow-up because it changes the write path.

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
@ewhauser
ewhauser enabled auto-merge (squash) October 19, 2026 04:18
@ewhauser
ewhauser merged commit 8282428 into main Oct 19, 2026
16 checks passed
@ewhauser
ewhauser deleted the fix/overlay-metadata-copyup branch October 19, 2026 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant