Skip to content

storage: new sync option for overlay/vfs#622

Open
giuseppe wants to merge 5 commits intocontainers:mainfrom
giuseppe:sync-policy
Open

storage: new sync option for overlay/vfs#622
giuseppe wants to merge 5 commits intocontainers:mainfrom
giuseppe:sync-policy

Conversation

@giuseppe
Copy link
Member

@giuseppe giuseppe commented Feb 2, 2026

Add a new driver-specific sync configuration option that controls filesystem synchronization during layer operations. When set to "filesystem", the driver ensures all pending writes are flushed to the file system before marking a layer as complete.

This helps prevent data corruption in scenarios where the system crashes or loses power before the filesystem has finished writing layer data.

@github-actions github-actions bot added the storage Related to "storage" package label Feb 2, 2026
@giuseppe
Copy link
Member Author

giuseppe commented Feb 2, 2026

@mrunalp PTAL

Copy link
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

just an initial skim.

Use ComposeFS to mount the data layers image. ComposeFS support is experimental and not recommended for production use.
This is a "string bool": "false"|"true" (cannot be native TOML boolean)

**sync_policy**=""
Copy link
Contributor

Choose a reason for hiding this comment

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

(“policy” is a unnecessary word here)

return err
}
defer windows.CloseHandle(h)
return windows.FlushFileBuffers(h)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this really sync the whole filesystem? A quick skim of the reference documentation suggests it’s just that one file.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, thanks. I don't find any equivalent of syncfs (or sync), so I am just going to return an error on Windows

doptions = append(doptions, fmt.Sprintf("%s.use_composefs=%s", driverName, options.Overlay.UseComposefs))
}
if options.Overlay.SyncPolicy != "" {
doptions = append(doptions, fmt.Sprintf("%s.sync_policy=%s", driverName, options.Overlay.SyncPolicy))
Copy link
Contributor

Choose a reason for hiding this comment

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

I seriously dislike this kind of turning of structured data back into strings.

I realize that’s not the fault of this PR, but can we stop doing that some time? There will never be a convenient time.

I suppose OptionsConfig, or something, could be stored in StoreOptions, and perhaps added to drivers.Options.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also it would be nice to parse the value into an enum already here.

return err
}

return d.syncPolicy.Sync(dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

UpdateLayerIDMap is a very surprising place for this, at a glance. Why is this the structure?

Copy link
Member Author

Choose a reason for hiding this comment

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

we chown the entire layer, we need to make sure these files are persisted. For overlay it is only metadata, but for vfs we copy the entire layer

@giuseppe giuseppe changed the title [RFC] new sync_policy option for overlay/vf [RFC] new sync option for overlay/vf Feb 2, 2026
@giuseppe giuseppe changed the title [RFC] new sync option for overlay/vf [RFC] new sync option for overlay/vfs Feb 2, 2026
@giuseppe giuseppe marked this pull request as ready for review February 3, 2026 11:58
@mrunalp
Copy link
Contributor

mrunalp commented Feb 3, 2026

👍 to adding this option.

@giuseppe giuseppe changed the title [RFC] new sync option for overlay/vfs storage: new sync option for overlay/vfs Feb 3, 2026
@mrunalp
Copy link
Contributor

mrunalp commented Feb 3, 2026

@nalind thoughts?

bitoku added a commit to bitoku/storage that referenced this pull request Feb 4, 2026
bitoku added a commit to bitoku/storage that referenced this pull request Feb 4, 2026
Signed-off-by: Ayato Tokubi <atokubi@redhat.com>
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

not really fully review just some drive by comments I might be missing the context of the origin of this.

Comment on lines 222 to 223
**sync**=""
Filesystem synchronization mode for layer creation. (default: "")
Copy link
Member

Choose a reason for hiding this comment

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

default: "" does not say what the default actually is, it should say none or filesystem.

I think it default to none? Is that the right default? I mean practically speaking should we not do the safe thing as default. I guess the concern would be performance? But the people needing that could opt. Without sync we need to worry about more store corruption which seems worse for us?

logrus.Debugf("Error Syncfs(%s) - %v", mountpoint, err)
}
unix.Close(fd)
if err := system.Syncfs(mountpoint); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

is this correct to not use the syncmode setting here and always sync?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, this was already done before, I've only reused the new function now.

If you kill a FUSE file system, all the data in memory will be lost, even if the system didn't crash. This is a fallback path taken when doing it correctly through fusermount failed.

The syncfs here prevents that when fusermount failed (or it is not present), we do not lose data on fuse-overlayfs when we unmount it.

@cgwalters
Copy link
Contributor

Of reference too containers/composefs-rs#185 (comment) Basically ostree keeps track of the boot id optionally - another option here is to have a periodic "walk layer dirs and fsync()" which is syscall expensive (without io-uring) but avoids flushing unrelated I/O.

This of course relates to "containers-storage on top of composefs(rs)" in that this option would today always be on by default...

save the layer info only after the tarsplit file was written.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
preparatory commit for the next patch.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Add a new driver-specific `sync` configuration option that controls
filesystem synchronization during layer operations.  When set to
"filesystem", the driver ensures all pending writes are flushed to the
file system before marking a layer as complete.

This helps prevent data corruption in scenarios where the system crashes
or loses power before the filesystem has finished writing layer data.

Only the vfs and overlay backends support the new flag.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
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.

5 participants