Page MenuHomeFreeBSD

Add O_DSYNC support to open(2) and fcntl(2).

Authored by tmunro on Jun 1 2020, 3:39 AM.
Referenced Files
Unknown Object (File)
Mon, Jun 17, 11:43 AM
Unknown Object (File)
Sat, Jun 8, 12:09 PM
Unknown Object (File)
Wed, May 29, 3:30 AM
Unknown Object (File)
Tue, May 28, 6:36 PM
Unknown Object (File)
Tue, May 21, 8:31 PM
Unknown Object (File)
Sun, May 19, 11:05 PM
Unknown Object (File)
May 19 2024, 4:22 PM
Unknown Object (File)
May 15 2024, 11:50 PM



This is mostly the same as O_SYNC, but can potentially skip writing out stuff that isn't required for reading the data back.

From the point of view of a file system, this is reported as the new flag IO_DATASYNC passed to VOP_WRITE(), along with the existing IO_SYNC flag. That means that filesystems that don't know about IO_DATASYNC yet can keep on doing what they're doing, but those that understand IO_DATASYNC can modify their behaviour.

Once D25072 goes in, it should be possible to teach ffs_write() to understand IO_DATASYNC, to avoid unnecesssary inode write-back.

Also, fix up some related outdated comments and man pages: a claim that f_flag is a short (not true for a very long time), some missing flags and a typo in fcntl.2, and some language that makes O_SYNC seem like second fiddle to O_FSYNC, when IMHO it should now be the other way around.

Also, adjust the ZFS macro that redefines FDSYNC not to do that anymore. Even though with this patch it becomes a value distinct from FFSYNC, that's OK because zfs_vnops.c, zfs_log.c, zvol.c, vdev_file.c always test for (FSYNC | FDSYNC) anwyay.

A separate patch will add O_DSYNC support for aio_fsync(2), see D25071.

Diff Detail

rG FreeBSD src repository
Lint Not Applicable
Tests Not Applicable

Event Timeline

tmunro requested review of this revision.Jun 1 2020, 3:39 AM

Two simple fixes for the man page.


A line break is needed after a sentence stop.


Another line break here after the sentence stop.

tmunro added reviewers: kib, mjg.
tmunro marked 2 inline comments as done.

Thanks! Fixed.


... all data and metadata required to read the data back will be ...


... instead set IO_SYNC | IO_DATASYNC there.


I suggest to not change this condition...

tmunro marked 3 inline comments as done.
kib added inline comments.

BTW I see no reason to not merge this to 12.

This revision is now accepted and ready to land.Jun 2 2020, 11:35 AM

Rebased (mostly: ZFS moved).

This revision now requires review to proceed.Jan 6 2021, 11:42 AM
This revision is now accepted and ready to land.Jan 6 2021, 5:18 PM
This revision was automatically updated to reflect the committed changes.