diff options
Diffstat (limited to 'fs/pipe.c')
-rw-r--r-- | fs/pipe.c | 61 |
1 files changed, 60 insertions, 1 deletions
@@ -164,6 +164,20 @@ static void anon_pipe_buf_release(struct pipe_inode_info *pipe, | |||
164 | page_cache_release(page); | 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 | void *generic_pipe_buf_map(struct pipe_inode_info *pipe, | 181 | void *generic_pipe_buf_map(struct pipe_inode_info *pipe, |
168 | struct pipe_buffer *buf, int atomic) | 182 | struct pipe_buffer *buf, int atomic) |
169 | { | 183 | { |
@@ -175,6 +189,15 @@ void *generic_pipe_buf_map(struct pipe_inode_info *pipe, | |||
175 | return kmap(buf->page); | 189 | return kmap(buf->page); |
176 | } | 190 | } |
177 | 191 | ||
192 | /** | ||
193 | * generic_pipe_buf_unmap - unmap a previously mapped pipe buffer | ||
194 | * @pipe: the pipe that the buffer belongs to | ||
195 | * @buf: the buffer that should be unmapped | ||
196 | * @map_data: the data that the mapping function returned | ||
197 | * | ||
198 | * Description: | ||
199 | * This function undoes the mapping that ->map() provided. | ||
200 | */ | ||
178 | void generic_pipe_buf_unmap(struct pipe_inode_info *pipe, | 201 | void generic_pipe_buf_unmap(struct pipe_inode_info *pipe, |
179 | struct pipe_buffer *buf, void *map_data) | 202 | struct pipe_buffer *buf, void *map_data) |
180 | { | 203 | { |
@@ -185,11 +208,28 @@ void generic_pipe_buf_unmap(struct pipe_inode_info *pipe, | |||
185 | kunmap(buf->page); | 208 | kunmap(buf->page); |
186 | } | 209 | } |
187 | 210 | ||
211 | /** | ||
212 | * generic_pipe_buf_steal - attempt to take ownership of a @pipe_buffer | ||
213 | * @pipe: the pipe that the buffer belongs to | ||
214 | * @buf: the buffer to attempt to steal | ||
215 | * | ||
216 | * Description: | ||
217 | * This function attempts to steal the @struct page attached to | ||
218 | * @buf. If successful, this function returns 0 and returns with | ||
219 | * the page locked. The caller may then reuse the page for whatever | ||
220 | * he wishes, the typical use is insertion into a different file | ||
221 | * page cache. | ||
222 | */ | ||
188 | int generic_pipe_buf_steal(struct pipe_inode_info *pipe, | 223 | int generic_pipe_buf_steal(struct pipe_inode_info *pipe, |
189 | struct pipe_buffer *buf) | 224 | struct pipe_buffer *buf) |
190 | { | 225 | { |
191 | struct page *page = buf->page; | 226 | struct page *page = buf->page; |
192 | 227 | ||
228 | /* | ||
229 | * A reference of one is golden, that means that the owner of this | ||
230 | * page is the only one holding a reference to it. lock the page | ||
231 | * and return OK. | ||
232 | */ | ||
193 | if (page_count(page) == 1) { | 233 | if (page_count(page) == 1) { |
194 | lock_page(page); | 234 | lock_page(page); |
195 | return 0; | 235 | return 0; |
@@ -198,11 +238,30 @@ int generic_pipe_buf_steal(struct pipe_inode_info *pipe, | |||
198 | return 1; | 238 | return 1; |
199 | } | 239 | } |
200 | 240 | ||
201 | void generic_pipe_buf_get(struct pipe_inode_info *info, struct pipe_buffer *buf) | 241 | /** |
242 | * generic_pipe_buf_get - get a reference to a @struct pipe_buffer | ||
243 | * @pipe: the pipe that the buffer belongs to | ||
244 | * @buf: the buffer to get a reference to | ||
245 | * | ||
246 | * Description: | ||
247 | * This function grabs an extra reference to @buf. It's used in | ||
248 | * in the tee() system call, when we duplicate the buffers in one | ||
249 | * pipe into another. | ||
250 | */ | ||
251 | void generic_pipe_buf_get(struct pipe_inode_info *pipe, struct pipe_buffer *buf) | ||
202 | { | 252 | { |
203 | page_cache_get(buf->page); | 253 | page_cache_get(buf->page); |
204 | } | 254 | } |
205 | 255 | ||
256 | /** | ||
257 | * generic_pipe_buf_confirm - verify contents of the pipe buffer | ||
258 | * @pipe: the pipe that the buffer belongs to | ||
259 | * @buf: the buffer to confirm | ||
260 | * | ||
261 | * Description: | ||
262 | * This function does nothing, because the generic pipe code uses | ||
263 | * pages that are always good when inserted into the pipe. | ||
264 | */ | ||
206 | int generic_pipe_buf_confirm(struct pipe_inode_info *info, | 265 | int generic_pipe_buf_confirm(struct pipe_inode_info *info, |
207 | struct pipe_buffer *buf) | 266 | struct pipe_buffer *buf) |
208 | { | 267 | { |