Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pipe: add documentation and comments

As per Andrew Mortons request, here's a set of documentation for
the generic pipe_buf_operations hooks, the pipe, and pipe_buffer
structures.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>

+140 -2
+60 -1
fs/pipe.c
··· 164 164 page_cache_release(page); 165 165 } 166 166 167 + /** 168 + * generic_pipe_buf_map - virtually map a pipe buffer 169 + * @pipe: the pipe that the buffer belongs to 170 + * @buf: the buffer that should be mapped 171 + * @atomic: whether to use an atomic map 172 + * 173 + * Description: 174 + * This function returns a kernel virtual address mapping for the 175 + * passed in @pipe_buffer. If @atomic is set, an atomic map is provided 176 + * and the caller has to be careful not to fault before calling 177 + * the unmap function. 178 + * 179 + * Note that this function occupies KM_USER0 if @atomic != 0. 180 + */ 167 181 void *generic_pipe_buf_map(struct pipe_inode_info *pipe, 168 182 struct pipe_buffer *buf, int atomic) 169 183 { ··· 189 175 return kmap(buf->page); 190 176 } 191 177 178 + /** 179 + * generic_pipe_buf_unmap - unmap a previously mapped pipe buffer 180 + * @pipe: the pipe that the buffer belongs to 181 + * @buf: the buffer that should be unmapped 182 + * @map_data: the data that the mapping function returned 183 + * 184 + * Description: 185 + * This function undoes the mapping that ->map() provided. 186 + */ 192 187 void generic_pipe_buf_unmap(struct pipe_inode_info *pipe, 193 188 struct pipe_buffer *buf, void *map_data) 194 189 { ··· 208 185 kunmap(buf->page); 209 186 } 210 187 188 + /** 189 + * generic_pipe_buf_steal - attempt to take ownership of a @pipe_buffer 190 + * @pipe: the pipe that the buffer belongs to 191 + * @buf: the buffer to attempt to steal 192 + * 193 + * Description: 194 + * This function attempts to steal the @struct page attached to 195 + * @buf. If successful, this function returns 0 and returns with 196 + * the page locked. The caller may then reuse the page for whatever 197 + * he wishes, the typical use is insertion into a different file 198 + * page cache. 199 + */ 211 200 int generic_pipe_buf_steal(struct pipe_inode_info *pipe, 212 201 struct pipe_buffer *buf) 213 202 { 214 203 struct page *page = buf->page; 215 204 205 + /* 206 + * A reference of one is golden, that means that the owner of this 207 + * page is the only one holding a reference to it. lock the page 208 + * and return OK. 209 + */ 216 210 if (page_count(page) == 1) { 217 211 lock_page(page); 218 212 return 0; ··· 238 198 return 1; 239 199 } 240 200 241 - void generic_pipe_buf_get(struct pipe_inode_info *info, struct pipe_buffer *buf) 201 + /** 202 + * generic_pipe_buf_get - get a reference to a @struct pipe_buffer 203 + * @pipe: the pipe that the buffer belongs to 204 + * @buf: the buffer to get a reference to 205 + * 206 + * Description: 207 + * This function grabs an extra reference to @buf. It's used in 208 + * in the tee() system call, when we duplicate the buffers in one 209 + * pipe into another. 210 + */ 211 + void generic_pipe_buf_get(struct pipe_inode_info *pipe, struct pipe_buffer *buf) 242 212 { 243 213 page_cache_get(buf->page); 244 214 } 245 215 216 + /** 217 + * generic_pipe_buf_confirm - verify contents of the pipe buffer 218 + * @pipe: the pipe that the buffer belongs to 219 + * @buf: the buffer to confirm 220 + * 221 + * Description: 222 + * This function does nothing, because the generic pipe code uses 223 + * pages that are always good when inserted into the pipe. 224 + */ 246 225 int generic_pipe_buf_confirm(struct pipe_inode_info *info, 247 226 struct pipe_buffer *buf) 248 227 {
+4
fs/splice.c
··· 85 85 buf->flags &= ~PIPE_BUF_FLAG_LRU; 86 86 } 87 87 88 + /* 89 + * Check whether the contents of buf is OK to access. Since the content 90 + * is a page cache page, IO may be in flight. 91 + */ 88 92 static int page_cache_pipe_buf_confirm(struct pipe_inode_info *pipe, 89 93 struct pipe_buffer *buf) 90 94 {
+76 -1
include/linux/pipe_fs_i.h
··· 9 9 #define PIPE_BUF_FLAG_ATOMIC 0x02 /* was atomically mapped */ 10 10 #define PIPE_BUF_FLAG_GIFT 0x04 /* page is a gift */ 11 11 12 + /** 13 + * struct pipe_buffer - a linux kernel pipe buffer 14 + * @page: the page containing the data for the pipe buffer 15 + * @offset: offset of data inside the @page 16 + * @len: length of data inside the @page 17 + * @ops: operations associated with this buffer. See @pipe_buf_operations. 18 + * @flags: pipe buffer flags. See above. 19 + * @private: private data owned by the ops. 20 + **/ 12 21 struct pipe_buffer { 13 22 struct page *page; 14 23 unsigned int offset, len; ··· 26 17 unsigned long private; 27 18 }; 28 19 20 + /** 21 + * struct pipe_inode_info - a linux kernel pipe 22 + * @wait: reader/writer wait point in case of empty/full pipe 23 + * @nrbufs: the number of non-empty pipe buffers in this pipe 24 + * @curbuf: the current pipe buffer entry 25 + * @tmp_page: cached released page 26 + * @readers: number of current readers of this pipe 27 + * @writers: number of current writers of this pipe 28 + * @waiting_writers: number of writers blocked waiting for room 29 + * @r_counter: reader counter 30 + * @w_counter: writer counter 31 + * @fasync_readers: reader side fasync 32 + * @fasync_writers: writer side fasync 33 + * @inode: inode this pipe is attached to 34 + * @bufs: the circular array of pipe buffers 35 + **/ 29 36 struct pipe_inode_info { 30 37 wait_queue_head_t wait; 31 38 unsigned int nrbufs, curbuf; ··· 68 43 * ->unmap() 69 44 * 70 45 * That is, ->map() must be called on a confirmed buffer, 71 - * same goes for ->steal(). 46 + * same goes for ->steal(). See below for the meaning of each 47 + * operation. Also see kerneldoc in fs/pipe.c for the pipe 48 + * and generic variants of these hooks. 72 49 */ 73 50 struct pipe_buf_operations { 51 + /* 52 + * This is set to 1, if the generic pipe read/write may coalesce 53 + * data into an existing buffer. If this is set to 0, a new pipe 54 + * page segment is always used for new data. 55 + */ 74 56 int can_merge; 57 + 58 + /* 59 + * ->map() returns a virtual address mapping of the pipe buffer. 60 + * The last integer flag reflects whether this should be an atomic 61 + * mapping or not. The atomic map is faster, however you can't take 62 + * page faults before calling ->unmap() again. So if you need to eg 63 + * access user data through copy_to/from_user(), then you must get 64 + * a non-atomic map. ->map() uses the KM_USER0 atomic slot for 65 + * atomic maps, so you can't map more than one pipe_buffer at once 66 + * and you have to be careful if mapping another page as source 67 + * or destination for a copy (IOW, it has to use something else 68 + * than KM_USER0). 69 + */ 75 70 void * (*map)(struct pipe_inode_info *, struct pipe_buffer *, int); 71 + 72 + /* 73 + * Undoes ->map(), finishes the virtual mapping of the pipe buffer. 74 + */ 76 75 void (*unmap)(struct pipe_inode_info *, struct pipe_buffer *, void *); 76 + 77 + /* 78 + * ->confirm() verifies that the data in the pipe buffer is there 79 + * and that the contents are good. If the pages in the pipe belong 80 + * to a file system, we may need to wait for IO completion in this 81 + * hook. Returns 0 for good, or a negative error value in case of 82 + * error. 83 + */ 77 84 int (*confirm)(struct pipe_inode_info *, struct pipe_buffer *); 85 + 86 + /* 87 + * When the contents of this pipe buffer has been completely 88 + * consumed by a reader, ->release() is called. 89 + */ 78 90 void (*release)(struct pipe_inode_info *, struct pipe_buffer *); 91 + 92 + /* 93 + * Attempt to take ownership of the pipe buffer and its contents. 94 + * ->steal() returns 0 for success, in which case the contents 95 + * of the pipe (the buf->page) is locked and now completely owned 96 + * by the caller. The page may then be transferred to a different 97 + * mapping, the most often used case is insertion into different 98 + * file address space cache. 99 + */ 79 100 int (*steal)(struct pipe_inode_info *, struct pipe_buffer *); 101 + 102 + /* 103 + * Get a reference to the pipe buffer. 104 + */ 80 105 void (*get)(struct pipe_inode_info *, struct pipe_buffer *); 81 106 }; 82 107