Lines Matching refs:pipe

78 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)  in pipe_lock_nested()  argument
80 if (pipe->files) in pipe_lock_nested()
81 mutex_lock_nested(&pipe->mutex, subclass); in pipe_lock_nested()
84 void pipe_lock(struct pipe_inode_info *pipe) in pipe_lock() argument
89 pipe_lock_nested(pipe, I_MUTEX_PARENT); in pipe_lock()
93 void pipe_unlock(struct pipe_inode_info *pipe) in pipe_unlock() argument
95 if (pipe->files) in pipe_unlock()
96 mutex_unlock(&pipe->mutex); in pipe_unlock()
100 static inline void __pipe_lock(struct pipe_inode_info *pipe) in __pipe_lock() argument
102 mutex_lock_nested(&pipe->mutex, I_MUTEX_PARENT); in __pipe_lock()
105 static inline void __pipe_unlock(struct pipe_inode_info *pipe) in __pipe_unlock() argument
107 mutex_unlock(&pipe->mutex); in __pipe_unlock()
124 static void anon_pipe_buf_release(struct pipe_inode_info *pipe, in anon_pipe_buf_release() argument
134 if (page_count(page) == 1 && !pipe->tmp_page) in anon_pipe_buf_release()
135 pipe->tmp_page = page; in anon_pipe_buf_release()
140 static bool anon_pipe_buf_try_steal(struct pipe_inode_info *pipe, in anon_pipe_buf_try_steal() argument
164 bool generic_pipe_buf_try_steal(struct pipe_inode_info *pipe, in generic_pipe_buf_try_steal() argument
192 bool generic_pipe_buf_get(struct pipe_inode_info *pipe, struct pipe_buffer *buf) in generic_pipe_buf_get() argument
206 void generic_pipe_buf_release(struct pipe_inode_info *pipe, in generic_pipe_buf_release() argument
220 static inline bool pipe_readable(const struct pipe_inode_info *pipe) in pipe_readable() argument
222 unsigned int head = READ_ONCE(pipe->head); in pipe_readable()
223 unsigned int tail = READ_ONCE(pipe->tail); in pipe_readable()
224 unsigned int writers = READ_ONCE(pipe->writers); in pipe_readable()
234 struct pipe_inode_info *pipe = filp->private_data; in pipe_read() local
243 __pipe_lock(pipe); in pipe_read()
253 was_full = pipe_full(pipe->head, pipe->tail, pipe->max_usage); in pipe_read()
255 unsigned int head = pipe->head; in pipe_read()
256 unsigned int tail = pipe->tail; in pipe_read()
257 unsigned int mask = pipe->ring_size - 1; in pipe_read()
260 if (pipe->note_loss) { in pipe_read()
279 pipe->note_loss = false; in pipe_read()
284 struct pipe_buffer *buf = &pipe->bufs[tail & mask]; in pipe_read()
298 error = pipe_buf_confirm(pipe, buf); in pipe_read()
322 pipe_buf_release(pipe, buf); in pipe_read()
323 spin_lock_irq(&pipe->rd_wait.lock); in pipe_read()
326 pipe->note_loss = true; in pipe_read()
329 pipe->tail = tail; in pipe_read()
330 spin_unlock_irq(&pipe->rd_wait.lock); in pipe_read()
339 if (!pipe->writers) in pipe_read()
347 __pipe_unlock(pipe); in pipe_read()
367 wake_up_interruptible_sync_poll(&pipe->wr_wait, EPOLLOUT | EPOLLWRNORM); in pipe_read()
368 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT); in pipe_read()
376 if (wait_event_interruptible_exclusive(pipe->rd_wait, pipe_readable(pipe)) < 0) in pipe_read()
379 __pipe_lock(pipe); in pipe_read()
380 was_full = pipe_full(pipe->head, pipe->tail, pipe->max_usage); in pipe_read()
383 if (pipe_empty(pipe->head, pipe->tail)) in pipe_read()
385 __pipe_unlock(pipe); in pipe_read()
388 wake_up_interruptible_sync_poll(&pipe->wr_wait, EPOLLOUT | EPOLLWRNORM); in pipe_read()
390 wake_up_interruptible_sync_poll(&pipe->rd_wait, EPOLLIN | EPOLLRDNORM); in pipe_read()
391 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT); in pipe_read()
403 static inline bool pipe_writable(const struct pipe_inode_info *pipe) in pipe_writable() argument
405 unsigned int head = READ_ONCE(pipe->head); in pipe_writable()
406 unsigned int tail = READ_ONCE(pipe->tail); in pipe_writable()
407 unsigned int max_usage = READ_ONCE(pipe->max_usage); in pipe_writable()
410 !READ_ONCE(pipe->readers); in pipe_writable()
417 struct pipe_inode_info *pipe = filp->private_data; in pipe_write() local
429 __pipe_lock(pipe); in pipe_write()
431 if (!pipe->readers) { in pipe_write()
438 if (pipe->watch_queue) { in pipe_write()
452 head = pipe->head; in pipe_write()
453 was_empty = pipe_empty(head, pipe->tail); in pipe_write()
456 unsigned int mask = pipe->ring_size - 1; in pipe_write()
457 struct pipe_buffer *buf = &pipe->bufs[(head - 1) & mask]; in pipe_write()
462 ret = pipe_buf_confirm(pipe, buf); in pipe_write()
479 if (!pipe->readers) { in pipe_write()
486 head = pipe->head; in pipe_write()
487 if (!pipe_full(head, pipe->tail, pipe->max_usage)) { in pipe_write()
488 unsigned int mask = pipe->ring_size - 1; in pipe_write()
489 struct pipe_buffer *buf = &pipe->bufs[head & mask]; in pipe_write()
490 struct page *page = pipe->tmp_page; in pipe_write()
499 pipe->tmp_page = page; in pipe_write()
507 spin_lock_irq(&pipe->rd_wait.lock); in pipe_write()
509 head = pipe->head; in pipe_write()
510 if (pipe_full(head, pipe->tail, pipe->max_usage)) { in pipe_write()
511 spin_unlock_irq(&pipe->rd_wait.lock); in pipe_write()
515 pipe->head = head + 1; in pipe_write()
516 spin_unlock_irq(&pipe->rd_wait.lock); in pipe_write()
519 buf = &pipe->bufs[head & mask]; in pipe_write()
528 pipe->tmp_page = NULL; in pipe_write()
544 if (!pipe_full(head, pipe->tail, pipe->max_usage)) in pipe_write()
565 __pipe_unlock(pipe); in pipe_write()
567 wake_up_interruptible_sync_poll(&pipe->rd_wait, EPOLLIN | EPOLLRDNORM); in pipe_write()
568 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN); in pipe_write()
569 wait_event_interruptible_exclusive(pipe->wr_wait, pipe_writable(pipe)); in pipe_write()
570 __pipe_lock(pipe); in pipe_write()
571 was_empty = pipe_empty(pipe->head, pipe->tail); in pipe_write()
575 if (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) in pipe_write()
577 __pipe_unlock(pipe); in pipe_write()
591 if (was_empty || pipe->poll_usage) in pipe_write()
592 wake_up_interruptible_sync_poll(&pipe->rd_wait, EPOLLIN | EPOLLRDNORM); in pipe_write()
593 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN); in pipe_write()
595 wake_up_interruptible_sync_poll(&pipe->wr_wait, EPOLLOUT | EPOLLWRNORM); in pipe_write()
607 struct pipe_inode_info *pipe = filp->private_data; in pipe_ioctl() local
612 __pipe_lock(pipe); in pipe_ioctl()
614 head = pipe->head; in pipe_ioctl()
615 tail = pipe->tail; in pipe_ioctl()
616 mask = pipe->ring_size - 1; in pipe_ioctl()
619 count += pipe->bufs[tail & mask].len; in pipe_ioctl()
622 __pipe_unlock(pipe); in pipe_ioctl()
629 __pipe_lock(pipe); in pipe_ioctl()
630 ret = watch_queue_set_size(pipe, arg); in pipe_ioctl()
631 __pipe_unlock(pipe); in pipe_ioctl()
637 pipe, (struct watch_notification_filter __user *)arg); in pipe_ioctl()
650 struct pipe_inode_info *pipe = filp->private_data; in pipe_poll() local
654 pipe->poll_usage = 1; in pipe_poll()
663 poll_wait(filp, &pipe->rd_wait, wait); in pipe_poll()
665 poll_wait(filp, &pipe->wr_wait, wait); in pipe_poll()
672 head = READ_ONCE(pipe->head); in pipe_poll()
673 tail = READ_ONCE(pipe->tail); in pipe_poll()
679 if (!pipe->writers && filp->f_version != pipe->w_counter) in pipe_poll()
684 if (!pipe_full(head, tail, pipe->max_usage)) in pipe_poll()
690 if (!pipe->readers) in pipe_poll()
697 static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe) in put_pipe_info() argument
702 if (!--pipe->files) { in put_pipe_info()
709 free_pipe_info(pipe); in put_pipe_info()
715 struct pipe_inode_info *pipe = file->private_data; in pipe_release() local
717 __pipe_lock(pipe); in pipe_release()
719 pipe->readers--; in pipe_release()
721 pipe->writers--; in pipe_release()
724 if (!pipe->readers != !pipe->writers) { in pipe_release()
725 wake_up_interruptible_all(&pipe->rd_wait); in pipe_release()
726 wake_up_interruptible_all(&pipe->wr_wait); in pipe_release()
727 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN); in pipe_release()
728 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT); in pipe_release()
730 __pipe_unlock(pipe); in pipe_release()
732 put_pipe_info(inode, pipe); in pipe_release()
739 struct pipe_inode_info *pipe = filp->private_data; in pipe_fasync() local
742 __pipe_lock(pipe); in pipe_fasync()
744 retval = fasync_helper(fd, filp, on, &pipe->fasync_readers); in pipe_fasync()
746 retval = fasync_helper(fd, filp, on, &pipe->fasync_writers); in pipe_fasync()
749 fasync_helper(-1, filp, 0, &pipe->fasync_readers); in pipe_fasync()
751 __pipe_unlock(pipe); in pipe_fasync()
782 struct pipe_inode_info *pipe; in alloc_pipe_info() local
788 pipe = kzalloc(sizeof(struct pipe_inode_info), GFP_KERNEL_ACCOUNT); in alloc_pipe_info()
789 if (pipe == NULL) in alloc_pipe_info()
805 pipe->bufs = kcalloc(pipe_bufs, sizeof(struct pipe_buffer), in alloc_pipe_info()
808 if (pipe->bufs) { in alloc_pipe_info()
809 init_waitqueue_head(&pipe->rd_wait); in alloc_pipe_info()
810 init_waitqueue_head(&pipe->wr_wait); in alloc_pipe_info()
811 pipe->r_counter = pipe->w_counter = 1; in alloc_pipe_info()
812 pipe->max_usage = pipe_bufs; in alloc_pipe_info()
813 pipe->ring_size = pipe_bufs; in alloc_pipe_info()
814 pipe->nr_accounted = pipe_bufs; in alloc_pipe_info()
815 pipe->user = user; in alloc_pipe_info()
816 mutex_init(&pipe->mutex); in alloc_pipe_info()
817 return pipe; in alloc_pipe_info()
822 kfree(pipe); in alloc_pipe_info()
828 void free_pipe_info(struct pipe_inode_info *pipe) in free_pipe_info() argument
833 if (pipe->watch_queue) { in free_pipe_info()
834 watch_queue_clear(pipe->watch_queue); in free_pipe_info()
835 put_watch_queue(pipe->watch_queue); in free_pipe_info()
839 (void) account_pipe_buffers(pipe->user, pipe->nr_accounted, 0); in free_pipe_info()
840 free_uid(pipe->user); in free_pipe_info()
841 for (i = 0; i < pipe->ring_size; i++) { in free_pipe_info()
842 struct pipe_buffer *buf = pipe->bufs + i; in free_pipe_info()
844 pipe_buf_release(pipe, buf); in free_pipe_info()
846 if (pipe->tmp_page) in free_pipe_info()
847 __free_page(pipe->tmp_page); in free_pipe_info()
848 kfree(pipe->bufs); in free_pipe_info()
849 kfree(pipe); in free_pipe_info()
870 struct pipe_inode_info *pipe; in get_pipe_inode() local
877 pipe = alloc_pipe_info(); in get_pipe_inode()
878 if (!pipe) in get_pipe_inode()
881 inode->i_pipe = pipe; in get_pipe_inode()
882 pipe->files = 2; in get_pipe_inode()
883 pipe->readers = pipe->writers = 1; in get_pipe_inode()
1027 SYSCALL_DEFINE1(pipe, int __user *, fildes) in SYSCALL_DEFINE1() argument
1041 void pipe_wait_readable(struct pipe_inode_info *pipe) in pipe_wait_readable() argument
1043 pipe_unlock(pipe); in pipe_wait_readable()
1044 wait_event_interruptible(pipe->rd_wait, pipe_readable(pipe)); in pipe_wait_readable()
1045 pipe_lock(pipe); in pipe_wait_readable()
1048 void pipe_wait_writable(struct pipe_inode_info *pipe) in pipe_wait_writable() argument
1050 pipe_unlock(pipe); in pipe_wait_writable()
1051 wait_event_interruptible(pipe->wr_wait, pipe_writable(pipe)); in pipe_wait_writable()
1052 pipe_lock(pipe); in pipe_wait_writable()
1067 static int wait_for_partner(struct pipe_inode_info *pipe, unsigned int *cnt) in wait_for_partner() argument
1073 prepare_to_wait(&pipe->rd_wait, &rdwait, TASK_INTERRUPTIBLE); in wait_for_partner()
1074 pipe_unlock(pipe); in wait_for_partner()
1076 finish_wait(&pipe->rd_wait, &rdwait); in wait_for_partner()
1077 pipe_lock(pipe); in wait_for_partner()
1084 static void wake_up_partner(struct pipe_inode_info *pipe) in wake_up_partner() argument
1086 wake_up_interruptible_all(&pipe->rd_wait); in wake_up_partner()
1091 struct pipe_inode_info *pipe; in fifo_open() local
1099 pipe = inode->i_pipe; in fifo_open()
1100 pipe->files++; in fifo_open()
1104 pipe = alloc_pipe_info(); in fifo_open()
1105 if (!pipe) in fifo_open()
1107 pipe->files = 1; in fifo_open()
1112 free_pipe_info(pipe); in fifo_open()
1113 pipe = inode->i_pipe; in fifo_open()
1115 inode->i_pipe = pipe; in fifo_open()
1119 filp->private_data = pipe; in fifo_open()
1122 __pipe_lock(pipe); in fifo_open()
1134 pipe->r_counter++; in fifo_open()
1135 if (pipe->readers++ == 0) in fifo_open()
1136 wake_up_partner(pipe); in fifo_open()
1138 if (!is_pipe && !pipe->writers) { in fifo_open()
1142 filp->f_version = pipe->w_counter; in fifo_open()
1144 if (wait_for_partner(pipe, &pipe->w_counter)) in fifo_open()
1157 if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers) in fifo_open()
1160 pipe->w_counter++; in fifo_open()
1161 if (!pipe->writers++) in fifo_open()
1162 wake_up_partner(pipe); in fifo_open()
1164 if (!is_pipe && !pipe->readers) { in fifo_open()
1165 if (wait_for_partner(pipe, &pipe->r_counter)) in fifo_open()
1178 pipe->readers++; in fifo_open()
1179 pipe->writers++; in fifo_open()
1180 pipe->r_counter++; in fifo_open()
1181 pipe->w_counter++; in fifo_open()
1182 if (pipe->readers == 1 || pipe->writers == 1) in fifo_open()
1183 wake_up_partner(pipe); in fifo_open()
1192 __pipe_unlock(pipe); in fifo_open()
1196 if (!--pipe->readers) in fifo_open()
1197 wake_up_interruptible(&pipe->wr_wait); in fifo_open()
1202 if (!--pipe->writers) in fifo_open()
1203 wake_up_interruptible_all(&pipe->rd_wait); in fifo_open()
1208 __pipe_unlock(pipe); in fifo_open()
1210 put_pipe_info(inode, pipe); in fifo_open()
1245 int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots) in pipe_resize_ring() argument
1256 mask = pipe->ring_size - 1; in pipe_resize_ring()
1257 head = pipe->head; in pipe_resize_ring()
1258 tail = pipe->tail; in pipe_resize_ring()
1259 n = pipe_occupancy(pipe->head, pipe->tail); in pipe_resize_ring()
1276 memcpy(bufs, pipe->bufs + t, in pipe_resize_ring()
1279 unsigned int tsize = pipe->ring_size - t; in pipe_resize_ring()
1281 memcpy(bufs + tsize, pipe->bufs, in pipe_resize_ring()
1283 memcpy(bufs, pipe->bufs + t, in pipe_resize_ring()
1291 kfree(pipe->bufs); in pipe_resize_ring()
1292 pipe->bufs = bufs; in pipe_resize_ring()
1293 pipe->ring_size = nr_slots; in pipe_resize_ring()
1294 if (pipe->max_usage > nr_slots) in pipe_resize_ring()
1295 pipe->max_usage = nr_slots; in pipe_resize_ring()
1296 pipe->tail = tail; in pipe_resize_ring()
1297 pipe->head = head; in pipe_resize_ring()
1300 wake_up_interruptible(&pipe->wr_wait); in pipe_resize_ring()
1308 static long pipe_set_size(struct pipe_inode_info *pipe, unsigned long arg) in pipe_set_size() argument
1315 if (pipe->watch_queue) in pipe_set_size()
1332 if (nr_slots > pipe->max_usage && in pipe_set_size()
1336 user_bufs = account_pipe_buffers(pipe->user, pipe->nr_accounted, nr_slots); in pipe_set_size()
1338 if (nr_slots > pipe->max_usage && in pipe_set_size()
1346 ret = pipe_resize_ring(pipe, nr_slots); in pipe_set_size()
1350 pipe->max_usage = nr_slots; in pipe_set_size()
1351 pipe->nr_accounted = nr_slots; in pipe_set_size()
1352 return pipe->max_usage * PAGE_SIZE; in pipe_set_size()
1355 (void) account_pipe_buffers(pipe->user, nr_slots, pipe->nr_accounted); in pipe_set_size()
1365 struct pipe_inode_info *pipe = file->private_data; in get_pipe_info() local
1367 if (file->f_op != &pipefifo_fops || !pipe) in get_pipe_info()
1370 if (for_splice && pipe->watch_queue) in get_pipe_info()
1373 return pipe; in get_pipe_info()
1378 struct pipe_inode_info *pipe; in pipe_fcntl() local
1381 pipe = get_pipe_info(file, false); in pipe_fcntl()
1382 if (!pipe) in pipe_fcntl()
1385 __pipe_lock(pipe); in pipe_fcntl()
1389 ret = pipe_set_size(pipe, arg); in pipe_fcntl()
1392 ret = pipe->max_usage * PAGE_SIZE; in pipe_fcntl()
1399 __pipe_unlock(pipe); in pipe_fcntl()