diff mbox series

[3/4] splice: Use init_sync_kiocb() in filemap_splice_read()

Message ID 20230213134619.2198965-4-dhowells@redhat.com (mailing list archive)
State New
Headers show
Series iov_iter: Adjust styling/location of new splice functions | expand

Commit Message

David Howells Feb. 13, 2023, 1:46 p.m. UTC
Use init_sync_kiocb() in filemap_splice_read() rather than open coding it
and filter out IOCB_NOWAIT since the splice is synchronous.

Requested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Christoph Hellwig <hch@lst.de>
cc: Jens Axboe <axboe@kernel.dk>
cc: Al Viro <viro@zeniv.linux.org.uk>
cc: John Hubbard <jhubbard@nvidia.com>
cc: David Hildenbrand <david@redhat.com>
cc: Matthew Wilcox <willy@infradead.org>
cc: linux-block@vger.kernel.org
cc: linux-fsdevel@vger.kernel.org
cc: linux-mm@kvack.org
---
 fs/splice.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Christoph Hellwig Feb. 13, 2023, 2:46 p.m. UTC | #1
On Mon, Feb 13, 2023 at 01:46:18PM +0000, David Howells wrote:
> +	init_sync_kiocb(&iocb, in);
> +	iocb.ki_pos = *ppos;
> +	iocb.ki_flags &= IOCB_NOWAIT;

This clears everything but IOCB_NOWAIT.  But even IOCB_NOWAIT should
not be cleared here as far as I can tell.
Matthew Wilcox Feb. 13, 2023, 3:24 p.m. UTC | #2
On Mon, Feb 13, 2023 at 01:46:18PM +0000, David Howells wrote:
> Use init_sync_kiocb() in filemap_splice_read() rather than open coding it
> and filter out IOCB_NOWAIT since the splice is synchronous.

If the user has asked for NOWAIT and the splice is going to be
synchronous, shouldn't we rather return -EWOULDBLOCK here?  Or
does this not block?

IOW, this either does the wrong thing, or it does something that's
irrelevant.
diff mbox series

Patch

diff --git a/fs/splice.c b/fs/splice.c
index 7c0ff187f87a..8b2a9d963bc4 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -419,15 +419,15 @@  static ssize_t filemap_splice_read(struct file *in, loff_t *ppos,
 				   size_t len, unsigned int flags)
 {
 	struct folio_batch fbatch;
+	struct kiocb iocb;
 	size_t total_spliced = 0, used, npages;
 	loff_t isize, end_offset;
 	bool writably_mapped;
 	int i, error = 0;
 
-	struct kiocb iocb = {
-		.ki_filp	= in,
-		.ki_pos		= *ppos,
-	};
+	init_sync_kiocb(&iocb, in);
+	iocb.ki_pos = *ppos;
+	iocb.ki_flags &= IOCB_NOWAIT;
 
 	/* Work out how much data we can actually add into the pipe */
 	used = pipe_occupancy(pipe->head, pipe->tail);