Lines Matching full:pipe
5 * This is the "extended pipe" functionality, where a pipe is used as
6 * an arbitrary in-memory buffer. Think of a pipe as a small kernel
10 * that transfers data buffers to or from a pipe buffer.
41 * Attempt to steal a page from a pipe buffer. This should perhaps go into
46 static bool page_cache_pipe_buf_try_steal(struct pipe_inode_info *pipe, in page_cache_pipe_buf_try_steal() argument
91 static void page_cache_pipe_buf_release(struct pipe_inode_info *pipe, in page_cache_pipe_buf_release() argument
102 static int page_cache_pipe_buf_confirm(struct pipe_inode_info *pipe, in page_cache_pipe_buf_confirm() argument
147 static bool user_page_pipe_buf_try_steal(struct pipe_inode_info *pipe, in user_page_pipe_buf_try_steal() argument
154 return generic_pipe_buf_try_steal(pipe, buf); in user_page_pipe_buf_try_steal()
163 static void wakeup_pipe_readers(struct pipe_inode_info *pipe) in wakeup_pipe_readers() argument
166 if (waitqueue_active(&pipe->rd_wait)) in wakeup_pipe_readers()
167 wake_up_interruptible(&pipe->rd_wait); in wakeup_pipe_readers()
168 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN); in wakeup_pipe_readers()
172 * splice_to_pipe - fill passed data into a pipe
173 * @pipe: pipe to fill
179 * function will link that data to the pipe.
182 ssize_t splice_to_pipe(struct pipe_inode_info *pipe, in splice_to_pipe() argument
186 unsigned int tail = pipe->tail; in splice_to_pipe()
187 unsigned int head = pipe->head; in splice_to_pipe()
188 unsigned int mask = pipe->ring_size - 1; in splice_to_pipe()
194 if (unlikely(!pipe->readers)) { in splice_to_pipe()
200 while (!pipe_full(head, tail, pipe->max_usage)) { in splice_to_pipe()
201 struct pipe_buffer *buf = &pipe->bufs[head & mask]; in splice_to_pipe()
211 pipe->head = head; in splice_to_pipe()
230 ssize_t add_to_pipe(struct pipe_inode_info *pipe, struct pipe_buffer *buf) in add_to_pipe() argument
232 unsigned int head = pipe->head; in add_to_pipe()
233 unsigned int tail = pipe->tail; in add_to_pipe()
234 unsigned int mask = pipe->ring_size - 1; in add_to_pipe()
237 if (unlikely(!pipe->readers)) { in add_to_pipe()
240 } else if (pipe_full(head, tail, pipe->max_usage)) { in add_to_pipe()
243 pipe->bufs[head & mask] = *buf; in add_to_pipe()
244 pipe->head = head + 1; in add_to_pipe()
247 pipe_buf_release(pipe, buf); in add_to_pipe()
256 int splice_grow_spd(const struct pipe_inode_info *pipe, struct splice_pipe_desc *spd) in splice_grow_spd() argument
258 unsigned int max_usage = READ_ONCE(pipe->max_usage); in splice_grow_spd()
286 * generic_file_splice_read - splice data from file to a pipe
289 * @pipe: pipe to splice to
294 * Will read pages from given file and fill them into a pipe. Can be
299 struct pipe_inode_info *pipe, size_t len, in generic_file_splice_read() argument
307 iov_iter_pipe(&to, READ, pipe, len); in generic_file_splice_read()
337 /* Pipe buffer operations for a socket and similar. */
348 static int pipe_to_sendpage(struct pipe_inode_info *pipe, in pipe_to_sendpage() argument
361 pipe_occupancy(pipe->head, pipe->tail) > 1) in pipe_to_sendpage()
368 static void wakeup_pipe_writers(struct pipe_inode_info *pipe) in wakeup_pipe_writers() argument
371 if (waitqueue_active(&pipe->wr_wait)) in wakeup_pipe_writers()
372 wake_up_interruptible(&pipe->wr_wait); in wakeup_pipe_writers()
373 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT); in wakeup_pipe_writers()
377 * splice_from_pipe_feed - feed available data from a pipe to a file
378 * @pipe: pipe to splice from
383 * This function loops over the pipe and calls @actor to do the
386 * the pipe or if the requested number of bytes (@sd->total_len)
388 * pipe needs to be filled with more data, zero if the required
393 * locking is required around copying the pipe buffers to the
396 static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd, in splice_from_pipe_feed() argument
399 unsigned int head = pipe->head; in splice_from_pipe_feed()
400 unsigned int tail = pipe->tail; in splice_from_pipe_feed()
401 unsigned int mask = pipe->ring_size - 1; in splice_from_pipe_feed()
405 struct pipe_buffer *buf = &pipe->bufs[tail & mask]; in splice_from_pipe_feed()
411 ret = pipe_buf_confirm(pipe, buf); in splice_from_pipe_feed()
418 ret = actor(pipe, buf, sd); in splice_from_pipe_feed()
431 pipe_buf_release(pipe, buf); in splice_from_pipe_feed()
433 pipe->tail = tail; in splice_from_pipe_feed()
434 if (pipe->files) in splice_from_pipe_feed()
445 /* We know we have a pipe buffer, but maybe it's empty? */
446 static inline bool eat_empty_buffer(struct pipe_inode_info *pipe) in eat_empty_buffer() argument
448 unsigned int tail = pipe->tail; in eat_empty_buffer()
449 unsigned int mask = pipe->ring_size - 1; in eat_empty_buffer()
450 struct pipe_buffer *buf = &pipe->bufs[tail & mask]; in eat_empty_buffer()
453 pipe_buf_release(pipe, buf); in eat_empty_buffer()
454 pipe->tail = tail+1; in eat_empty_buffer()
463 * @pipe: pipe to splice from
468 * value (one) if pipe buffers are available. It will return zero
471 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd) in splice_from_pipe_next() argument
481 while (pipe_empty(pipe->head, pipe->tail)) { in splice_from_pipe_next()
482 if (!pipe->writers) in splice_from_pipe_next()
495 wakeup_pipe_writers(pipe); in splice_from_pipe_next()
499 pipe_wait_readable(pipe); in splice_from_pipe_next()
502 if (eat_empty_buffer(pipe)) in splice_from_pipe_next()
509 * splice_from_pipe_begin - start splicing from pipe
524 * splice_from_pipe_end - finish splicing from pipe
525 * @pipe: pipe to splice from
529 * This function will wake up pipe writers if necessary. It should
533 static void splice_from_pipe_end(struct pipe_inode_info *pipe, struct splice_desc *sd) in splice_from_pipe_end() argument
536 wakeup_pipe_writers(pipe); in splice_from_pipe_end()
540 * __splice_from_pipe - splice data from a pipe to given actor
541 * @pipe: pipe to splice from
546 * This function does little more than loop over the pipe and call
552 ssize_t __splice_from_pipe(struct pipe_inode_info *pipe, struct splice_desc *sd, in __splice_from_pipe() argument
560 ret = splice_from_pipe_next(pipe, sd); in __splice_from_pipe()
562 ret = splice_from_pipe_feed(pipe, sd, actor); in __splice_from_pipe()
564 splice_from_pipe_end(pipe, sd); in __splice_from_pipe()
571 * splice_from_pipe - splice data from a pipe to a file
572 * @pipe: pipe to splice from
580 * See __splice_from_pipe. This function locks the pipe inode,
584 ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out, in splice_from_pipe() argument
596 pipe_lock(pipe); in splice_from_pipe()
597 ret = __splice_from_pipe(pipe, &sd, actor); in splice_from_pipe()
598 pipe_unlock(pipe); in splice_from_pipe()
604 * iter_file_splice_write - splice data from a pipe to a file
605 * @pipe: pipe info
613 * the given pipe inode to the given file.
618 iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, in iter_file_splice_write() argument
627 int nbufs = pipe->max_usage; in iter_file_splice_write()
635 pipe_lock(pipe); in iter_file_splice_write()
644 ret = splice_from_pipe_next(pipe, &sd); in iter_file_splice_write()
648 if (unlikely(nbufs < pipe->max_usage)) { in iter_file_splice_write()
650 nbufs = pipe->max_usage; in iter_file_splice_write()
659 head = pipe->head; in iter_file_splice_write()
660 tail = pipe->tail; in iter_file_splice_write()
661 mask = pipe->ring_size - 1; in iter_file_splice_write()
666 struct pipe_buffer *buf = &pipe->bufs[tail & mask]; in iter_file_splice_write()
672 ret = pipe_buf_confirm(pipe, buf); in iter_file_splice_write()
695 tail = pipe->tail; in iter_file_splice_write()
697 struct pipe_buffer *buf = &pipe->bufs[tail & mask]; in iter_file_splice_write()
701 pipe_buf_release(pipe, buf); in iter_file_splice_write()
703 pipe->tail = tail; in iter_file_splice_write()
704 if (pipe->files) in iter_file_splice_write()
715 splice_from_pipe_end(pipe, &sd); in iter_file_splice_write()
717 pipe_unlock(pipe); in iter_file_splice_write()
728 * generic_splice_sendpage - splice data from a pipe to a socket
729 * @pipe: pipe to splice from
736 * Will send @len bytes from the pipe to a network socket. No data copying
740 ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe, struct file *out, in generic_splice_sendpage() argument
743 return splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_sendpage); in generic_splice_sendpage()
757 * Attempt to initiate a splice from pipe to file.
759 static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, in do_splice_from() argument
764 return out->f_op->splice_write(pipe, out, ppos, len, flags); in do_splice_from()
768 * Attempt to initiate a splice from a file to a pipe.
771 struct pipe_inode_info *pipe, size_t len, in do_splice_to() argument
788 return in->f_op->splice_read(in, ppos, pipe, len, flags); in do_splice_to()
799 * points, without requiring an explicit pipe. Internally an allocated
800 * pipe is cached in the process, and reused during the lifetime of
807 struct pipe_inode_info *pipe; in splice_direct_to_actor() local
823 * neither in nor out is a pipe, setup an internal pipe attached to in splice_direct_to_actor()
826 pipe = current->splice_pipe; in splice_direct_to_actor()
827 if (unlikely(!pipe)) { in splice_direct_to_actor()
828 pipe = alloc_pipe_info(); in splice_direct_to_actor()
829 if (!pipe) in splice_direct_to_actor()
834 * out of the pipe right after the splice_to_pipe(). So set in splice_direct_to_actor()
837 pipe->readers = 1; in splice_direct_to_actor()
839 current->splice_pipe = pipe; in splice_direct_to_actor()
851 * Don't block on output, we have to drain the direct pipe. in splice_direct_to_actor()
856 WARN_ON_ONCE(!pipe_empty(pipe->head, pipe->tail)); in splice_direct_to_actor()
863 /* Don't try to read more the pipe has space for. */ in splice_direct_to_actor()
864 p_space = pipe->max_usage - in splice_direct_to_actor()
865 pipe_occupancy(pipe->head, pipe->tail); in splice_direct_to_actor()
867 ret = do_splice_to(in, &pos, pipe, read_len, flags); in splice_direct_to_actor()
886 * could get stuck data in the internal pipe: in splice_direct_to_actor()
888 ret = actor(pipe, sd); in splice_direct_to_actor()
905 pipe->tail = pipe->head = 0; in splice_direct_to_actor()
912 * the pipe buffers in question: in splice_direct_to_actor()
914 for (i = 0; i < pipe->ring_size; i++) { in splice_direct_to_actor()
915 struct pipe_buffer *buf = &pipe->bufs[i]; in splice_direct_to_actor()
918 pipe_buf_release(pipe, buf); in splice_direct_to_actor()
928 static int direct_splice_actor(struct pipe_inode_info *pipe, in direct_splice_actor() argument
933 return do_splice_from(pipe, file, sd->opos, sd->total_len, in direct_splice_actor()
950 * can splice directly through a process-private pipe.
984 static int wait_for_space(struct pipe_inode_info *pipe, unsigned flags) in wait_for_space() argument
987 if (unlikely(!pipe->readers)) { in wait_for_space()
991 if (!pipe_full(pipe->head, pipe->tail, pipe->max_usage)) in wait_for_space()
997 pipe_wait_writable(pipe); in wait_for_space()
1089 /* Don't try to read more the pipe has space for. */ in do_splice()
1150 struct pipe_inode_info *pipe, in iter_to_pipe() argument
1179 ret = add_to_pipe(pipe, &buf); in iter_to_pipe()
1195 static int pipe_to_user(struct pipe_inode_info *pipe, struct pipe_buffer *buf, in pipe_to_user() argument
1209 struct pipe_inode_info *pipe = get_pipe_info(file, true); in vmsplice_to_user() local
1217 if (!pipe) in vmsplice_to_user()
1221 pipe_lock(pipe); in vmsplice_to_user()
1222 ret = __splice_from_pipe(pipe, &sd, pipe_to_user); in vmsplice_to_user()
1223 pipe_unlock(pipe); in vmsplice_to_user()
1230 * vmsplice splices a user address range into a pipe. It can be thought of
1232 * to file). In both cases the output is a pipe, naturally.
1237 struct pipe_inode_info *pipe; in vmsplice_to_pipe() local
1244 pipe = get_pipe_info(file, true); in vmsplice_to_pipe()
1245 if (!pipe) in vmsplice_to_pipe()
1248 pipe_lock(pipe); in vmsplice_to_pipe()
1249 ret = wait_for_space(pipe, flags); in vmsplice_to_pipe()
1251 ret = iter_to_pipe(iter, pipe, buf_flag); in vmsplice_to_pipe()
1252 pipe_unlock(pipe); in vmsplice_to_pipe()
1254 wakeup_pipe_readers(pipe); in vmsplice_to_pipe()
1275 * to a pipe, not the other way around. Splicing from user memory is a simple
1278 * a pipe. The reverse isn't quite as easy, though. There are two possible
1284 * has restriction limitations on both ends of the pipe).
1356 static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags) in ipipe_prep() argument
1361 * Check the pipe occupancy without the inode lock first. This function in ipipe_prep()
1364 if (!pipe_empty(pipe->head, pipe->tail)) in ipipe_prep()
1368 pipe_lock(pipe); in ipipe_prep()
1370 while (pipe_empty(pipe->head, pipe->tail)) { in ipipe_prep()
1375 if (!pipe->writers) in ipipe_prep()
1381 pipe_wait_readable(pipe); in ipipe_prep()
1384 pipe_unlock(pipe); in ipipe_prep()
1392 static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags) in opipe_prep() argument
1397 * Check pipe occupancy without the inode lock first. This function in opipe_prep()
1400 if (!pipe_full(pipe->head, pipe->tail, pipe->max_usage)) in opipe_prep()
1404 pipe_lock(pipe); in opipe_prep()
1406 while (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) { in opipe_prep()
1407 if (!pipe->readers) { in opipe_prep()
1420 pipe_wait_writable(pipe); in opipe_prep()
1423 pipe_unlock(pipe); in opipe_prep()
1453 * grabbing by pipe info address. Otherwise two different processes in splice_pipe_to_pipe()
1481 * pipe is empty or the output pipe is full. in splice_pipe_to_pipe()
1521 * Get a reference to this pipe buffer, in splice_pipe_to_pipe()
1553 * If we put data in the output pipe, wakeup any potential readers. in splice_pipe_to_pipe()
1579 * grabbing by pipe info address. Otherwise two different processes in link_pipe()
1612 * Get a reference to this pipe buffer, in link_pipe()
1644 * If we put data in the output pipe, wakeup any potential readers. in link_pipe()
1654 * any data, it simply references the 'in' pages on the 'out' pipe.