@@ -153,9 +153,16 @@ static const struct pipe_buf_operations user_page_pipe_buf_ops = {
153153 .get = generic_pipe_buf_get ,
154154};
155155
156- /*
157- * Pipe output worker. This fills a pipe with the information contained
158- * from splice_pipe_desc().
156+ /**
157+ * splice_to_pipe - fill passed data into a pipe
158+ * @pipe: pipe to fill
159+ * @spd: data to fill
160+ *
161+ * Description:
162+ * @spd contains a map of pages and len/offset tupples, a long with
163+ * the struct pipe_buf_operations associated with these pages. This
164+ * function will link that data to the pipe.
165+ *
159166 */
160167ssize_t splice_to_pipe (struct pipe_inode_info * pipe ,
161168 struct splice_pipe_desc * spd )
@@ -280,20 +287,16 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
280287 */
281288 page_cache_readahead (mapping , & in -> f_ra , in , index , nr_pages );
282289
283- /*
284- * Now fill in the holes:
285- */
286- error = 0 ;
287-
288290 /*
289291 * Lookup the (hopefully) full range of pages we need.
290292 */
291293 spd .nr_pages = find_get_pages_contig (mapping , index , nr_pages , pages );
292294
293295 /*
294296 * If find_get_pages_contig() returned fewer pages than we needed,
295- * allocate the rest.
297+ * allocate the rest and fill in the holes .
296298 */
299+ error = 0 ;
297300 index += spd .nr_pages ;
298301 while (spd .nr_pages < nr_pages ) {
299302 /*
@@ -455,11 +458,16 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
455458/**
456459 * generic_file_splice_read - splice data from file to a pipe
457460 * @in: file to splice from
461+ * @ppos: position in @in
458462 * @pipe: pipe to splice to
459463 * @len: number of bytes to splice
460464 * @flags: splice modifier flags
461465 *
462- * Will read pages from given file and fill them into a pipe.
466+ * Description:
467+ * Will read pages from given file and fill them into a pipe. Can be
468+ * used as long as the address_space operations for the source implements
469+ * a readpage() hook.
470+ *
463471 */
464472ssize_t generic_file_splice_read (struct file * in , loff_t * ppos ,
465473 struct pipe_inode_info * pipe , size_t len ,
@@ -648,10 +656,18 @@ static int pipe_to_file(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
648656 return ret ;
649657}
650658
651- /*
652- * Pipe input worker. Most of this logic works like a regular pipe, the
653- * key here is the 'actor' worker passed in that actually moves the data
654- * to the wanted destination. See pipe_to_file/pipe_to_sendpage above.
659+ /**
660+ * __splice_from_pipe - splice data from a pipe to given actor
661+ * @pipe: pipe to splice from
662+ * @sd: information to @actor
663+ * @actor: handler that splices the data
664+ *
665+ * Description:
666+ * This function does little more than loop over the pipe and call
667+ * @actor to do the actual moving of a single struct pipe_buffer to
668+ * the desired destination. See pipe_to_file, pipe_to_sendpage, or
669+ * pipe_to_user.
670+ *
655671 */
656672ssize_t __splice_from_pipe (struct pipe_inode_info * pipe , struct splice_desc * sd ,
657673 splice_actor * actor )
@@ -744,6 +760,20 @@ ssize_t __splice_from_pipe(struct pipe_inode_info *pipe, struct splice_desc *sd,
744760}
745761EXPORT_SYMBOL (__splice_from_pipe );
746762
763+ /**
764+ * splice_from_pipe - splice data from a pipe to a file
765+ * @pipe: pipe to splice from
766+ * @out: file to splice to
767+ * @ppos: position in @out
768+ * @len: how many bytes to splice
769+ * @flags: splice modifier flags
770+ * @actor: handler that splices the data
771+ *
772+ * Description:
773+ * See __splice_from_pipe. This function locks the input and output inodes,
774+ * otherwise it's identical to __splice_from_pipe().
775+ *
776+ */
747777ssize_t splice_from_pipe (struct pipe_inode_info * pipe , struct file * out ,
748778 loff_t * ppos , size_t len , unsigned int flags ,
749779 splice_actor * actor )
@@ -774,12 +804,14 @@ ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out,
774804 * generic_file_splice_write_nolock - generic_file_splice_write without mutexes
775805 * @pipe: pipe info
776806 * @out: file to write to
807+ * @ppos: position in @out
777808 * @len: number of bytes to splice
778809 * @flags: splice modifier flags
779810 *
780- * Will either move or copy pages (determined by @flags options) from
781- * the given pipe inode to the given file. The caller is responsible
782- * for acquiring i_mutex on both inodes.
811+ * Description:
812+ * Will either move or copy pages (determined by @flags options) from
813+ * the given pipe inode to the given file. The caller is responsible
814+ * for acquiring i_mutex on both inodes.
783815 *
784816 */
785817ssize_t
@@ -831,11 +863,13 @@ EXPORT_SYMBOL(generic_file_splice_write_nolock);
831863 * generic_file_splice_write - splice data from a pipe to a file
832864 * @pipe: pipe info
833865 * @out: file to write to
866+ * @ppos: position in @out
834867 * @len: number of bytes to splice
835868 * @flags: splice modifier flags
836869 *
837- * Will either move or copy pages (determined by @flags options) from
838- * the given pipe inode to the given file.
870+ * Description:
871+ * Will either move or copy pages (determined by @flags options) from
872+ * the given pipe inode to the given file.
839873 *
840874 */
841875ssize_t
@@ -886,13 +920,15 @@ EXPORT_SYMBOL(generic_file_splice_write);
886920
887921/**
888922 * generic_splice_sendpage - splice data from a pipe to a socket
889- * @inode : pipe inode
923+ * @pipe : pipe to splice from
890924 * @out: socket to write to
925+ * @ppos: position in @out
891926 * @len: number of bytes to splice
892927 * @flags: splice modifier flags
893928 *
894- * Will send @len bytes from the pipe to a network socket. No data copying
895- * is involved.
929+ * Description:
930+ * Will send @len bytes from the pipe to a network socket. No data copying
931+ * is involved.
896932 *
897933 */
898934ssize_t generic_splice_sendpage (struct pipe_inode_info * pipe , struct file * out ,
@@ -946,8 +982,18 @@ static long do_splice_to(struct file *in, loff_t *ppos,
946982 return in -> f_op -> splice_read (in , ppos , pipe , len , flags );
947983}
948984
949- /*
950- * Splices from an input file to an actor, using a 'direct' pipe.
985+ /**
986+ * splice_direct_to_actor - splices data directly between two non-pipes
987+ * @in: file to splice from
988+ * @sd: actor information on where to splice to
989+ * @actor: handles the data splicing
990+ *
991+ * Description:
992+ * This is a special case helper to splice directly between two
993+ * points, without requiring an explicit pipe. Internally an allocated
994+ * pipe is cached in the process, and reused during the life time of
995+ * that process.
996+ *
951997 */
952998ssize_t splice_direct_to_actor (struct file * in , struct splice_desc * sd ,
953999 splice_direct_actor * actor )
@@ -1077,6 +1123,21 @@ static int direct_splice_actor(struct pipe_inode_info *pipe,
10771123 return do_splice_from (pipe , file , & sd -> pos , sd -> total_len , sd -> flags );
10781124}
10791125
1126+ /**
1127+ * do_splice_direct - splices data directly between two files
1128+ * @in: file to splice from
1129+ * @ppos: input file offset
1130+ * @out: file to splice to
1131+ * @len: number of bytes to splice
1132+ * @flags: splice modifier flags
1133+ *
1134+ * Description:
1135+ * For use by do_sendfile(). splice can easily emulate sendfile, but
1136+ * doing it in the application would incur an extra system call
1137+ * (splice in + splice out, as compared to just sendfile()). So this helper
1138+ * can splice directly through a process-private pipe.
1139+ *
1140+ */
10801141long do_splice_direct (struct file * in , loff_t * ppos , struct file * out ,
10811142 size_t len , unsigned int flags )
10821143{
0 commit comments