pipe.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383
  1. /*
  2. * linux/fs/pipe.c
  3. *
  4. * Copyright (C) 1991, 1992, 1999 Linus Torvalds
  5. */
  6. #include <linux/mm.h>
  7. #include <linux/file.h>
  8. #include <linux/poll.h>
  9. #include <linux/slab.h>
  10. #include <linux/module.h>
  11. #include <linux/init.h>
  12. #include <linux/fs.h>
  13. #include <linux/log2.h>
  14. #include <linux/mount.h>
  15. #include <linux/magic.h>
  16. #include <linux/pipe_fs_i.h>
  17. #include <linux/uio.h>
  18. #include <linux/highmem.h>
  19. #include <linux/pagemap.h>
  20. #include <linux/audit.h>
  21. #include <linux/syscalls.h>
  22. #include <linux/fcntl.h>
  23. #include <asm/uaccess.h>
  24. #include <asm/ioctls.h>
  25. /*
  26. * The max size that a non-root user is allowed to grow the pipe. Can
  27. * be set by root in /proc/sys/fs/pipe-max-size
  28. */
  29. unsigned int pipe_max_size = 1048576;
  30. /*
  31. * Minimum pipe size, as required by POSIX
  32. */
  33. unsigned int pipe_min_size = PAGE_SIZE;
  34. /* Maximum allocatable pages per user. Hard limit is unset by default, soft
  35. * matches default values.
  36. */
  37. unsigned long pipe_user_pages_hard;
  38. unsigned long pipe_user_pages_soft = PIPE_DEF_BUFFERS * INR_OPEN_CUR;
  39. /*
  40. * We use a start+len construction, which provides full use of the
  41. * allocated memory.
  42. * -- Florian Coosmann (FGC)
  43. *
  44. * Reads with count = 0 should always return 0.
  45. * -- Julian Bradfield 1999-06-07.
  46. *
  47. * FIFOs and Pipes now generate SIGIO for both readers and writers.
  48. * -- Jeremy Elson <jelson@circlemud.org> 2001-08-16
  49. *
  50. * pipe_read & write cleanup
  51. * -- Manfred Spraul <manfred@colorfullife.com> 2002-05-09
  52. */
  53. static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
  54. {
  55. if (pipe->inode)
  56. mutex_lock_nested(&pipe->inode->i_mutex, subclass);
  57. }
  58. void pipe_lock(struct pipe_inode_info *pipe)
  59. {
  60. /*
  61. * pipe_lock() nests non-pipe inode locks (for writing to a file)
  62. */
  63. pipe_lock_nested(pipe, I_MUTEX_PARENT);
  64. }
  65. EXPORT_SYMBOL(pipe_lock);
  66. void pipe_unlock(struct pipe_inode_info *pipe)
  67. {
  68. if (pipe->inode)
  69. mutex_unlock(&pipe->inode->i_mutex);
  70. }
  71. EXPORT_SYMBOL(pipe_unlock);
  72. void pipe_double_lock(struct pipe_inode_info *pipe1,
  73. struct pipe_inode_info *pipe2)
  74. {
  75. BUG_ON(pipe1 == pipe2);
  76. if (pipe1 < pipe2) {
  77. pipe_lock_nested(pipe1, I_MUTEX_PARENT);
  78. pipe_lock_nested(pipe2, I_MUTEX_CHILD);
  79. } else {
  80. pipe_lock_nested(pipe2, I_MUTEX_PARENT);
  81. pipe_lock_nested(pipe1, I_MUTEX_CHILD);
  82. }
  83. }
  84. /* Drop the inode semaphore and wait for a pipe event, atomically */
  85. void pipe_wait(struct pipe_inode_info *pipe)
  86. {
  87. DEFINE_WAIT(wait);
  88. /*
  89. * Pipes are system-local resources, so sleeping on them
  90. * is considered a noninteractive wait:
  91. */
  92. prepare_to_wait(&pipe->wait, &wait, TASK_INTERRUPTIBLE);
  93. pipe_unlock(pipe);
  94. schedule();
  95. finish_wait(&pipe->wait, &wait);
  96. pipe_lock(pipe);
  97. }
  98. static int
  99. pipe_iov_copy_from_user(void *addr, int *offset, struct iovec *iov,
  100. size_t *remaining, int atomic)
  101. {
  102. unsigned long copy;
  103. while (*remaining > 0) {
  104. while (!iov->iov_len)
  105. iov++;
  106. copy = min_t(unsigned long, *remaining, iov->iov_len);
  107. if (atomic) {
  108. if (__copy_from_user_inatomic(addr + *offset,
  109. iov->iov_base, copy))
  110. return -EFAULT;
  111. } else {
  112. if (copy_from_user(addr + *offset,
  113. iov->iov_base, copy))
  114. return -EFAULT;
  115. }
  116. *offset += copy;
  117. *remaining -= copy;
  118. iov->iov_base += copy;
  119. iov->iov_len -= copy;
  120. }
  121. return 0;
  122. }
  123. static int
  124. pipe_iov_copy_to_user(struct iovec *iov, void *addr, int *offset,
  125. size_t *remaining, int atomic)
  126. {
  127. unsigned long copy;
  128. while (*remaining > 0) {
  129. while (!iov->iov_len)
  130. iov++;
  131. copy = min_t(unsigned long, *remaining, iov->iov_len);
  132. if (atomic) {
  133. if (__copy_to_user_inatomic(iov->iov_base,
  134. addr + *offset, copy))
  135. return -EFAULT;
  136. } else {
  137. if (copy_to_user(iov->iov_base,
  138. addr + *offset, copy))
  139. return -EFAULT;
  140. }
  141. *offset += copy;
  142. *remaining -= copy;
  143. iov->iov_base += copy;
  144. iov->iov_len -= copy;
  145. }
  146. return 0;
  147. }
  148. /*
  149. * Attempt to pre-fault in the user memory, so we can use atomic copies.
  150. * Returns the number of bytes not faulted in.
  151. */
  152. static int iov_fault_in_pages_write(struct iovec *iov, unsigned long len)
  153. {
  154. while (!iov->iov_len)
  155. iov++;
  156. while (len > 0) {
  157. unsigned long this_len;
  158. this_len = min_t(unsigned long, len, iov->iov_len);
  159. if (fault_in_pages_writeable(iov->iov_base, this_len))
  160. break;
  161. len -= this_len;
  162. iov++;
  163. }
  164. return len;
  165. }
  166. /*
  167. * Pre-fault in the user memory, so we can use atomic copies.
  168. */
  169. static void iov_fault_in_pages_read(struct iovec *iov, unsigned long len)
  170. {
  171. while (!iov->iov_len)
  172. iov++;
  173. while (len > 0) {
  174. unsigned long this_len;
  175. this_len = min_t(unsigned long, len, iov->iov_len);
  176. fault_in_pages_readable(iov->iov_base, this_len);
  177. len -= this_len;
  178. iov++;
  179. }
  180. }
  181. static void anon_pipe_buf_release(struct pipe_inode_info *pipe,
  182. struct pipe_buffer *buf)
  183. {
  184. struct page *page = buf->page;
  185. /*
  186. * If nobody else uses this page, and we don't already have a
  187. * temporary page, let's keep track of it as a one-deep
  188. * allocation cache. (Otherwise just release our reference to it)
  189. */
  190. if (page_count(page) == 1 && !pipe->tmp_page)
  191. pipe->tmp_page = page;
  192. else
  193. page_cache_release(page);
  194. }
  195. /**
  196. * generic_pipe_buf_map - virtually map a pipe buffer
  197. * @pipe: the pipe that the buffer belongs to
  198. * @buf: the buffer that should be mapped
  199. * @atomic: whether to use an atomic map
  200. *
  201. * Description:
  202. * This function returns a kernel virtual address mapping for the
  203. * pipe_buffer passed in @buf. If @atomic is set, an atomic map is provided
  204. * and the caller has to be careful not to fault before calling
  205. * the unmap function.
  206. *
  207. * Note that this function occupies KM_USER0 if @atomic != 0.
  208. */
  209. void *generic_pipe_buf_map(struct pipe_inode_info *pipe,
  210. struct pipe_buffer *buf, int atomic)
  211. {
  212. if (atomic) {
  213. buf->flags |= PIPE_BUF_FLAG_ATOMIC;
  214. return kmap_atomic(buf->page);
  215. }
  216. return kmap(buf->page);
  217. }
  218. EXPORT_SYMBOL(generic_pipe_buf_map);
  219. /**
  220. * generic_pipe_buf_unmap - unmap a previously mapped pipe buffer
  221. * @pipe: the pipe that the buffer belongs to
  222. * @buf: the buffer that should be unmapped
  223. * @map_data: the data that the mapping function returned
  224. *
  225. * Description:
  226. * This function undoes the mapping that ->map() provided.
  227. */
  228. void generic_pipe_buf_unmap(struct pipe_inode_info *pipe,
  229. struct pipe_buffer *buf, void *map_data)
  230. {
  231. if (buf->flags & PIPE_BUF_FLAG_ATOMIC) {
  232. buf->flags &= ~PIPE_BUF_FLAG_ATOMIC;
  233. kunmap_atomic(map_data);
  234. } else
  235. kunmap(buf->page);
  236. }
  237. EXPORT_SYMBOL(generic_pipe_buf_unmap);
  238. /**
  239. * generic_pipe_buf_steal - attempt to take ownership of a &pipe_buffer
  240. * @pipe: the pipe that the buffer belongs to
  241. * @buf: the buffer to attempt to steal
  242. *
  243. * Description:
  244. * This function attempts to steal the &struct page attached to
  245. * @buf. If successful, this function returns 0 and returns with
  246. * the page locked. The caller may then reuse the page for whatever
  247. * he wishes; the typical use is insertion into a different file
  248. * page cache.
  249. */
  250. int generic_pipe_buf_steal(struct pipe_inode_info *pipe,
  251. struct pipe_buffer *buf)
  252. {
  253. struct page *page = buf->page;
  254. /*
  255. * A reference of one is golden, that means that the owner of this
  256. * page is the only one holding a reference to it. lock the page
  257. * and return OK.
  258. */
  259. if (page_count(page) == 1) {
  260. lock_page(page);
  261. return 0;
  262. }
  263. return 1;
  264. }
  265. EXPORT_SYMBOL(generic_pipe_buf_steal);
  266. /**
  267. * generic_pipe_buf_get - get a reference to a &struct pipe_buffer
  268. * @pipe: the pipe that the buffer belongs to
  269. * @buf: the buffer to get a reference to
  270. *
  271. * Description:
  272. * This function grabs an extra reference to @buf. It's used in
  273. * in the tee() system call, when we duplicate the buffers in one
  274. * pipe into another.
  275. */
  276. void generic_pipe_buf_get(struct pipe_inode_info *pipe, struct pipe_buffer *buf)
  277. {
  278. page_cache_get(buf->page);
  279. }
  280. EXPORT_SYMBOL(generic_pipe_buf_get);
  281. /**
  282. * generic_pipe_buf_confirm - verify contents of the pipe buffer
  283. * @info: the pipe that the buffer belongs to
  284. * @buf: the buffer to confirm
  285. *
  286. * Description:
  287. * This function does nothing, because the generic pipe code uses
  288. * pages that are always good when inserted into the pipe.
  289. */
  290. int generic_pipe_buf_confirm(struct pipe_inode_info *info,
  291. struct pipe_buffer *buf)
  292. {
  293. return 0;
  294. }
  295. EXPORT_SYMBOL(generic_pipe_buf_confirm);
  296. /**
  297. * generic_pipe_buf_release - put a reference to a &struct pipe_buffer
  298. * @pipe: the pipe that the buffer belongs to
  299. * @buf: the buffer to put a reference to
  300. *
  301. * Description:
  302. * This function releases a reference to @buf.
  303. */
  304. void generic_pipe_buf_release(struct pipe_inode_info *pipe,
  305. struct pipe_buffer *buf)
  306. {
  307. page_cache_release(buf->page);
  308. }
  309. EXPORT_SYMBOL(generic_pipe_buf_release);
  310. static const struct pipe_buf_operations anon_pipe_buf_ops = {
  311. .can_merge = 1,
  312. .map = generic_pipe_buf_map,
  313. .unmap = generic_pipe_buf_unmap,
  314. .confirm = generic_pipe_buf_confirm,
  315. .release = anon_pipe_buf_release,
  316. .steal = generic_pipe_buf_steal,
  317. .get = generic_pipe_buf_get,
  318. };
  319. static const struct pipe_buf_operations packet_pipe_buf_ops = {
  320. .can_merge = 0,
  321. .map = generic_pipe_buf_map,
  322. .unmap = generic_pipe_buf_unmap,
  323. .confirm = generic_pipe_buf_confirm,
  324. .release = anon_pipe_buf_release,
  325. .steal = generic_pipe_buf_steal,
  326. .get = generic_pipe_buf_get,
  327. };
  328. static ssize_t
  329. pipe_read(struct kiocb *iocb, const struct iovec *_iov,
  330. unsigned long nr_segs, loff_t pos)
  331. {
  332. struct file *filp = iocb->ki_filp;
  333. struct inode *inode = filp->f_path.dentry->d_inode;
  334. struct pipe_inode_info *pipe;
  335. int do_wakeup;
  336. ssize_t ret;
  337. struct iovec *iov = (struct iovec *)_iov;
  338. size_t total_len;
  339. total_len = iov_length(iov, nr_segs);
  340. /* Null read succeeds. */
  341. if (unlikely(total_len == 0))
  342. return 0;
  343. do_wakeup = 0;
  344. ret = 0;
  345. mutex_lock(&inode->i_mutex);
  346. pipe = inode->i_pipe;
  347. for (;;) {
  348. int bufs = pipe->nrbufs;
  349. if (bufs) {
  350. int curbuf = pipe->curbuf;
  351. struct pipe_buffer *buf = pipe->bufs + curbuf;
  352. const struct pipe_buf_operations *ops = buf->ops;
  353. void *addr;
  354. size_t chars = buf->len, remaining;
  355. int error, atomic;
  356. int offset;
  357. if (chars > total_len)
  358. chars = total_len;
  359. error = ops->confirm(pipe, buf);
  360. if (error) {
  361. if (!ret)
  362. ret = error;
  363. break;
  364. }
  365. atomic = !iov_fault_in_pages_write(iov, chars);
  366. remaining = chars;
  367. offset = buf->offset;
  368. redo:
  369. addr = ops->map(pipe, buf, atomic);
  370. error = pipe_iov_copy_to_user(iov, addr, &offset,
  371. &remaining, atomic);
  372. ops->unmap(pipe, buf, addr);
  373. if (unlikely(error)) {
  374. /*
  375. * Just retry with the slow path if we failed.
  376. */
  377. if (atomic) {
  378. atomic = 0;
  379. goto redo;
  380. }
  381. if (!ret)
  382. ret = error;
  383. break;
  384. }
  385. ret += chars;
  386. buf->offset += chars;
  387. buf->len -= chars;
  388. /* Was it a packet buffer? Clean up and exit */
  389. if (buf->flags & PIPE_BUF_FLAG_PACKET) {
  390. total_len = chars;
  391. buf->len = 0;
  392. }
  393. if (!buf->len) {
  394. buf->ops = NULL;
  395. ops->release(pipe, buf);
  396. curbuf = (curbuf + 1) & (pipe->buffers - 1);
  397. pipe->curbuf = curbuf;
  398. pipe->nrbufs = --bufs;
  399. do_wakeup = 1;
  400. }
  401. total_len -= chars;
  402. if (!total_len)
  403. break; /* common path: read succeeded */
  404. }
  405. if (bufs) /* More to do? */
  406. continue;
  407. if (!pipe->writers)
  408. break;
  409. if (!pipe->waiting_writers) {
  410. /* syscall merging: Usually we must not sleep
  411. * if O_NONBLOCK is set, or if we got some data.
  412. * But if a writer sleeps in kernel space, then
  413. * we can wait for that data without violating POSIX.
  414. */
  415. if (ret)
  416. break;
  417. if (filp->f_flags & O_NONBLOCK) {
  418. ret = -EAGAIN;
  419. break;
  420. }
  421. }
  422. if (signal_pending(current)) {
  423. if (!ret)
  424. ret = -ERESTARTSYS;
  425. break;
  426. }
  427. if (do_wakeup) {
  428. wake_up_interruptible_sync_poll(&pipe->wait, POLLOUT | POLLWRNORM);
  429. kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
  430. }
  431. pipe_wait(pipe);
  432. }
  433. mutex_unlock(&inode->i_mutex);
  434. /* Signal writers asynchronously that there is more room. */
  435. if (do_wakeup) {
  436. wake_up_interruptible_sync_poll(&pipe->wait, POLLOUT | POLLWRNORM);
  437. kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
  438. }
  439. if (ret > 0)
  440. file_accessed(filp);
  441. return ret;
  442. }
  443. static inline int is_packetized(struct file *file)
  444. {
  445. return (file->f_flags & O_DIRECT) != 0;
  446. }
  447. static ssize_t
  448. pipe_write(struct kiocb *iocb, const struct iovec *_iov,
  449. unsigned long nr_segs, loff_t ppos)
  450. {
  451. struct file *filp = iocb->ki_filp;
  452. struct inode *inode = filp->f_path.dentry->d_inode;
  453. struct pipe_inode_info *pipe;
  454. ssize_t ret;
  455. int do_wakeup;
  456. struct iovec *iov = (struct iovec *)_iov;
  457. size_t total_len;
  458. ssize_t chars;
  459. total_len = iov_length(iov, nr_segs);
  460. /* Null write succeeds. */
  461. if (unlikely(total_len == 0))
  462. return 0;
  463. do_wakeup = 0;
  464. ret = 0;
  465. mutex_lock(&inode->i_mutex);
  466. pipe = inode->i_pipe;
  467. if (!pipe->readers) {
  468. send_sig(SIGPIPE, current, 0);
  469. ret = -EPIPE;
  470. goto out;
  471. }
  472. /* We try to merge small writes */
  473. chars = total_len & (PAGE_SIZE-1); /* size of the last buffer */
  474. if (pipe->nrbufs && chars != 0) {
  475. int lastbuf = (pipe->curbuf + pipe->nrbufs - 1) &
  476. (pipe->buffers - 1);
  477. struct pipe_buffer *buf = pipe->bufs + lastbuf;
  478. const struct pipe_buf_operations *ops = buf->ops;
  479. int offset = buf->offset + buf->len;
  480. if (ops->can_merge && offset + chars <= PAGE_SIZE) {
  481. int error, atomic = 1;
  482. void *addr;
  483. size_t remaining = chars;
  484. error = ops->confirm(pipe, buf);
  485. if (error)
  486. goto out;
  487. iov_fault_in_pages_read(iov, chars);
  488. redo1:
  489. addr = ops->map(pipe, buf, atomic);
  490. error = pipe_iov_copy_from_user(addr, &offset, iov,
  491. &remaining, atomic);
  492. ops->unmap(pipe, buf, addr);
  493. ret = error;
  494. do_wakeup = 1;
  495. if (error) {
  496. if (atomic) {
  497. atomic = 0;
  498. goto redo1;
  499. }
  500. goto out;
  501. }
  502. buf->len += chars;
  503. total_len -= chars;
  504. ret = chars;
  505. if (!total_len)
  506. goto out;
  507. }
  508. }
  509. for (;;) {
  510. int bufs;
  511. if (!pipe->readers) {
  512. send_sig(SIGPIPE, current, 0);
  513. if (!ret)
  514. ret = -EPIPE;
  515. break;
  516. }
  517. bufs = pipe->nrbufs;
  518. if (bufs < pipe->buffers) {
  519. int newbuf = (pipe->curbuf + bufs) & (pipe->buffers-1);
  520. struct pipe_buffer *buf = pipe->bufs + newbuf;
  521. struct page *page = pipe->tmp_page;
  522. char *src;
  523. int error, atomic = 1;
  524. int offset = 0;
  525. size_t remaining;
  526. if (!page) {
  527. page = alloc_page(GFP_HIGHUSER);
  528. if (unlikely(!page)) {
  529. ret = ret ? : -ENOMEM;
  530. break;
  531. }
  532. pipe->tmp_page = page;
  533. }
  534. /* Always wake up, even if the copy fails. Otherwise
  535. * we lock up (O_NONBLOCK-)readers that sleep due to
  536. * syscall merging.
  537. * FIXME! Is this really true?
  538. */
  539. do_wakeup = 1;
  540. chars = PAGE_SIZE;
  541. if (chars > total_len)
  542. chars = total_len;
  543. iov_fault_in_pages_read(iov, chars);
  544. remaining = chars;
  545. redo2:
  546. if (atomic)
  547. src = kmap_atomic(page);
  548. else
  549. src = kmap(page);
  550. error = pipe_iov_copy_from_user(src, &offset, iov,
  551. &remaining, atomic);
  552. if (atomic)
  553. kunmap_atomic(src);
  554. else
  555. kunmap(page);
  556. if (unlikely(error)) {
  557. if (atomic) {
  558. atomic = 0;
  559. goto redo2;
  560. }
  561. if (!ret)
  562. ret = error;
  563. break;
  564. }
  565. ret += chars;
  566. /* Insert it into the buffer array */
  567. buf->page = page;
  568. buf->ops = &anon_pipe_buf_ops;
  569. buf->offset = 0;
  570. buf->len = chars;
  571. buf->flags = 0;
  572. if (is_packetized(filp)) {
  573. buf->ops = &packet_pipe_buf_ops;
  574. buf->flags = PIPE_BUF_FLAG_PACKET;
  575. }
  576. pipe->nrbufs = ++bufs;
  577. pipe->tmp_page = NULL;
  578. total_len -= chars;
  579. if (!total_len)
  580. break;
  581. }
  582. if (bufs < pipe->buffers)
  583. continue;
  584. if (filp->f_flags & O_NONBLOCK) {
  585. if (!ret)
  586. ret = -EAGAIN;
  587. break;
  588. }
  589. if (signal_pending(current)) {
  590. if (!ret)
  591. ret = -ERESTARTSYS;
  592. break;
  593. }
  594. if (do_wakeup) {
  595. wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLRDNORM);
  596. kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
  597. do_wakeup = 0;
  598. }
  599. pipe->waiting_writers++;
  600. pipe_wait(pipe);
  601. pipe->waiting_writers--;
  602. }
  603. out:
  604. mutex_unlock(&inode->i_mutex);
  605. if (do_wakeup) {
  606. wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLRDNORM);
  607. kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
  608. }
  609. if (ret > 0) {
  610. int err = file_update_time(filp);
  611. if (err)
  612. ret = err;
  613. }
  614. return ret;
  615. }
  616. static ssize_t
  617. bad_pipe_r(struct file *filp, char __user *buf, size_t count, loff_t *ppos)
  618. {
  619. return -EBADF;
  620. }
  621. static ssize_t
  622. bad_pipe_w(struct file *filp, const char __user *buf, size_t count,
  623. loff_t *ppos)
  624. {
  625. return -EBADF;
  626. }
  627. static long pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  628. {
  629. struct inode *inode = filp->f_path.dentry->d_inode;
  630. struct pipe_inode_info *pipe;
  631. int count, buf, nrbufs;
  632. switch (cmd) {
  633. case FIONREAD:
  634. mutex_lock(&inode->i_mutex);
  635. pipe = inode->i_pipe;
  636. count = 0;
  637. buf = pipe->curbuf;
  638. nrbufs = pipe->nrbufs;
  639. while (--nrbufs >= 0) {
  640. count += pipe->bufs[buf].len;
  641. buf = (buf+1) & (pipe->buffers - 1);
  642. }
  643. mutex_unlock(&inode->i_mutex);
  644. return put_user(count, (int __user *)arg);
  645. default:
  646. return -EINVAL;
  647. }
  648. }
  649. /* No kernel lock held - fine */
  650. static unsigned int
  651. pipe_poll(struct file *filp, poll_table *wait)
  652. {
  653. unsigned int mask;
  654. struct inode *inode = filp->f_path.dentry->d_inode;
  655. struct pipe_inode_info *pipe = inode->i_pipe;
  656. int nrbufs;
  657. poll_wait(filp, &pipe->wait, wait);
  658. /* Reading only -- no need for acquiring the semaphore. */
  659. nrbufs = pipe->nrbufs;
  660. mask = 0;
  661. if (filp->f_mode & FMODE_READ) {
  662. mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
  663. if (!pipe->writers && filp->f_version != pipe->w_counter)
  664. mask |= POLLHUP;
  665. }
  666. if (filp->f_mode & FMODE_WRITE) {
  667. mask |= (nrbufs < pipe->buffers) ? POLLOUT | POLLWRNORM : 0;
  668. /*
  669. * Most Unices do not set POLLERR for FIFOs but on Linux they
  670. * behave exactly like pipes for poll().
  671. */
  672. if (!pipe->readers)
  673. mask |= POLLERR;
  674. }
  675. return mask;
  676. }
  677. static int
  678. pipe_release(struct inode *inode, int decr, int decw)
  679. {
  680. struct pipe_inode_info *pipe;
  681. mutex_lock(&inode->i_mutex);
  682. pipe = inode->i_pipe;
  683. pipe->readers -= decr;
  684. pipe->writers -= decw;
  685. if (!pipe->readers && !pipe->writers) {
  686. free_pipe_info(inode);
  687. } else {
  688. wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
  689. kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
  690. kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
  691. }
  692. mutex_unlock(&inode->i_mutex);
  693. return 0;
  694. }
  695. static int
  696. pipe_read_fasync(int fd, struct file *filp, int on)
  697. {
  698. struct inode *inode = filp->f_path.dentry->d_inode;
  699. int retval;
  700. mutex_lock(&inode->i_mutex);
  701. retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_readers);
  702. mutex_unlock(&inode->i_mutex);
  703. return retval;
  704. }
  705. static int
  706. pipe_write_fasync(int fd, struct file *filp, int on)
  707. {
  708. struct inode *inode = filp->f_path.dentry->d_inode;
  709. int retval;
  710. mutex_lock(&inode->i_mutex);
  711. retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_writers);
  712. mutex_unlock(&inode->i_mutex);
  713. return retval;
  714. }
  715. static int
  716. pipe_rdwr_fasync(int fd, struct file *filp, int on)
  717. {
  718. struct inode *inode = filp->f_path.dentry->d_inode;
  719. struct pipe_inode_info *pipe = inode->i_pipe;
  720. int retval;
  721. mutex_lock(&inode->i_mutex);
  722. retval = fasync_helper(fd, filp, on, &pipe->fasync_readers);
  723. if (retval >= 0) {
  724. retval = fasync_helper(fd, filp, on, &pipe->fasync_writers);
  725. if (retval < 0) /* this can happen only if on == T */
  726. fasync_helper(-1, filp, 0, &pipe->fasync_readers);
  727. }
  728. mutex_unlock(&inode->i_mutex);
  729. return retval;
  730. }
  731. static int
  732. pipe_read_release(struct inode *inode, struct file *filp)
  733. {
  734. return pipe_release(inode, 1, 0);
  735. }
  736. static int
  737. pipe_write_release(struct inode *inode, struct file *filp)
  738. {
  739. return pipe_release(inode, 0, 1);
  740. }
  741. static int
  742. pipe_rdwr_release(struct inode *inode, struct file *filp)
  743. {
  744. int decr, decw;
  745. decr = (filp->f_mode & FMODE_READ) != 0;
  746. decw = (filp->f_mode & FMODE_WRITE) != 0;
  747. return pipe_release(inode, decr, decw);
  748. }
  749. static int
  750. pipe_read_open(struct inode *inode, struct file *filp)
  751. {
  752. int ret = -ENOENT;
  753. mutex_lock(&inode->i_mutex);
  754. if (inode->i_pipe) {
  755. ret = 0;
  756. inode->i_pipe->readers++;
  757. }
  758. mutex_unlock(&inode->i_mutex);
  759. return ret;
  760. }
  761. static int
  762. pipe_write_open(struct inode *inode, struct file *filp)
  763. {
  764. int ret = -ENOENT;
  765. mutex_lock(&inode->i_mutex);
  766. if (inode->i_pipe) {
  767. ret = 0;
  768. inode->i_pipe->writers++;
  769. }
  770. mutex_unlock(&inode->i_mutex);
  771. return ret;
  772. }
  773. static int
  774. pipe_rdwr_open(struct inode *inode, struct file *filp)
  775. {
  776. int ret = -ENOENT;
  777. if (!(filp->f_mode & (FMODE_READ|FMODE_WRITE)))
  778. return -EINVAL;
  779. mutex_lock(&inode->i_mutex);
  780. if (inode->i_pipe) {
  781. ret = 0;
  782. if (filp->f_mode & FMODE_READ)
  783. inode->i_pipe->readers++;
  784. if (filp->f_mode & FMODE_WRITE)
  785. inode->i_pipe->writers++;
  786. }
  787. mutex_unlock(&inode->i_mutex);
  788. return ret;
  789. }
  790. /*
  791. * The file_operations structs are not static because they
  792. * are also used in linux/fs/fifo.c to do operations on FIFOs.
  793. *
  794. * Pipes reuse fifos' file_operations structs.
  795. */
  796. const struct file_operations read_pipefifo_fops = {
  797. .llseek = no_llseek,
  798. .read = do_sync_read,
  799. .aio_read = pipe_read,
  800. .write = bad_pipe_w,
  801. .poll = pipe_poll,
  802. .unlocked_ioctl = pipe_ioctl,
  803. .open = pipe_read_open,
  804. .release = pipe_read_release,
  805. .fasync = pipe_read_fasync,
  806. };
  807. const struct file_operations write_pipefifo_fops = {
  808. .llseek = no_llseek,
  809. .read = bad_pipe_r,
  810. .write = do_sync_write,
  811. .aio_write = pipe_write,
  812. .poll = pipe_poll,
  813. .unlocked_ioctl = pipe_ioctl,
  814. .open = pipe_write_open,
  815. .release = pipe_write_release,
  816. .fasync = pipe_write_fasync,
  817. };
  818. const struct file_operations rdwr_pipefifo_fops = {
  819. .llseek = no_llseek,
  820. .read = do_sync_read,
  821. .aio_read = pipe_read,
  822. .write = do_sync_write,
  823. .aio_write = pipe_write,
  824. .poll = pipe_poll,
  825. .unlocked_ioctl = pipe_ioctl,
  826. .open = pipe_rdwr_open,
  827. .release = pipe_rdwr_release,
  828. .fasync = pipe_rdwr_fasync,
  829. };
  830. static void account_pipe_buffers(struct pipe_inode_info *pipe,
  831. unsigned long old, unsigned long new)
  832. {
  833. atomic_long_add(new - old, &pipe->user->pipe_bufs);
  834. }
  835. static bool too_many_pipe_buffers_soft(struct user_struct *user)
  836. {
  837. return pipe_user_pages_soft &&
  838. atomic_long_read(&user->pipe_bufs) >= pipe_user_pages_soft;
  839. }
  840. static bool too_many_pipe_buffers_hard(struct user_struct *user)
  841. {
  842. return pipe_user_pages_hard &&
  843. atomic_long_read(&user->pipe_bufs) >= pipe_user_pages_hard;
  844. }
  845. struct pipe_inode_info * alloc_pipe_info(struct inode *inode)
  846. {
  847. struct pipe_inode_info *pipe;
  848. pipe = kzalloc(sizeof(struct pipe_inode_info), GFP_KERNEL);
  849. if (pipe) {
  850. unsigned long pipe_bufs = PIPE_DEF_BUFFERS;
  851. struct user_struct *user = get_current_user();
  852. if (!too_many_pipe_buffers_hard(user)) {
  853. if (too_many_pipe_buffers_soft(user))
  854. pipe_bufs = 1;
  855. pipe->bufs = kzalloc(sizeof(struct pipe_buffer) * pipe_bufs, GFP_KERNEL);
  856. }
  857. if (pipe->bufs) {
  858. init_waitqueue_head(&pipe->wait);
  859. pipe->r_counter = pipe->w_counter = 1;
  860. pipe->inode = inode;
  861. pipe->buffers = pipe_bufs;
  862. pipe->user = user;
  863. account_pipe_buffers(pipe, 0, pipe_bufs);
  864. return pipe;
  865. }
  866. free_uid(user);
  867. kfree(pipe);
  868. }
  869. return NULL;
  870. }
  871. void __free_pipe_info(struct pipe_inode_info *pipe)
  872. {
  873. int i;
  874. account_pipe_buffers(pipe, pipe->buffers, 0);
  875. free_uid(pipe->user);
  876. for (i = 0; i < pipe->buffers; i++) {
  877. struct pipe_buffer *buf = pipe->bufs + i;
  878. if (buf->ops)
  879. buf->ops->release(pipe, buf);
  880. }
  881. if (pipe->tmp_page)
  882. __free_page(pipe->tmp_page);
  883. kfree(pipe->bufs);
  884. kfree(pipe);
  885. }
  886. void free_pipe_info(struct inode *inode)
  887. {
  888. __free_pipe_info(inode->i_pipe);
  889. inode->i_pipe = NULL;
  890. }
  891. static struct vfsmount *pipe_mnt __read_mostly;
  892. /*
  893. * pipefs_dname() is called from d_path().
  894. */
  895. static char *pipefs_dname(struct dentry *dentry, char *buffer, int buflen)
  896. {
  897. return dynamic_dname(dentry, buffer, buflen, "pipe:[%lu]",
  898. dentry->d_inode->i_ino);
  899. }
  900. static const struct dentry_operations pipefs_dentry_operations = {
  901. .d_dname = pipefs_dname,
  902. };
  903. static struct inode * get_pipe_inode(void)
  904. {
  905. struct inode *inode = new_inode_pseudo(pipe_mnt->mnt_sb);
  906. struct pipe_inode_info *pipe;
  907. if (!inode)
  908. goto fail_inode;
  909. inode->i_ino = get_next_ino();
  910. pipe = alloc_pipe_info(inode);
  911. if (!pipe)
  912. goto fail_iput;
  913. inode->i_pipe = pipe;
  914. pipe->readers = pipe->writers = 1;
  915. inode->i_fop = &rdwr_pipefifo_fops;
  916. /*
  917. * Mark the inode dirty from the very beginning,
  918. * that way it will never be moved to the dirty
  919. * list because "mark_inode_dirty()" will think
  920. * that it already _is_ on the dirty list.
  921. */
  922. inode->i_state = I_DIRTY;
  923. inode->i_mode = S_IFIFO | S_IRUSR | S_IWUSR;
  924. inode->i_uid = current_fsuid();
  925. inode->i_gid = current_fsgid();
  926. inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  927. return inode;
  928. fail_iput:
  929. iput(inode);
  930. fail_inode:
  931. return NULL;
  932. }
  933. struct file *create_write_pipe(int flags)
  934. {
  935. int err;
  936. struct inode *inode;
  937. struct file *f;
  938. struct path path;
  939. struct qstr name = { .name = "" };
  940. err = -ENFILE;
  941. inode = get_pipe_inode();
  942. if (!inode)
  943. goto err;
  944. err = -ENOMEM;
  945. path.dentry = d_alloc_pseudo(pipe_mnt->mnt_sb, &name);
  946. if (!path.dentry)
  947. goto err_inode;
  948. path.mnt = mntget(pipe_mnt);
  949. d_instantiate(path.dentry, inode);
  950. err = -ENFILE;
  951. f = alloc_file(&path, FMODE_WRITE, &write_pipefifo_fops);
  952. if (!f)
  953. goto err_dentry;
  954. f->f_mapping = inode->i_mapping;
  955. f->f_flags = O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT));
  956. f->f_version = 0;
  957. return f;
  958. err_dentry:
  959. free_pipe_info(inode);
  960. path_put(&path);
  961. return ERR_PTR(err);
  962. err_inode:
  963. free_pipe_info(inode);
  964. iput(inode);
  965. err:
  966. return ERR_PTR(err);
  967. }
  968. void free_write_pipe(struct file *f)
  969. {
  970. free_pipe_info(f->f_dentry->d_inode);
  971. path_put(&f->f_path);
  972. put_filp(f);
  973. }
  974. struct file *create_read_pipe(struct file *wrf, int flags)
  975. {
  976. /* Grab pipe from the writer */
  977. struct file *f = alloc_file(&wrf->f_path, FMODE_READ,
  978. &read_pipefifo_fops);
  979. if (!f)
  980. return ERR_PTR(-ENFILE);
  981. path_get(&wrf->f_path);
  982. f->f_flags = O_RDONLY | (flags & O_NONBLOCK);
  983. return f;
  984. }
  985. int do_pipe_flags(int *fd, int flags)
  986. {
  987. struct file *fw, *fr;
  988. int error;
  989. int fdw, fdr;
  990. if (flags & ~(O_CLOEXEC | O_NONBLOCK | O_DIRECT))
  991. return -EINVAL;
  992. fw = create_write_pipe(flags);
  993. if (IS_ERR(fw))
  994. return PTR_ERR(fw);
  995. fr = create_read_pipe(fw, flags);
  996. error = PTR_ERR(fr);
  997. if (IS_ERR(fr))
  998. goto err_write_pipe;
  999. error = get_unused_fd_flags(flags);
  1000. if (error < 0)
  1001. goto err_read_pipe;
  1002. fdr = error;
  1003. error = get_unused_fd_flags(flags);
  1004. if (error < 0)
  1005. goto err_fdr;
  1006. fdw = error;
  1007. audit_fd_pair(fdr, fdw);
  1008. fd_install(fdr, fr);
  1009. fd_install(fdw, fw);
  1010. fd[0] = fdr;
  1011. fd[1] = fdw;
  1012. return 0;
  1013. err_fdr:
  1014. put_unused_fd(fdr);
  1015. err_read_pipe:
  1016. path_put(&fr->f_path);
  1017. put_filp(fr);
  1018. err_write_pipe:
  1019. free_write_pipe(fw);
  1020. return error;
  1021. }
  1022. /*
  1023. * sys_pipe() is the normal C calling standard for creating
  1024. * a pipe. It's not the way Unix traditionally does this, though.
  1025. */
  1026. SYSCALL_DEFINE2(pipe2, int __user *, fildes, int, flags)
  1027. {
  1028. int fd[2];
  1029. int error;
  1030. error = do_pipe_flags(fd, flags);
  1031. if (!error) {
  1032. if (copy_to_user(fildes, fd, sizeof(fd))) {
  1033. sys_close(fd[0]);
  1034. sys_close(fd[1]);
  1035. error = -EFAULT;
  1036. }
  1037. }
  1038. return error;
  1039. }
  1040. SYSCALL_DEFINE1(pipe, int __user *, fildes)
  1041. {
  1042. return sys_pipe2(fildes, 0);
  1043. }
  1044. /*
  1045. * Allocate a new array of pipe buffers and copy the info over. Returns the
  1046. * pipe size if successful, or return -ERROR on error.
  1047. */
  1048. static long pipe_set_size(struct pipe_inode_info *pipe, unsigned long nr_pages)
  1049. {
  1050. struct pipe_buffer *bufs;
  1051. /*
  1052. * We can shrink the pipe, if arg >= pipe->nrbufs. Since we don't
  1053. * expect a lot of shrink+grow operations, just free and allocate
  1054. * again like we would do for growing. If the pipe currently
  1055. * contains more buffers than arg, then return busy.
  1056. */
  1057. if (nr_pages < pipe->nrbufs)
  1058. return -EBUSY;
  1059. bufs = kcalloc(nr_pages, sizeof(*bufs), GFP_KERNEL | __GFP_NOWARN);
  1060. if (unlikely(!bufs))
  1061. return -ENOMEM;
  1062. /*
  1063. * The pipe array wraps around, so just start the new one at zero
  1064. * and adjust the indexes.
  1065. */
  1066. if (pipe->nrbufs) {
  1067. unsigned int tail;
  1068. unsigned int head;
  1069. tail = pipe->curbuf + pipe->nrbufs;
  1070. if (tail < pipe->buffers)
  1071. tail = 0;
  1072. else
  1073. tail &= (pipe->buffers - 1);
  1074. head = pipe->nrbufs - tail;
  1075. if (head)
  1076. memcpy(bufs, pipe->bufs + pipe->curbuf, head * sizeof(struct pipe_buffer));
  1077. if (tail)
  1078. memcpy(bufs + head, pipe->bufs, tail * sizeof(struct pipe_buffer));
  1079. }
  1080. account_pipe_buffers(pipe, pipe->buffers, nr_pages);
  1081. pipe->curbuf = 0;
  1082. kfree(pipe->bufs);
  1083. pipe->bufs = bufs;
  1084. pipe->buffers = nr_pages;
  1085. return nr_pages * PAGE_SIZE;
  1086. }
  1087. /*
  1088. * Currently we rely on the pipe array holding a power-of-2 number
  1089. * of pages.
  1090. */
  1091. static inline unsigned int round_pipe_size(unsigned int size)
  1092. {
  1093. unsigned long nr_pages;
  1094. nr_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
  1095. return roundup_pow_of_two(nr_pages) << PAGE_SHIFT;
  1096. }
  1097. /*
  1098. * This should work even if CONFIG_PROC_FS isn't set, as proc_dointvec_minmax
  1099. * will return an error.
  1100. */
  1101. int pipe_proc_fn(struct ctl_table *table, int write, void __user *buf,
  1102. size_t *lenp, loff_t *ppos)
  1103. {
  1104. int ret;
  1105. ret = proc_dointvec_minmax(table, write, buf, lenp, ppos);
  1106. if (ret < 0 || !write)
  1107. return ret;
  1108. pipe_max_size = round_pipe_size(pipe_max_size);
  1109. return ret;
  1110. }
  1111. /*
  1112. * After the inode slimming patch, i_pipe/i_bdev/i_cdev share the same
  1113. * location, so checking ->i_pipe is not enough to verify that this is a
  1114. * pipe.
  1115. */
  1116. struct pipe_inode_info *get_pipe_info(struct file *file)
  1117. {
  1118. struct inode *i = file->f_path.dentry->d_inode;
  1119. return S_ISFIFO(i->i_mode) ? i->i_pipe : NULL;
  1120. }
  1121. long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
  1122. {
  1123. struct pipe_inode_info *pipe;
  1124. long ret;
  1125. pipe = get_pipe_info(file);
  1126. if (!pipe)
  1127. return -EBADF;
  1128. mutex_lock(&pipe->inode->i_mutex);
  1129. switch (cmd) {
  1130. case F_SETPIPE_SZ: {
  1131. unsigned int size, nr_pages;
  1132. size = round_pipe_size(arg);
  1133. nr_pages = size >> PAGE_SHIFT;
  1134. ret = -EINVAL;
  1135. if (!nr_pages)
  1136. goto out;
  1137. if (!capable(CAP_SYS_RESOURCE) && size > pipe_max_size) {
  1138. ret = -EPERM;
  1139. goto out;
  1140. } else if ((too_many_pipe_buffers_hard(pipe->user) ||
  1141. too_many_pipe_buffers_soft(pipe->user)) &&
  1142. !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN)) {
  1143. ret = -EPERM;
  1144. goto out;
  1145. }
  1146. ret = pipe_set_size(pipe, nr_pages);
  1147. break;
  1148. }
  1149. case F_GETPIPE_SZ:
  1150. ret = pipe->buffers * PAGE_SIZE;
  1151. break;
  1152. default:
  1153. ret = -EINVAL;
  1154. break;
  1155. }
  1156. out:
  1157. mutex_unlock(&pipe->inode->i_mutex);
  1158. return ret;
  1159. }
  1160. static const struct super_operations pipefs_ops = {
  1161. .destroy_inode = free_inode_nonrcu,
  1162. .statfs = simple_statfs,
  1163. };
  1164. /*
  1165. * pipefs should _never_ be mounted by userland - too much of security hassle,
  1166. * no real gain from having the whole whorehouse mounted. So we don't need
  1167. * any operations on the root directory. However, we need a non-trivial
  1168. * d_name - pipe: will go nicely and kill the special-casing in procfs.
  1169. */
  1170. static struct dentry *pipefs_mount(struct file_system_type *fs_type,
  1171. int flags, const char *dev_name, void *data)
  1172. {
  1173. return mount_pseudo(fs_type, "pipe:", &pipefs_ops,
  1174. &pipefs_dentry_operations, PIPEFS_MAGIC);
  1175. }
  1176. static struct file_system_type pipe_fs_type = {
  1177. .name = "pipefs",
  1178. .mount = pipefs_mount,
  1179. .kill_sb = kill_anon_super,
  1180. };
  1181. static int __init init_pipe_fs(void)
  1182. {
  1183. int err = register_filesystem(&pipe_fs_type);
  1184. if (!err) {
  1185. pipe_mnt = kern_mount(&pipe_fs_type);
  1186. if (IS_ERR(pipe_mnt)) {
  1187. err = PTR_ERR(pipe_mnt);
  1188. unregister_filesystem(&pipe_fs_type);
  1189. }
  1190. }
  1191. return err;
  1192. }
  1193. fs_initcall(init_pipe_fs);