diff mbox series

[v21,07/30] splice: Make splice from an O_DIRECT fd use copy_splice_read()

Message ID 20230520000049.2226926-8-dhowells@redhat.com (mailing list archive)
State New
Headers show
Series splice: Kill ITER_PIPE | expand

Commit Message

David Howells May 20, 2023, midnight UTC
Make a read splice from a file descriptor that's open O_DIRECT use
copy_splice_read() to do the reading as filemap_splice_read() is unlikely
to find any pagecache to splice.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Christoph Hellwig <hch@lst.de>
cc: Al Viro <viro@zeniv.linux.org.uk>
cc: Jens Axboe <axboe@kernel.dk>
cc: linux-fsdevel@vger.kernel.org
cc: linux-block@vger.kernel.org
cc: linux-mm@kvack.org
---

Notes:
    ver #21)
     - Needs to be in vfs_splice_read(), not generic_file_splice_read().

 fs/splice.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Christoph Hellwig May 20, 2023, 4:11 a.m. UTC | #1
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Christian Brauner May 20, 2023, 9:39 a.m. UTC | #2
On Sat, May 20, 2023 at 01:00:26AM +0100, David Howells wrote:
> Make a read splice from a file descriptor that's open O_DIRECT use
> copy_splice_read() to do the reading as filemap_splice_read() is unlikely
> to find any pagecache to splice.
> 
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: Christoph Hellwig <hch@lst.de>
> cc: Al Viro <viro@zeniv.linux.org.uk>
> cc: Jens Axboe <axboe@kernel.dk>
> cc: linux-fsdevel@vger.kernel.org
> cc: linux-block@vger.kernel.org
> cc: linux-mm@kvack.org
> ---

Reviewed-by: Christian Brauner <brauner@kernel.org>
diff mbox series

Patch

diff --git a/fs/splice.c b/fs/splice.c
index fe3309ffeb26..76126b1aafcb 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -907,6 +907,12 @@  long vfs_splice_read(struct file *in, loff_t *ppos,
 
 	if (unlikely(!in->f_op->splice_read))
 		return warn_unsupported(in, "read");
+	/*
+	 * O_DIRECT doesn't deal with the pagecache, so we allocate a buffer,
+	 * copy into it and splice that into the pipe.
+	 */
+	if ((in->f_flags & O_DIRECT))
+		return copy_splice_read(in, ppos, pipe, len, flags);
 	return in->f_op->splice_read(in, ppos, pipe, len, flags);
 }
 EXPORT_SYMBOL_GPL(vfs_splice_read);