Lines Matching refs: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,
108 static void page_cache_pipe_buf_release(struct pipe_inode_info *pipe,
119 static int page_cache_pipe_buf_confirm(struct pipe_inode_info *pipe,
162 static bool user_page_pipe_buf_try_steal(struct pipe_inode_info *pipe,
169 return generic_pipe_buf_try_steal(pipe, buf);
178 static void wakeup_pipe_readers(struct pipe_inode_info *pipe)
181 if (waitqueue_active(&pipe->rd_wait))
182 wake_up_interruptible(&pipe->rd_wait);
183 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
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,
201 unsigned int tail = pipe->tail;
202 unsigned int head = pipe->head;
203 unsigned int mask = pipe->ring_size - 1;
209 if (unlikely(!pipe->readers)) {
215 while (!pipe_full(head, tail, pipe->max_usage)) {
216 struct pipe_buffer *buf = &pipe->bufs[head & mask];
226 pipe->head = head;
245 ssize_t add_to_pipe(struct pipe_inode_info *pipe, struct pipe_buffer *buf)
247 unsigned int head = pipe->head;
248 unsigned int tail = pipe->tail;
249 unsigned int mask = pipe->ring_size - 1;
252 if (unlikely(!pipe->readers)) {
255 } else if (pipe_full(head, tail, pipe->max_usage)) {
258 pipe->bufs[head & mask] = *buf;
259 pipe->head = head + 1;
262 pipe_buf_release(pipe, buf);
271 int splice_grow_spd(const struct pipe_inode_info *pipe, struct splice_pipe_desc *spd)
273 unsigned int max_usage = READ_ONCE(pipe->max_usage);
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,
332 /* Work out how much data we can actually add into the pipe */
333 used = pipe_occupancy(pipe->head, pipe->tail);
334 npages = max_t(ssize_t, pipe->max_usage - used, 0);
382 /* Push the remaining pages into the pipe. */
385 struct pipe_buffer *buf = pipe_head_buf(pipe);
394 pipe->head++;
416 static void wakeup_pipe_writers(struct pipe_inode_info *pipe)
419 if (waitqueue_active(&pipe->wr_wait))
420 wake_up_interruptible(&pipe->wr_wait);
421 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
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,
447 unsigned int head = pipe->head;
448 unsigned int tail = pipe->tail;
449 unsigned int mask = pipe->ring_size - 1;
453 struct pipe_buffer *buf = &pipe->bufs[tail & mask];
459 ret = pipe_buf_confirm(pipe, buf);
466 ret = actor(pipe, buf, sd);
479 pipe_buf_release(pipe, buf);
481 pipe->tail = tail;
482 if (pipe->files)
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)
496 unsigned int tail = pipe->tail;
497 unsigned int mask = pipe->ring_size - 1;
498 struct pipe_buffer *buf = &pipe->bufs[tail & mask];
501 pipe_buf_release(pipe, buf);
502 pipe->tail = tail+1;
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)
529 while (pipe_empty(pipe->head, pipe->tail)) {
530 if (!pipe->writers)
543 wakeup_pipe_writers(pipe);
547 pipe_wait_readable(pipe);
550 if (eat_empty_buffer(pipe))
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)
584 wakeup_pipe_writers(pipe);
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,
608 ret = splice_from_pipe_next(pipe, sd);
610 ret = splice_from_pipe_feed(pipe, sd, actor);
612 splice_from_pipe_end(pipe, sd);
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,
644 pipe_lock(pipe);
645 ret = __splice_from_pipe(pipe, &sd, actor);
646 pipe_unlock(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,
675 int nbufs = pipe->max_usage;
683 pipe_lock(pipe);
692 ret = splice_from_pipe_next(pipe, &sd);
696 if (unlikely(nbufs < pipe->max_usage)) {
698 nbufs = pipe->max_usage;
707 head = pipe->head;
708 tail = pipe->tail;
709 mask = pipe->ring_size - 1;
714 struct pipe_buffer *buf = &pipe->bufs[tail & mask];
722 ret = pipe_buf_confirm(pipe, buf);
745 tail = pipe->tail;
747 struct pipe_buffer *buf = &pipe->bufs[tail & mask];
751 pipe_buf_release(pipe, buf);
753 pipe->tail = tail;
754 if (pipe->files)
765 splice_from_pipe_end(pipe, &sd);
767 pipe_unlock(pipe);
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,
801 pipe_lock(pipe);
815 while (pipe_empty(pipe->head, pipe->tail)) {
817 if (!pipe->writers)
832 wakeup_pipe_writers(pipe);
836 pipe_wait_readable(pipe);
839 head = pipe->head;
840 tail = pipe->tail;
841 mask = pipe->ring_size - 1;
844 struct pipe_buffer *buf = &pipe->bufs[tail & mask];
854 ret = pipe_buf_confirm(pipe, buf);
874 if (remain && pipe_occupancy(pipe->head, tail) > 0)
887 tail = pipe->tail;
889 struct pipe_buffer *buf = &pipe->bufs[tail & mask];
897 pipe_buf_release(pipe, buf);
902 if (tail != pipe->tail) {
903 pipe->tail = tail;
904 if (pipe->files)
910 pipe_unlock(pipe);
912 wakeup_pipe_writers(pipe);
926 * Attempt to initiate a splice from pipe to file.
928 static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
933 return out->f_op->splice_write(pipe, out, ppos, len, flags);
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,
974 /* Don't try to read more the pipe has space for. */
975 p_space = pipe->max_usage - pipe_occupancy(pipe->head, pipe->tail);
989 * buffer, copy into it and splice that into the pipe.
992 return copy_splice_read(in, ppos, pipe, len, flags);
993 return in->f_op->splice_read(in, ppos, pipe, len, flags);
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;
1027 * neither in nor out is a pipe, setup an internal pipe attached to
1030 pipe = current->splice_pipe;
1031 if (unlikely(!pipe)) {
1032 pipe = alloc_pipe_info();
1033 if (!pipe)
1038 * out of the pipe right after the splice_to_pipe(). So set
1041 pipe->readers = 1;
1043 current->splice_pipe = pipe;
1052 /* Don't block on output, we have to drain the direct pipe. */
1063 WARN_ON_ONCE(!pipe_empty(pipe->head, pipe->tail));
1069 ret = vfs_splice_read(in, &pos, pipe, len, flags);
1086 * could get stuck data in the internal pipe:
1088 ret = actor(pipe, sd);
1105 pipe->tail = pipe->head = 0;
1121 * the pipe buffers in question:
1123 for (i = 0; i < pipe->ring_size; i++) {
1124 struct pipe_buffer *buf = &pipe->bufs[i];
1127 pipe_buf_release(pipe, buf);
1137 static int direct_splice_actor(struct pipe_inode_info *pipe,
1142 return do_splice_from(pipe, file, sd->opos, sd->total_len,
1167 * can splice directly through a process-private pipe.
1202 static int wait_for_space(struct pipe_inode_info *pipe, unsigned flags)
1205 if (unlikely(!pipe->readers)) {
1209 if (!pipe_full(pipe->head, pipe->tail, pipe->max_usage))
1215 pipe_wait_writable(pipe);
1383 struct pipe_inode_info *pipe,
1412 ret = add_to_pipe(pipe, &buf);
1429 static int pipe_to_user(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
1443 struct pipe_inode_info *pipe = get_pipe_info(file, true);
1451 if (!pipe)
1457 pipe_lock(pipe);
1458 ret = __splice_from_pipe(pipe, &sd, pipe_to_user);
1459 pipe_unlock(pipe);
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;
1483 pipe = get_pipe_info(file, true);
1484 if (!pipe)
1489 pipe_lock(pipe);
1490 ret = wait_for_space(pipe, flags);
1492 ret = iter_to_pipe(iter, pipe, buf_flag);
1493 pipe_unlock(pipe);
1495 wakeup_pipe_readers(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)
1604 * Check the pipe occupancy without the inode lock first. This function
1607 if (!pipe_empty(pipe->head, pipe->tail))
1611 pipe_lock(pipe);
1613 while (pipe_empty(pipe->head, pipe->tail)) {
1618 if (!pipe->writers)
1624 pipe_wait_readable(pipe);
1627 pipe_unlock(pipe);
1635 static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
1640 * Check pipe occupancy without the inode lock first. This function
1643 if (!pipe_full(pipe->head, pipe->tail, pipe->max_usage))
1647 pipe_lock(pipe);
1649 while (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) {
1650 if (!pipe->readers) {
1663 pipe_wait_writable(pipe);
1666 pipe_unlock(pipe);
1696 * grabbing by pipe info address. Otherwise two different processes
1724 * pipe is empty or the output pipe is full.
1764 * Get a reference to this pipe buffer,
1796 * If we put data in the output pipe, wakeup any potential readers.
1822 * grabbing by pipe info address. Otherwise two different processes
1855 * Get a reference to this pipe buffer,
1887 * If we put data in the output pipe, wakeup any potential readers.
1897 * any data, it simply references the 'in' pages on the 'out' pipe.