aboutsummaryrefslogtreecommitdiffstats
path: root/fs/splice.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/splice.c')
-rw-r--r--fs/splice.c109
1 files changed, 85 insertions, 24 deletions
diff --git a/fs/splice.c b/fs/splice.c
index 00850e56280d..d257d666358b 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -153,9 +153,16 @@ static const struct pipe_buf_operations user_page_pipe_buf_ops = {
153 .get = generic_pipe_buf_get, 153 .get = generic_pipe_buf_get,
154}; 154};
155 155
156/* 156/**
157 * Pipe output worker. This fills a pipe with the information contained 157 * splice_to_pipe - fill passed data into a pipe
158 * from splice_pipe_desc(). 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 *
159 */ 166 */
160ssize_t splice_to_pipe(struct pipe_inode_info *pipe, 167ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
161 struct splice_pipe_desc *spd) 168 struct splice_pipe_desc *spd)
@@ -281,19 +288,15 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
281 page_cache_readahead(mapping, &in->f_ra, in, index, nr_pages); 288 page_cache_readahead(mapping, &in->f_ra, in, index, nr_pages);
282 289
283 /* 290 /*
284 * Now fill in the holes:
285 */
286 error = 0;
287
288 /*
289 * Lookup the (hopefully) full range of pages we need. 291 * Lookup the (hopefully) full range of pages we need.
290 */ 292 */
291 spd.nr_pages = find_get_pages_contig(mapping, index, nr_pages, pages); 293 spd.nr_pages = find_get_pages_contig(mapping, index, nr_pages, pages);
292 294
293 /* 295 /*
294 * If find_get_pages_contig() returned fewer pages than we needed, 296 * If find_get_pages_contig() returned fewer pages than we needed,
295 * allocate the rest. 297 * allocate the rest and fill in the holes.
296 */ 298 */
299 error = 0;
297 index += spd.nr_pages; 300 index += spd.nr_pages;
298 while (spd.nr_pages < nr_pages) { 301 while (spd.nr_pages < nr_pages) {
299 /* 302 /*
@@ -455,11 +458,16 @@ fill_it:
455/** 458/**
456 * generic_file_splice_read - splice data from file to a pipe 459 * generic_file_splice_read - splice data from file to a pipe
457 * @in: file to splice from 460 * @in: file to splice from
461 * @ppos: position in @in
458 * @pipe: pipe to splice to 462 * @pipe: pipe to splice to
459 * @len: number of bytes to splice 463 * @len: number of bytes to splice
460 * @flags: splice modifier flags 464 * @flags: splice modifier flags
461 * 465 *
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 *
463 */ 471 */
464ssize_t generic_file_splice_read(struct file *in, loff_t *ppos, 472ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,
465 struct pipe_inode_info *pipe, size_t len, 473 struct pipe_inode_info *pipe, size_t len,
@@ -648,10 +656,18 @@ out_ret:
648 return ret; 656 return ret;
649} 657}
650 658
651/* 659/**
652 * Pipe input worker. Most of this logic works like a regular pipe, the 660 * __splice_from_pipe - splice data from a pipe to given actor
653 * key here is the 'actor' worker passed in that actually moves the data 661 * @pipe: pipe to splice from
654 * to the wanted destination. See pipe_to_file/pipe_to_sendpage above. 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 *
655 */ 671 */
656ssize_t __splice_from_pipe(struct pipe_inode_info *pipe, struct splice_desc *sd, 672ssize_t __splice_from_pipe(struct pipe_inode_info *pipe, struct splice_desc *sd,
657 splice_actor *actor) 673 splice_actor *actor)
@@ -744,6 +760,20 @@ ssize_t __splice_from_pipe(struct pipe_inode_info *pipe, struct splice_desc *sd,
744} 760}
745EXPORT_SYMBOL(__splice_from_pipe); 761EXPORT_SYMBOL(__splice_from_pipe);
746 762
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 */
747ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out, 777ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out,
748 loff_t *ppos, size_t len, unsigned int flags, 778 loff_t *ppos, size_t len, unsigned int flags,
749 splice_actor *actor) 779 splice_actor *actor)
@@ -774,12 +804,14 @@ ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out,
774 * generic_file_splice_write_nolock - generic_file_splice_write without mutexes 804 * generic_file_splice_write_nolock - generic_file_splice_write without mutexes
775 * @pipe: pipe info 805 * @pipe: pipe info
776 * @out: file to write to 806 * @out: file to write to
807 * @ppos: position in @out
777 * @len: number of bytes to splice 808 * @len: number of bytes to splice
778 * @flags: splice modifier flags 809 * @flags: splice modifier flags
779 * 810 *
780 * Will either move or copy pages (determined by @flags options) from 811 * Description:
781 * the given pipe inode to the given file. The caller is responsible 812 * Will either move or copy pages (determined by @flags options) from
782 * for acquiring i_mutex on both inodes. 813 * the given pipe inode to the given file. The caller is responsible
814 * for acquiring i_mutex on both inodes.
783 * 815 *
784 */ 816 */
785ssize_t 817ssize_t
@@ -831,11 +863,13 @@ EXPORT_SYMBOL(generic_file_splice_write_nolock);
831 * generic_file_splice_write - splice data from a pipe to a file 863 * generic_file_splice_write - splice data from a pipe to a file
832 * @pipe: pipe info 864 * @pipe: pipe info
833 * @out: file to write to 865 * @out: file to write to
866 * @ppos: position in @out
834 * @len: number of bytes to splice 867 * @len: number of bytes to splice
835 * @flags: splice modifier flags 868 * @flags: splice modifier flags
836 * 869 *
837 * Will either move or copy pages (determined by @flags options) from 870 * Description:
838 * the given pipe inode to the given file. 871 * Will either move or copy pages (determined by @flags options) from
872 * the given pipe inode to the given file.
839 * 873 *
840 */ 874 */
841ssize_t 875ssize_t
@@ -886,13 +920,15 @@ EXPORT_SYMBOL(generic_file_splice_write);
886 920
887/** 921/**
888 * generic_splice_sendpage - splice data from a pipe to a socket 922 * generic_splice_sendpage - splice data from a pipe to a socket
889 * @inode: pipe inode 923 * @pipe: pipe to splice from
890 * @out: socket to write to 924 * @out: socket to write to
925 * @ppos: position in @out
891 * @len: number of bytes to splice 926 * @len: number of bytes to splice
892 * @flags: splice modifier flags 927 * @flags: splice modifier flags
893 * 928 *
894 * Will send @len bytes from the pipe to a network socket. No data copying 929 * Description:
895 * is involved. 930 * Will send @len bytes from the pipe to a network socket. No data copying
931 * is involved.
896 * 932 *
897 */ 933 */
898ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe, struct file *out, 934ssize_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,
946 return in->f_op->splice_read(in, ppos, pipe, len, flags); 982 return in->f_op->splice_read(in, ppos, pipe, len, flags);
947} 983}
948 984
949/* 985/**
950 * Splices from an input file to an actor, using a 'direct' pipe. 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 *
951 */ 997 */
952ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd, 998ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
953 splice_direct_actor *actor) 999 splice_direct_actor *actor)
@@ -1077,6 +1123,21 @@ static int direct_splice_actor(struct pipe_inode_info *pipe,
1077 return do_splice_from(pipe, file, &sd->pos, sd->total_len, sd->flags); 1123 return do_splice_from(pipe, file, &sd->pos, sd->total_len, sd->flags);
1078} 1124}
1079 1125
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 */
1080long do_splice_direct(struct file *in, loff_t *ppos, struct file *out, 1141long do_splice_direct(struct file *in, loff_t *ppos, struct file *out,
1081 size_t len, unsigned int flags) 1142 size_t len, unsigned int flags)
1082{ 1143{