TL;DR: If the Linux kernel loses a buffered I/O write, is there any way for the application to find out?
I know you have to fsync()
Since the application's write() will have already returned without error, there seems to be no way to report an error back to the application.
I do not agree. write
can return without error if the write is simply queued, but the error will be reported on the next operation that will require the actual writing on disk, that means on next fsync
, possibly on a following write if the system decides to flush the cache and at least on last file close.
That is the reason why it is essential for application to test the return value of close to detect possible write errors.
If you really need to be able to do clever error processing you must assume that everything that was written since the last successful fsync
may have failed and that in all that at least something has failed.