net: splice() from tcp to pipe should take into account O_NONBLOCK

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Friday, October 2, 2009 - 3:59 pm

Gitweb:     http://git.kernel.org/linus/42324c62704365d6a3e89138dea55909d2f26afe
Commit:     42324c62704365d6a3e89138dea55909d2f26afe
Parent:     914a9ab386a288d0f22252fc268ecbc048cdcbd5
Author:     Eric Dumazet <eric.dumazet@gmail.com>
AuthorDate: Thu Oct 1 15:26:00 2009 -0700
Committer:  David S. Miller <davem@davemloft.net>
CommitDate: Fri Oct 2 09:46:05 2009 -0700

    net: splice() from tcp to pipe should take into account O_NONBLOCK
    
    tcp_splice_read() doesnt take into account socket's O_NONBLOCK flag
    
    Before this patch :
    
    splice(socket,0,pipe,0,128*1024,SPLICE_F_MOVE);
    causes a random endless block (if pipe is full) and
    splice(socket,0,pipe,0,128*1024,SPLICE_F_MOVE | SPLICE_F_NONBLOCK);
    will return 0 immediately if the TCP buffer is empty.
    
    User application has no way to instruct splice() that socket should be in blocking mode
    but pipe in nonblock more.
    
    Many projects cannot use splice(tcp -> pipe) because of this flaw.
    
    http://git.samba.org/?p=samba.git;a=history;f=source3/lib/recvfile.c;h=ea0159642137390...
    http://lkml.indiana.edu/hypermail/linux/kernel/0807.2/0687.html
    
    Linus introduced  SPLICE_F_NONBLOCK in commit 29e350944fdc2dfca102500790d8ad6d6ff4f69d
    (splice: add SPLICE_F_NONBLOCK flag )
    
      It doesn't make the splice itself necessarily nonblocking (because the
      actual file descriptors that are spliced from/to may block unless they
      have the O_NONBLOCK flag set), but it makes the splice pipe operations
      nonblocking.
    
    Linus intention was clear : let SPLICE_F_NONBLOCK control the splice pipe mode only
    
    This patch instruct tcp_splice_read() to use the underlying file O_NONBLOCK
    flag, as other socket operations do.
    
    Users will then call :
    
    splice(socket,0,pipe,0,128*1024,SPLICE_F_MOVE | SPLICE_F_NONBLOCK );
    
    to block on data coming from socket (if file is in blocking mode),
    and not block on pipe output (to avoid deadlock)
    
    First version of this patch was submitted by Octavian Purdila
    
    Reported-by: Volker Lendecke <vl@samba.org>
    Reported-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
    Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
    Signed-off-by: Octavian Purdila <opurdila@ixiacom.com>
    Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
    Acked-by: Jens Axboe <jens.axboe@oracle.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>
---
 net/ipv4/tcp.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 7bb8479..64d0af6 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -580,7 +580,7 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
 
 	lock_sock(sk);
 
-	timeo = sock_rcvtimeo(sk, flags & SPLICE_F_NONBLOCK);
+	timeo = sock_rcvtimeo(sk, sock->file->f_flags & O_NONBLOCK);
 	while (tss.len) {
 		ret = __tcp_splice_read(sk, &tss);
 		if (ret < 0)
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
net: splice() from tcp to pipe should take into account O_ ..., Linux Kernel Mailing ..., (Fri Oct 2, 3:59 pm)