Page MenuHomeFreeBSD

First stage of implementing fdatasync(2).

Authored by kib on Aug 11 2016, 8:37 AM.
Referenced Files
Unknown Object (File)
Oct 29 2016, 5:59 PM
Unknown Object (File)
Oct 14 2016, 10:40 AM
Unknown Object (File)
Aug 17 2016, 8:26 PM
Unknown Object (File)
Aug 16 2016, 11:31 PM
Unknown Object (File)
Aug 15 2016, 10:14 AM



The patch implements fdatasync(2) syscall, which purpose is to request flushing of user data for given file to disk. Difference with fsync(2) is that metadata flush is not required.

The implementation provides non-trivial and believed to be correct VOPs for UFS and msdosfs. For all other filesystems, VOP_FDATASYNC() redirects to VOP_FSYNC(), which should be functionally, but not performance-wise, correct. I believe that ZFS has some code which just needs to be called from VOP to get the implementation as well, but I do not know how.

Still, this is not a complete implementation of the POSIX requirements, because SUSv7 contains the following language:

The fdatasync( ) function shall force all currently queued I/O operations associated with the file
indicated by file descriptor fildes to the synchronized I/O completion state.

I believe that the statement requires OS to complete all queued AIO requests before fdatasync(2) returns. This is not done, the code for the syscall contains placeholder. Still, I think it is useful first step, and right now I am concerned with the correctness of UFS implementation rather then AIO bits.

Test Plan

This was tested by Peter Holm, including specific tests for fdatasync(2).

Diff Detail

rS FreeBSD src repository - subversion
Lint Not Applicable
Tests Not Applicable

Event Timeline

kib retitled this revision from to First stage of implementing fdatasync(2)..
kib updated this object.
kib edited the test plan for this revision. (Show Details)
kib added reviewers: jhb, mckusick, trasz, emaste, avg.
kib set the repository for this revision to rS FreeBSD src repository - subversion.
kib added a subscriber: pho.

Regarding ZFS, as far as I know, it does not make any distinction between metadata and data operations when it creates ZIL records. And sync commits all ZIL records related to a file to disk. That's how fsync is implemented. So, I do not see any easy way to implement fdatasync that would do a subset of what fsync does.

kib edited edge metadata.

Update after private Kirk' notes:

  • invert the flag to kern_fsync().
  • change order of the then/else statements in still_dirty calculation in ffs_syncvnode().
  • consider fdatasync() done if only indirect metadata blocks are left on dirty buffer queue.
mckusick edited edge metadata.

I am in agreement with the latest proposed change and am ready to have it committed.

This revision is now accepted and ready to land.Aug 15 2016, 4:22 AM
This revision was automatically updated to reflect the committed changes.