[PATCH -next] fs: pipe -- Take into account requested @len in iter_file_splice_write

From: Cyrill Gorcunov
Date: Fri May 30 2014 - 16:33:40 EST


Currently iter_file_splice_write pushes into the output IOVs as much
as it can, so that if one previously pushed into pipe 8K of data and
then try to fetch 4K -- he get the complete 8K instead.

Lest count how many bytes were requested by a caller and
stop looping once request is complete.

Signed-off-by: Cyrill Gorcunov <gorcunov@xxxxxxxxxx>
CC: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
CC: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
CC: "Kirill A. Shutemov" <kirill.shutemov@xxxxxxxxxxxxxxx>
CC: Pavel Emelyanov <xemul@xxxxxxxxxxxxx>
---

Al, take a look please, hope I didn't do something stupid.
Here was a testcase https://lkml.org/lkml/2014/5/27/167

fs/splice.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

Index: linux-2.6.git/fs/splice.c
===================================================================
--- linux-2.6.git.orig/fs/splice.c
+++ linux-2.6.git/fs/splice.c
@@ -979,14 +979,14 @@ iter_file_splice_write(struct pipe_inode
break;
}
}
-
+
/* build the vector */
- for (n = 0, idx = pipe->curbuf; n < pipe->nrbufs; n++, idx++) {
+ for (n = 0, idx = pipe->curbuf; count < sd.total_len && n < pipe->nrbufs; n++, idx++) {
struct pipe_buffer *buf = pipe->bufs + idx;
size_t this_len = buf->len;

- if (this_len > sd.total_len)
- this_len = sd.total_len;
+ if (this_len + count > sd.total_len)
+ this_len = sd.total_len - count;

if (idx == pipe->buffers - 1)
idx = -1;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/