All of lore.kernel.org
 help / color / mirror / Atom feed
* sendfile and EAGAIN
@ 2013-02-25 17:22 Ulrich Drepper
  2013-02-25 19:22 ` Eric Dumazet
  2013-03-03  3:53 ` H. Peter Anvin
  0 siblings, 2 replies; 8+ messages in thread
From: Ulrich Drepper @ 2013-02-25 17:22 UTC (permalink / raw)
  To: Linux Kernel Mailing List, Al Viro

When using sendfile with a non-blocking output file descriptor for a
socket the operation can cause a partial write because of capacity
issues.  This is nothing critical and the operation could resume after
the output queue is cleared.  The problem is: there is no way to
determine where to resume.

The system call just returns -EAGAIN without any further indication.
The caller doesn't know what to resend.

And this even though the interface of sendfile would be capable of
communicating this information and the man page (I know, it's not
authoritive) describes this behavior as well.

The problem is probably in a few places, here is one (fs/splice.c):

static ssize_t default_file_splice_write(struct pipe_inode_info *pipe,
                                         struct file *out, loff_t *ppos,
                                         size_t len, unsigned int flags)
{
        ssize_t ret;

        ret = splice_from_pipe(pipe, out, ppos, len, flags, write_pipe_buf);
        if (ret > 0)
                *ppos += ret;

        return ret;
}

Note that *ppos is only updated if the call doesn't fail.  We could
also update the position if ret == -EAGAIN.  This would require
re-architecting the system a bit to either update *ppos in
splice_from_pipe etc or to communicate number of the bytes which are
written from the splice_from_pipe call.  In any case, the result would
be that the caller knows where to resume the operation.

I would argue that this doesn't break the ABI.  In case existing
programs today just resend packages today from the beginning they will
have send an unpredictable number of bytes in the previous sendfile()
call, making the state of the communication unpredictable.

Opinions?  I think as is sendfile() isn't useful with O_NONBLOCK.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-03-05  0:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-25 17:22 sendfile and EAGAIN Ulrich Drepper
2013-02-25 19:22 ` Eric Dumazet
2013-03-03  1:41   ` Ulrich Drepper
2013-03-03  3:09     ` Eric Dumazet
2013-03-03  3:16       ` Ulrich Drepper
2013-03-04 10:28     ` Eric Wong
2013-03-05  0:11       ` Ulrich Drepper
2013-03-03  3:53 ` H. Peter Anvin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.