Skip to content

storage: fsync staging directory before atomic rename#922

Draft
asahay19 wants to merge 1 commit into
podman-container-tools:mainfrom
asahay19:asahay-storage-fsync
Draft

storage: fsync staging directory before atomic rename#922
asahay19 wants to merge 1 commit into
podman-container-tools:mainfrom
asahay19:asahay-storage-fsync

Conversation

@asahay19

@asahay19 asahay19 commented Jun 17, 2026

Copy link
Copy Markdown

PR Summary

Add fsync of overlay staging directory contents before the atomic rename that
commits 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 written
into a staging directory and then committed with os.Rename(). If power is lost
after 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_repair path may run a broad storage
repair 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:

  1. File datafdatasync() on each file under the staging dir
  2. Directory metadatafsync() on each directory, bottom-up

This mirrors the durability pattern already used by atomicFileWriter in
storage/pkg/ioutils/fswriters_linux.go, extended to a whole staging tree.

Changes

File Change
storage/pkg/ioutils/sync_directory_linux.go New SyncDirectoryContents() helper (Linux)
storage/pkg/ioutils/sync_directory_linux_test.go Unit test
storage/drivers/overlay/overlay.go Call sync before rename in ApplyDiffFromStagingDirectory()

Testing

 asahay@asahay-ubuntu:~/container-libs/storage$ go test ./pkg/ioutils/ -run TestSyncDirectoryContents -v
=== RUN   TestSyncDirectoryContents
--- PASS: TestSyncDirectoryContents (0.00s)
PASS
ok  	go.podman.io/storage/pkg/ioutils	0

@github-actions github-actions Bot added the storage Related to "storage" package label Jun 17, 2026

@mtrmac mtrmac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

storage Related to "storage" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants