diff mbox series

[13/44] splice: stop abusing iov_iter_advance() to flush a pipe

Message ID 20220622041552.737754-13-viro@zeniv.linux.org.uk (mailing list archive)
State New, archived
Headers show
Series [01/44] 9p: handling Rerror without copy_from_iter_full() | expand

Commit Message

Al Viro June 22, 2022, 4:15 a.m. UTC
Use pipe_discard_from() explicitly in generic_file_read_iter(); don't bother
with rather non-obvious use of iov_iter_advance() in there.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/splice.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Jeff Layton June 27, 2022, 7:17 p.m. UTC | #1
On Wed, 2022-06-22 at 05:15 +0100, Al Viro wrote:
> Use pipe_discard_from() explicitly in generic_file_read_iter(); don't bother
> with rather non-obvious use of iov_iter_advance() in there.
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---
>  fs/splice.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/splice.c b/fs/splice.c
> index 047b79db8eb5..6645b30ec990 100644
> --- a/fs/splice.c
> +++ b/fs/splice.c
> @@ -301,11 +301,9 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,
>  {
>  	struct iov_iter to;
>  	struct kiocb kiocb;
> -	unsigned int i_head;
>  	int ret;
>  
>  	iov_iter_pipe(&to, READ, pipe, len);
> -	i_head = to.head;
>  	init_sync_kiocb(&kiocb, in);
>  	kiocb.ki_pos = *ppos;
>  	ret = call_read_iter(in, &kiocb, &to);
> @@ -313,9 +311,8 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,
>  		*ppos = kiocb.ki_pos;
>  		file_accessed(in);
>  	} else if (ret < 0) {
> -		to.head = i_head;
> -		to.iov_offset = 0;
> -		iov_iter_advance(&to, 0); /* to free what was emitted */
> +		/* free what was emitted */
> +		pipe_discard_from(pipe, to.start_head);
>  		/*
>  		 * callers of ->splice_read() expect -EAGAIN on
>  		 * "can't put anything in there", rather than -EFAULT.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Christian Brauner June 28, 2022, 12:43 p.m. UTC | #2
On Wed, Jun 22, 2022 at 05:15:21AM +0100, Al Viro wrote:
> Use pipe_discard_from() explicitly in generic_file_read_iter(); don't bother
> with rather non-obvious use of iov_iter_advance() in there.
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---

Looks good to me,
Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org>
diff mbox series

Patch

diff --git a/fs/splice.c b/fs/splice.c
index 047b79db8eb5..6645b30ec990 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -301,11 +301,9 @@  ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,
 {
 	struct iov_iter to;
 	struct kiocb kiocb;
-	unsigned int i_head;
 	int ret;
 
 	iov_iter_pipe(&to, READ, pipe, len);
-	i_head = to.head;
 	init_sync_kiocb(&kiocb, in);
 	kiocb.ki_pos = *ppos;
 	ret = call_read_iter(in, &kiocb, &to);
@@ -313,9 +311,8 @@  ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,
 		*ppos = kiocb.ki_pos;
 		file_accessed(in);
 	} else if (ret < 0) {
-		to.head = i_head;
-		to.iov_offset = 0;
-		iov_iter_advance(&to, 0); /* to free what was emitted */
+		/* free what was emitted */
+		pipe_discard_from(pipe, to.start_head);
 		/*
 		 * callers of ->splice_read() expect -EAGAIN on
 		 * "can't put anything in there", rather than -EFAULT.