3 ms·
> > I was also (incorrectly) assuming that renaming a file after having fsynced the contents is a valid mechanism > Where does anyone say that this doesn't wo
by tsimionescu 6y ago
> > I was also (incorrectly) assuming that renaming a file after having fsynced the contents is a valid mechanism
> Where does anyone say that this doesn't work?
The article explains it here:
> This trick doesn't work. People seem to think that this is safe becaus the POSIX spec says that rename is atomic, but that only means rename is atomic with respect to normal operation, that doesn't mean it's atomic on crash. This isn't just a theoretical problem; if we look at mainstream Linux filesystems, most have at least one mode where rename isn't atomic on crash. Rename also isn't guaranteed to execute in program order, as people sometimes expect.
According to the article, open+write+fsync+close+dir-fsync is indeed safe on ext4 on any new-ish Linux kernel (on older kernels, fsync() wouldn't report errors in some cases, e.g. if it happened after the FS attempted and failed to write the data before the fsync).
Not sure what it has to do with rename though.