Directory fsync
Directory fsync is a synchronization request on a directory descriptor, used to persist namespace changes under the filesystem's directory-synchronization contract.
On Linux, syncing a file does not necessarily persist its directory entry. With working file and directory synchronization, a replacement within one already durable directory writes and syncs the temporary file, renames it, then syncs the containing directory. [1] [4]
A 2014 study of 11 widely used applications found 60 static crash vulnerabilities, corresponding to 156 dynamic ones and failures in more than 4,000 crash states. Durability loss affected 7 applications, and 6 of them needed fsync calls on directories: three relied on a flushed file's directory entry being persisted implicitly, and four needed other directory fsyncs. In one key-value store, compaction output files whose directory entries were never persisted could vanish after a crash and leave the store unavailable. [3]
The 2014 study found that implicit persistence of a flushed file's directory entry varied with the tested filesystem configuration; its findings do not establish a guarantee for other implementations. Directory fsync covers the names in one directory and is not a transaction across several files or directories. [3] [1]
A successful return still needs an implementation-specific interpretation. In Linux v6.12, FUSE_FSYNCDIR returning ENOSYS sets the connection's no_fsyncdir flag and becomes success; later directory syncs skip that daemon request after the bad-inode check. In libfuse 3.16.2's low-level dispatcher, an absent fsyncdir callback produces ENOSYS. This does not establish whether earlier namespace changes were persisted by another mechanism. Verify the daemon's backing-store contract before acknowledging durable publication. [5] [6]
Relations
- related
- fsync, Persistence ordering, Crash consistency, Atomic rename, Hard link, Unlink, fflush, FUSE, O_PATH, fdatasync
Advantages
- Explicit directory synchronization makes name persistence a separate checked step instead of relying on implicit persistence of directory entries, provided the implementation supports the required contract. [1, 5]
Limitations
- Safe-rename heuristics, which persist a file's data before a later rename on file systems with delayed allocation, matched only 3 of the 60 vulnerabilities found in the study. [3]
- Even with a file system that promises full ordering between system calls, 4 of the 12 durability vulnerabilities in the study remained exposed. [3]
- Directory synchronization does not by itself guarantee recursive synchronization of child-file contents or an atomic transaction across multiple directories. [1]
- After rename succeeds, a failed directory sync leaves durability unresolved; it does not establish that the visible namespace change was rolled back. [2]
Citations
- Linux man-pages 6.19, fsync(2): DESCRIPTION and error handling.
- Hesela: Atomic rename is not a durable commit
- Pillai et al. All File Systems Are Not Created Equal: On the Complexity of Crafting Crash-Consistent Applications. OSDI 2014.
- Moyer. Ensuring data reaches disk. LWN.net, 7 September 2011.
- Linux v6.12: fuse_dir_fsync and no_fsyncdir handling
- libfuse 3.16.2: do_fsyncdir and an absent low-level callback
Sources & caveats
- fsync-api is the Linux man-pages 6.19 fsync(2) page, re-read in the DESCRIPTION and ERRORS sections.
- alice is the OSDI 2014 paper by University of Wisconsin-Madison authors, read in the abstract and sections 4.2 to 4.4.
- lwn-moyer is a September 2011 LWN.net article by Jeff Moyer of Red Hat, read in full.
- The study counts vulnerabilities per application and update protocol, so its figures describe the tested versions rather than current releases.
- The FUSE qualification is a version-pinned source review of Linux v6.12 fuse_dir_fsync and libfuse 3.16.2 do_fsyncdir, not a mounted-filesystem or crash experiment.