diff mbox series

[v2,1/7] splice: don't generate zero-len segement bvecs

Message ID ca14f80bf5156d83b38f543be2b9434a571474c9.1609461359.git.asml.silence@gmail.com
State New
Headers show
Series no-copy bvec | expand

Commit Message

Pavel Begunkov Jan. 2, 2021, 3:17 p.m. UTC
iter_file_splice_write() may spawn bvec segments with zero-length. In
preparation for prohibiting them, filter out by hand at splice level.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 fs/splice.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Christoph Hellwig Jan. 4, 2021, 4:17 p.m. UTC | #1
On Sat, Jan 02, 2021 at 03:17:33PM +0000, Pavel Begunkov wrote:
> iter_file_splice_write() may spawn bvec segments with zero-length. In

> preparation for prohibiting them, filter out by hand at splice level.

> 

> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>

> ---

>  fs/splice.c | 9 +++++----

>  1 file changed, 5 insertions(+), 4 deletions(-)

> 

> diff --git a/fs/splice.c b/fs/splice.c

> index 866d5c2367b2..7299330c3270 100644

> --- a/fs/splice.c

> +++ b/fs/splice.c

> @@ -644,7 +644,6 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,

>  		ret = splice_from_pipe_next(pipe, &sd);

>  		if (ret <= 0)

>  			break;

> -


Spurious empty line removal..

> +			if (!this_len)

> +				continue;


Maybe throw in a comment on why we skip empty segments here?

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Pavel Begunkov Jan. 4, 2021, 4:54 p.m. UTC | #2
On 04/01/2021 16:17, Christoph Hellwig wrote:
> On Sat, Jan 02, 2021 at 03:17:33PM +0000, Pavel Begunkov wrote:

>> iter_file_splice_write() may spawn bvec segments with zero-length. In

>> preparation for prohibiting them, filter out by hand at splice level.

>>

>> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>

>> ---

>>  fs/splice.c | 9 +++++----

>>  1 file changed, 5 insertions(+), 4 deletions(-)

>>

>> diff --git a/fs/splice.c b/fs/splice.c

>> index 866d5c2367b2..7299330c3270 100644

>> --- a/fs/splice.c

>> +++ b/fs/splice.c

>> @@ -644,7 +644,6 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,

>>  		ret = splice_from_pipe_next(pipe, &sd);

>>  		if (ret <= 0)

>>  			break;

>> -

> 

> Spurious empty line removal..

> 

>> +			if (!this_len)

>> +				continue;

> 

> Maybe throw in a comment on why we skip empty segments here?


Definitely won't hurt. Thanks for taking a look

> 

> Otherwise looks good:

> 

> Reviewed-by: Christoph Hellwig <hch@lst.de>

> 


-- 
Pavel Begunkov
diff mbox series

Patch

diff --git a/fs/splice.c b/fs/splice.c
index 866d5c2367b2..7299330c3270 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -644,7 +644,6 @@  iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
 		ret = splice_from_pipe_next(pipe, &sd);
 		if (ret <= 0)
 			break;
-
 		if (unlikely(nbufs < pipe->max_usage)) {
 			kfree(array);
 			nbufs = pipe->max_usage;
@@ -662,12 +661,13 @@  iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
 
 		/* build the vector */
 		left = sd.total_len;
-		for (n = 0; !pipe_empty(head, tail) && left && n < nbufs; tail++, n++) {
+		for (n = 0; !pipe_empty(head, tail) && left && n < nbufs; tail++) {
 			struct pipe_buffer *buf = &pipe->bufs[tail & mask];
 			size_t this_len = buf->len;
 
-			if (this_len > left)
-				this_len = left;
+			if (!this_len)
+				continue;
+			this_len = min(this_len, left);
 
 			ret = pipe_buf_confirm(pipe, buf);
 			if (unlikely(ret)) {
@@ -680,6 +680,7 @@  iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
 			array[n].bv_len = this_len;
 			array[n].bv_offset = buf->offset;
 			left -= this_len;
+			n++;
 		}
 
 		iov_iter_bvec(&from, WRITE, array, n, sd.total_len - left);