3 ms·
Leaving aside that the normative part of the spec is still very clear that fsync() applies to all data for the open file descriptor, your line of reasoning fail
by tsimionescu 5y ago
Leaving aside that the normative part of the spec is still very clear that fsync() applies to all data for the open file descriptor, your line of reasoning fails for another reason. If we accept that fsync() as implemented in Linux is correct, what is its use? Is there any way to use fsync() "correctly" in the presence of IO errors?
As far as I understand, the answer is "definitely not" on Linux before 4.13, since failed async writes to the file could clear the dirty bit long before you called fsync(). There are some improvements since then, so arguably fsync() can now be used for something meaningful, though you have to take great care, and the only recourse on error is probably to start rewriting the file from scratch, even for transient errors (since the buffers may or may not be lost after the error, but future calls to fsync() will report success regardless).
Whether this behavior is a good idea or not is the only question that matters, since POSIX compliance hasn't mattered to Linux anyway for who knows how many years.