Skip to content

Commit 0f0fa27

Browse files
jstancekkuba-moo
authored andcommitted
splice, net: Fix splice_to_socket() for O_NONBLOCK socket
LTP sendfile07 [1], which expects sendfile() to return EAGAIN when transferring data from regular file to a "full" O_NONBLOCK socket, started failing after commit 2dc334f ("splice, net: Use sendmsg(MSG_SPLICE_PAGES) rather than ->sendpage()"). sendfile() no longer immediately returns, but now blocks. Removed sock_sendpage() handled this case by setting a MSG_DONTWAIT flag, fix new splice_to_socket() to do the same for O_NONBLOCK sockets. [1] https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/sendfile/sendfile07.c Fixes: 2dc334f ("splice, net: Use sendmsg(MSG_SPLICE_PAGES) rather than ->sendpage()") Acked-by: David Howells <[email protected]> Signed-off-by: Jan Stancek <[email protected]> Tested-by: Xi Ruoyao <[email protected]> Link: https://lore.kernel.org/r/023c0e21e595e00b93903a813bc0bfb9a5d7e368.1690219914.git.jstancek@redhat.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 15cec63 commit 0f0fa27

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/splice.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,8 @@ ssize_t splice_to_socket(struct pipe_inode_info *pipe, struct file *out,
876876
msg.msg_flags |= MSG_MORE;
877877
if (remain && pipe_occupancy(pipe->head, tail) > 0)
878878
msg.msg_flags |= MSG_MORE;
879+
if (out->f_flags & O_NONBLOCK)
880+
msg.msg_flags |= MSG_DONTWAIT;
879881

880882
iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, bvec, bc,
881883
len - remain);

0 commit comments

Comments
 (0)