[PATCH] splice: add comments documenting more of the code

Hopefully this will make Andrew a little more happy.

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

+66 -4
+66 -4
fs/splice.c
··· 37 37 loff_t pos; /* file position */ 38 38 }; 39 39 40 + /* 41 + * Attempt to steal a page from a pipe buffer. This should perhaps go into 42 + * a vm helper function, it's already simplified quite a bit by the 43 + * addition of remove_mapping(). If success is returned, the caller may 44 + * attempt to reuse this page for another destination. 45 + */ 40 46 static int page_cache_pipe_buf_steal(struct pipe_inode_info *info, 41 47 struct pipe_buffer *buf) 42 48 { ··· 114 108 .steal = page_cache_pipe_buf_steal, 115 109 }; 116 110 111 + /* 112 + * Pipe output worker. This sets up our pipe format with the page cache 113 + * pipe buffer operations. Otherwise very similar to the regular pipe_writev(). 114 + */ 117 115 static ssize_t move_to_pipe(struct inode *inode, struct page **pages, 118 116 int nr_pages, unsigned long offset, 119 117 unsigned long len, unsigned int flags) ··· 302 292 return move_to_pipe(pipe, pages, i, offset, len, flags); 303 293 } 304 294 295 + /** 296 + * generic_file_splice_read - splice data from file to a pipe 297 + * @in: file to splice from 298 + * @pipe: pipe to splice to 299 + * @len: number of bytes to splice 300 + * @flags: splice modifier flags 301 + * 302 + * Will read pages from given file and fill them into a pipe. 303 + * 304 + */ 305 305 ssize_t generic_file_splice_read(struct file *in, struct inode *pipe, 306 306 size_t len, unsigned int flags) 307 307 { ··· 390 370 * - Destination page does not exist, we can add the pipe page to 391 371 * the page cache and avoid the copy. 392 372 * 393 - * For now we just do the slower thing and always copy pages over, it's 394 - * easier than migrating pages from the pipe to the target file. For the 395 - * case of doing file | file splicing, the migrate approach had some LRU 396 - * nastiness... 373 + * If asked to move pages to the output file (SPLICE_F_MOVE is set in 374 + * sd->flags), we attempt to migrate pages from the pipe to the output 375 + * file address space page cache. This is possible if no one else has 376 + * the pipe page referenced outside of the pipe and page cache. If 377 + * SPLICE_F_MOVE isn't set, or we cannot move the page, we simply create 378 + * a new page in the output file page cache and fill/dirty that. 397 379 */ 398 380 static int pipe_to_file(struct pipe_inode_info *info, struct pipe_buffer *buf, 399 381 struct splice_desc *sd) ··· 423 401 * reuse buf page, if SPLICE_F_MOVE is set 424 402 */ 425 403 if (sd->flags & SPLICE_F_MOVE) { 404 + /* 405 + * If steal succeeds, buf->page is now pruned from the vm 406 + * side (LRU and page cache) and we can reuse it. 407 + */ 426 408 if (buf->ops->steal(info, buf)) 427 409 goto find_page; 428 410 ··· 510 484 typedef int (splice_actor)(struct pipe_inode_info *, struct pipe_buffer *, 511 485 struct splice_desc *); 512 486 487 + /* 488 + * Pipe input worker. Most of this logic works like a regular pipe, the 489 + * key here is the 'actor' worker passed in that actually moves the data 490 + * to the wanted destination. See pipe_to_file/pipe_to_sendpage above. 491 + */ 513 492 static ssize_t move_from_pipe(struct inode *inode, struct file *out, 514 493 size_t len, unsigned int flags, 515 494 splice_actor *actor) ··· 616 585 617 586 } 618 587 588 + /** 589 + * generic_file_splice_write - splice data from a pipe to a file 590 + * @inode: pipe inode 591 + * @out: file to write to 592 + * @len: number of bytes to splice 593 + * @flags: splice modifier flags 594 + * 595 + * Will either move or copy pages (determined by @flags options) from 596 + * the given pipe inode to the given file. 597 + * 598 + */ 619 599 ssize_t generic_file_splice_write(struct inode *inode, struct file *out, 620 600 size_t len, unsigned int flags) 621 601 { ··· 653 611 return ret; 654 612 } 655 613 614 + /** 615 + * generic_splice_sendpage - splice data from a pipe to a socket 616 + * @inode: pipe inode 617 + * @out: socket to write to 618 + * @len: number of bytes to splice 619 + * @flags: splice modifier flags 620 + * 621 + * Will send @len bytes from the pipe to a network socket. No data copying 622 + * is involved. 623 + * 624 + */ 656 625 ssize_t generic_splice_sendpage(struct inode *inode, struct file *out, 657 626 size_t len, unsigned int flags) 658 627 { ··· 673 620 EXPORT_SYMBOL(generic_file_splice_write); 674 621 EXPORT_SYMBOL(generic_file_splice_read); 675 622 623 + /* 624 + * Attempt to initiate a splice from pipe to file. 625 + */ 676 626 static long do_splice_from(struct inode *pipe, struct file *out, size_t len, 677 627 unsigned int flags) 678 628 { ··· 696 640 return out->f_op->splice_write(pipe, out, len, flags); 697 641 } 698 642 643 + /* 644 + * Attempt to initiate a splice from a file to a pipe. 645 + */ 699 646 static long do_splice_to(struct file *in, struct inode *pipe, size_t len, 700 647 unsigned int flags) 701 648 { ··· 727 668 return in->f_op->splice_read(in, pipe, len, flags); 728 669 } 729 670 671 + /* 672 + * Determine where to splice to/from. 673 + */ 730 674 static long do_splice(struct file *in, struct file *out, size_t len, 731 675 unsigned int flags) 732 676 {