Lines Matching defs: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,
91 static void page_cache_pipe_buf_release(struct pipe_inode_info *pipe,
102 static int page_cache_pipe_buf_confirm(struct pipe_inode_info *pipe,
147 static bool user_page_pipe_buf_try_steal(struct pipe_inode_info *pipe,
154 return generic_pipe_buf_try_steal(pipe, buf);
163 static void wakeup_pipe_readers(struct pipe_inode_info *pipe)
166 if (waitqueue_active(&pipe->rd_wait))
167 wake_up_interruptible(&pipe->rd_wait);
168 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
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,
186 unsigned int tail = pipe->tail;
187 unsigned int head = pipe->head;
188 unsigned int mask = pipe->ring_size - 1;
194 if (unlikely(!pipe->readers)) {
200 while (!pipe_full(head, tail, pipe->max_usage)) {
201 struct pipe_buffer *buf = &pipe->bufs[head & mask];
211 pipe->head = head;
230 ssize_t add_to_pipe(struct pipe_inode_info *pipe, struct pipe_buffer *buf)
232 unsigned int head = pipe->head;
233 unsigned int tail = pipe->tail;
234 unsigned int mask = pipe->ring_size - 1;
237 if (unlikely(!pipe->readers)) {
240 } else if (pipe_full(head, tail, pipe->max_usage)) {
243 pipe->bufs[head & mask] = *buf;
244 pipe->head = head + 1;
247 pipe_buf_release(pipe, buf);
256 int splice_grow_spd(const struct pipe_inode_info *pipe, struct splice_pipe_desc *spd)
258 unsigned int max_usage = READ_ONCE(pipe->max_usage);
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,
307 iov_iter_pipe(&to, READ, pipe, len);
348 static int pipe_to_sendpage(struct pipe_inode_info *pipe,
361 pipe_occupancy(pipe->head, pipe->tail) > 1)
368 static void wakeup_pipe_writers(struct pipe_inode_info *pipe)
371 if (waitqueue_active(&pipe->wr_wait))
372 wake_up_interruptible(&pipe->wr_wait);
373 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
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,
399 unsigned int head = pipe->head;
400 unsigned int tail = pipe->tail;
401 unsigned int mask = pipe->ring_size - 1;
405 struct pipe_buffer *buf = &pipe->bufs[tail & mask];
411 ret = pipe_buf_confirm(pipe, buf);
418 ret = actor(pipe, buf, sd);
431 pipe_buf_release(pipe, buf);
433 pipe->tail = tail;
434 if (pipe->files)
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)
448 unsigned int tail = pipe->tail;
449 unsigned int mask = pipe->ring_size - 1;
450 struct pipe_buffer *buf = &pipe->bufs[tail & mask];
453 pipe_buf_release(pipe, buf);
454 pipe->tail = tail+1;
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)
481 while (pipe_empty(pipe->head, pipe->tail)) {
482 if (!pipe->writers)
495 wakeup_pipe_writers(pipe);
499 pipe_wait_readable(pipe);
502 if (eat_empty_buffer(pipe))
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)
536 wakeup_pipe_writers(pipe);
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,
560 ret = splice_from_pipe_next(pipe, sd);
562 ret = splice_from_pipe_feed(pipe, sd, actor);
564 splice_from_pipe_end(pipe, sd);
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,
596 pipe_lock(pipe);
597 ret = __splice_from_pipe(pipe, &sd, actor);
598 pipe_unlock(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,
627 int nbufs = pipe->max_usage;
635 pipe_lock(pipe);
644 ret = splice_from_pipe_next(pipe, &sd);
648 if (unlikely(nbufs < pipe->max_usage)) {
650 nbufs = pipe->max_usage;
659 head = pipe->head;
660 tail = pipe->tail;
661 mask = pipe->ring_size - 1;
666 struct pipe_buffer *buf = &pipe->bufs[tail & mask];
672 ret = pipe_buf_confirm(pipe, buf);
695 tail = pipe->tail;
697 struct pipe_buffer *buf = &pipe->bufs[tail & mask];
701 pipe_buf_release(pipe, buf);
703 pipe->tail = tail;
704 if (pipe->files)
715 splice_from_pipe_end(pipe, &sd);
717 pipe_unlock(pipe);
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,
743 return splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_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,
764 return out->f_op->splice_write(pipe, out, ppos, len, flags);
768 * Attempt to initiate a splice from a file to a pipe.
771 struct pipe_inode_info *pipe, size_t len,
788 return in->f_op->splice_read(in, ppos, pipe, len, flags);
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;
823 * neither in nor out is a pipe, setup an internal pipe attached to
826 pipe = current->splice_pipe;
827 if (unlikely(!pipe)) {
828 pipe = alloc_pipe_info();
829 if (!pipe)
834 * out of the pipe right after the splice_to_pipe(). So set
837 pipe->readers = 1;
839 current->splice_pipe = pipe;
851 * Don't block on output, we have to drain the direct pipe.
856 WARN_ON_ONCE(!pipe_empty(pipe->head, pipe->tail));
863 /* Don't try to read more the pipe has space for. */
864 p_space = pipe->max_usage -
865 pipe_occupancy(pipe->head, pipe->tail);
867 ret = do_splice_to(in, &pos, pipe, read_len, flags);
886 * could get stuck data in the internal pipe:
888 ret = actor(pipe, sd);
905 pipe->tail = pipe->head = 0;
912 * the pipe buffers in question:
914 for (i = 0; i < pipe->ring_size; i++) {
915 struct pipe_buffer *buf = &pipe->bufs[i];
918 pipe_buf_release(pipe, buf);
928 static int direct_splice_actor(struct pipe_inode_info *pipe,
933 return do_splice_from(pipe, file, sd->opos, sd->total_len,
950 * can splice directly through a process-private pipe.
984 static int wait_for_space(struct pipe_inode_info *pipe, unsigned flags)
987 if (unlikely(!pipe->readers)) {
991 if (!pipe_full(pipe->head, pipe->tail, pipe->max_usage))
997 pipe_wait_writable(pipe);
1089 /* Don't try to read more the pipe has space for. */
1150 struct pipe_inode_info *pipe,
1179 ret = add_to_pipe(pipe, &buf);
1195 static int pipe_to_user(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
1209 struct pipe_inode_info *pipe = get_pipe_info(file, true);
1217 if (!pipe)
1221 pipe_lock(pipe);
1222 ret = __splice_from_pipe(pipe, &sd, pipe_to_user);
1223 pipe_unlock(pipe);
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;
1244 pipe = get_pipe_info(file, true);
1245 if (!pipe)
1248 pipe_lock(pipe);
1249 ret = wait_for_space(pipe, flags);
1251 ret = iter_to_pipe(iter, pipe, buf_flag);
1252 pipe_unlock(pipe);
1254 wakeup_pipe_readers(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)
1361 * Check the pipe occupancy without the inode lock first. This function
1364 if (!pipe_empty(pipe->head, pipe->tail))
1368 pipe_lock(pipe);
1370 while (pipe_empty(pipe->head, pipe->tail)) {
1375 if (!pipe->writers)
1381 pipe_wait_readable(pipe);
1384 pipe_unlock(pipe);
1392 static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
1397 * Check pipe occupancy without the inode lock first. This function
1400 if (!pipe_full(pipe->head, pipe->tail, pipe->max_usage))
1404 pipe_lock(pipe);
1406 while (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) {
1407 if (!pipe->readers) {
1420 pipe_wait_writable(pipe);
1423 pipe_unlock(pipe);
1453 * grabbing by pipe info address. Otherwise two different processes
1481 * pipe is empty or the output pipe is full.
1521 * Get a reference to this pipe buffer,
1553 * If we put data in the output pipe, wakeup any potential readers.
1579 * grabbing by pipe info address. Otherwise two different processes
1612 * Get a reference to this pipe buffer,
1644 * If we put data in the output pipe, wakeup any potential readers.
1654 * any data, it simply references the 'in' pages on the 'out' pipe.