Skip to content

Commit

Permalink
splice: only return -EAGAIN if there's hope of more data
Browse files Browse the repository at this point in the history
sys_tee() currently is a bit eager in returning -EAGAIN, it may do so
even if we don't have a chance of anymore data becoming available. So
improve the logic and only return -EAGAIN if we have an attached writer
to the input pipe.

Reported by Johann Felix Soden <johfel@gmx.de> and
Patrick McManus <mcmanus@ducksong.com>.

Tested-by: Johann Felix Soden <johfel@users.sourceforge.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
  • Loading branch information
Jens Axboe authored and Jens Axboe committed Mar 4, 2008
1 parent 5d87a05 commit 02cf01a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions fs/splice.c
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,13 @@ static int link_pipe(struct pipe_inode_info *ipipe,
i++;
} while (len);

/*
* return EAGAIN if we have the potential of some data in the
* future, otherwise just return 0
*/
if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
ret = -EAGAIN;

inode_double_unlock(ipipe->inode, opipe->inode);

/*
Expand Down Expand Up @@ -1709,11 +1716,8 @@ static long do_tee(struct file *in, struct file *out, size_t len,
ret = link_ipipe_prep(ipipe, flags);
if (!ret) {
ret = link_opipe_prep(opipe, flags);
if (!ret) {
if (!ret)
ret = link_pipe(ipipe, opipe, len, flags);
if (!ret && (flags & SPLICE_F_NONBLOCK))
ret = -EAGAIN;
}
}
}

Expand Down

0 comments on commit 02cf01a

Please sign in to comment.