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()
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_buf(pipe, head); 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()
251 if (unlikely(!pipe->readers)) { in add_to_pipe()
254 } else if (pipe_full(head, tail, pipe->max_usage)) { in add_to_pipe()
257 *pipe_buf(pipe, head) = *buf; in add_to_pipe()
258 pipe->head = head + 1; in add_to_pipe()
261 pipe_buf_release(pipe, buf); in add_to_pipe()
270 int splice_grow_spd(const struct pipe_inode_info *pipe, struct splice_pipe_desc *spd) in splice_grow_spd() argument
272 unsigned int max_usage = READ_ONCE(pipe->max_usage); in splice_grow_spd()
300 * copy_splice_read - Copy data from a file and splice the copy into a pipe
303 * @pipe: The pipe to splice into
308 * amount of data (but limited by the remaining pipe capacity), passes it to
310 * the pipe.
314 * to be read; -EAGAIN will be returned if the pipe had no space, and some
316 * if the pipe has insufficient space, we reach the end of the data or we hit a
320 struct pipe_inode_info *pipe, in copy_splice_read() argument
331 /* Work out how much data we can actually add into the pipe */ in copy_splice_read()
332 used = pipe_buf_usage(pipe); in copy_splice_read()
333 npages = max_t(ssize_t, pipe->max_usage - used, 0); in copy_splice_read()
381 /* Push the remaining pages into the pipe. */ in copy_splice_read()
384 struct pipe_buffer *buf = pipe_head_buf(pipe); in copy_splice_read()
393 pipe->head++; in copy_splice_read()
408 /* Pipe buffer operations for a socket and similar. */
415 static void wakeup_pipe_writers(struct pipe_inode_info *pipe) in wakeup_pipe_writers() argument
418 if (waitqueue_active(&pipe->wr_wait)) in wakeup_pipe_writers()
419 wake_up_interruptible(&pipe->wr_wait); in wakeup_pipe_writers()
420 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT); in wakeup_pipe_writers()
424 * splice_from_pipe_feed - feed available data from a pipe to a file
425 * @pipe: pipe to splice from
430 * This function loops over the pipe and calls @actor to do the
433 * the pipe or if the requested number of bytes (@sd->total_len)
435 * pipe needs to be filled with more data, zero if the required
440 * locking is required around copying the pipe buffers to the
443 static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd, in splice_from_pipe_feed() argument
446 unsigned int head = pipe->head; in splice_from_pipe_feed()
447 unsigned int tail = pipe->tail; in splice_from_pipe_feed()
451 struct pipe_buffer *buf = pipe_buf(pipe, tail); in splice_from_pipe_feed()
457 ret = pipe_buf_confirm(pipe, buf); in splice_from_pipe_feed()
464 ret = actor(pipe, buf, sd); in splice_from_pipe_feed()
477 pipe_buf_release(pipe, buf); in splice_from_pipe_feed()
479 pipe->tail = tail; in splice_from_pipe_feed()
480 if (pipe->files) in splice_from_pipe_feed()
491 /* We know we have a pipe buffer, but maybe it's empty? */
492 static inline bool eat_empty_buffer(struct pipe_inode_info *pipe) in eat_empty_buffer() argument
494 unsigned int tail = pipe->tail; in eat_empty_buffer()
495 struct pipe_buffer *buf = pipe_buf(pipe, tail); in eat_empty_buffer()
498 pipe_buf_release(pipe, buf); in eat_empty_buffer()
499 pipe->tail = tail+1; in eat_empty_buffer()
508 * @pipe: pipe to splice from
513 * value (one) if pipe buffers are available. It will return zero
516 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd) in splice_from_pipe_next() argument
526 while (pipe_is_empty(pipe)) { in splice_from_pipe_next()
527 if (!pipe->writers) in splice_from_pipe_next()
540 wakeup_pipe_writers(pipe); in splice_from_pipe_next()
544 pipe_wait_readable(pipe); in splice_from_pipe_next()
547 if (eat_empty_buffer(pipe)) in splice_from_pipe_next()
554 * splice_from_pipe_begin - start splicing from pipe
569 * splice_from_pipe_end - finish splicing from pipe
570 * @pipe: pipe to splice from
574 * This function will wake up pipe writers if necessary. It should
578 static void splice_from_pipe_end(struct pipe_inode_info *pipe, struct splice_desc *sd) in splice_from_pipe_end() argument
581 wakeup_pipe_writers(pipe); in splice_from_pipe_end()
585 * __splice_from_pipe - splice data from a pipe to given actor
586 * @pipe: pipe to splice from
591 * This function does little more than loop over the pipe and call
597 ssize_t __splice_from_pipe(struct pipe_inode_info *pipe, struct splice_desc *sd, in __splice_from_pipe() argument
605 ret = splice_from_pipe_next(pipe, sd); in __splice_from_pipe()
607 ret = splice_from_pipe_feed(pipe, sd, actor); in __splice_from_pipe()
609 splice_from_pipe_end(pipe, sd); in __splice_from_pipe()
616 * splice_from_pipe - splice data from a pipe to a file
617 * @pipe: pipe to splice from
625 * See __splice_from_pipe. This function locks the pipe inode,
629 ssize_t splice_from_pipe(struct pipe_inode_info *pipe, struct file *out, in splice_from_pipe() argument
641 pipe_lock(pipe); in splice_from_pipe()
642 ret = __splice_from_pipe(pipe, &sd, actor); in splice_from_pipe()
643 pipe_unlock(pipe); in splice_from_pipe()
649 * iter_file_splice_write - splice data from a pipe to a file
650 * @pipe: pipe info
658 * the given pipe inode to the given file.
663 iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, in iter_file_splice_write() argument
672 int nbufs = pipe->max_usage; in iter_file_splice_write()
683 pipe_lock(pipe); in iter_file_splice_write()
693 ret = splice_from_pipe_next(pipe, &sd); in iter_file_splice_write()
697 if (unlikely(nbufs < pipe->max_usage)) { in iter_file_splice_write()
699 nbufs = pipe->max_usage; in iter_file_splice_write()
708 head = pipe->head; in iter_file_splice_write()
709 tail = pipe->tail; in iter_file_splice_write()
714 struct pipe_buffer *buf = pipe_buf(pipe, tail); in iter_file_splice_write()
722 ret = pipe_buf_confirm(pipe, buf); in iter_file_splice_write()
748 tail = pipe->tail; in iter_file_splice_write()
750 struct pipe_buffer *buf = pipe_buf(pipe, tail); in iter_file_splice_write()
754 pipe_buf_release(pipe, buf); in iter_file_splice_write()
756 pipe->tail = tail; in iter_file_splice_write()
757 if (pipe->files) in iter_file_splice_write()
768 splice_from_pipe_end(pipe, &sd); in iter_file_splice_write()
770 pipe_unlock(pipe); in iter_file_splice_write()
782 * splice_to_socket - splice data from a pipe to a socket
783 * @pipe: pipe to splice from
790 * Will send @len bytes from the pipe to a network socket. No data copying
794 ssize_t splice_to_socket(struct pipe_inode_info *pipe, struct file *out, in splice_to_socket() argument
804 pipe_lock(pipe); in splice_to_socket()
818 while (pipe_is_empty(pipe)) { in splice_to_socket()
820 if (!pipe->writers) in splice_to_socket()
835 wakeup_pipe_writers(pipe); in splice_to_socket()
839 pipe_wait_readable(pipe); in splice_to_socket()
842 head = pipe->head; in splice_to_socket()
843 tail = pipe->tail; in splice_to_socket()
846 struct pipe_buffer *buf = pipe_buf(pipe, tail); in splice_to_socket()
856 ret = pipe_buf_confirm(pipe, buf); in splice_to_socket()
876 if (remain && pipe_occupancy(pipe->head, tail) > 0) in splice_to_socket()
889 tail = pipe->tail; in splice_to_socket()
891 struct pipe_buffer *buf = pipe_buf(pipe, tail); in splice_to_socket()
899 pipe_buf_release(pipe, buf); in splice_to_socket()
904 if (tail != pipe->tail) { in splice_to_socket()
905 pipe->tail = tail; in splice_to_socket()
906 if (pipe->files) in splice_to_socket()
912 pipe_unlock(pipe); in splice_to_socket()
914 wakeup_pipe_writers(pipe); in splice_to_socket()
928 * Attempt to initiate a splice from pipe to file.
930 static ssize_t do_splice_from(struct pipe_inode_info *pipe, struct file *out, in do_splice_from() argument
935 return out->f_op->splice_write(pipe, out, ppos, len, flags); in do_splice_from()
954 struct pipe_inode_info *pipe, size_t len, in do_splice_read() argument
964 /* Don't try to read more the pipe has space for. */ in do_splice_read()
965 p_space = pipe->max_usage - pipe_buf_usage(pipe); in do_splice_read()
975 * buffer, copy into it and splice that into the pipe. in do_splice_read()
978 return copy_splice_read(in, ppos, pipe, len, flags); in do_splice_read()
979 return in->f_op->splice_read(in, ppos, pipe, len, flags); in do_splice_read()
983 * vfs_splice_read - Read data from a file and splice it into a pipe
986 * @pipe: Pipe to splice to
990 * Splice the requested amount of data from the input file to the pipe. This
991 * is synchronous as the caller must hold the pipe lock across the entire
998 struct pipe_inode_info *pipe, size_t len, in vfs_splice_read() argument
1007 return do_splice_read(in, ppos, pipe, len, flags); in vfs_splice_read()
1019 * points, without requiring an explicit pipe. Internally an allocated
1020 * pipe is cached in the process, and reused during the lifetime of
1027 struct pipe_inode_info *pipe; in splice_direct_to_actor() local
1041 * neither in nor out is a pipe, setup an internal pipe attached to in splice_direct_to_actor()
1044 pipe = current->splice_pipe; in splice_direct_to_actor()
1045 if (unlikely(!pipe)) { in splice_direct_to_actor()
1046 pipe = alloc_pipe_info(); in splice_direct_to_actor()
1047 if (!pipe) in splice_direct_to_actor()
1052 * out of the pipe right after the splice_to_pipe(). So set in splice_direct_to_actor()
1055 pipe->readers = 1; in splice_direct_to_actor()
1057 current->splice_pipe = pipe; in splice_direct_to_actor()
1066 /* Don't block on output, we have to drain the direct pipe. */ in splice_direct_to_actor()
1077 WARN_ON_ONCE(!pipe_is_empty(pipe)); in splice_direct_to_actor()
1083 ret = do_splice_read(in, &pos, pipe, len, flags); in splice_direct_to_actor()
1100 * could get stuck data in the internal pipe: in splice_direct_to_actor()
1102 ret = actor(pipe, sd); in splice_direct_to_actor()
1119 pipe->tail = pipe->head = 0; in splice_direct_to_actor()
1135 * the pipe buffers in question: in splice_direct_to_actor()
1137 for (i = 0; i < pipe->ring_size; i++) { in splice_direct_to_actor()
1138 struct pipe_buffer *buf = &pipe->bufs[i]; in splice_direct_to_actor()
1141 pipe_buf_release(pipe, buf); in splice_direct_to_actor()
1151 static int direct_splice_actor(struct pipe_inode_info *pipe, in direct_splice_actor() argument
1158 ret = do_splice_from(pipe, file, sd->opos, sd->total_len, sd->flags); in direct_splice_actor()
1163 static int splice_file_range_actor(struct pipe_inode_info *pipe, in splice_file_range_actor() argument
1168 return do_splice_from(pipe, file, sd->opos, sd->total_len, sd->flags); in splice_file_range_actor()
1220 * can splice directly through a process-private pipe.
1258 static int wait_for_space(struct pipe_inode_info *pipe, unsigned flags) in wait_for_space() argument
1261 if (unlikely(!pipe->readers)) { in wait_for_space()
1265 if (!pipe_is_full(pipe)) in wait_for_space()
1271 pipe_wait_writable(pipe); in wait_for_space()
1443 struct pipe_inode_info *pipe, in iter_to_pipe() argument
1472 ret = add_to_pipe(pipe, &buf); in iter_to_pipe()
1489 static int pipe_to_user(struct pipe_inode_info *pipe, struct pipe_buffer *buf, in pipe_to_user() argument
1503 struct pipe_inode_info *pipe = get_pipe_info(file, true); in vmsplice_to_user() local
1511 if (!pipe) in vmsplice_to_user()
1517 pipe_lock(pipe); in vmsplice_to_user()
1518 ret = __splice_from_pipe(pipe, &sd, pipe_to_user); in vmsplice_to_user()
1519 pipe_unlock(pipe); in vmsplice_to_user()
1529 * vmsplice splices a user address range into a pipe. It can be thought of
1531 * to file). In both cases the output is a pipe, naturally.
1536 struct pipe_inode_info *pipe; in vmsplice_to_pipe() local
1543 pipe = get_pipe_info(file, true); in vmsplice_to_pipe()
1544 if (!pipe) in vmsplice_to_pipe()
1549 pipe_lock(pipe); in vmsplice_to_pipe()
1550 ret = wait_for_space(pipe, flags); in vmsplice_to_pipe()
1552 ret = iter_to_pipe(iter, pipe, buf_flag); in vmsplice_to_pipe()
1553 pipe_unlock(pipe); in vmsplice_to_pipe()
1555 wakeup_pipe_readers(pipe); in vmsplice_to_pipe()
1563 * to a pipe, not the other way around. Splicing from user memory is a simple
1566 * a pipe. The reverse isn't quite as easy, though. There are two possible
1572 * has restriction limitations on both ends of the pipe).
1641 static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags) in ipipe_prep() argument
1646 * Check the pipe occupancy without the inode lock first. This function in ipipe_prep()
1649 if (!pipe_is_empty(pipe)) in ipipe_prep()
1653 pipe_lock(pipe); in ipipe_prep()
1655 while (pipe_is_empty(pipe)) { in ipipe_prep()
1660 if (!pipe->writers) in ipipe_prep()
1666 pipe_wait_readable(pipe); in ipipe_prep()
1669 pipe_unlock(pipe); in ipipe_prep()
1677 static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags) in opipe_prep() argument
1682 * Check pipe occupancy without the inode lock first. This function in opipe_prep()
1685 if (!pipe_is_full(pipe)) in opipe_prep()
1689 pipe_lock(pipe); in opipe_prep()
1691 while (pipe_is_full(pipe)) { in opipe_prep()
1692 if (!pipe->readers) { in opipe_prep()
1705 pipe_wait_writable(pipe); in opipe_prep()
1708 pipe_unlock(pipe); in opipe_prep()
1737 * grabbing by pipe info address. Otherwise two different processes in splice_pipe_to_pipe()
1763 * pipe is empty or the output pipe is full. in splice_pipe_to_pipe()
1803 * Get a reference to this pipe buffer, in splice_pipe_to_pipe()
1835 * If we put data in the output pipe, wakeup any potential readers. in splice_pipe_to_pipe()
1860 * grabbing by pipe info address. Otherwise two different processes in link_pipe()
1891 * Get a reference to this pipe buffer, in link_pipe()
1923 * If we put data in the output pipe, wakeup any potential readers. in link_pipe()
1933 * any data, it simply references the 'in' pages on the 'out' pipe.