rpc_pipe.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * net/sunrpc/rpc_pipe.c
  4. *
  5. * Userland/kernel interface for rpcauth_gss.
  6. * Code shamelessly plagiarized from fs/nfsd/nfsctl.c
  7. * and fs/sysfs/inode.c
  8. *
  9. * Copyright (c) 2002, Trond Myklebust <trond.myklebust@fys.uio.no>
  10. *
  11. */
  12. #include <linux/module.h>
  13. #include <linux/slab.h>
  14. #include <linux/string.h>
  15. #include <linux/pagemap.h>
  16. #include <linux/mount.h>
  17. #include <linux/fs_context.h>
  18. #include <linux/namei.h>
  19. #include <linux/fsnotify.h>
  20. #include <linux/kernel.h>
  21. #include <linux/rcupdate.h>
  22. #include <linux/utsname.h>
  23. #include <asm/ioctls.h>
  24. #include <linux/poll.h>
  25. #include <linux/wait.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/sunrpc/clnt.h>
  28. #include <linux/workqueue.h>
  29. #include <linux/sunrpc/rpc_pipe_fs.h>
  30. #include <linux/sunrpc/cache.h>
  31. #include <linux/nsproxy.h>
  32. #include <linux/notifier.h>
  33. #include "netns.h"
  34. #include "sunrpc.h"
  35. #define RPCDBG_FACILITY RPCDBG_DEBUG
  36. #define NET_NAME(net) ((net == &init_net) ? " (init_net)" : "")
  37. static struct file_system_type rpc_pipe_fs_type;
  38. static const struct rpc_pipe_ops gssd_dummy_pipe_ops;
  39. static struct kmem_cache *rpc_inode_cachep __read_mostly;
  40. #define RPC_UPCALL_TIMEOUT (30*HZ)
  41. static BLOCKING_NOTIFIER_HEAD(rpc_pipefs_notifier_list);
  42. int rpc_pipefs_notifier_register(struct notifier_block *nb)
  43. {
  44. return blocking_notifier_chain_register(&rpc_pipefs_notifier_list, nb);
  45. }
  46. EXPORT_SYMBOL_GPL(rpc_pipefs_notifier_register);
  47. void rpc_pipefs_notifier_unregister(struct notifier_block *nb)
  48. {
  49. blocking_notifier_chain_unregister(&rpc_pipefs_notifier_list, nb);
  50. }
  51. EXPORT_SYMBOL_GPL(rpc_pipefs_notifier_unregister);
  52. static void rpc_purge_list(wait_queue_head_t *waitq, struct list_head *head,
  53. void (*destroy_msg)(struct rpc_pipe_msg *), int err)
  54. {
  55. struct rpc_pipe_msg *msg;
  56. if (list_empty(head))
  57. return;
  58. do {
  59. msg = list_entry(head->next, struct rpc_pipe_msg, list);
  60. list_del_init(&msg->list);
  61. msg->errno = err;
  62. destroy_msg(msg);
  63. } while (!list_empty(head));
  64. if (waitq)
  65. wake_up(waitq);
  66. }
  67. static void
  68. rpc_timeout_upcall_queue(struct work_struct *work)
  69. {
  70. LIST_HEAD(free_list);
  71. struct rpc_pipe *pipe =
  72. container_of(work, struct rpc_pipe, queue_timeout.work);
  73. void (*destroy_msg)(struct rpc_pipe_msg *);
  74. struct dentry *dentry;
  75. spin_lock(&pipe->lock);
  76. destroy_msg = pipe->ops->destroy_msg;
  77. if (pipe->nreaders == 0) {
  78. list_splice_init(&pipe->pipe, &free_list);
  79. pipe->pipelen = 0;
  80. }
  81. dentry = dget(pipe->dentry);
  82. spin_unlock(&pipe->lock);
  83. rpc_purge_list(dentry ? &RPC_I(d_inode(dentry))->waitq : NULL,
  84. &free_list, destroy_msg, -ETIMEDOUT);
  85. dput(dentry);
  86. }
  87. ssize_t rpc_pipe_generic_upcall(struct file *filp, struct rpc_pipe_msg *msg,
  88. char __user *dst, size_t buflen)
  89. {
  90. char *data = (char *)msg->data + msg->copied;
  91. size_t mlen = min(msg->len - msg->copied, buflen);
  92. unsigned long left;
  93. left = copy_to_user(dst, data, mlen);
  94. if (left == mlen) {
  95. msg->errno = -EFAULT;
  96. return -EFAULT;
  97. }
  98. mlen -= left;
  99. msg->copied += mlen;
  100. msg->errno = 0;
  101. return mlen;
  102. }
  103. EXPORT_SYMBOL_GPL(rpc_pipe_generic_upcall);
  104. /**
  105. * rpc_queue_upcall - queue an upcall message to userspace
  106. * @pipe: upcall pipe on which to queue given message
  107. * @msg: message to queue
  108. *
  109. * Call with an @inode created by rpc_mkpipe() to queue an upcall.
  110. * A userspace process may then later read the upcall by performing a
  111. * read on an open file for this inode. It is up to the caller to
  112. * initialize the fields of @msg (other than @msg->list) appropriately.
  113. */
  114. int
  115. rpc_queue_upcall(struct rpc_pipe *pipe, struct rpc_pipe_msg *msg)
  116. {
  117. int res = -EPIPE;
  118. struct dentry *dentry;
  119. spin_lock(&pipe->lock);
  120. if (pipe->nreaders) {
  121. list_add_tail(&msg->list, &pipe->pipe);
  122. pipe->pipelen += msg->len;
  123. res = 0;
  124. } else if (pipe->flags & RPC_PIPE_WAIT_FOR_OPEN) {
  125. if (list_empty(&pipe->pipe))
  126. queue_delayed_work(rpciod_workqueue,
  127. &pipe->queue_timeout,
  128. RPC_UPCALL_TIMEOUT);
  129. list_add_tail(&msg->list, &pipe->pipe);
  130. pipe->pipelen += msg->len;
  131. res = 0;
  132. }
  133. dentry = dget(pipe->dentry);
  134. spin_unlock(&pipe->lock);
  135. if (dentry) {
  136. wake_up(&RPC_I(d_inode(dentry))->waitq);
  137. dput(dentry);
  138. }
  139. return res;
  140. }
  141. EXPORT_SYMBOL_GPL(rpc_queue_upcall);
  142. static inline void
  143. rpc_inode_setowner(struct inode *inode, void *private)
  144. {
  145. RPC_I(inode)->private = private;
  146. }
  147. static void
  148. rpc_close_pipes(struct dentry *dentry)
  149. {
  150. struct inode *inode = dentry->d_inode;
  151. struct rpc_pipe *pipe = RPC_I(inode)->pipe;
  152. int need_release;
  153. LIST_HEAD(free_list);
  154. inode_lock(inode);
  155. spin_lock(&pipe->lock);
  156. need_release = pipe->nreaders != 0 || pipe->nwriters != 0;
  157. pipe->nreaders = 0;
  158. list_splice_init(&pipe->in_upcall, &free_list);
  159. list_splice_init(&pipe->pipe, &free_list);
  160. pipe->pipelen = 0;
  161. pipe->dentry = NULL;
  162. spin_unlock(&pipe->lock);
  163. rpc_purge_list(&RPC_I(inode)->waitq, &free_list, pipe->ops->destroy_msg, -EPIPE);
  164. pipe->nwriters = 0;
  165. if (need_release && pipe->ops->release_pipe)
  166. pipe->ops->release_pipe(inode);
  167. cancel_delayed_work_sync(&pipe->queue_timeout);
  168. rpc_inode_setowner(inode, NULL);
  169. RPC_I(inode)->pipe = NULL;
  170. inode_unlock(inode);
  171. }
  172. static struct inode *
  173. rpc_alloc_inode(struct super_block *sb)
  174. {
  175. struct rpc_inode *rpci;
  176. rpci = alloc_inode_sb(sb, rpc_inode_cachep, GFP_KERNEL);
  177. if (!rpci)
  178. return NULL;
  179. return &rpci->vfs_inode;
  180. }
  181. static void
  182. rpc_free_inode(struct inode *inode)
  183. {
  184. kmem_cache_free(rpc_inode_cachep, RPC_I(inode));
  185. }
  186. static int
  187. rpc_pipe_open(struct inode *inode, struct file *filp)
  188. {
  189. struct rpc_pipe *pipe;
  190. int first_open;
  191. int res = -ENXIO;
  192. inode_lock(inode);
  193. pipe = RPC_I(inode)->pipe;
  194. if (pipe == NULL)
  195. goto out;
  196. first_open = pipe->nreaders == 0 && pipe->nwriters == 0;
  197. if (first_open && pipe->ops->open_pipe) {
  198. res = pipe->ops->open_pipe(inode);
  199. if (res)
  200. goto out;
  201. }
  202. if (filp->f_mode & FMODE_READ)
  203. pipe->nreaders++;
  204. if (filp->f_mode & FMODE_WRITE)
  205. pipe->nwriters++;
  206. res = 0;
  207. out:
  208. inode_unlock(inode);
  209. return res;
  210. }
  211. static int
  212. rpc_pipe_release(struct inode *inode, struct file *filp)
  213. {
  214. struct rpc_pipe *pipe;
  215. struct rpc_pipe_msg *msg;
  216. int last_close;
  217. inode_lock(inode);
  218. pipe = RPC_I(inode)->pipe;
  219. if (pipe == NULL)
  220. goto out;
  221. msg = filp->private_data;
  222. if (msg != NULL) {
  223. spin_lock(&pipe->lock);
  224. msg->errno = -EAGAIN;
  225. list_del_init(&msg->list);
  226. spin_unlock(&pipe->lock);
  227. pipe->ops->destroy_msg(msg);
  228. }
  229. if (filp->f_mode & FMODE_WRITE)
  230. pipe->nwriters --;
  231. if (filp->f_mode & FMODE_READ) {
  232. pipe->nreaders --;
  233. if (pipe->nreaders == 0) {
  234. LIST_HEAD(free_list);
  235. spin_lock(&pipe->lock);
  236. list_splice_init(&pipe->pipe, &free_list);
  237. pipe->pipelen = 0;
  238. spin_unlock(&pipe->lock);
  239. rpc_purge_list(&RPC_I(inode)->waitq, &free_list,
  240. pipe->ops->destroy_msg, -EAGAIN);
  241. }
  242. }
  243. last_close = pipe->nwriters == 0 && pipe->nreaders == 0;
  244. if (last_close && pipe->ops->release_pipe)
  245. pipe->ops->release_pipe(inode);
  246. out:
  247. inode_unlock(inode);
  248. return 0;
  249. }
  250. static ssize_t
  251. rpc_pipe_read(struct file *filp, char __user *buf, size_t len, loff_t *offset)
  252. {
  253. struct inode *inode = file_inode(filp);
  254. struct rpc_pipe *pipe;
  255. struct rpc_pipe_msg *msg;
  256. int res = 0;
  257. inode_lock(inode);
  258. pipe = RPC_I(inode)->pipe;
  259. if (pipe == NULL) {
  260. res = -EPIPE;
  261. goto out_unlock;
  262. }
  263. msg = filp->private_data;
  264. if (msg == NULL) {
  265. spin_lock(&pipe->lock);
  266. if (!list_empty(&pipe->pipe)) {
  267. msg = list_entry(pipe->pipe.next,
  268. struct rpc_pipe_msg,
  269. list);
  270. list_move(&msg->list, &pipe->in_upcall);
  271. pipe->pipelen -= msg->len;
  272. filp->private_data = msg;
  273. msg->copied = 0;
  274. }
  275. spin_unlock(&pipe->lock);
  276. if (msg == NULL)
  277. goto out_unlock;
  278. }
  279. /* NOTE: it is up to the callback to update msg->copied */
  280. res = pipe->ops->upcall(filp, msg, buf, len);
  281. if (res < 0 || msg->len == msg->copied) {
  282. filp->private_data = NULL;
  283. spin_lock(&pipe->lock);
  284. list_del_init(&msg->list);
  285. spin_unlock(&pipe->lock);
  286. pipe->ops->destroy_msg(msg);
  287. }
  288. out_unlock:
  289. inode_unlock(inode);
  290. return res;
  291. }
  292. static ssize_t
  293. rpc_pipe_write(struct file *filp, const char __user *buf, size_t len, loff_t *offset)
  294. {
  295. struct inode *inode = file_inode(filp);
  296. int res;
  297. inode_lock(inode);
  298. res = -EPIPE;
  299. if (RPC_I(inode)->pipe != NULL)
  300. res = RPC_I(inode)->pipe->ops->downcall(filp, buf, len);
  301. inode_unlock(inode);
  302. return res;
  303. }
  304. static __poll_t
  305. rpc_pipe_poll(struct file *filp, struct poll_table_struct *wait)
  306. {
  307. struct inode *inode = file_inode(filp);
  308. struct rpc_inode *rpci = RPC_I(inode);
  309. __poll_t mask = EPOLLOUT | EPOLLWRNORM;
  310. poll_wait(filp, &rpci->waitq, wait);
  311. inode_lock(inode);
  312. if (rpci->pipe == NULL)
  313. mask |= EPOLLERR | EPOLLHUP;
  314. else if (filp->private_data || !list_empty(&rpci->pipe->pipe))
  315. mask |= EPOLLIN | EPOLLRDNORM;
  316. inode_unlock(inode);
  317. return mask;
  318. }
  319. static long
  320. rpc_pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  321. {
  322. struct inode *inode = file_inode(filp);
  323. struct rpc_pipe *pipe;
  324. int len;
  325. switch (cmd) {
  326. case FIONREAD:
  327. inode_lock(inode);
  328. pipe = RPC_I(inode)->pipe;
  329. if (pipe == NULL) {
  330. inode_unlock(inode);
  331. return -EPIPE;
  332. }
  333. spin_lock(&pipe->lock);
  334. len = pipe->pipelen;
  335. if (filp->private_data) {
  336. struct rpc_pipe_msg *msg;
  337. msg = filp->private_data;
  338. len += msg->len - msg->copied;
  339. }
  340. spin_unlock(&pipe->lock);
  341. inode_unlock(inode);
  342. return put_user(len, (int __user *)arg);
  343. default:
  344. return -EINVAL;
  345. }
  346. }
  347. static const struct file_operations rpc_pipe_fops = {
  348. .owner = THIS_MODULE,
  349. .read = rpc_pipe_read,
  350. .write = rpc_pipe_write,
  351. .poll = rpc_pipe_poll,
  352. .unlocked_ioctl = rpc_pipe_ioctl,
  353. .open = rpc_pipe_open,
  354. .release = rpc_pipe_release,
  355. };
  356. static int
  357. rpc_show_info(struct seq_file *m, void *v)
  358. {
  359. struct rpc_clnt *clnt = m->private;
  360. rcu_read_lock();
  361. seq_printf(m, "RPC server: %s\n",
  362. rcu_dereference(clnt->cl_xprt)->servername);
  363. seq_printf(m, "service: %s (%d) version %d\n", clnt->cl_program->name,
  364. clnt->cl_prog, clnt->cl_vers);
  365. seq_printf(m, "address: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_ADDR));
  366. seq_printf(m, "protocol: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_PROTO));
  367. seq_printf(m, "port: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_PORT));
  368. rcu_read_unlock();
  369. return 0;
  370. }
  371. static int
  372. rpc_info_open(struct inode *inode, struct file *file)
  373. {
  374. struct rpc_clnt *clnt = NULL;
  375. int ret = single_open(file, rpc_show_info, NULL);
  376. if (!ret) {
  377. struct seq_file *m = file->private_data;
  378. spin_lock(&file->f_path.dentry->d_lock);
  379. if (!d_unhashed(file->f_path.dentry))
  380. clnt = RPC_I(inode)->private;
  381. if (clnt != NULL && refcount_inc_not_zero(&clnt->cl_count)) {
  382. spin_unlock(&file->f_path.dentry->d_lock);
  383. m->private = clnt;
  384. } else {
  385. spin_unlock(&file->f_path.dentry->d_lock);
  386. single_release(inode, file);
  387. ret = -EINVAL;
  388. }
  389. }
  390. return ret;
  391. }
  392. static int
  393. rpc_info_release(struct inode *inode, struct file *file)
  394. {
  395. struct seq_file *m = file->private_data;
  396. struct rpc_clnt *clnt = (struct rpc_clnt *)m->private;
  397. if (clnt)
  398. rpc_release_client(clnt);
  399. return single_release(inode, file);
  400. }
  401. static const struct file_operations rpc_info_operations = {
  402. .owner = THIS_MODULE,
  403. .open = rpc_info_open,
  404. .read = seq_read,
  405. .llseek = seq_lseek,
  406. .release = rpc_info_release,
  407. };
  408. /*
  409. * Description of fs contents.
  410. */
  411. struct rpc_filelist {
  412. const char *name;
  413. const struct file_operations *i_fop;
  414. umode_t mode;
  415. };
  416. static struct inode *
  417. rpc_get_inode(struct super_block *sb, umode_t mode)
  418. {
  419. struct inode *inode = new_inode(sb);
  420. if (!inode)
  421. return NULL;
  422. inode->i_ino = get_next_ino();
  423. inode->i_mode = mode;
  424. simple_inode_init_ts(inode);
  425. switch (mode & S_IFMT) {
  426. case S_IFDIR:
  427. inode->i_fop = &simple_dir_operations;
  428. inode->i_op = &simple_dir_inode_operations;
  429. inc_nlink(inode);
  430. break;
  431. default:
  432. break;
  433. }
  434. return inode;
  435. }
  436. static void
  437. init_pipe(struct rpc_pipe *pipe)
  438. {
  439. pipe->nreaders = 0;
  440. pipe->nwriters = 0;
  441. INIT_LIST_HEAD(&pipe->in_upcall);
  442. INIT_LIST_HEAD(&pipe->in_downcall);
  443. INIT_LIST_HEAD(&pipe->pipe);
  444. pipe->pipelen = 0;
  445. INIT_DELAYED_WORK(&pipe->queue_timeout,
  446. rpc_timeout_upcall_queue);
  447. pipe->ops = NULL;
  448. spin_lock_init(&pipe->lock);
  449. pipe->dentry = NULL;
  450. }
  451. void rpc_destroy_pipe_data(struct rpc_pipe *pipe)
  452. {
  453. kfree(pipe);
  454. }
  455. EXPORT_SYMBOL_GPL(rpc_destroy_pipe_data);
  456. struct rpc_pipe *rpc_mkpipe_data(const struct rpc_pipe_ops *ops, int flags)
  457. {
  458. struct rpc_pipe *pipe;
  459. pipe = kzalloc_obj(struct rpc_pipe);
  460. if (!pipe)
  461. return ERR_PTR(-ENOMEM);
  462. init_pipe(pipe);
  463. pipe->ops = ops;
  464. pipe->flags = flags;
  465. return pipe;
  466. }
  467. EXPORT_SYMBOL_GPL(rpc_mkpipe_data);
  468. static int rpc_new_file(struct dentry *parent,
  469. const char *name,
  470. umode_t mode,
  471. const struct file_operations *i_fop,
  472. void *private)
  473. {
  474. struct dentry *dentry = simple_start_creating(parent, name);
  475. struct inode *dir = parent->d_inode;
  476. struct inode *inode;
  477. if (IS_ERR(dentry))
  478. return PTR_ERR(dentry);
  479. inode = rpc_get_inode(dir->i_sb, S_IFREG | mode);
  480. if (unlikely(!inode)) {
  481. simple_done_creating(dentry);
  482. return -ENOMEM;
  483. }
  484. inode->i_ino = iunique(dir->i_sb, 100);
  485. if (i_fop)
  486. inode->i_fop = i_fop;
  487. rpc_inode_setowner(inode, private);
  488. d_make_persistent(dentry, inode);
  489. fsnotify_create(dir, dentry);
  490. simple_done_creating(dentry);
  491. return 0;
  492. }
  493. static struct dentry *rpc_new_dir(struct dentry *parent,
  494. const char *name,
  495. umode_t mode)
  496. {
  497. struct dentry *dentry = simple_start_creating(parent, name);
  498. struct inode *dir = parent->d_inode;
  499. struct inode *inode;
  500. if (IS_ERR(dentry))
  501. return dentry;
  502. inode = rpc_get_inode(dir->i_sb, S_IFDIR | mode);
  503. if (unlikely(!inode)) {
  504. simple_done_creating(dentry);
  505. return ERR_PTR(-ENOMEM);
  506. }
  507. inode->i_ino = iunique(dir->i_sb, 100);
  508. inc_nlink(dir);
  509. d_make_persistent(dentry, inode);
  510. fsnotify_mkdir(dir, dentry);
  511. simple_done_creating(dentry);
  512. return dentry; // borrowed
  513. }
  514. static int rpc_populate(struct dentry *parent,
  515. const struct rpc_filelist *files,
  516. int start, int eof,
  517. void *private)
  518. {
  519. struct dentry *dentry;
  520. int i, err;
  521. for (i = start; i < eof; i++) {
  522. switch (files[i].mode & S_IFMT) {
  523. default:
  524. BUG();
  525. case S_IFREG:
  526. err = rpc_new_file(parent,
  527. files[i].name,
  528. files[i].mode,
  529. files[i].i_fop,
  530. private);
  531. if (err)
  532. goto out_bad;
  533. break;
  534. case S_IFDIR:
  535. dentry = rpc_new_dir(parent,
  536. files[i].name,
  537. files[i].mode);
  538. if (IS_ERR(dentry)) {
  539. err = PTR_ERR(dentry);
  540. goto out_bad;
  541. }
  542. }
  543. }
  544. return 0;
  545. out_bad:
  546. printk(KERN_WARNING "%s: %s failed to populate directory %pd\n",
  547. __FILE__, __func__, parent);
  548. return err;
  549. }
  550. /**
  551. * rpc_mkpipe_dentry - make an rpc_pipefs file for kernel<->userspace
  552. * communication
  553. * @parent: dentry of directory to create new "pipe" in
  554. * @name: name of pipe
  555. * @private: private data to associate with the pipe, for the caller's use
  556. * @pipe: &rpc_pipe containing input parameters
  557. *
  558. * Data is made available for userspace to read by calls to
  559. * rpc_queue_upcall(). The actual reads will result in calls to
  560. * @ops->upcall, which will be called with the file pointer,
  561. * message, and userspace buffer to copy to.
  562. *
  563. * Writes can come at any time, and do not necessarily have to be
  564. * responses to upcalls. They will result in calls to @msg->downcall.
  565. *
  566. * The @private argument passed here will be available to all these methods
  567. * from the file pointer, via RPC_I(file_inode(file))->private.
  568. */
  569. int rpc_mkpipe_dentry(struct dentry *parent, const char *name,
  570. void *private, struct rpc_pipe *pipe)
  571. {
  572. struct inode *dir = d_inode(parent);
  573. struct dentry *dentry;
  574. struct inode *inode;
  575. struct rpc_inode *rpci;
  576. umode_t umode = S_IFIFO | 0600;
  577. int err;
  578. if (pipe->ops->upcall == NULL)
  579. umode &= ~0444;
  580. if (pipe->ops->downcall == NULL)
  581. umode &= ~0222;
  582. dentry = simple_start_creating(parent, name);
  583. if (IS_ERR(dentry)) {
  584. err = PTR_ERR(dentry);
  585. goto failed;
  586. }
  587. inode = rpc_get_inode(dir->i_sb, umode);
  588. if (unlikely(!inode)) {
  589. simple_done_creating(dentry);
  590. err = -ENOMEM;
  591. goto failed;
  592. }
  593. inode->i_ino = iunique(dir->i_sb, 100);
  594. inode->i_fop = &rpc_pipe_fops;
  595. rpci = RPC_I(inode);
  596. rpci->private = private;
  597. rpci->pipe = pipe;
  598. rpc_inode_setowner(inode, private);
  599. pipe->dentry = dentry; // borrowed
  600. d_make_persistent(dentry, inode);
  601. fsnotify_create(dir, dentry);
  602. simple_done_creating(dentry);
  603. return 0;
  604. failed:
  605. pr_warn("%s() failed to create pipe %pd/%s (errno = %d)\n",
  606. __func__, parent, name, err);
  607. return err;
  608. }
  609. EXPORT_SYMBOL_GPL(rpc_mkpipe_dentry);
  610. /**
  611. * rpc_unlink - remove a pipe
  612. * @pipe: the pipe to be removed
  613. *
  614. * After this call, lookups will no longer find the pipe, and any
  615. * attempts to read or write using preexisting opens of the pipe will
  616. * return -EPIPE.
  617. */
  618. void
  619. rpc_unlink(struct rpc_pipe *pipe)
  620. {
  621. if (pipe->dentry) {
  622. simple_recursive_removal(pipe->dentry, rpc_close_pipes);
  623. pipe->dentry = NULL;
  624. }
  625. }
  626. EXPORT_SYMBOL_GPL(rpc_unlink);
  627. /**
  628. * rpc_init_pipe_dir_head - initialise a struct rpc_pipe_dir_head
  629. * @pdh: pointer to struct rpc_pipe_dir_head
  630. */
  631. void rpc_init_pipe_dir_head(struct rpc_pipe_dir_head *pdh)
  632. {
  633. INIT_LIST_HEAD(&pdh->pdh_entries);
  634. pdh->pdh_dentry = NULL;
  635. }
  636. EXPORT_SYMBOL_GPL(rpc_init_pipe_dir_head);
  637. /**
  638. * rpc_init_pipe_dir_object - initialise a struct rpc_pipe_dir_object
  639. * @pdo: pointer to struct rpc_pipe_dir_object
  640. * @pdo_ops: pointer to const struct rpc_pipe_dir_object_ops
  641. * @pdo_data: pointer to caller-defined data
  642. */
  643. void rpc_init_pipe_dir_object(struct rpc_pipe_dir_object *pdo,
  644. const struct rpc_pipe_dir_object_ops *pdo_ops,
  645. void *pdo_data)
  646. {
  647. INIT_LIST_HEAD(&pdo->pdo_head);
  648. pdo->pdo_ops = pdo_ops;
  649. pdo->pdo_data = pdo_data;
  650. }
  651. EXPORT_SYMBOL_GPL(rpc_init_pipe_dir_object);
  652. static int
  653. rpc_add_pipe_dir_object_locked(struct net *net,
  654. struct rpc_pipe_dir_head *pdh,
  655. struct rpc_pipe_dir_object *pdo)
  656. {
  657. int ret = 0;
  658. if (pdh->pdh_dentry)
  659. ret = pdo->pdo_ops->create(pdh->pdh_dentry, pdo);
  660. if (ret == 0)
  661. list_add_tail(&pdo->pdo_head, &pdh->pdh_entries);
  662. return ret;
  663. }
  664. static void
  665. rpc_remove_pipe_dir_object_locked(struct net *net,
  666. struct rpc_pipe_dir_head *pdh,
  667. struct rpc_pipe_dir_object *pdo)
  668. {
  669. if (pdh->pdh_dentry)
  670. pdo->pdo_ops->destroy(pdh->pdh_dentry, pdo);
  671. list_del_init(&pdo->pdo_head);
  672. }
  673. /**
  674. * rpc_add_pipe_dir_object - associate a rpc_pipe_dir_object to a directory
  675. * @net: pointer to struct net
  676. * @pdh: pointer to struct rpc_pipe_dir_head
  677. * @pdo: pointer to struct rpc_pipe_dir_object
  678. *
  679. */
  680. int
  681. rpc_add_pipe_dir_object(struct net *net,
  682. struct rpc_pipe_dir_head *pdh,
  683. struct rpc_pipe_dir_object *pdo)
  684. {
  685. int ret = 0;
  686. if (list_empty(&pdo->pdo_head)) {
  687. struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
  688. mutex_lock(&sn->pipefs_sb_lock);
  689. ret = rpc_add_pipe_dir_object_locked(net, pdh, pdo);
  690. mutex_unlock(&sn->pipefs_sb_lock);
  691. }
  692. return ret;
  693. }
  694. EXPORT_SYMBOL_GPL(rpc_add_pipe_dir_object);
  695. /**
  696. * rpc_remove_pipe_dir_object - remove a rpc_pipe_dir_object from a directory
  697. * @net: pointer to struct net
  698. * @pdh: pointer to struct rpc_pipe_dir_head
  699. * @pdo: pointer to struct rpc_pipe_dir_object
  700. *
  701. */
  702. void
  703. rpc_remove_pipe_dir_object(struct net *net,
  704. struct rpc_pipe_dir_head *pdh,
  705. struct rpc_pipe_dir_object *pdo)
  706. {
  707. if (!list_empty(&pdo->pdo_head)) {
  708. struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
  709. mutex_lock(&sn->pipefs_sb_lock);
  710. rpc_remove_pipe_dir_object_locked(net, pdh, pdo);
  711. mutex_unlock(&sn->pipefs_sb_lock);
  712. }
  713. }
  714. EXPORT_SYMBOL_GPL(rpc_remove_pipe_dir_object);
  715. /**
  716. * rpc_find_or_alloc_pipe_dir_object
  717. * @net: pointer to struct net
  718. * @pdh: pointer to struct rpc_pipe_dir_head
  719. * @match: match struct rpc_pipe_dir_object to data
  720. * @alloc: allocate a new struct rpc_pipe_dir_object
  721. * @data: user defined data for match() and alloc()
  722. *
  723. */
  724. struct rpc_pipe_dir_object *
  725. rpc_find_or_alloc_pipe_dir_object(struct net *net,
  726. struct rpc_pipe_dir_head *pdh,
  727. int (*match)(struct rpc_pipe_dir_object *, void *),
  728. struct rpc_pipe_dir_object *(*alloc)(void *),
  729. void *data)
  730. {
  731. struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
  732. struct rpc_pipe_dir_object *pdo;
  733. mutex_lock(&sn->pipefs_sb_lock);
  734. list_for_each_entry(pdo, &pdh->pdh_entries, pdo_head) {
  735. if (!match(pdo, data))
  736. continue;
  737. goto out;
  738. }
  739. pdo = alloc(data);
  740. if (!pdo)
  741. goto out;
  742. rpc_add_pipe_dir_object_locked(net, pdh, pdo);
  743. out:
  744. mutex_unlock(&sn->pipefs_sb_lock);
  745. return pdo;
  746. }
  747. EXPORT_SYMBOL_GPL(rpc_find_or_alloc_pipe_dir_object);
  748. static void
  749. rpc_create_pipe_dir_objects(struct rpc_pipe_dir_head *pdh)
  750. {
  751. struct rpc_pipe_dir_object *pdo;
  752. struct dentry *dir = pdh->pdh_dentry;
  753. list_for_each_entry(pdo, &pdh->pdh_entries, pdo_head)
  754. pdo->pdo_ops->create(dir, pdo);
  755. }
  756. static void
  757. rpc_destroy_pipe_dir_objects(struct rpc_pipe_dir_head *pdh)
  758. {
  759. struct rpc_pipe_dir_object *pdo;
  760. struct dentry *dir = pdh->pdh_dentry;
  761. list_for_each_entry(pdo, &pdh->pdh_entries, pdo_head)
  762. pdo->pdo_ops->destroy(dir, pdo);
  763. }
  764. /**
  765. * rpc_create_client_dir - Create a new rpc_client directory in rpc_pipefs
  766. * @dentry: the parent of new directory
  767. * @name: the name of new directory
  768. * @rpc_client: rpc client to associate with this directory
  769. *
  770. * This creates a directory at the given @path associated with
  771. * @rpc_clnt, which will contain a file named "info" with some basic
  772. * information about the client, together with any "pipes" that may
  773. * later be created using rpc_mkpipe().
  774. */
  775. int rpc_create_client_dir(struct dentry *dentry,
  776. const char *name,
  777. struct rpc_clnt *rpc_client)
  778. {
  779. struct dentry *ret;
  780. int err;
  781. ret = rpc_new_dir(dentry, name, 0555);
  782. if (IS_ERR(ret))
  783. return PTR_ERR(ret);
  784. err = rpc_new_file(ret, "info", S_IFREG | 0400,
  785. &rpc_info_operations, rpc_client);
  786. if (err) {
  787. pr_warn("%s failed to populate directory %pd\n",
  788. __func__, ret);
  789. simple_recursive_removal(ret, NULL);
  790. return err;
  791. }
  792. rpc_client->cl_pipedir_objects.pdh_dentry = ret;
  793. rpc_create_pipe_dir_objects(&rpc_client->cl_pipedir_objects);
  794. return 0;
  795. }
  796. /**
  797. * rpc_remove_client_dir - Remove a directory created with rpc_create_client_dir()
  798. * @rpc_client: rpc_client for the pipe
  799. */
  800. int rpc_remove_client_dir(struct rpc_clnt *rpc_client)
  801. {
  802. struct dentry *dentry = rpc_client->cl_pipedir_objects.pdh_dentry;
  803. if (dentry == NULL)
  804. return 0;
  805. rpc_destroy_pipe_dir_objects(&rpc_client->cl_pipedir_objects);
  806. rpc_client->cl_pipedir_objects.pdh_dentry = NULL;
  807. simple_recursive_removal(dentry, NULL);
  808. return 0;
  809. }
  810. static const struct rpc_filelist cache_pipefs_files[3] = {
  811. [0] = {
  812. .name = "channel",
  813. .i_fop = &cache_file_operations_pipefs,
  814. .mode = S_IFREG | 0600,
  815. },
  816. [1] = {
  817. .name = "content",
  818. .i_fop = &content_file_operations_pipefs,
  819. .mode = S_IFREG | 0400,
  820. },
  821. [2] = {
  822. .name = "flush",
  823. .i_fop = &cache_flush_operations_pipefs,
  824. .mode = S_IFREG | 0600,
  825. },
  826. };
  827. struct dentry *rpc_create_cache_dir(struct dentry *parent, const char *name,
  828. umode_t umode, struct cache_detail *cd)
  829. {
  830. struct dentry *dentry;
  831. dentry = rpc_new_dir(parent, name, umode);
  832. if (!IS_ERR(dentry)) {
  833. int error = rpc_populate(dentry, cache_pipefs_files, 0, 3, cd);
  834. if (error) {
  835. simple_recursive_removal(dentry, NULL);
  836. return ERR_PTR(error);
  837. }
  838. }
  839. return dentry;
  840. }
  841. void rpc_remove_cache_dir(struct dentry *dentry)
  842. {
  843. simple_recursive_removal(dentry, NULL);
  844. }
  845. /*
  846. * populate the filesystem
  847. */
  848. static const struct super_operations s_ops = {
  849. .alloc_inode = rpc_alloc_inode,
  850. .free_inode = rpc_free_inode,
  851. .statfs = simple_statfs,
  852. };
  853. #define RPCAUTH_GSSMAGIC 0x67596969
  854. /*
  855. * We have a single directory with 1 node in it.
  856. */
  857. enum {
  858. RPCAUTH_lockd,
  859. RPCAUTH_mount,
  860. RPCAUTH_nfs,
  861. RPCAUTH_portmap,
  862. RPCAUTH_statd,
  863. RPCAUTH_nfsd4_cb,
  864. RPCAUTH_cache,
  865. RPCAUTH_nfsd,
  866. RPCAUTH_RootEOF
  867. };
  868. static const struct rpc_filelist files[] = {
  869. [RPCAUTH_lockd] = {
  870. .name = "lockd",
  871. .mode = S_IFDIR | 0555,
  872. },
  873. [RPCAUTH_mount] = {
  874. .name = "mount",
  875. .mode = S_IFDIR | 0555,
  876. },
  877. [RPCAUTH_nfs] = {
  878. .name = "nfs",
  879. .mode = S_IFDIR | 0555,
  880. },
  881. [RPCAUTH_portmap] = {
  882. .name = "portmap",
  883. .mode = S_IFDIR | 0555,
  884. },
  885. [RPCAUTH_statd] = {
  886. .name = "statd",
  887. .mode = S_IFDIR | 0555,
  888. },
  889. [RPCAUTH_nfsd4_cb] = {
  890. .name = "nfsd4_cb",
  891. .mode = S_IFDIR | 0555,
  892. },
  893. [RPCAUTH_cache] = {
  894. .name = "cache",
  895. .mode = S_IFDIR | 0555,
  896. },
  897. [RPCAUTH_nfsd] = {
  898. .name = "nfsd",
  899. .mode = S_IFDIR | 0555,
  900. },
  901. };
  902. /*
  903. * This call can be used only in RPC pipefs mount notification hooks.
  904. */
  905. struct dentry *rpc_d_lookup_sb(const struct super_block *sb,
  906. const unsigned char *dir_name)
  907. {
  908. return try_lookup_noperm(&QSTR(dir_name), sb->s_root);
  909. }
  910. EXPORT_SYMBOL_GPL(rpc_d_lookup_sb);
  911. int rpc_pipefs_init_net(struct net *net)
  912. {
  913. struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
  914. sn->gssd_dummy = rpc_mkpipe_data(&gssd_dummy_pipe_ops, 0);
  915. if (IS_ERR(sn->gssd_dummy))
  916. return PTR_ERR(sn->gssd_dummy);
  917. mutex_init(&sn->pipefs_sb_lock);
  918. sn->pipe_version = -1;
  919. return 0;
  920. }
  921. void rpc_pipefs_exit_net(struct net *net)
  922. {
  923. struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
  924. rpc_destroy_pipe_data(sn->gssd_dummy);
  925. }
  926. /*
  927. * This call will be used for per network namespace operations calls.
  928. * Note: Function will be returned with pipefs_sb_lock taken if superblock was
  929. * found. This lock have to be released by rpc_put_sb_net() when all operations
  930. * will be completed.
  931. */
  932. struct super_block *rpc_get_sb_net(const struct net *net)
  933. {
  934. struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
  935. mutex_lock(&sn->pipefs_sb_lock);
  936. if (sn->pipefs_sb)
  937. return sn->pipefs_sb;
  938. mutex_unlock(&sn->pipefs_sb_lock);
  939. return NULL;
  940. }
  941. EXPORT_SYMBOL_GPL(rpc_get_sb_net);
  942. void rpc_put_sb_net(const struct net *net)
  943. {
  944. struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
  945. WARN_ON(sn->pipefs_sb == NULL);
  946. mutex_unlock(&sn->pipefs_sb_lock);
  947. }
  948. EXPORT_SYMBOL_GPL(rpc_put_sb_net);
  949. static ssize_t
  950. dummy_downcall(struct file *filp, const char __user *src, size_t len)
  951. {
  952. return -EINVAL;
  953. }
  954. static const struct rpc_pipe_ops gssd_dummy_pipe_ops = {
  955. .upcall = rpc_pipe_generic_upcall,
  956. .downcall = dummy_downcall,
  957. };
  958. /*
  959. * Here we present a bogus "info" file to keep rpc.gssd happy. We don't expect
  960. * that it will ever use this info to handle an upcall, but rpc.gssd expects
  961. * that this file will be there and have a certain format.
  962. */
  963. static int
  964. rpc_dummy_info_show(struct seq_file *m, void *v)
  965. {
  966. seq_printf(m, "RPC server: %s\n", utsname()->nodename);
  967. seq_printf(m, "service: foo (1) version 0\n");
  968. seq_printf(m, "address: 127.0.0.1\n");
  969. seq_printf(m, "protocol: tcp\n");
  970. seq_printf(m, "port: 0\n");
  971. return 0;
  972. }
  973. DEFINE_SHOW_ATTRIBUTE(rpc_dummy_info);
  974. /**
  975. * rpc_gssd_dummy_populate - create a dummy gssd pipe
  976. * @root: root of the rpc_pipefs filesystem
  977. * @pipe_data: pipe data created when netns is initialized
  978. *
  979. * Create a dummy set of directories and a pipe that gssd can hold open to
  980. * indicate that it is up and running.
  981. */
  982. static int
  983. rpc_gssd_dummy_populate(struct dentry *root, struct rpc_pipe *pipe_data)
  984. {
  985. struct dentry *gssd_dentry, *clnt_dentry;
  986. int err;
  987. gssd_dentry = rpc_new_dir(root, "gssd", 0555);
  988. if (IS_ERR(gssd_dentry))
  989. return -ENOENT;
  990. clnt_dentry = rpc_new_dir(gssd_dentry, "clntXX", 0555);
  991. if (IS_ERR(clnt_dentry))
  992. return -ENOENT;
  993. err = rpc_new_file(clnt_dentry, "info", 0400,
  994. &rpc_dummy_info_fops, NULL);
  995. if (!err)
  996. err = rpc_mkpipe_dentry(clnt_dentry, "gssd", NULL, pipe_data);
  997. return err;
  998. }
  999. static int
  1000. rpc_fill_super(struct super_block *sb, struct fs_context *fc)
  1001. {
  1002. struct inode *inode;
  1003. struct dentry *root;
  1004. struct net *net = sb->s_fs_info;
  1005. struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
  1006. int err;
  1007. sb->s_blocksize = PAGE_SIZE;
  1008. sb->s_blocksize_bits = PAGE_SHIFT;
  1009. sb->s_magic = RPCAUTH_GSSMAGIC;
  1010. sb->s_op = &s_ops;
  1011. sb->s_d_flags = DCACHE_DONTCACHE;
  1012. sb->s_time_gran = 1;
  1013. inode = rpc_get_inode(sb, S_IFDIR | 0555);
  1014. sb->s_root = root = d_make_root(inode);
  1015. if (!root)
  1016. return -ENOMEM;
  1017. if (rpc_populate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF, NULL))
  1018. return -ENOMEM;
  1019. err = rpc_gssd_dummy_populate(root, sn->gssd_dummy);
  1020. if (err)
  1021. return err;
  1022. dprintk("RPC: sending pipefs MOUNT notification for net %x%s\n",
  1023. net->ns.inum, NET_NAME(net));
  1024. mutex_lock(&sn->pipefs_sb_lock);
  1025. sn->pipefs_sb = sb;
  1026. err = blocking_notifier_call_chain(&rpc_pipefs_notifier_list,
  1027. RPC_PIPEFS_MOUNT,
  1028. sb);
  1029. mutex_unlock(&sn->pipefs_sb_lock);
  1030. return err;
  1031. }
  1032. bool
  1033. gssd_running(struct net *net)
  1034. {
  1035. struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
  1036. struct rpc_pipe *pipe = sn->gssd_dummy;
  1037. return pipe->nreaders || pipe->nwriters;
  1038. }
  1039. EXPORT_SYMBOL_GPL(gssd_running);
  1040. static int rpc_fs_get_tree(struct fs_context *fc)
  1041. {
  1042. return get_tree_keyed(fc, rpc_fill_super, get_net(fc->net_ns));
  1043. }
  1044. static void rpc_fs_free_fc(struct fs_context *fc)
  1045. {
  1046. if (fc->s_fs_info)
  1047. put_net(fc->s_fs_info);
  1048. }
  1049. static const struct fs_context_operations rpc_fs_context_ops = {
  1050. .free = rpc_fs_free_fc,
  1051. .get_tree = rpc_fs_get_tree,
  1052. };
  1053. static int rpc_init_fs_context(struct fs_context *fc)
  1054. {
  1055. put_user_ns(fc->user_ns);
  1056. fc->user_ns = get_user_ns(fc->net_ns->user_ns);
  1057. fc->ops = &rpc_fs_context_ops;
  1058. return 0;
  1059. }
  1060. static void rpc_kill_sb(struct super_block *sb)
  1061. {
  1062. struct net *net = sb->s_fs_info;
  1063. struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
  1064. mutex_lock(&sn->pipefs_sb_lock);
  1065. if (sn->pipefs_sb != sb) {
  1066. mutex_unlock(&sn->pipefs_sb_lock);
  1067. goto out;
  1068. }
  1069. sn->pipefs_sb = NULL;
  1070. dprintk("RPC: sending pipefs UMOUNT notification for net %x%s\n",
  1071. net->ns.inum, NET_NAME(net));
  1072. blocking_notifier_call_chain(&rpc_pipefs_notifier_list,
  1073. RPC_PIPEFS_UMOUNT,
  1074. sb);
  1075. mutex_unlock(&sn->pipefs_sb_lock);
  1076. out:
  1077. kill_anon_super(sb);
  1078. put_net(net);
  1079. }
  1080. static struct file_system_type rpc_pipe_fs_type = {
  1081. .owner = THIS_MODULE,
  1082. .name = "rpc_pipefs",
  1083. .init_fs_context = rpc_init_fs_context,
  1084. .kill_sb = rpc_kill_sb,
  1085. };
  1086. MODULE_ALIAS_FS("rpc_pipefs");
  1087. MODULE_ALIAS("rpc_pipefs");
  1088. static void
  1089. init_once(void *foo)
  1090. {
  1091. struct rpc_inode *rpci = (struct rpc_inode *) foo;
  1092. inode_init_once(&rpci->vfs_inode);
  1093. rpci->private = NULL;
  1094. rpci->pipe = NULL;
  1095. init_waitqueue_head(&rpci->waitq);
  1096. }
  1097. int register_rpc_pipefs(void)
  1098. {
  1099. int err;
  1100. rpc_inode_cachep = kmem_cache_create("rpc_inode_cache",
  1101. sizeof(struct rpc_inode),
  1102. 0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1103. SLAB_ACCOUNT),
  1104. init_once);
  1105. if (!rpc_inode_cachep)
  1106. return -ENOMEM;
  1107. err = rpc_clients_notifier_register();
  1108. if (err)
  1109. goto err_notifier;
  1110. err = register_filesystem(&rpc_pipe_fs_type);
  1111. if (err)
  1112. goto err_register;
  1113. return 0;
  1114. err_register:
  1115. rpc_clients_notifier_unregister();
  1116. err_notifier:
  1117. kmem_cache_destroy(rpc_inode_cachep);
  1118. return err;
  1119. }
  1120. void unregister_rpc_pipefs(void)
  1121. {
  1122. rpc_clients_notifier_unregister();
  1123. unregister_filesystem(&rpc_pipe_fs_type);
  1124. kmem_cache_destroy(rpc_inode_cachep);
  1125. }