storage: fsync staging directory before atomic rename#922
Draft
asahay19 wants to merge 1 commit into
Draft
Conversation
mtrmac
reviewed
Jun 17, 2026
mtrmac
left a comment
Contributor
There was a problem hiding this comment.
https://github.com/podman-container-tools/container-libs/blob/main/CONTRIBUTING.md#sign-your-prs please, we can’t really even look at contributions with unclear copyright status.
We now have sync=filesystem via #622 , isn’t that sufficient? What is missing?
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.
PR Summary
Add
fsyncof overlay staging directory contents before the atomic rename thatcommits a new layer during image pull/unpack.
STRAT: https://redhat.atlassian.net/browse/OCPSTRAT-3097
Replaces auto-closed containers/storage#2397
after the storage library moved into this monorepo.
Problem
When CRI-O (via
go.podman.io/storage) pulls an image, layer data is writteninto a staging directory and then committed with
os.Rename(). If power is lostafter files are written but before metadata is durable on disk, the layer can be
left in a partially written state.
On unclean shutdown, CRI-O's
internal_repairpath may run a broad storagerepair that can wipe local image data — a serious problem on disconnected or
air-gapped edge/SNO nodes where re-pulling images is expensive or impossible.
Solution
Before atomically renaming the fully populated staging directory to its final
layer path, flush:
fdatasync()on each file under the staging dirfsync()on each directory, bottom-upThis mirrors the durability pattern already used by
atomicFileWriterinstorage/pkg/ioutils/fswriters_linux.go, extended to a whole staging tree.Changes
storage/pkg/ioutils/sync_directory_linux.goSyncDirectoryContents()helper (Linux)storage/pkg/ioutils/sync_directory_linux_test.gostorage/drivers/overlay/overlay.goApplyDiffFromStagingDirectory()Testing