[PATCH] splice: rearrange moving to/from pipe helpers

We need these for people writing their own ->splice_read/write hooks.

Signed-off-by: Jens Axboe <axboe@suse.de>

+28 -24
+11 -24
fs/splice.c
··· 29 #include <linux/syscalls.h> 30 #include <linux/uio.h> 31 32 - /* 33 - * Passed to the actors 34 - */ 35 - struct splice_desc { 36 - unsigned int len, total_len; /* current and remaining length */ 37 - unsigned int flags; /* splice flags */ 38 - struct file *file; /* file to read/write */ 39 - loff_t pos; /* file position */ 40 - }; 41 - 42 struct partial_page { 43 unsigned int offset; 44 unsigned int len; 45 }; 46 47 /* 48 - * Passed to move_to_pipe 49 */ 50 struct splice_pipe_desc { 51 struct page **pages; /* page map */ ··· 182 * Pipe output worker. This sets up our pipe format with the page cache 183 * pipe buffer operations. Otherwise very similar to the regular pipe_writev(). 184 */ 185 - static ssize_t move_to_pipe(struct pipe_inode_info *pipe, 186 - struct splice_pipe_desc *spd) 187 { 188 int ret, do_wakeup, page_nr; 189 ··· 422 } 423 424 if (spd.nr_pages) 425 - return move_to_pipe(pipe, &spd); 426 427 return error; 428 } ··· 656 return ret; 657 } 658 659 - typedef int (splice_actor)(struct pipe_inode_info *, struct pipe_buffer *, 660 - struct splice_desc *); 661 - 662 /* 663 * Pipe input worker. Most of this logic works like a regular pipe, the 664 * key here is the 'actor' worker passed in that actually moves the data 665 * to the wanted destination. See pipe_to_file/pipe_to_sendpage above. 666 */ 667 - static ssize_t move_from_pipe(struct pipe_inode_info *pipe, struct file *out, 668 - loff_t *ppos, size_t len, unsigned int flags, 669 - splice_actor *actor) 670 { 671 int ret, do_wakeup, err; 672 struct splice_desc sd; ··· 782 struct address_space *mapping = out->f_mapping; 783 ssize_t ret; 784 785 - ret = move_from_pipe(pipe, out, ppos, len, flags, pipe_to_file); 786 if (ret > 0) { 787 struct inode *inode = mapping->host; 788 ··· 824 ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe, struct file *out, 825 loff_t *ppos, size_t len, unsigned int flags) 826 { 827 - return move_from_pipe(pipe, out, ppos, len, flags, pipe_to_sendpage); 828 } 829 830 EXPORT_SYMBOL(generic_splice_sendpage); ··· 911 912 /* 913 * We don't have an immediate reader, but we'll read the stuff 914 - * out of the pipe right after the move_to_pipe(). So set 915 * PIPE_READERS appropriately. 916 */ 917 pipe->readers = 1; ··· 1197 if (spd.nr_pages <= 0) 1198 return spd.nr_pages; 1199 1200 - return move_to_pipe(pipe, &spd); 1201 } 1202 1203 asmlinkage long sys_vmsplice(int fd, const struct iovec __user *iov,
··· 29 #include <linux/syscalls.h> 30 #include <linux/uio.h> 31 32 struct partial_page { 33 unsigned int offset; 34 unsigned int len; 35 }; 36 37 /* 38 + * Passed to splice_to_pipe 39 */ 40 struct splice_pipe_desc { 41 struct page **pages; /* page map */ ··· 192 * Pipe output worker. This sets up our pipe format with the page cache 193 * pipe buffer operations. Otherwise very similar to the regular pipe_writev(). 194 */ 195 + static ssize_t splice_to_pipe(struct pipe_inode_info *pipe, 196 + struct splice_pipe_desc *spd) 197 { 198 int ret, do_wakeup, page_nr; 199 ··· 432 } 433 434 if (spd.nr_pages) 435 + return splice_to_pipe(pipe, &spd); 436 437 return error; 438 } ··· 666 return ret; 667 } 668 669 /* 670 * Pipe input worker. Most of this logic works like a regular pipe, the 671 * key here is the 'actor' worker passed in that actually moves the data 672 * to the wanted destination. See pipe_to_file/pipe_to_sendpage above. 673 */ 674 + ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out, 675 + loff_t *ppos, size_t len, unsigned int flags, 676 + splice_actor *actor) 677 { 678 int ret, do_wakeup, err; 679 struct splice_desc sd; ··· 795 struct address_space *mapping = out->f_mapping; 796 ssize_t ret; 797 798 + ret = splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_file); 799 if (ret > 0) { 800 struct inode *inode = mapping->host; 801 ··· 837 ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe, struct file *out, 838 loff_t *ppos, size_t len, unsigned int flags) 839 { 840 + return splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_sendpage); 841 } 842 843 EXPORT_SYMBOL(generic_splice_sendpage); ··· 924 925 /* 926 * We don't have an immediate reader, but we'll read the stuff 927 + * out of the pipe right after the splice_to_pipe(). So set 928 * PIPE_READERS appropriately. 929 */ 930 pipe->readers = 1; ··· 1210 if (spd.nr_pages <= 0) 1211 return spd.nr_pages; 1212 1213 + return splice_to_pipe(pipe, &spd); 1214 } 1215 1216 asmlinkage long sys_vmsplice(int fd, const struct iovec __user *iov,
+17
include/linux/pipe_fs_i.h
··· 61 /* from/to, of course */ 62 #define SPLICE_F_MORE (0x04) /* expect more data */ 63 64 #endif
··· 61 /* from/to, of course */ 62 #define SPLICE_F_MORE (0x04) /* expect more data */ 63 64 + /* 65 + * Passed to the actors 66 + */ 67 + struct splice_desc { 68 + unsigned int len, total_len; /* current and remaining length */ 69 + unsigned int flags; /* splice flags */ 70 + struct file *file; /* file to read/write */ 71 + loff_t pos; /* file position */ 72 + }; 73 + 74 + typedef int (splice_actor)(struct pipe_inode_info *, struct pipe_buffer *, 75 + struct splice_desc *); 76 + 77 + extern ssize_t splice_from_pipe(struct pipe_inode_info *, struct file *, 78 + loff_t *, size_t, unsigned int, 79 + splice_actor *); 80 + 81 #endif