Re: [splice PATCH 3/3] splice: added support for pipe-to-pipe splice()

From: Vegard Nossum
Date: Thu Apr 30 2009 - 09:35:39 EST


2009/4/30 Max Kellermann <mk@xxxxxxxxxx>:
> This patch enables the splice() system call to copy buffers from one
> pipe to another. ÂThis obvious and trivial use case for splice() was
> not supported until now.
>
> It reuses the functions link_ipipe_prep() and link_opipe_prep() from
> the tee() system call implementation.
>
> Signed-off-by: Max Kellermann <mk@xxxxxxxxxx>
> ---
>
> Âfs/splice.c | Â166 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Â1 files changed, 166 insertions(+), 0 deletions(-)
>
> diff --git a/fs/splice.c b/fs/splice.c
> index 96135eb..f69a88f 100644
> --- a/fs/splice.c
> +++ b/fs/splice.c
> @@ -902,6 +902,156 @@ ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe, struct file *out,
>
> ÂEXPORT_SYMBOL(generic_splice_sendpage);
>
> +static int link_ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags);
> +static int link_opipe_prep(struct pipe_inode_info *pipe, unsigned int flags);
> +
> +/**
> + * Returns the nth pipe buffer after the current one.
> + *
> + * @i the buffer index, relative to the current one
> + */
> +static inline struct pipe_buffer *
> +pipe_buffer_at(struct pipe_inode_info *pipe, unsigned i)
> +{
> + Â Â Â BUG_ON(i >= PIPE_BUFFERS);
> +
> + Â Â Â return pipe->bufs + ((pipe->curbuf + i) & (PIPE_BUFFERS - 1));
> +}
> +
> +/**
> + * Splice pages from one pipe to another.
> + *
> + * @ipipe the input pipe
> + * @opipe the output pipe
> + * @len the maximum number of bytes to move
> + * @flags splice modifier flags
> + */
> +static long do_splice_pipes(struct pipe_inode_info *ipipe,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â struct pipe_inode_info *opipe,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â size_t len, unsigned int flags)
> +{
> + Â Â Â struct pipe_buffer *ibuf, *obuf;
> + Â Â Â long ret;
> + Â Â Â int do_wakeup = 0;
> +
> + Â Â Â if (ipipe == opipe)
> + Â Â Â Â Â Â Â /* cannot splice a pipe to itself */
> + Â Â Â Â Â Â Â return -EINVAL;
> +

What happens if you splice two pipes, in separate threads, to each other? :-)


Vegard
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/