···3737 loff_t pos; /* file position */3838};39394040+/*4141+ * Attempt to steal a page from a pipe buffer. This should perhaps go into4242+ * a vm helper function, it's already simplified quite a bit by the4343+ * addition of remove_mapping(). If success is returned, the caller may4444+ * attempt to reuse this page for another destination.4545+ */4046static int page_cache_pipe_buf_steal(struct pipe_inode_info *info,4147 struct pipe_buffer *buf)4248{···114108 .steal = page_cache_pipe_buf_steal,115109};116110111111+/*112112+ * Pipe output worker. This sets up our pipe format with the page cache113113+ * pipe buffer operations. Otherwise very similar to the regular pipe_writev().114114+ */117115static ssize_t move_to_pipe(struct inode *inode, struct page **pages,118116 int nr_pages, unsigned long offset,119117 unsigned long len, unsigned int flags)···302292 return move_to_pipe(pipe, pages, i, offset, len, flags);303293}304294295295+/**296296+ * generic_file_splice_read - splice data from file to a pipe297297+ * @in: file to splice from298298+ * @pipe: pipe to splice to299299+ * @len: number of bytes to splice300300+ * @flags: splice modifier flags301301+ *302302+ * Will read pages from given file and fill them into a pipe.303303+ *304304+ */305305ssize_t generic_file_splice_read(struct file *in, struct inode *pipe,306306 size_t len, unsigned int flags)307307{···390370 * - Destination page does not exist, we can add the pipe page to391371 * the page cache and avoid the copy.392372 *393393- * For now we just do the slower thing and always copy pages over, it's394394- * easier than migrating pages from the pipe to the target file. For the395395- * case of doing file | file splicing, the migrate approach had some LRU396396- * nastiness...373373+ * If asked to move pages to the output file (SPLICE_F_MOVE is set in374374+ * sd->flags), we attempt to migrate pages from the pipe to the output375375+ * file address space page cache. This is possible if no one else has376376+ * the pipe page referenced outside of the pipe and page cache. If377377+ * SPLICE_F_MOVE isn't set, or we cannot move the page, we simply create378378+ * a new page in the output file page cache and fill/dirty that.397379 */398380static int pipe_to_file(struct pipe_inode_info *info, struct pipe_buffer *buf,399381 struct splice_desc *sd)···423401 * reuse buf page, if SPLICE_F_MOVE is set424402 */425403 if (sd->flags & SPLICE_F_MOVE) {404404+ /*405405+ * If steal succeeds, buf->page is now pruned from the vm406406+ * side (LRU and page cache) and we can reuse it.407407+ */426408 if (buf->ops->steal(info, buf))427409 goto find_page;428410···510484typedef int (splice_actor)(struct pipe_inode_info *, struct pipe_buffer *,511485 struct splice_desc *);512486487487+/*488488+ * Pipe input worker. Most of this logic works like a regular pipe, the489489+ * key here is the 'actor' worker passed in that actually moves the data490490+ * to the wanted destination. See pipe_to_file/pipe_to_sendpage above.491491+ */513492static ssize_t move_from_pipe(struct inode *inode, struct file *out,514493 size_t len, unsigned int flags,515494 splice_actor *actor)···616585617586}618587588588+/**589589+ * generic_file_splice_write - splice data from a pipe to a file590590+ * @inode: pipe inode591591+ * @out: file to write to592592+ * @len: number of bytes to splice593593+ * @flags: splice modifier flags594594+ *595595+ * Will either move or copy pages (determined by @flags options) from596596+ * the given pipe inode to the given file.597597+ *598598+ */619599ssize_t generic_file_splice_write(struct inode *inode, struct file *out,620600 size_t len, unsigned int flags)621601{···653611 return ret;654612}655613614614+/**615615+ * generic_splice_sendpage - splice data from a pipe to a socket616616+ * @inode: pipe inode617617+ * @out: socket to write to618618+ * @len: number of bytes to splice619619+ * @flags: splice modifier flags620620+ *621621+ * Will send @len bytes from the pipe to a network socket. No data copying622622+ * is involved.623623+ *624624+ */656625ssize_t generic_splice_sendpage(struct inode *inode, struct file *out,657626 size_t len, unsigned int flags)658627{···673620EXPORT_SYMBOL(generic_file_splice_write);674621EXPORT_SYMBOL(generic_file_splice_read);675622623623+/*624624+ * Attempt to initiate a splice from pipe to file.625625+ */676626static long do_splice_from(struct inode *pipe, struct file *out, size_t len,677627 unsigned int flags)678628{···696640 return out->f_op->splice_write(pipe, out, len, flags);697641}698642643643+/*644644+ * Attempt to initiate a splice from a file to a pipe.645645+ */699646static long do_splice_to(struct file *in, struct inode *pipe, size_t len,700647 unsigned int flags)701648{···727668 return in->f_op->splice_read(in, pipe, len, flags);728669}729670671671+/*672672+ * Determine where to splice to/from.673673+ */730674static long do_splice(struct file *in, struct file *out, size_t len,731675 unsigned int flags)732676{