blob: 5acd8954aaa0a58a582e3910d1fb1eb50aa5f592 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/pipe.c
3 *
4 * Copyright (C) 1991, 1992, 1999 Linus Torvalds
5 */
6
7#include <linux/mm.h>
8#include <linux/file.h>
9#include <linux/poll.h>
10#include <linux/slab.h>
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/fs.h>
14#include <linux/mount.h>
15#include <linux/pipe_fs_i.h>
16#include <linux/uio.h>
17#include <linux/highmem.h>
Jens Axboe5274f052006-03-30 15:15:30 +020018#include <linux/pagemap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#include <asm/uaccess.h>
21#include <asm/ioctls.h>
22
23/*
24 * We use a start+len construction, which provides full use of the
25 * allocated memory.
26 * -- Florian Coosmann (FGC)
27 *
28 * Reads with count = 0 should always return 0.
29 * -- Julian Bradfield 1999-06-07.
30 *
31 * FIFOs and Pipes now generate SIGIO for both readers and writers.
32 * -- Jeremy Elson <jelson@circlemud.org> 2001-08-16
33 *
34 * pipe_read & write cleanup
35 * -- Manfred Spraul <manfred@colorfullife.com> 2002-05-09
36 */
37
38/* Drop the inode semaphore and wait for a pipe event, atomically */
Ingo Molnar3a326a22006-04-10 15:18:35 +020039void pipe_wait(struct pipe_inode_info *pipe)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
41 DEFINE_WAIT(wait);
42
Ingo Molnard79fc0f2005-09-10 00:26:12 -070043 /*
44 * Pipes are system-local resources, so sleeping on them
45 * is considered a noninteractive wait:
46 */
Ingo Molnar341b4462006-04-11 13:57:45 +020047 prepare_to_wait(&pipe->wait, &wait,
48 TASK_INTERRUPTIBLE | TASK_NONINTERACTIVE);
Ingo Molnar3a326a22006-04-10 15:18:35 +020049 if (pipe->inode)
50 mutex_unlock(&pipe->inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 schedule();
Ingo Molnar3a326a22006-04-10 15:18:35 +020052 finish_wait(&pipe->wait, &wait);
53 if (pipe->inode)
54 mutex_lock(&pipe->inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
Arjan van de Ven858119e2006-01-14 13:20:43 -080057static int
Jens Axboef6762b72006-05-01 20:02:05 +020058pipe_iov_copy_from_user(void *to, struct iovec *iov, unsigned long len,
59 int atomic)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 unsigned long copy;
62
63 while (len > 0) {
64 while (!iov->iov_len)
65 iov++;
66 copy = min_t(unsigned long, len, iov->iov_len);
67
Jens Axboef6762b72006-05-01 20:02:05 +020068 if (atomic) {
69 if (__copy_from_user_inatomic(to, iov->iov_base, copy))
70 return -EFAULT;
71 } else {
72 if (copy_from_user(to, iov->iov_base, copy))
73 return -EFAULT;
74 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 to += copy;
76 len -= copy;
77 iov->iov_base += copy;
78 iov->iov_len -= copy;
79 }
80 return 0;
81}
82
Arjan van de Ven858119e2006-01-14 13:20:43 -080083static int
Jens Axboef6762b72006-05-01 20:02:05 +020084pipe_iov_copy_to_user(struct iovec *iov, const void *from, unsigned long len,
85 int atomic)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
87 unsigned long copy;
88
89 while (len > 0) {
90 while (!iov->iov_len)
91 iov++;
92 copy = min_t(unsigned long, len, iov->iov_len);
93
Jens Axboef6762b72006-05-01 20:02:05 +020094 if (atomic) {
95 if (__copy_to_user_inatomic(iov->iov_base, from, copy))
96 return -EFAULT;
97 } else {
98 if (copy_to_user(iov->iov_base, from, copy))
99 return -EFAULT;
100 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 from += copy;
102 len -= copy;
103 iov->iov_base += copy;
104 iov->iov_len -= copy;
105 }
106 return 0;
107}
108
Jens Axboef6762b72006-05-01 20:02:05 +0200109/*
110 * Attempt to pre-fault in the user memory, so we can use atomic copies.
111 * Returns the number of bytes not faulted in.
112 */
113static int iov_fault_in_pages_write(struct iovec *iov, unsigned long len)
114{
115 while (!iov->iov_len)
116 iov++;
117
118 while (len > 0) {
119 unsigned long this_len;
120
121 this_len = min_t(unsigned long, len, iov->iov_len);
122 if (fault_in_pages_writeable(iov->iov_base, this_len))
123 break;
124
125 len -= this_len;
126 iov++;
127 }
128
129 return len;
130}
131
132/*
133 * Pre-fault in the user memory, so we can use atomic copies.
134 */
135static void iov_fault_in_pages_read(struct iovec *iov, unsigned long len)
136{
137 while (!iov->iov_len)
138 iov++;
139
140 while (len > 0) {
141 unsigned long this_len;
142
143 this_len = min_t(unsigned long, len, iov->iov_len);
144 fault_in_pages_readable(iov->iov_base, this_len);
145 len -= this_len;
146 iov++;
147 }
148}
149
Ingo Molnar341b4462006-04-11 13:57:45 +0200150static void anon_pipe_buf_release(struct pipe_inode_info *pipe,
151 struct pipe_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
153 struct page *page = buf->page;
154
Jens Axboe5274f052006-03-30 15:15:30 +0200155 /*
156 * If nobody else uses this page, and we don't already have a
157 * temporary page, let's keep track of it as a one-deep
Ingo Molnar341b4462006-04-11 13:57:45 +0200158 * allocation cache. (Otherwise just release our reference to it)
Jens Axboe5274f052006-03-30 15:15:30 +0200159 */
Ingo Molnar341b4462006-04-11 13:57:45 +0200160 if (page_count(page) == 1 && !pipe->tmp_page)
Ingo Molnar923f4f22006-04-11 13:53:33 +0200161 pipe->tmp_page = page;
Ingo Molnar341b4462006-04-11 13:57:45 +0200162 else
163 page_cache_release(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164}
165
Jens Axboef84d7512006-05-01 19:59:03 +0200166void *generic_pipe_buf_map(struct pipe_inode_info *pipe,
Jens Axboef6762b72006-05-01 20:02:05 +0200167 struct pipe_buffer *buf, int atomic)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
Jens Axboef6762b72006-05-01 20:02:05 +0200169 if (atomic) {
170 buf->flags |= PIPE_BUF_FLAG_ATOMIC;
171 return kmap_atomic(buf->page, KM_USER0);
172 }
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 return kmap(buf->page);
175}
176
Jens Axboef84d7512006-05-01 19:59:03 +0200177void generic_pipe_buf_unmap(struct pipe_inode_info *pipe,
Jens Axboef6762b72006-05-01 20:02:05 +0200178 struct pipe_buffer *buf, void *map_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
Jens Axboef6762b72006-05-01 20:02:05 +0200180 if (buf->flags & PIPE_BUF_FLAG_ATOMIC) {
181 buf->flags &= ~PIPE_BUF_FLAG_ATOMIC;
182 kunmap_atomic(map_data, KM_USER0);
183 } else
184 kunmap(buf->page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185}
186
Jens Axboe330ab712006-05-02 15:29:57 +0200187int generic_pipe_buf_steal(struct pipe_inode_info *pipe,
188 struct pipe_buffer *buf)
Jens Axboe5abc97a2006-03-30 15:16:46 +0200189{
Jens Axboe46e678c2006-04-30 16:36:32 +0200190 struct page *page = buf->page;
191
192 if (page_count(page) == 1) {
Jens Axboe46e678c2006-04-30 16:36:32 +0200193 lock_page(page);
194 return 0;
195 }
196
197 return 1;
Jens Axboe5abc97a2006-03-30 15:16:46 +0200198}
199
Jens Axboef84d7512006-05-01 19:59:03 +0200200void generic_pipe_buf_get(struct pipe_inode_info *info, struct pipe_buffer *buf)
Jens Axboe70524492006-04-11 15:51:17 +0200201{
202 page_cache_get(buf->page);
203}
204
Jens Axboef84d7512006-05-01 19:59:03 +0200205int generic_pipe_buf_pin(struct pipe_inode_info *info, struct pipe_buffer *buf)
206{
207 return 0;
208}
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210static struct pipe_buf_operations anon_pipe_buf_ops = {
211 .can_merge = 1,
Jens Axboef84d7512006-05-01 19:59:03 +0200212 .map = generic_pipe_buf_map,
213 .unmap = generic_pipe_buf_unmap,
214 .pin = generic_pipe_buf_pin,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 .release = anon_pipe_buf_release,
Jens Axboe330ab712006-05-02 15:29:57 +0200216 .steal = generic_pipe_buf_steal,
Jens Axboef84d7512006-05-01 19:59:03 +0200217 .get = generic_pipe_buf_get,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218};
219
220static ssize_t
221pipe_readv(struct file *filp, const struct iovec *_iov,
222 unsigned long nr_segs, loff_t *ppos)
223{
224 struct inode *inode = filp->f_dentry->d_inode;
Ingo Molnar923f4f22006-04-11 13:53:33 +0200225 struct pipe_inode_info *pipe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 int do_wakeup;
227 ssize_t ret;
228 struct iovec *iov = (struct iovec *)_iov;
229 size_t total_len;
230
231 total_len = iov_length(iov, nr_segs);
232 /* Null read succeeds. */
233 if (unlikely(total_len == 0))
234 return 0;
235
236 do_wakeup = 0;
237 ret = 0;
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200238 mutex_lock(&inode->i_mutex);
Ingo Molnar923f4f22006-04-11 13:53:33 +0200239 pipe = inode->i_pipe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 for (;;) {
Ingo Molnar923f4f22006-04-11 13:53:33 +0200241 int bufs = pipe->nrbufs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 if (bufs) {
Ingo Molnar923f4f22006-04-11 13:53:33 +0200243 int curbuf = pipe->curbuf;
244 struct pipe_buffer *buf = pipe->bufs + curbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 struct pipe_buf_operations *ops = buf->ops;
246 void *addr;
247 size_t chars = buf->len;
Jens Axboef6762b72006-05-01 20:02:05 +0200248 int error, atomic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250 if (chars > total_len)
251 chars = total_len;
252
Jens Axboef84d7512006-05-01 19:59:03 +0200253 error = ops->pin(pipe, buf);
254 if (error) {
Jens Axboe5274f052006-03-30 15:15:30 +0200255 if (!ret)
Jens Axboef84d7512006-05-01 19:59:03 +0200256 error = ret;
Jens Axboe5274f052006-03-30 15:15:30 +0200257 break;
258 }
Jens Axboef84d7512006-05-01 19:59:03 +0200259
Jens Axboef6762b72006-05-01 20:02:05 +0200260 atomic = !iov_fault_in_pages_write(iov, chars);
261redo:
262 addr = ops->map(pipe, buf, atomic);
263 error = pipe_iov_copy_to_user(iov, addr + buf->offset, chars, atomic);
264 ops->unmap(pipe, buf, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 if (unlikely(error)) {
Jens Axboef6762b72006-05-01 20:02:05 +0200266 /*
267 * Just retry with the slow path if we failed.
268 */
269 if (atomic) {
270 atomic = 0;
271 goto redo;
272 }
Ingo Molnar341b4462006-04-11 13:57:45 +0200273 if (!ret)
Jens Axboef6762b72006-05-01 20:02:05 +0200274 ret = error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 break;
276 }
277 ret += chars;
278 buf->offset += chars;
279 buf->len -= chars;
280 if (!buf->len) {
281 buf->ops = NULL;
Ingo Molnar923f4f22006-04-11 13:53:33 +0200282 ops->release(pipe, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 curbuf = (curbuf + 1) & (PIPE_BUFFERS-1);
Ingo Molnar923f4f22006-04-11 13:53:33 +0200284 pipe->curbuf = curbuf;
285 pipe->nrbufs = --bufs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 do_wakeup = 1;
287 }
288 total_len -= chars;
289 if (!total_len)
290 break; /* common path: read succeeded */
291 }
292 if (bufs) /* More to do? */
293 continue;
Ingo Molnar923f4f22006-04-11 13:53:33 +0200294 if (!pipe->writers)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 break;
Ingo Molnar923f4f22006-04-11 13:53:33 +0200296 if (!pipe->waiting_writers) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 /* syscall merging: Usually we must not sleep
298 * if O_NONBLOCK is set, or if we got some data.
299 * But if a writer sleeps in kernel space, then
300 * we can wait for that data without violating POSIX.
301 */
302 if (ret)
303 break;
304 if (filp->f_flags & O_NONBLOCK) {
305 ret = -EAGAIN;
306 break;
307 }
308 }
309 if (signal_pending(current)) {
Ingo Molnar341b4462006-04-11 13:57:45 +0200310 if (!ret)
311 ret = -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 break;
313 }
314 if (do_wakeup) {
Ingo Molnar923f4f22006-04-11 13:53:33 +0200315 wake_up_interruptible_sync(&pipe->wait);
316 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 }
Ingo Molnar923f4f22006-04-11 13:53:33 +0200318 pipe_wait(pipe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 }
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200320 mutex_unlock(&inode->i_mutex);
Ingo Molnar341b4462006-04-11 13:57:45 +0200321
322 /* Signal writers asynchronously that there is more room. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 if (do_wakeup) {
Ingo Molnar923f4f22006-04-11 13:53:33 +0200324 wake_up_interruptible(&pipe->wait);
325 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 }
327 if (ret > 0)
328 file_accessed(filp);
329 return ret;
330}
331
332static ssize_t
333pipe_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos)
334{
335 struct iovec iov = { .iov_base = buf, .iov_len = count };
Ingo Molnar341b4462006-04-11 13:57:45 +0200336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 return pipe_readv(filp, &iov, 1, ppos);
338}
339
340static ssize_t
341pipe_writev(struct file *filp, const struct iovec *_iov,
342 unsigned long nr_segs, loff_t *ppos)
343{
344 struct inode *inode = filp->f_dentry->d_inode;
Ingo Molnar923f4f22006-04-11 13:53:33 +0200345 struct pipe_inode_info *pipe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 ssize_t ret;
347 int do_wakeup;
348 struct iovec *iov = (struct iovec *)_iov;
349 size_t total_len;
350 ssize_t chars;
351
352 total_len = iov_length(iov, nr_segs);
353 /* Null write succeeds. */
354 if (unlikely(total_len == 0))
355 return 0;
356
357 do_wakeup = 0;
358 ret = 0;
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200359 mutex_lock(&inode->i_mutex);
Ingo Molnar923f4f22006-04-11 13:53:33 +0200360 pipe = inode->i_pipe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Ingo Molnar923f4f22006-04-11 13:53:33 +0200362 if (!pipe->readers) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 send_sig(SIGPIPE, current, 0);
364 ret = -EPIPE;
365 goto out;
366 }
367
368 /* We try to merge small writes */
369 chars = total_len & (PAGE_SIZE-1); /* size of the last buffer */
Ingo Molnar923f4f22006-04-11 13:53:33 +0200370 if (pipe->nrbufs && chars != 0) {
Ingo Molnar341b4462006-04-11 13:57:45 +0200371 int lastbuf = (pipe->curbuf + pipe->nrbufs - 1) &
372 (PIPE_BUFFERS-1);
Ingo Molnar923f4f22006-04-11 13:53:33 +0200373 struct pipe_buffer *buf = pipe->bufs + lastbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 struct pipe_buf_operations *ops = buf->ops;
375 int offset = buf->offset + buf->len;
Ingo Molnar341b4462006-04-11 13:57:45 +0200376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 if (ops->can_merge && offset + chars <= PAGE_SIZE) {
Jens Axboef6762b72006-05-01 20:02:05 +0200378 int error, atomic = 1;
Jens Axboe5274f052006-03-30 15:15:30 +0200379 void *addr;
Jens Axboe5274f052006-03-30 15:15:30 +0200380
Jens Axboef84d7512006-05-01 19:59:03 +0200381 error = ops->pin(pipe, buf);
382 if (error)
Jens Axboe5274f052006-03-30 15:15:30 +0200383 goto out;
Jens Axboef84d7512006-05-01 19:59:03 +0200384
Jens Axboef6762b72006-05-01 20:02:05 +0200385 iov_fault_in_pages_read(iov, chars);
386redo1:
387 addr = ops->map(pipe, buf, atomic);
Jens Axboe5274f052006-03-30 15:15:30 +0200388 error = pipe_iov_copy_from_user(offset + addr, iov,
Jens Axboef6762b72006-05-01 20:02:05 +0200389 chars, atomic);
390 ops->unmap(pipe, buf, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 ret = error;
392 do_wakeup = 1;
Jens Axboef6762b72006-05-01 20:02:05 +0200393 if (error) {
394 if (atomic) {
395 atomic = 0;
396 goto redo1;
397 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 goto out;
Jens Axboef6762b72006-05-01 20:02:05 +0200399 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 buf->len += chars;
401 total_len -= chars;
402 ret = chars;
403 if (!total_len)
404 goto out;
405 }
406 }
407
408 for (;;) {
409 int bufs;
Ingo Molnar341b4462006-04-11 13:57:45 +0200410
Ingo Molnar923f4f22006-04-11 13:53:33 +0200411 if (!pipe->readers) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 send_sig(SIGPIPE, current, 0);
Ingo Molnar341b4462006-04-11 13:57:45 +0200413 if (!ret)
414 ret = -EPIPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 break;
416 }
Ingo Molnar923f4f22006-04-11 13:53:33 +0200417 bufs = pipe->nrbufs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 if (bufs < PIPE_BUFFERS) {
Ingo Molnar923f4f22006-04-11 13:53:33 +0200419 int newbuf = (pipe->curbuf + bufs) & (PIPE_BUFFERS-1);
420 struct pipe_buffer *buf = pipe->bufs + newbuf;
421 struct page *page = pipe->tmp_page;
Jens Axboef6762b72006-05-01 20:02:05 +0200422 char *src;
423 int error, atomic = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 if (!page) {
426 page = alloc_page(GFP_HIGHUSER);
427 if (unlikely(!page)) {
428 ret = ret ? : -ENOMEM;
429 break;
430 }
Ingo Molnar923f4f22006-04-11 13:53:33 +0200431 pipe->tmp_page = page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 }
Ingo Molnar341b4462006-04-11 13:57:45 +0200433 /* Always wake up, even if the copy fails. Otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 * we lock up (O_NONBLOCK-)readers that sleep due to
435 * syscall merging.
436 * FIXME! Is this really true?
437 */
438 do_wakeup = 1;
439 chars = PAGE_SIZE;
440 if (chars > total_len)
441 chars = total_len;
442
Jens Axboef6762b72006-05-01 20:02:05 +0200443 iov_fault_in_pages_read(iov, chars);
444redo2:
445 if (atomic)
446 src = kmap_atomic(page, KM_USER0);
447 else
448 src = kmap(page);
449
450 error = pipe_iov_copy_from_user(src, iov, chars,
451 atomic);
452 if (atomic)
453 kunmap_atomic(src, KM_USER0);
454 else
455 kunmap(page);
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 if (unlikely(error)) {
Jens Axboef6762b72006-05-01 20:02:05 +0200458 if (atomic) {
459 atomic = 0;
460 goto redo2;
461 }
Ingo Molnar341b4462006-04-11 13:57:45 +0200462 if (!ret)
Jens Axboef6762b72006-05-01 20:02:05 +0200463 ret = error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 break;
465 }
466 ret += chars;
467
468 /* Insert it into the buffer array */
469 buf->page = page;
470 buf->ops = &anon_pipe_buf_ops;
471 buf->offset = 0;
472 buf->len = chars;
Ingo Molnar923f4f22006-04-11 13:53:33 +0200473 pipe->nrbufs = ++bufs;
474 pipe->tmp_page = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
476 total_len -= chars;
477 if (!total_len)
478 break;
479 }
480 if (bufs < PIPE_BUFFERS)
481 continue;
482 if (filp->f_flags & O_NONBLOCK) {
Ingo Molnar341b4462006-04-11 13:57:45 +0200483 if (!ret)
484 ret = -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 break;
486 }
487 if (signal_pending(current)) {
Ingo Molnar341b4462006-04-11 13:57:45 +0200488 if (!ret)
489 ret = -ERESTARTSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 break;
491 }
492 if (do_wakeup) {
Ingo Molnar923f4f22006-04-11 13:53:33 +0200493 wake_up_interruptible_sync(&pipe->wait);
494 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 do_wakeup = 0;
496 }
Ingo Molnar923f4f22006-04-11 13:53:33 +0200497 pipe->waiting_writers++;
498 pipe_wait(pipe);
499 pipe->waiting_writers--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 }
501out:
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200502 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 if (do_wakeup) {
Ingo Molnar923f4f22006-04-11 13:53:33 +0200504 wake_up_interruptible(&pipe->wait);
505 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 }
507 if (ret > 0)
Christoph Hellwig870f4812006-01-09 20:52:01 -0800508 file_update_time(filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 return ret;
510}
511
512static ssize_t
513pipe_write(struct file *filp, const char __user *buf,
514 size_t count, loff_t *ppos)
515{
516 struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = count };
Ingo Molnar341b4462006-04-11 13:57:45 +0200517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 return pipe_writev(filp, &iov, 1, ppos);
519}
520
521static ssize_t
522bad_pipe_r(struct file *filp, char __user *buf, size_t count, loff_t *ppos)
523{
524 return -EBADF;
525}
526
527static ssize_t
Ingo Molnar341b4462006-04-11 13:57:45 +0200528bad_pipe_w(struct file *filp, const char __user *buf, size_t count,
529 loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530{
531 return -EBADF;
532}
533
534static int
535pipe_ioctl(struct inode *pino, struct file *filp,
536 unsigned int cmd, unsigned long arg)
537{
538 struct inode *inode = filp->f_dentry->d_inode;
Ingo Molnar923f4f22006-04-11 13:53:33 +0200539 struct pipe_inode_info *pipe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 int count, buf, nrbufs;
541
542 switch (cmd) {
543 case FIONREAD:
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200544 mutex_lock(&inode->i_mutex);
Ingo Molnar923f4f22006-04-11 13:53:33 +0200545 pipe = inode->i_pipe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 count = 0;
Ingo Molnar923f4f22006-04-11 13:53:33 +0200547 buf = pipe->curbuf;
548 nrbufs = pipe->nrbufs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 while (--nrbufs >= 0) {
Ingo Molnar923f4f22006-04-11 13:53:33 +0200550 count += pipe->bufs[buf].len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 buf = (buf+1) & (PIPE_BUFFERS-1);
552 }
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200553 mutex_unlock(&inode->i_mutex);
Ingo Molnar923f4f22006-04-11 13:53:33 +0200554
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 return put_user(count, (int __user *)arg);
556 default:
557 return -EINVAL;
558 }
559}
560
561/* No kernel lock held - fine */
562static unsigned int
563pipe_poll(struct file *filp, poll_table *wait)
564{
565 unsigned int mask;
566 struct inode *inode = filp->f_dentry->d_inode;
Ingo Molnar923f4f22006-04-11 13:53:33 +0200567 struct pipe_inode_info *pipe = inode->i_pipe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 int nrbufs;
569
Ingo Molnar923f4f22006-04-11 13:53:33 +0200570 poll_wait(filp, &pipe->wait, wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
572 /* Reading only -- no need for acquiring the semaphore. */
Ingo Molnar923f4f22006-04-11 13:53:33 +0200573 nrbufs = pipe->nrbufs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 mask = 0;
575 if (filp->f_mode & FMODE_READ) {
576 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
Ingo Molnar923f4f22006-04-11 13:53:33 +0200577 if (!pipe->writers && filp->f_version != pipe->w_counter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 mask |= POLLHUP;
579 }
580
581 if (filp->f_mode & FMODE_WRITE) {
582 mask |= (nrbufs < PIPE_BUFFERS) ? POLLOUT | POLLWRNORM : 0;
Pekka Enberg5e5d7a22005-09-06 15:17:48 -0700583 /*
584 * Most Unices do not set POLLERR for FIFOs but on Linux they
585 * behave exactly like pipes for poll().
586 */
Ingo Molnar923f4f22006-04-11 13:53:33 +0200587 if (!pipe->readers)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 mask |= POLLERR;
589 }
590
591 return mask;
592}
593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594static int
595pipe_release(struct inode *inode, int decr, int decw)
596{
Ingo Molnar923f4f22006-04-11 13:53:33 +0200597 struct pipe_inode_info *pipe;
598
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200599 mutex_lock(&inode->i_mutex);
Ingo Molnar923f4f22006-04-11 13:53:33 +0200600 pipe = inode->i_pipe;
601 pipe->readers -= decr;
602 pipe->writers -= decw;
Ingo Molnar341b4462006-04-11 13:57:45 +0200603
Ingo Molnar923f4f22006-04-11 13:53:33 +0200604 if (!pipe->readers && !pipe->writers) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 free_pipe_info(inode);
606 } else {
Ingo Molnar923f4f22006-04-11 13:53:33 +0200607 wake_up_interruptible(&pipe->wait);
608 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
609 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 }
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200611 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 return 0;
614}
615
616static int
617pipe_read_fasync(int fd, struct file *filp, int on)
618{
619 struct inode *inode = filp->f_dentry->d_inode;
620 int retval;
621
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200622 mutex_lock(&inode->i_mutex);
623 retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_readers);
624 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
626 if (retval < 0)
627 return retval;
628
629 return 0;
630}
631
632
633static int
634pipe_write_fasync(int fd, struct file *filp, int on)
635{
636 struct inode *inode = filp->f_dentry->d_inode;
637 int retval;
638
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200639 mutex_lock(&inode->i_mutex);
640 retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_writers);
641 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
643 if (retval < 0)
644 return retval;
645
646 return 0;
647}
648
649
650static int
651pipe_rdwr_fasync(int fd, struct file *filp, int on)
652{
653 struct inode *inode = filp->f_dentry->d_inode;
Ingo Molnar341b4462006-04-11 13:57:45 +0200654 struct pipe_inode_info *pipe = inode->i_pipe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 int retval;
656
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200657 mutex_lock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Ingo Molnar341b4462006-04-11 13:57:45 +0200659 retval = fasync_helper(fd, filp, on, &pipe->fasync_readers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
661 if (retval >= 0)
Ingo Molnar341b4462006-04-11 13:57:45 +0200662 retval = fasync_helper(fd, filp, on, &pipe->fasync_writers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200664 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666 if (retval < 0)
667 return retval;
668
669 return 0;
670}
671
672
673static int
674pipe_read_release(struct inode *inode, struct file *filp)
675{
676 pipe_read_fasync(-1, filp, 0);
677 return pipe_release(inode, 1, 0);
678}
679
680static int
681pipe_write_release(struct inode *inode, struct file *filp)
682{
683 pipe_write_fasync(-1, filp, 0);
684 return pipe_release(inode, 0, 1);
685}
686
687static int
688pipe_rdwr_release(struct inode *inode, struct file *filp)
689{
690 int decr, decw;
691
692 pipe_rdwr_fasync(-1, filp, 0);
693 decr = (filp->f_mode & FMODE_READ) != 0;
694 decw = (filp->f_mode & FMODE_WRITE) != 0;
695 return pipe_release(inode, decr, decw);
696}
697
698static int
699pipe_read_open(struct inode *inode, struct file *filp)
700{
701 /* We could have perhaps used atomic_t, but this and friends
702 below are the only places. So it doesn't seem worthwhile. */
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200703 mutex_lock(&inode->i_mutex);
704 inode->i_pipe->readers++;
705 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
707 return 0;
708}
709
710static int
711pipe_write_open(struct inode *inode, struct file *filp)
712{
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200713 mutex_lock(&inode->i_mutex);
714 inode->i_pipe->writers++;
715 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717 return 0;
718}
719
720static int
721pipe_rdwr_open(struct inode *inode, struct file *filp)
722{
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200723 mutex_lock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 if (filp->f_mode & FMODE_READ)
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200725 inode->i_pipe->readers++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 if (filp->f_mode & FMODE_WRITE)
Ingo Molnar9aeedfc2006-04-11 13:53:10 +0200727 inode->i_pipe->writers++;
728 mutex_unlock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730 return 0;
731}
732
733/*
734 * The file_operations structs are not static because they
735 * are also used in linux/fs/fifo.c to do operations on FIFOs.
736 */
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800737const struct file_operations read_fifo_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 .llseek = no_llseek,
739 .read = pipe_read,
740 .readv = pipe_readv,
741 .write = bad_pipe_w,
Pekka Enberg5e5d7a22005-09-06 15:17:48 -0700742 .poll = pipe_poll,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 .ioctl = pipe_ioctl,
744 .open = pipe_read_open,
745 .release = pipe_read_release,
746 .fasync = pipe_read_fasync,
747};
748
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800749const struct file_operations write_fifo_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 .llseek = no_llseek,
751 .read = bad_pipe_r,
752 .write = pipe_write,
753 .writev = pipe_writev,
Pekka Enberg5e5d7a22005-09-06 15:17:48 -0700754 .poll = pipe_poll,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 .ioctl = pipe_ioctl,
756 .open = pipe_write_open,
757 .release = pipe_write_release,
758 .fasync = pipe_write_fasync,
759};
760
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800761const struct file_operations rdwr_fifo_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 .llseek = no_llseek,
763 .read = pipe_read,
764 .readv = pipe_readv,
765 .write = pipe_write,
766 .writev = pipe_writev,
Pekka Enberg5e5d7a22005-09-06 15:17:48 -0700767 .poll = pipe_poll,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 .ioctl = pipe_ioctl,
769 .open = pipe_rdwr_open,
770 .release = pipe_rdwr_release,
771 .fasync = pipe_rdwr_fasync,
772};
773
Linus Torvaldsa19cbd42006-03-08 14:03:09 -0800774static struct file_operations read_pipe_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 .llseek = no_llseek,
776 .read = pipe_read,
777 .readv = pipe_readv,
778 .write = bad_pipe_w,
779 .poll = pipe_poll,
780 .ioctl = pipe_ioctl,
781 .open = pipe_read_open,
782 .release = pipe_read_release,
783 .fasync = pipe_read_fasync,
784};
785
Linus Torvaldsa19cbd42006-03-08 14:03:09 -0800786static struct file_operations write_pipe_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 .llseek = no_llseek,
788 .read = bad_pipe_r,
789 .write = pipe_write,
790 .writev = pipe_writev,
791 .poll = pipe_poll,
792 .ioctl = pipe_ioctl,
793 .open = pipe_write_open,
794 .release = pipe_write_release,
795 .fasync = pipe_write_fasync,
796};
797
Linus Torvaldsa19cbd42006-03-08 14:03:09 -0800798static struct file_operations rdwr_pipe_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 .llseek = no_llseek,
800 .read = pipe_read,
801 .readv = pipe_readv,
802 .write = pipe_write,
803 .writev = pipe_writev,
804 .poll = pipe_poll,
805 .ioctl = pipe_ioctl,
806 .open = pipe_rdwr_open,
807 .release = pipe_rdwr_release,
808 .fasync = pipe_rdwr_fasync,
809};
810
Ingo Molnar3a326a22006-04-10 15:18:35 +0200811struct pipe_inode_info * alloc_pipe_info(struct inode *inode)
812{
Ingo Molnar923f4f22006-04-11 13:53:33 +0200813 struct pipe_inode_info *pipe;
Ingo Molnar3a326a22006-04-10 15:18:35 +0200814
Ingo Molnar923f4f22006-04-11 13:53:33 +0200815 pipe = kzalloc(sizeof(struct pipe_inode_info), GFP_KERNEL);
816 if (pipe) {
817 init_waitqueue_head(&pipe->wait);
818 pipe->r_counter = pipe->w_counter = 1;
819 pipe->inode = inode;
Ingo Molnar3a326a22006-04-10 15:18:35 +0200820 }
821
Ingo Molnar923f4f22006-04-11 13:53:33 +0200822 return pipe;
Ingo Molnar3a326a22006-04-10 15:18:35 +0200823}
824
Ingo Molnar923f4f22006-04-11 13:53:33 +0200825void __free_pipe_info(struct pipe_inode_info *pipe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826{
827 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 for (i = 0; i < PIPE_BUFFERS; i++) {
Ingo Molnar923f4f22006-04-11 13:53:33 +0200830 struct pipe_buffer *buf = pipe->bufs + i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 if (buf->ops)
Ingo Molnar923f4f22006-04-11 13:53:33 +0200832 buf->ops->release(pipe, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 }
Ingo Molnar923f4f22006-04-11 13:53:33 +0200834 if (pipe->tmp_page)
835 __free_page(pipe->tmp_page);
836 kfree(pipe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837}
838
Jens Axboeb92ce552006-04-11 13:52:07 +0200839void free_pipe_info(struct inode *inode)
840{
841 __free_pipe_info(inode->i_pipe);
842 inode->i_pipe = NULL;
843}
844
Eric Dumazetfa3536c2006-03-26 01:37:24 -0800845static struct vfsmount *pipe_mnt __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846static int pipefs_delete_dentry(struct dentry *dentry)
847{
848 return 1;
849}
Ingo Molnar341b4462006-04-11 13:57:45 +0200850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851static struct dentry_operations pipefs_dentry_operations = {
852 .d_delete = pipefs_delete_dentry,
853};
854
855static struct inode * get_pipe_inode(void)
856{
857 struct inode *inode = new_inode(pipe_mnt->mnt_sb);
Ingo Molnar923f4f22006-04-11 13:53:33 +0200858 struct pipe_inode_info *pipe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
860 if (!inode)
861 goto fail_inode;
862
Ingo Molnar923f4f22006-04-11 13:53:33 +0200863 pipe = alloc_pipe_info(inode);
864 if (!pipe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 goto fail_iput;
Ingo Molnar923f4f22006-04-11 13:53:33 +0200866 inode->i_pipe = pipe;
Ingo Molnar3a326a22006-04-10 15:18:35 +0200867
Ingo Molnar923f4f22006-04-11 13:53:33 +0200868 pipe->readers = pipe->writers = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 inode->i_fop = &rdwr_pipe_fops;
870
871 /*
872 * Mark the inode dirty from the very beginning,
873 * that way it will never be moved to the dirty
874 * list because "mark_inode_dirty()" will think
875 * that it already _is_ on the dirty list.
876 */
877 inode->i_state = I_DIRTY;
878 inode->i_mode = S_IFIFO | S_IRUSR | S_IWUSR;
879 inode->i_uid = current->fsuid;
880 inode->i_gid = current->fsgid;
881 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
882 inode->i_blksize = PAGE_SIZE;
Ingo Molnar923f4f22006-04-11 13:53:33 +0200883
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 return inode;
885
886fail_iput:
887 iput(inode);
Ingo Molnar341b4462006-04-11 13:57:45 +0200888
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889fail_inode:
890 return NULL;
891}
892
893int do_pipe(int *fd)
894{
895 struct qstr this;
896 char name[32];
897 struct dentry *dentry;
898 struct inode * inode;
899 struct file *f1, *f2;
900 int error;
Ingo Molnar341b4462006-04-11 13:57:45 +0200901 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
903 error = -ENFILE;
904 f1 = get_empty_filp();
905 if (!f1)
906 goto no_files;
907
908 f2 = get_empty_filp();
909 if (!f2)
910 goto close_f1;
911
912 inode = get_pipe_inode();
913 if (!inode)
914 goto close_f12;
915
916 error = get_unused_fd();
917 if (error < 0)
918 goto close_f12_inode;
919 i = error;
920
921 error = get_unused_fd();
922 if (error < 0)
923 goto close_f12_inode_i;
924 j = error;
925
926 error = -ENOMEM;
927 sprintf(name, "[%lu]", inode->i_ino);
928 this.name = name;
929 this.len = strlen(name);
930 this.hash = inode->i_ino; /* will go */
931 dentry = d_alloc(pipe_mnt->mnt_sb->s_root, &this);
932 if (!dentry)
933 goto close_f12_inode_i_j;
Ingo Molnar341b4462006-04-11 13:57:45 +0200934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 dentry->d_op = &pipefs_dentry_operations;
936 d_add(dentry, inode);
937 f1->f_vfsmnt = f2->f_vfsmnt = mntget(mntget(pipe_mnt));
938 f1->f_dentry = f2->f_dentry = dget(dentry);
939 f1->f_mapping = f2->f_mapping = inode->i_mapping;
940
941 /* read file */
942 f1->f_pos = f2->f_pos = 0;
943 f1->f_flags = O_RDONLY;
944 f1->f_op = &read_pipe_fops;
945 f1->f_mode = FMODE_READ;
946 f1->f_version = 0;
947
948 /* write file */
949 f2->f_flags = O_WRONLY;
950 f2->f_op = &write_pipe_fops;
951 f2->f_mode = FMODE_WRITE;
952 f2->f_version = 0;
953
954 fd_install(i, f1);
955 fd_install(j, f2);
956 fd[0] = i;
957 fd[1] = j;
Ingo Molnar341b4462006-04-11 13:57:45 +0200958
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 return 0;
960
961close_f12_inode_i_j:
962 put_unused_fd(j);
963close_f12_inode_i:
964 put_unused_fd(i);
965close_f12_inode:
966 free_pipe_info(inode);
967 iput(inode);
968close_f12:
969 put_filp(f2);
970close_f1:
971 put_filp(f1);
972no_files:
973 return error;
974}
975
976/*
977 * pipefs should _never_ be mounted by userland - too much of security hassle,
978 * no real gain from having the whole whorehouse mounted. So we don't need
979 * any operations on the root directory. However, we need a non-trivial
980 * d_name - pipe: will go nicely and kill the special-casing in procfs.
981 */
982
Ingo Molnar341b4462006-04-11 13:57:45 +0200983static struct super_block *
984pipefs_get_sb(struct file_system_type *fs_type, int flags,
985 const char *dev_name, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986{
987 return get_sb_pseudo(fs_type, "pipe:", NULL, PIPEFS_MAGIC);
988}
989
990static struct file_system_type pipe_fs_type = {
991 .name = "pipefs",
992 .get_sb = pipefs_get_sb,
993 .kill_sb = kill_anon_super,
994};
995
996static int __init init_pipe_fs(void)
997{
998 int err = register_filesystem(&pipe_fs_type);
Ingo Molnar341b4462006-04-11 13:57:45 +0200999
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 if (!err) {
1001 pipe_mnt = kern_mount(&pipe_fs_type);
1002 if (IS_ERR(pipe_mnt)) {
1003 err = PTR_ERR(pipe_mnt);
1004 unregister_filesystem(&pipe_fs_type);
1005 }
1006 }
1007 return err;
1008}
1009
1010static void __exit exit_pipe_fs(void)
1011{
1012 unregister_filesystem(&pipe_fs_type);
1013 mntput(pipe_mnt);
1014}
1015
1016fs_initcall(init_pipe_fs);
1017module_exit(exit_pipe_fs);