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.
45 * here if set to avoid blocking other users of this pipe if splice is
59 * Attempt to steal a page from a pipe buffer. This should perhaps go into
64 static bool page_cache_pipe_buf_try_steal(struct pipe_inode_info *pipe, in page_cache_pipe_buf_try_steal() argument
108 static void page_cache_pipe_buf_release(struct pipe_inode_info *pipe, in page_cache_pipe_buf_release() argument
119 static int page_cache_pipe_buf_confirm(struct pipe_inode_info *pipe, in page_cache_pipe_buf_confirm() argument
162 static bool user_page_pipe_buf_try_steal(struct pipe_inode_info *pipe, in user_page_pipe_buf_try_steal() argument
169 return generic_pipe_buf_try_steal(pipe, buf); in user_page_pipe_buf_try_steal()
178 static void wakeup_pipe_readers(struct pipe_inode_info *pipe) in wakeup_pipe_readers() argument
181 if (waitqueue_active(&pipe->rd_wait)) in wakeup_pipe_readers()
182 wake_up_interruptible(&pipe->rd_wait); in wakeup_pipe_readers()
183 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN); in wakeup_pipe_readers()
187 * splice_to_pipe - fill passed data into a pipe
188 * @pipe: pipe to fill
194 * function will link that data to the pipe.
197 ssize_t splice_to_pipe(struct pipe_inode_info *pipe, in splice_to_pipe() argument
201 unsigned int tail = pipe->tail; in splice_to_pipe()
202 unsigned int head = pipe->head; in splice_to_pipe()
203 unsigned int mask = pipe->ring_size - 1; in splice_to_pipe()
209 if (unlikely(!pipe->readers)) { in splice_to_pipe()
215 while (!pipe_full(head, tail, pipe->max_usage)) { in splice_to_pipe()
216 struct pipe_buffer *buf = &pipe->bufs[head & mask]; in splice_to_pipe()
226 pipe->head = head; in splice_to_pipe()
245 ssize_t add_to_pipe(struct pipe_inode_info *pipe, struct pipe_buffer *buf) in add_to_pipe() argument
247 unsigned int head = pipe->head; in add_to_pipe()
248 unsigned int tail = pipe->tail; in add_to_pipe()
249 unsigned int mask = pipe->ring_size - 1; in add_to_pipe()
252 if (unlikely(!pipe->readers)) { in add_to_pipe()
255 } else if (pipe_full(head, tail, pipe->max_usage)) { in add_to_pipe()
258 pipe->bufs[head & mask] = *buf; in add_to_pipe()
259 pipe->head = head + 1; in add_to_pipe()
262 pipe_buf_release(pipe, buf); in add_to_pipe()
271 int splice_grow_spd(const struct pipe_inode_info *pipe, struct splice_pipe_desc *spd) in splice_grow_spd() argument
273 unsigned int max_usage = READ_ONCE(pipe->max_usage); in splice_grow_spd()
301 * copy_splice_read - Copy data from a file and splice the copy into a pipe
304 * @pipe: The pipe to splice into
309 * amount of data (but limited by the remaining pipe capacity), passes it to
311 * the pipe.
315 * to be read; -EAGAIN will be returned if the pipe had no space, and some
317 * if the pipe has insufficient space, we reach the end of the data or we hit a
321 struct pipe_inode_info *pipe, in copy_splice_read() argument
332 /* Work out how much data we can actually add into the pipe */ in copy_splice_read()
333 used = pipe_occupancy(pipe->head, pipe->tail); in copy_splice_read()
334 npages = max_t(ssize_t, pipe->max_usage - used, 0); in copy_splice_read()
382 /* Push the remaining pages into the pipe. */ in copy_splice_read()
385 struct pipe_buffer *buf = pipe_head_buf(pipe); in copy_splice_read()
394 pipe->head++; in copy_splice_read()
409 /* Pipe buffer operations for a socket and similar. */
416 static void wakeup_pipe_writers(struct pipe_inode_info *pipe) in wakeup_pipe_writers() argument
419 if (waitqueue_active(&pipe->wr_wait)) in wakeup_pipe_writers()
420 wake_up_interruptible(&pipe->wr_wait); in wakeup_pipe_writers()
421 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT); in wakeup_pipe_writers()
425 * splice_from_pipe_feed - feed available data from a pipe to a file
426 * @pipe: pipe to splice from
431 * This function loops over the pipe and calls @actor to do the
434 * the pipe or if the requested number of bytes (@sd->total_len)
436 * pipe needs to be filled with more data, zero if the required
441 * locking is required around copying the pipe buffers to the
444 static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd, in splice_from_pipe_feed() argument
447 unsigned int head = pipe->head; in splice_from_pipe_feed()
448 unsigned int tail = pipe->tail; in splice_from_pipe_feed()
449 unsigned int mask = pipe->ring_size - 1; in splice_from_pipe_feed()
453 struct pipe_buffer *buf = &pipe->bufs[tail & mask]; in splice_from_pipe_feed()
459 ret = pipe_buf_confirm(pipe, buf); in splice_from_pipe_feed()
466 ret = actor(pipe, buf, sd); in splice_from_pipe_feed()
479 pipe_buf_release(pipe, buf); in splice_from_pipe_feed()
481 pipe->tail = tail; in splice_from_pipe_feed()
482 if (pipe->files) in splice_from_pipe_feed()
493 /* We know we have a pipe buffer, but maybe it's empty? */
494 static inline bool eat_empty_buffer(struct pipe_inode_info *pipe) in eat_empty_buffer() argument
496 unsigned int tail = pipe->tail; in eat_empty_buffer()
497 unsigned int mask = pipe->ring_size - 1; in eat_empty_buffer()
498 struct pipe_buffer *buf = &pipe->bufs[tail & mask]; in eat_empty_buffer()
501 pipe_buf_release(pipe, buf); in eat_empty_buffer()
502 pipe->tail = tail+1; in eat_empty_buffer()
511 * @pipe: pipe to splice from
516 * value (one) if pipe buffers are available. It will return zero
519 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd) in splice_from_pipe_next() argument
529 while (pipe_empty(pipe->head, pipe->tail)) { in splice_from_pipe_next()
530 if (!pipe->writers) in splice_from_pipe_next()
543 wakeup_pipe_writers(pipe); in splice_from_pipe_next()
547 pipe_wait_readable(pipe); in splice_from_pipe_next()
550 if (eat_empty_buffer(pipe)) in splice_from_pipe_next()
557 * splice_from_pipe_begin - start splicing from pipe
572 * splice_from_pipe_end - finish splicing from pipe
573 * @pipe: pipe to splice from
577 * This function will wake up pipe writers if necessary. It should
581 static void splice_from_pipe_end(struct pipe_inode_info *pipe, struct splice_desc *sd) in splice_from_pipe_end() argument
584 wakeup_pipe_writers(pipe); in splice_from_pipe_end()
588 * __splice_from_pipe - splice data from a pipe to given actor
589 * @pipe: pipe to splice from
594 * This function does little more than loop over the pipe and call
600 ssize_t __splice_from_pipe(struct pipe_inode_info *pipe, struct splice_desc *sd, in __splice_from_pipe() argument
608 ret = splice_from_pipe_next(pipe, sd); in __splice_from_pipe()
610 ret = splice_from_pipe_feed(pipe, sd, actor); in __splice_from_pipe()
612 splice_from_pipe_end(pipe, sd); in __splice_from_pipe()
619 * splice_from_pipe - splice data from a pipe to a file
620 * @pipe: pipe to splice from
628 * See __splice_from_pipe. This function locks the pipe inode,
632 ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out, in splice_from_pipe() argument
644 pipe_lock(pipe); in splice_from_pipe()
645 ret = __splice_from_pipe(pipe, &sd, actor); in splice_from_pipe()
646 pipe_unlock(pipe); in splice_from_pipe()
652 * iter_file_splice_write - splice data from a pipe to a file
653 * @pipe: pipe info
661 * the given pipe inode to the given file.
666 iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, in iter_file_splice_write() argument
675 int nbufs = pipe->max_usage; in iter_file_splice_write()
683 pipe_lock(pipe); in iter_file_splice_write()
692 ret = splice_from_pipe_next(pipe, &sd); in iter_file_splice_write()
696 if (unlikely(nbufs < pipe->max_usage)) { in iter_file_splice_write()
698 nbufs = pipe->max_usage; in iter_file_splice_write()
707 head = pipe->head; in iter_file_splice_write()
708 tail = pipe->tail; in iter_file_splice_write()
709 mask = pipe->ring_size - 1; in iter_file_splice_write()
714 struct pipe_buffer *buf = &pipe->bufs[tail & mask]; in iter_file_splice_write()
722 ret = pipe_buf_confirm(pipe, buf); in iter_file_splice_write()
745 tail = pipe->tail; in iter_file_splice_write()
747 struct pipe_buffer *buf = &pipe->bufs[tail & mask]; in iter_file_splice_write()
751 pipe_buf_release(pipe, buf); in iter_file_splice_write()
753 pipe->tail = tail; in iter_file_splice_write()
754 if (pipe->files) in iter_file_splice_write()
765 splice_from_pipe_end(pipe, &sd); in iter_file_splice_write()
767 pipe_unlock(pipe); in iter_file_splice_write()
779 * splice_to_socket - splice data from a pipe to a socket
780 * @pipe: pipe to splice from
787 * Will send @len bytes from the pipe to a network socket. No data copying
791 ssize_t splice_to_socket(struct pipe_inode_info *pipe, struct file *out, in splice_to_socket() argument
801 pipe_lock(pipe); in splice_to_socket()
815 while (pipe_empty(pipe->head, pipe->tail)) { in splice_to_socket()
817 if (!pipe->writers) in splice_to_socket()
832 wakeup_pipe_writers(pipe); in splice_to_socket()
836 pipe_wait_readable(pipe); in splice_to_socket()
839 head = pipe->head; in splice_to_socket()
840 tail = pipe->tail; in splice_to_socket()
841 mask = pipe->ring_size - 1; in splice_to_socket()
844 struct pipe_buffer *buf = &pipe->bufs[tail & mask]; in splice_to_socket()
854 ret = pipe_buf_confirm(pipe, buf); in splice_to_socket()
874 if (remain && pipe_occupancy(pipe->head, tail) > 0) in splice_to_socket()
887 tail = pipe->tail; in splice_to_socket()
889 struct pipe_buffer *buf = &pipe->bufs[tail & mask]; in splice_to_socket()
897 pipe_buf_release(pipe, buf); in splice_to_socket()
902 if (tail != pipe->tail) { in splice_to_socket()
903 pipe->tail = tail; in splice_to_socket()
904 if (pipe->files) in splice_to_socket()
910 pipe_unlock(pipe); in splice_to_socket()
912 wakeup_pipe_writers(pipe); in splice_to_socket()
926 * Attempt to initiate a splice from pipe to file.
928 static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, in do_splice_from() argument
933 return out->f_op->splice_write(pipe, out, ppos, len, flags); in do_splice_from()
948 * vfs_splice_read - Read data from a file and splice it into a pipe
951 * @pipe: Pipe to splice to
955 * Splice the requested amount of data from the input file to the pipe. This
956 * is synchronous as the caller must hold the pipe lock across the entire
963 struct pipe_inode_info *pipe, size_t len, in vfs_splice_read() argument
974 /* Don't try to read more the pipe has space for. */ in vfs_splice_read()
975 p_space = pipe->max_usage - pipe_occupancy(pipe->head, pipe->tail); in vfs_splice_read()
989 * buffer, copy into it and splice that into the pipe. in vfs_splice_read()
992 return copy_splice_read(in, ppos, pipe, len, flags); in vfs_splice_read()
993 return in->f_op->splice_read(in, ppos, pipe, len, flags); in vfs_splice_read()
1005 * points, without requiring an explicit pipe. Internally an allocated
1006 * pipe is cached in the process, and reused during the lifetime of
1013 struct pipe_inode_info *pipe; in splice_direct_to_actor() local
1027 * neither in nor out is a pipe, setup an internal pipe attached to in splice_direct_to_actor()
1030 pipe = current->splice_pipe; in splice_direct_to_actor()
1031 if (unlikely(!pipe)) { in splice_direct_to_actor()
1032 pipe = alloc_pipe_info(); in splice_direct_to_actor()
1033 if (!pipe) in splice_direct_to_actor()
1038 * out of the pipe right after the splice_to_pipe(). So set in splice_direct_to_actor()
1041 pipe->readers = 1; in splice_direct_to_actor()
1043 current->splice_pipe = pipe; in splice_direct_to_actor()
1052 /* Don't block on output, we have to drain the direct pipe. */ in splice_direct_to_actor()
1063 WARN_ON_ONCE(!pipe_empty(pipe->head, pipe->tail)); in splice_direct_to_actor()
1069 ret = vfs_splice_read(in, &pos, pipe, len, flags); in splice_direct_to_actor()
1086 * could get stuck data in the internal pipe: in splice_direct_to_actor()
1088 ret = actor(pipe, sd); in splice_direct_to_actor()
1105 pipe->tail = pipe->head = 0; in splice_direct_to_actor()
1121 * the pipe buffers in question: in splice_direct_to_actor()
1123 for (i = 0; i < pipe->ring_size; i++) { in splice_direct_to_actor()
1124 struct pipe_buffer *buf = &pipe->bufs[i]; in splice_direct_to_actor()
1127 pipe_buf_release(pipe, buf); in splice_direct_to_actor()
1137 static int direct_splice_actor(struct pipe_inode_info *pipe, in direct_splice_actor() argument
1142 return do_splice_from(pipe, file, sd->opos, sd->total_len, in direct_splice_actor()
1167 * can splice directly through a process-private pipe.
1202 static int wait_for_space(struct pipe_inode_info *pipe, unsigned flags) in wait_for_space() argument
1205 if (unlikely(!pipe->readers)) { in wait_for_space()
1209 if (!pipe_full(pipe->head, pipe->tail, pipe->max_usage)) in wait_for_space()
1215 pipe_wait_writable(pipe); in wait_for_space()
1383 struct pipe_inode_info *pipe, in iter_to_pipe() argument
1412 ret = add_to_pipe(pipe, &buf); in iter_to_pipe()
1429 static int pipe_to_user(struct pipe_inode_info *pipe, struct pipe_buffer *buf, in pipe_to_user() argument
1443 struct pipe_inode_info *pipe = get_pipe_info(file, true); in vmsplice_to_user() local
1451 if (!pipe) in vmsplice_to_user()
1457 pipe_lock(pipe); in vmsplice_to_user()
1458 ret = __splice_from_pipe(pipe, &sd, pipe_to_user); in vmsplice_to_user()
1459 pipe_unlock(pipe); in vmsplice_to_user()
1469 * vmsplice splices a user address range into a pipe. It can be thought of
1471 * to file). In both cases the output is a pipe, naturally.
1476 struct pipe_inode_info *pipe; in vmsplice_to_pipe() local
1483 pipe = get_pipe_info(file, true); in vmsplice_to_pipe()
1484 if (!pipe) in vmsplice_to_pipe()
1489 pipe_lock(pipe); in vmsplice_to_pipe()
1490 ret = wait_for_space(pipe, flags); in vmsplice_to_pipe()
1492 ret = iter_to_pipe(iter, pipe, buf_flag); in vmsplice_to_pipe()
1493 pipe_unlock(pipe); in vmsplice_to_pipe()
1495 wakeup_pipe_readers(pipe); in vmsplice_to_pipe()
1518 * to a pipe, not the other way around. Splicing from user memory is a simple
1521 * a pipe. The reverse isn't quite as easy, though. There are two possible
1527 * has restriction limitations on both ends of the pipe).
1599 static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags) in ipipe_prep() argument
1604 * Check the pipe occupancy without the inode lock first. This function in ipipe_prep()
1607 if (!pipe_empty(pipe->head, pipe->tail)) in ipipe_prep()
1611 pipe_lock(pipe); in ipipe_prep()
1613 while (pipe_empty(pipe->head, pipe->tail)) { in ipipe_prep()
1618 if (!pipe->writers) in ipipe_prep()
1624 pipe_wait_readable(pipe); in ipipe_prep()
1627 pipe_unlock(pipe); in ipipe_prep()
1635 static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags) in opipe_prep() argument
1640 * Check pipe occupancy without the inode lock first. This function in opipe_prep()
1643 if (!pipe_full(pipe->head, pipe->tail, pipe->max_usage)) in opipe_prep()
1647 pipe_lock(pipe); in opipe_prep()
1649 while (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) { in opipe_prep()
1650 if (!pipe->readers) { in opipe_prep()
1663 pipe_wait_writable(pipe); in opipe_prep()
1666 pipe_unlock(pipe); in opipe_prep()
1696 * grabbing by pipe info address. Otherwise two different processes in splice_pipe_to_pipe()
1724 * pipe is empty or the output pipe is full. in splice_pipe_to_pipe()
1764 * Get a reference to this pipe buffer, in splice_pipe_to_pipe()
1796 * If we put data in the output pipe, wakeup any potential readers. in splice_pipe_to_pipe()
1822 * grabbing by pipe info address. Otherwise two different processes in link_pipe()
1855 * Get a reference to this pipe buffer, in link_pipe()
1887 * If we put data in the output pipe, wakeup any potential readers. in link_pipe()
1897 * any data, it simply references the 'in' pages on the 'out' pipe.