Created attachment 147521 [details] sendfile append bug test case attached test case dd if=/dev/zero of=/tmp/input bs=1M count=1 gcc sendfile_append_bug.c -o sendfile_append_bug ./sendfile_append_bug sendfile failed: Invalid argument Removing O_APPEND on the output file descriptor will prevent sendfile from squaking and you will receive this output: sendfile copied 1 bytes sendfile is critical to the IO workloads I work with - real time/mission critical stuff that needs a fair amount of fault tolerance from say a machine being force rebooted. I use O_APPEND to ensure the file cursor is always pointing at the end of file and believe some filesystems make use of this flag internally in addition to it doing the right thing more often than me issuing equivalent lseeks. I mainly use XFS for these workloads and shared memory files which then act as input fds to sendfile.
O_APPEND is not supported for sendfile(). It's documented in the splice() manual page but not for sendfile so I've moved this to a documentation bug
(In reply to Alan from comment #1) > O_APPEND is not supported for sendfile(). > > It's documented in the splice() manual page but not for sendfile so I've > moved this to a documentation bug OK so this quirk was not out in the open in documentation - before I opened this bug report I read a few years old discussion: http://fixunix.com/kernel/543017-splice-vs-o_append.html Most of what they're talking about is splice, not sendfile. They might use the same implementation but sendfile should be O_APPEND safe as there is no specifiable offset in the output filedescriptor. Is there a reason to not support it?
sendfile is just a wrapper around splice() Whether it could therefore support O_APPEND is a good question - but one that would need asking and discussing on the lists not here, and someone to contribute the patches to do so. In the meantime we ought to get the man page fixed.
I added the following text in ERRORS for sendfile(2). EINVAL out_fd was has the O_APPEND flag set. This is not cur‐ rently supported by sendfile() So, am closing this bug now.