Repository navigation
Conversation
mike-sul
reviewed
Jul 29, 2026
cgwalters
force-pushed
the
mkcomposefs-hardlinks
branch
from
July 30, 2026 12:57
a19bfd4 to
49dfcd3
Compare
lcfs_build() is a recursive directory walker, but the only state it threads through recursive calls today is the plain buildflags int. To support detecting hardlinks across an entire directory tree (a link's two names can live in arbitrary subdirectories), we need a lookup table that persists across the whole walk rather than just a single readdir() loop. Split the existing body into a static lcfs_build_internal() that takes a struct lcfs_build_ctx * instead of a bare buildflags int, and turn the public lcfs_build() into a thin wrapper that sets up the context and delegates to it. For now the context only holds buildflags, so this is a pure refactor with no behavior change; a follow-up commit adds the hardlink tracking state. Assisted-by: AI Signed-off-by: Colin Walters <[email protected]>
lcfs_build() walks a directory tree via readdir()/fstatat() and never looks at st_ino/st_dev, so two paths that are hardlinked to the same inode on disk silently become two independent inodes with nlink=1 in the composefs image. This causes fs-verity digest mismatches against hardlink-aware tools and a mounted image that misreports nlink/size (composefs#444). Add an opt-in LCFS_BUILD_TRACK_HARDLINKS flag that keeps a (dev,ino) -> node hash table alive for the whole recursive walk (a link's two names can be anywhere under the root, not just siblings) and, on a repeat inode, wires up a hardlink via the existing lcfs_node_make_hardlink() instead of re-reading the file content. This is opt-in and not the default, matching composefs-rs's own mkcomposefs-compatible implementation, which requires the same --hardlinks flag to enable deduplication. Directories from scanning a real filesystem today rely on every path becoming an independent inode, and changing that by default would change digests for existing consumers (RHEL9, ostree, etc.) that build composefs images from directories. Tracking is also unconditional on st_nlink, i.e. it doesn't skip looking up a file just because its st_nlink report is 1: some filesystems (e.g. fuse-overlayfs, see containers/fuse-overlayfs#435) can misreport that field. Every non-directory type is tracked (regular files, symlinks, FIFOs, device nodes, sockets), since all of them are hardlinkable on disk (e.g. via `ln -P`) and composefs-rs's own scanner doesn't special-case regular files either. The one deliberate exception is a chardev with rdev=0: composefs represents an overlayfs whiteout this way, and the EROFS writer already rejects such an inode outright if it ends up with nlink>1 (a whiteout marks the absence of a file, so hardlinking two of them together is semantically invalid) -- but only when *loading* an image, not when writing one. Leave those untracked so a directory scan can't silently produce an image composefs itself would refuse to read back. Assisted-by: AI Signed-off-by: Colin Walters <[email protected]>
Wire up LCFS_BUILD_TRACK_HARDLINKS behind a new --hardlinks CLI option. The name matches composefs-rs's own drop-in mkcomposefs reimplementation, which likewise defaults to not tracking hardlinks (bit-for-bit compatible with this tool) and requires --hardlinks to opt into deduplication. The flag only affects the directory-scan path; combined with --from-file it is a harmless no-op since dumpfiles already encode hardlinks explicitly via the '@' prefix. Assisted-by: AI Closes: composefs#444 Signed-off-by: Colin Walters <[email protected]>
cgwalters
force-pushed
the
mkcomposefs-hardlinks
branch
from
July 30, 2026 14:23
49dfcd3 to
a819a1b
Compare
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.
Closes: #444