Fix splice for packetized pipes
cover Fix splice for packetized pipes
With introduction of packetized pipes, splice wasn't updated to respect this new behaviour.
In terms of splice it means, that it never set PIPE_BUF_FLAG_PACKET on created pipe buffer regarless pipe operating mode, thus breaking the whole logic.
To fix this, new SPLICE_F_PACKET flag was introduced. It's supposed to be used only in kernel and set, when write pipe is in packetized mode. In splice_to_pipe() it's converted into created pipe buffer PIPE_BUF_FLAG_PACKET flag.
The following series implements...
---
Stanislav Kinsburskiy (3):
pipe: make is_packetized() non-static and declare in pipe_fs_i.h
splice: new SPLICE_F_PACKET flag introduced
splice: add support of splicing to packetized pipe
fs/pipe.c | 2 +- fs/splice.c | 8 ++++++++ include/linux/pipe_fs_i.h | 2 ++ include/linux/splice.h | 5 +++++ 4 files changed, 16 insertions(+), 1 deletion(-)
RFC PATCH 1/3 pipe: make is_packetized() non-static and declare in pipe_fs_i.h
With introduction of packetized pipe mode, represented by O_DIRECT flag, splice stopped working correctly with a pipe in this mode. To be able to fix them, this helper have to exposed.
--- fs/pipe.c | 2 +- include/linux/pipe_fs_i.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
fs/pipe.c +1 -1
@@ -329,7 +329,7 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)return ret; } -static inline int is_packetized (struct file *file) +int is_packetized (struct file *file) {return (file->f_flags &O_DIRECT ) !=0 ; }
include/linux/pipe_fs_i.h +2 -0
@@ -146,4 +146,6 @@ struct pipe_inode_info *get_pipe_info(struct file *file);int create_pipe_files (struct file **,int ); +int is_packetized (struct file *file); +#endif
RFC PATCH 2/3 splice: new SPLICE_F_PACKET flag introduced
In reply to Stanislav KinsburskiyThis flag is used by kernel only to represent pipe packetized mode for splice engine.
--- include/linux/splice.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/splice.h +5 -0
@@ -20,6 +20,11 @@#define SPLICE_F_MORE (0x04)/* expect more data */ #define SPLICE_F_GIFT (0x08)/* pages passed in are a gift */ +#ifdef __KERNEL__ + +#define SPLICE_F_PACKET (0x1000)/* pipe buffers have to be packetized */ + +#endif /* * Passed to the actors */
RFC PATCH 3/3 splice: add support of splicing to packetized pipe
In reply to Stanislav KinsburskiyThis patch uses SPLICE_F_PACKET as a flag, representing packetized pipe. In splice_to_pipe() this flag is converted into PIPE_BUF_FLAG_PACKET on pipe buffer.
--- fs/splice.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/splice.c +8 -0
@@ -210,6 +210,8 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe, buf->ops = spd->ops;if (spd->flags &SPLICE_F_GIFT ) buf->flags |=PIPE_BUF_FLAG_GIFT ; +if (spd->flags &SPLICE_F_PACKET ) + buf->flags |=PIPE_BUF_FLAG_PACKET ; pipe->nrbufs++; page_nr++;
@@ -1420,6 +1422,9 @@ static long do_splice(struct file *in, loff_t __user *off_in, offset = in->f_pos; } +if (is_packetized (out)) + flags |=SPLICE_F_PACKET ; + ret =do_splice_to (in, &offset, opipe, len, flags);if (!off_in)
@@ -1609,6 +1614,9 @@ static long vmsplice_to_pipe(struct file *file, const struct iovec __user *iov,if (splice_grow_spd (pipe, &spd))return -ENOMEM ; +if (is_packetized (file)) + spd.flags |=SPLICE_F_PACKET ; + spd.nr_pages =get_iovec_page_array (iov, nr_segs, spd.pages, spd.partial, false, spd.nr_pages_max);