···164164 page_cache_release(page);165165}166166167167+/**168168+ * generic_pipe_buf_map - virtually map a pipe buffer169169+ * @pipe: the pipe that the buffer belongs to170170+ * @buf: the buffer that should be mapped171171+ * @atomic: whether to use an atomic map172172+ *173173+ * Description:174174+ * This function returns a kernel virtual address mapping for the175175+ * passed in @pipe_buffer. If @atomic is set, an atomic map is provided176176+ * and the caller has to be careful not to fault before calling177177+ * the unmap function.178178+ *179179+ * Note that this function occupies KM_USER0 if @atomic != 0.180180+ */167181void *generic_pipe_buf_map(struct pipe_inode_info *pipe,168182 struct pipe_buffer *buf, int atomic)169183{···189175 return kmap(buf->page);190176}191177178178+/**179179+ * generic_pipe_buf_unmap - unmap a previously mapped pipe buffer180180+ * @pipe: the pipe that the buffer belongs to181181+ * @buf: the buffer that should be unmapped182182+ * @map_data: the data that the mapping function returned183183+ *184184+ * Description:185185+ * This function undoes the mapping that ->map() provided.186186+ */192187void generic_pipe_buf_unmap(struct pipe_inode_info *pipe,193188 struct pipe_buffer *buf, void *map_data)194189{···208185 kunmap(buf->page);209186}210187188188+/**189189+ * generic_pipe_buf_steal - attempt to take ownership of a @pipe_buffer190190+ * @pipe: the pipe that the buffer belongs to191191+ * @buf: the buffer to attempt to steal192192+ *193193+ * Description:194194+ * This function attempts to steal the @struct page attached to195195+ * @buf. If successful, this function returns 0 and returns with196196+ * the page locked. The caller may then reuse the page for whatever197197+ * he wishes, the typical use is insertion into a different file198198+ * page cache.199199+ */211200int generic_pipe_buf_steal(struct pipe_inode_info *pipe,212201 struct pipe_buffer *buf)213202{214203 struct page *page = buf->page;215204205205+ /*206206+ * A reference of one is golden, that means that the owner of this207207+ * page is the only one holding a reference to it. lock the page208208+ * and return OK.209209+ */216210 if (page_count(page) == 1) {217211 lock_page(page);218212 return 0;···238198 return 1;239199}240200241241-void generic_pipe_buf_get(struct pipe_inode_info *info, struct pipe_buffer *buf)201201+/**202202+ * generic_pipe_buf_get - get a reference to a @struct pipe_buffer203203+ * @pipe: the pipe that the buffer belongs to204204+ * @buf: the buffer to get a reference to205205+ *206206+ * Description:207207+ * This function grabs an extra reference to @buf. It's used in208208+ * in the tee() system call, when we duplicate the buffers in one209209+ * pipe into another.210210+ */211211+void generic_pipe_buf_get(struct pipe_inode_info *pipe, struct pipe_buffer *buf)242212{243213 page_cache_get(buf->page);244214}245215216216+/**217217+ * generic_pipe_buf_confirm - verify contents of the pipe buffer218218+ * @pipe: the pipe that the buffer belongs to219219+ * @buf: the buffer to confirm220220+ *221221+ * Description:222222+ * This function does nothing, because the generic pipe code uses223223+ * pages that are always good when inserted into the pipe.224224+ */246225int generic_pipe_buf_confirm(struct pipe_inode_info *info,247226 struct pipe_buffer *buf)248227{
+4
fs/splice.c
···8585 buf->flags &= ~PIPE_BUF_FLAG_LRU;8686}87878888+/*8989+ * Check whether the contents of buf is OK to access. Since the content9090+ * is a page cache page, IO may be in flight.9191+ */8892static int page_cache_pipe_buf_confirm(struct pipe_inode_info *pipe,8993 struct pipe_buffer *buf)9094{
+76-1
include/linux/pipe_fs_i.h
···99#define PIPE_BUF_FLAG_ATOMIC 0x02 /* was atomically mapped */1010#define PIPE_BUF_FLAG_GIFT 0x04 /* page is a gift */11111212+/**1313+ * struct pipe_buffer - a linux kernel pipe buffer1414+ * @page: the page containing the data for the pipe buffer1515+ * @offset: offset of data inside the @page1616+ * @len: length of data inside the @page1717+ * @ops: operations associated with this buffer. See @pipe_buf_operations.1818+ * @flags: pipe buffer flags. See above.1919+ * @private: private data owned by the ops.2020+ **/1221struct pipe_buffer {1322 struct page *page;1423 unsigned int offset, len;···2617 unsigned long private;2718};28192020+/**2121+ * struct pipe_inode_info - a linux kernel pipe2222+ * @wait: reader/writer wait point in case of empty/full pipe2323+ * @nrbufs: the number of non-empty pipe buffers in this pipe2424+ * @curbuf: the current pipe buffer entry2525+ * @tmp_page: cached released page2626+ * @readers: number of current readers of this pipe2727+ * @writers: number of current writers of this pipe2828+ * @waiting_writers: number of writers blocked waiting for room2929+ * @r_counter: reader counter3030+ * @w_counter: writer counter3131+ * @fasync_readers: reader side fasync3232+ * @fasync_writers: writer side fasync3333+ * @inode: inode this pipe is attached to3434+ * @bufs: the circular array of pipe buffers3535+ **/2936struct pipe_inode_info {3037 wait_queue_head_t wait;3138 unsigned int nrbufs, curbuf;···6843 * ->unmap()6944 *7045 * That is, ->map() must be called on a confirmed buffer,7171- * same goes for ->steal().4646+ * same goes for ->steal(). See below for the meaning of each4747+ * operation. Also see kerneldoc in fs/pipe.c for the pipe4848+ * and generic variants of these hooks.7249 */7350struct pipe_buf_operations {5151+ /*5252+ * This is set to 1, if the generic pipe read/write may coalesce5353+ * data into an existing buffer. If this is set to 0, a new pipe5454+ * page segment is always used for new data.5555+ */7456 int can_merge;5757+5858+ /*5959+ * ->map() returns a virtual address mapping of the pipe buffer.6060+ * The last integer flag reflects whether this should be an atomic6161+ * mapping or not. The atomic map is faster, however you can't take6262+ * page faults before calling ->unmap() again. So if you need to eg6363+ * access user data through copy_to/from_user(), then you must get6464+ * a non-atomic map. ->map() uses the KM_USER0 atomic slot for6565+ * atomic maps, so you can't map more than one pipe_buffer at once6666+ * and you have to be careful if mapping another page as source6767+ * or destination for a copy (IOW, it has to use something else6868+ * than KM_USER0).6969+ */7570 void * (*map)(struct pipe_inode_info *, struct pipe_buffer *, int);7171+7272+ /*7373+ * Undoes ->map(), finishes the virtual mapping of the pipe buffer.7474+ */7675 void (*unmap)(struct pipe_inode_info *, struct pipe_buffer *, void *);7676+7777+ /*7878+ * ->confirm() verifies that the data in the pipe buffer is there7979+ * and that the contents are good. If the pages in the pipe belong8080+ * to a file system, we may need to wait for IO completion in this8181+ * hook. Returns 0 for good, or a negative error value in case of8282+ * error.8383+ */7784 int (*confirm)(struct pipe_inode_info *, struct pipe_buffer *);8585+8686+ /*8787+ * When the contents of this pipe buffer has been completely8888+ * consumed by a reader, ->release() is called.8989+ */7890 void (*release)(struct pipe_inode_info *, struct pipe_buffer *);9191+9292+ /*9393+ * Attempt to take ownership of the pipe buffer and its contents.9494+ * ->steal() returns 0 for success, in which case the contents9595+ * of the pipe (the buf->page) is locked and now completely owned9696+ * by the caller. The page may then be transferred to a different9797+ * mapping, the most often used case is insertion into different9898+ * file address space cache.9999+ */79100 int (*steal)(struct pipe_inode_info *, struct pipe_buffer *);101101+102102+ /*103103+ * Get a reference to the pipe buffer.104104+ */80105 void (*get)(struct pipe_inode_info *, struct pipe_buffer *);81106};82107