nfs4recover.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  1. /*
  2. * Copyright (c) 2004 The Regents of the University of Michigan.
  3. * Copyright (c) 2012 Jeff Layton <jlayton@redhat.com>
  4. * All rights reserved.
  5. *
  6. * Andy Adamson <andros@citi.umich.edu>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the University nor the names of its
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  22. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  23. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  28. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. */
  34. #include <linux/file.h>
  35. #include <linux/slab.h>
  36. #include <linux/namei.h>
  37. #include <linux/crypto.h>
  38. #include <linux/sched.h>
  39. #include <linux/fs.h>
  40. #include <linux/module.h>
  41. #include <net/net_namespace.h>
  42. #include <linux/sunrpc/rpc_pipe_fs.h>
  43. #include <linux/sunrpc/clnt.h>
  44. #include <linux/nfsd/cld.h>
  45. #include "nfsd.h"
  46. #include "state.h"
  47. #include "vfs.h"
  48. #include "netns.h"
  49. #define NFSDDBG_FACILITY NFSDDBG_PROC
  50. /* Declarations */
  51. struct nfsd4_client_tracking_ops {
  52. int (*init)(struct net *);
  53. void (*exit)(struct net *);
  54. void (*create)(struct nfs4_client *);
  55. void (*remove)(struct nfs4_client *);
  56. int (*check)(struct nfs4_client *);
  57. void (*grace_done)(struct net *, time_t);
  58. };
  59. /* Globals */
  60. static struct file *rec_file;
  61. static char user_recovery_dirname[PATH_MAX] = "/var/lib/nfs/v4recovery";
  62. static struct nfsd4_client_tracking_ops *client_tracking_ops;
  63. static bool in_grace;
  64. static int
  65. nfs4_save_creds(const struct cred **original_creds)
  66. {
  67. struct cred *new;
  68. new = prepare_creds();
  69. if (!new)
  70. return -ENOMEM;
  71. new->fsuid = 0;
  72. new->fsgid = 0;
  73. *original_creds = override_creds(new);
  74. put_cred(new);
  75. return 0;
  76. }
  77. static void
  78. nfs4_reset_creds(const struct cred *original)
  79. {
  80. revert_creds(original);
  81. }
  82. static void
  83. md5_to_hex(char *out, char *md5)
  84. {
  85. int i;
  86. for (i=0; i<16; i++) {
  87. unsigned char c = md5[i];
  88. *out++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1);
  89. *out++ = '0' + (c&0x0f) + ((c&0x0f)>=0x0a)*('a'-'9'-1);
  90. }
  91. *out = '\0';
  92. }
  93. static int
  94. nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
  95. {
  96. struct xdr_netobj cksum;
  97. struct hash_desc desc;
  98. struct scatterlist sg;
  99. int status;
  100. dprintk("NFSD: nfs4_make_rec_clidname for %.*s\n",
  101. clname->len, clname->data);
  102. desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;
  103. desc.tfm = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC);
  104. if (IS_ERR(desc.tfm)) {
  105. status = PTR_ERR(desc.tfm);
  106. goto out_no_tfm;
  107. }
  108. cksum.len = crypto_hash_digestsize(desc.tfm);
  109. cksum.data = kmalloc(cksum.len, GFP_KERNEL);
  110. if (cksum.data == NULL) {
  111. status = -ENOMEM;
  112. goto out;
  113. }
  114. sg_init_one(&sg, clname->data, clname->len);
  115. status = crypto_hash_digest(&desc, &sg, sg.length, cksum.data);
  116. if (status)
  117. goto out;
  118. md5_to_hex(dname, cksum.data);
  119. status = 0;
  120. out:
  121. kfree(cksum.data);
  122. crypto_free_hash(desc.tfm);
  123. out_no_tfm:
  124. return status;
  125. }
  126. /*
  127. * If we had an error generating the recdir name for the legacy tracker
  128. * then warn the admin. If the error doesn't appear to be transient,
  129. * then disable recovery tracking.
  130. */
  131. static void
  132. legacy_recdir_name_error(int error)
  133. {
  134. printk(KERN_ERR "NFSD: unable to generate recoverydir "
  135. "name (%d).\n", error);
  136. /*
  137. * if the algorithm just doesn't exist, then disable the recovery
  138. * tracker altogether. The crypto libs will generally return this if
  139. * FIPS is enabled as well.
  140. */
  141. if (error == -ENOENT) {
  142. printk(KERN_ERR "NFSD: disabling legacy clientid tracking. "
  143. "Reboot recovery will not function correctly!\n");
  144. /* the argument is ignored by the legacy exit function */
  145. nfsd4_client_tracking_exit(NULL);
  146. }
  147. }
  148. static void
  149. nfsd4_create_clid_dir(struct nfs4_client *clp)
  150. {
  151. const struct cred *original_cred;
  152. char dname[HEXDIR_LEN];
  153. struct dentry *dir, *dentry;
  154. struct nfs4_client_reclaim *crp;
  155. int status;
  156. dprintk("NFSD: nfsd4_create_clid_dir for \"%s\"\n", dname);
  157. if (test_and_set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
  158. return;
  159. if (!rec_file)
  160. return;
  161. status = nfs4_make_rec_clidname(dname, &clp->cl_name);
  162. if (status)
  163. return legacy_recdir_name_error(status);
  164. status = nfs4_save_creds(&original_cred);
  165. if (status < 0)
  166. return;
  167. status = mnt_want_write_file(rec_file);
  168. if (status)
  169. return;
  170. dir = rec_file->f_path.dentry;
  171. /* lock the parent */
  172. mutex_lock(&dir->d_inode->i_mutex);
  173. dentry = lookup_one_len(dname, dir, HEXDIR_LEN-1);
  174. if (IS_ERR(dentry)) {
  175. status = PTR_ERR(dentry);
  176. goto out_unlock;
  177. }
  178. if (dentry->d_inode)
  179. /*
  180. * In the 4.1 case, where we're called from
  181. * reclaim_complete(), records from the previous reboot
  182. * may still be left, so this is OK.
  183. *
  184. * In the 4.0 case, we should never get here; but we may
  185. * as well be forgiving and just succeed silently.
  186. */
  187. goto out_put;
  188. status = vfs_mkdir(dir->d_inode, dentry, S_IRWXU);
  189. out_put:
  190. dput(dentry);
  191. out_unlock:
  192. mutex_unlock(&dir->d_inode->i_mutex);
  193. if (status == 0) {
  194. if (in_grace) {
  195. crp = nfs4_client_to_reclaim(dname);
  196. if (crp)
  197. crp->cr_clp = clp;
  198. }
  199. vfs_fsync(rec_file, 0);
  200. } else {
  201. printk(KERN_ERR "NFSD: failed to write recovery record"
  202. " (err %d); please check that %s exists"
  203. " and is writeable", status,
  204. user_recovery_dirname);
  205. }
  206. mnt_drop_write_file(rec_file);
  207. nfs4_reset_creds(original_cred);
  208. }
  209. typedef int (recdir_func)(struct dentry *, struct dentry *);
  210. struct name_list {
  211. char name[HEXDIR_LEN];
  212. struct list_head list;
  213. };
  214. static int
  215. nfsd4_build_namelist(void *arg, const char *name, int namlen,
  216. loff_t offset, u64 ino, unsigned int d_type)
  217. {
  218. struct list_head *names = arg;
  219. struct name_list *entry;
  220. if (namlen != HEXDIR_LEN - 1)
  221. return 0;
  222. entry = kmalloc(sizeof(struct name_list), GFP_KERNEL);
  223. if (entry == NULL)
  224. return -ENOMEM;
  225. memcpy(entry->name, name, HEXDIR_LEN - 1);
  226. entry->name[HEXDIR_LEN - 1] = '\0';
  227. list_add(&entry->list, names);
  228. return 0;
  229. }
  230. static int
  231. nfsd4_list_rec_dir(recdir_func *f)
  232. {
  233. const struct cred *original_cred;
  234. struct dentry *dir = rec_file->f_path.dentry;
  235. LIST_HEAD(names);
  236. int status;
  237. status = nfs4_save_creds(&original_cred);
  238. if (status < 0)
  239. return status;
  240. status = vfs_llseek(rec_file, 0, SEEK_SET);
  241. if (status < 0) {
  242. nfs4_reset_creds(original_cred);
  243. return status;
  244. }
  245. status = vfs_readdir(rec_file, nfsd4_build_namelist, &names);
  246. mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
  247. while (!list_empty(&names)) {
  248. struct name_list *entry;
  249. entry = list_entry(names.next, struct name_list, list);
  250. if (!status) {
  251. struct dentry *dentry;
  252. dentry = lookup_one_len(entry->name, dir, HEXDIR_LEN-1);
  253. if (IS_ERR(dentry)) {
  254. status = PTR_ERR(dentry);
  255. break;
  256. }
  257. status = f(dir, dentry);
  258. dput(dentry);
  259. }
  260. list_del(&entry->list);
  261. kfree(entry);
  262. }
  263. mutex_unlock(&dir->d_inode->i_mutex);
  264. nfs4_reset_creds(original_cred);
  265. return status;
  266. }
  267. static int
  268. nfsd4_unlink_clid_dir(char *name, int namlen)
  269. {
  270. struct dentry *dir, *dentry;
  271. int status;
  272. dprintk("NFSD: nfsd4_unlink_clid_dir. name %.*s\n", namlen, name);
  273. dir = rec_file->f_path.dentry;
  274. mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
  275. dentry = lookup_one_len(name, dir, namlen);
  276. if (IS_ERR(dentry)) {
  277. status = PTR_ERR(dentry);
  278. goto out_unlock;
  279. }
  280. status = -ENOENT;
  281. if (!dentry->d_inode)
  282. goto out;
  283. status = vfs_rmdir(dir->d_inode, dentry);
  284. out:
  285. dput(dentry);
  286. out_unlock:
  287. mutex_unlock(&dir->d_inode->i_mutex);
  288. return status;
  289. }
  290. static void
  291. nfsd4_remove_clid_dir(struct nfs4_client *clp)
  292. {
  293. const struct cred *original_cred;
  294. struct nfs4_client_reclaim *crp;
  295. char dname[HEXDIR_LEN];
  296. int status;
  297. if (!rec_file || !test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
  298. return;
  299. status = nfs4_make_rec_clidname(dname, &clp->cl_name);
  300. if (status)
  301. return legacy_recdir_name_error(status);
  302. status = mnt_want_write_file(rec_file);
  303. if (status)
  304. goto out;
  305. clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
  306. status = nfs4_save_creds(&original_cred);
  307. if (status < 0)
  308. goto out_drop_write;
  309. status = nfsd4_unlink_clid_dir(dname, HEXDIR_LEN-1);
  310. nfs4_reset_creds(original_cred);
  311. if (status == 0) {
  312. vfs_fsync(rec_file, 0);
  313. if (in_grace) {
  314. /* remove reclaim record */
  315. crp = nfsd4_find_reclaim_client(dname);
  316. if (crp)
  317. nfs4_remove_reclaim_record(crp);
  318. }
  319. }
  320. out_drop_write:
  321. mnt_drop_write_file(rec_file);
  322. out:
  323. if (status)
  324. printk("NFSD: Failed to remove expired client state directory"
  325. " %.*s\n", HEXDIR_LEN, dname);
  326. }
  327. static int
  328. purge_old(struct dentry *parent, struct dentry *child)
  329. {
  330. int status;
  331. if (nfs4_has_reclaimed_state(child->d_name.name))
  332. return 0;
  333. status = vfs_rmdir(parent->d_inode, child);
  334. if (status)
  335. printk("failed to remove client recovery directory %s\n",
  336. child->d_name.name);
  337. /* Keep trying, success or failure: */
  338. return 0;
  339. }
  340. static void
  341. nfsd4_recdir_purge_old(struct net *net, time_t boot_time)
  342. {
  343. int status;
  344. in_grace = false;
  345. if (!rec_file)
  346. return;
  347. status = mnt_want_write_file(rec_file);
  348. if (status)
  349. goto out;
  350. status = nfsd4_list_rec_dir(purge_old);
  351. if (status == 0)
  352. vfs_fsync(rec_file, 0);
  353. mnt_drop_write_file(rec_file);
  354. out:
  355. nfs4_release_reclaim();
  356. if (status)
  357. printk("nfsd4: failed to purge old clients from recovery"
  358. " directory %s\n", rec_file->f_path.dentry->d_name.name);
  359. }
  360. static int
  361. load_recdir(struct dentry *parent, struct dentry *child)
  362. {
  363. if (child->d_name.len != HEXDIR_LEN - 1) {
  364. printk("nfsd4: illegal name %s in recovery directory\n",
  365. child->d_name.name);
  366. /* Keep trying; maybe the others are OK: */
  367. return 0;
  368. }
  369. nfs4_client_to_reclaim(child->d_name.name);
  370. return 0;
  371. }
  372. static int
  373. nfsd4_recdir_load(void) {
  374. int status;
  375. if (!rec_file)
  376. return 0;
  377. status = nfsd4_list_rec_dir(load_recdir);
  378. if (status)
  379. printk("nfsd4: failed loading clients from recovery"
  380. " directory %s\n", rec_file->f_path.dentry->d_name.name);
  381. return status;
  382. }
  383. /*
  384. * Hold reference to the recovery directory.
  385. */
  386. static int
  387. nfsd4_init_recdir(void)
  388. {
  389. const struct cred *original_cred;
  390. int status;
  391. printk("NFSD: Using %s as the NFSv4 state recovery directory\n",
  392. user_recovery_dirname);
  393. BUG_ON(rec_file);
  394. status = nfs4_save_creds(&original_cred);
  395. if (status < 0) {
  396. printk("NFSD: Unable to change credentials to find recovery"
  397. " directory: error %d\n",
  398. status);
  399. return status;
  400. }
  401. rec_file = filp_open(user_recovery_dirname, O_RDONLY | O_DIRECTORY, 0);
  402. if (IS_ERR(rec_file)) {
  403. printk("NFSD: unable to find recovery directory %s\n",
  404. user_recovery_dirname);
  405. status = PTR_ERR(rec_file);
  406. rec_file = NULL;
  407. }
  408. nfs4_reset_creds(original_cred);
  409. if (!status)
  410. in_grace = true;
  411. return status;
  412. }
  413. static int
  414. nfsd4_load_reboot_recovery_data(struct net *net)
  415. {
  416. int status;
  417. /* XXX: The legacy code won't work in a container */
  418. if (net != &init_net) {
  419. WARN(1, KERN_ERR "NFSD: attempt to initialize legacy client "
  420. "tracking in a container!\n");
  421. return -EINVAL;
  422. }
  423. nfs4_lock_state();
  424. status = nfsd4_init_recdir();
  425. if (!status)
  426. status = nfsd4_recdir_load();
  427. nfs4_unlock_state();
  428. if (status)
  429. printk(KERN_ERR "NFSD: Failure reading reboot recovery data\n");
  430. return status;
  431. }
  432. static void
  433. nfsd4_shutdown_recdir(void)
  434. {
  435. if (!rec_file)
  436. return;
  437. fput(rec_file);
  438. rec_file = NULL;
  439. }
  440. static void
  441. nfsd4_legacy_tracking_exit(struct net *net)
  442. {
  443. nfs4_release_reclaim();
  444. nfsd4_shutdown_recdir();
  445. }
  446. /*
  447. * Change the NFSv4 recovery directory to recdir.
  448. */
  449. int
  450. nfs4_reset_recoverydir(char *recdir)
  451. {
  452. int status;
  453. struct path path;
  454. status = kern_path(recdir, LOOKUP_FOLLOW, &path);
  455. if (status)
  456. return status;
  457. status = -ENOTDIR;
  458. if (S_ISDIR(path.dentry->d_inode->i_mode)) {
  459. strcpy(user_recovery_dirname, recdir);
  460. status = 0;
  461. }
  462. path_put(&path);
  463. return status;
  464. }
  465. char *
  466. nfs4_recoverydir(void)
  467. {
  468. return user_recovery_dirname;
  469. }
  470. static int
  471. nfsd4_check_legacy_client(struct nfs4_client *clp)
  472. {
  473. int status;
  474. char dname[HEXDIR_LEN];
  475. struct nfs4_client_reclaim *crp;
  476. /* did we already find that this client is stable? */
  477. if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
  478. return 0;
  479. status = nfs4_make_rec_clidname(dname, &clp->cl_name);
  480. if (status) {
  481. legacy_recdir_name_error(status);
  482. return status;
  483. }
  484. /* look for it in the reclaim hashtable otherwise */
  485. crp = nfsd4_find_reclaim_client(dname);
  486. if (crp) {
  487. set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
  488. crp->cr_clp = clp;
  489. return 0;
  490. }
  491. return -ENOENT;
  492. }
  493. static struct nfsd4_client_tracking_ops nfsd4_legacy_tracking_ops = {
  494. .init = nfsd4_load_reboot_recovery_data,
  495. .exit = nfsd4_legacy_tracking_exit,
  496. .create = nfsd4_create_clid_dir,
  497. .remove = nfsd4_remove_clid_dir,
  498. .check = nfsd4_check_legacy_client,
  499. .grace_done = nfsd4_recdir_purge_old,
  500. };
  501. /* Globals */
  502. #define NFSD_PIPE_DIR "nfsd"
  503. #define NFSD_CLD_PIPE "cld"
  504. /* per-net-ns structure for holding cld upcall info */
  505. struct cld_net {
  506. struct rpc_pipe *cn_pipe;
  507. spinlock_t cn_lock;
  508. struct list_head cn_list;
  509. unsigned int cn_xid;
  510. };
  511. struct cld_upcall {
  512. struct list_head cu_list;
  513. struct cld_net *cu_net;
  514. struct task_struct *cu_task;
  515. struct cld_msg cu_msg;
  516. };
  517. static int
  518. __cld_pipe_upcall(struct rpc_pipe *pipe, struct cld_msg *cmsg)
  519. {
  520. int ret;
  521. struct rpc_pipe_msg msg;
  522. memset(&msg, 0, sizeof(msg));
  523. msg.data = cmsg;
  524. msg.len = sizeof(*cmsg);
  525. /*
  526. * Set task state before we queue the upcall. That prevents
  527. * wake_up_process in the downcall from racing with schedule.
  528. */
  529. set_current_state(TASK_UNINTERRUPTIBLE);
  530. ret = rpc_queue_upcall(pipe, &msg);
  531. if (ret < 0) {
  532. set_current_state(TASK_RUNNING);
  533. goto out;
  534. }
  535. schedule();
  536. set_current_state(TASK_RUNNING);
  537. if (msg.errno < 0)
  538. ret = msg.errno;
  539. out:
  540. return ret;
  541. }
  542. static int
  543. cld_pipe_upcall(struct rpc_pipe *pipe, struct cld_msg *cmsg)
  544. {
  545. int ret;
  546. /*
  547. * -EAGAIN occurs when pipe is closed and reopened while there are
  548. * upcalls queued.
  549. */
  550. do {
  551. ret = __cld_pipe_upcall(pipe, cmsg);
  552. } while (ret == -EAGAIN);
  553. return ret;
  554. }
  555. static ssize_t
  556. cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
  557. {
  558. struct cld_upcall *tmp, *cup;
  559. struct cld_msg __user *cmsg = (struct cld_msg __user *)src;
  560. uint32_t xid;
  561. struct nfsd_net *nn = net_generic(filp->f_dentry->d_sb->s_fs_info,
  562. nfsd_net_id);
  563. struct cld_net *cn = nn->cld_net;
  564. if (mlen != sizeof(*cmsg)) {
  565. dprintk("%s: got %zu bytes, expected %zu\n", __func__, mlen,
  566. sizeof(*cmsg));
  567. return -EINVAL;
  568. }
  569. /* copy just the xid so we can try to find that */
  570. if (copy_from_user(&xid, &cmsg->cm_xid, sizeof(xid)) != 0) {
  571. dprintk("%s: error when copying xid from userspace", __func__);
  572. return -EFAULT;
  573. }
  574. /* walk the list and find corresponding xid */
  575. cup = NULL;
  576. spin_lock(&cn->cn_lock);
  577. list_for_each_entry(tmp, &cn->cn_list, cu_list) {
  578. if (get_unaligned(&tmp->cu_msg.cm_xid) == xid) {
  579. cup = tmp;
  580. list_del_init(&cup->cu_list);
  581. break;
  582. }
  583. }
  584. spin_unlock(&cn->cn_lock);
  585. /* couldn't find upcall? */
  586. if (!cup) {
  587. dprintk("%s: couldn't find upcall -- xid=%u\n", __func__, xid);
  588. return -EINVAL;
  589. }
  590. if (copy_from_user(&cup->cu_msg, src, mlen) != 0)
  591. return -EFAULT;
  592. wake_up_process(cup->cu_task);
  593. return mlen;
  594. }
  595. static void
  596. cld_pipe_destroy_msg(struct rpc_pipe_msg *msg)
  597. {
  598. struct cld_msg *cmsg = msg->data;
  599. struct cld_upcall *cup = container_of(cmsg, struct cld_upcall,
  600. cu_msg);
  601. /* errno >= 0 means we got a downcall */
  602. if (msg->errno >= 0)
  603. return;
  604. wake_up_process(cup->cu_task);
  605. }
  606. static const struct rpc_pipe_ops cld_upcall_ops = {
  607. .upcall = rpc_pipe_generic_upcall,
  608. .downcall = cld_pipe_downcall,
  609. .destroy_msg = cld_pipe_destroy_msg,
  610. };
  611. static struct dentry *
  612. nfsd4_cld_register_sb(struct super_block *sb, struct rpc_pipe *pipe)
  613. {
  614. struct dentry *dir, *dentry;
  615. dir = rpc_d_lookup_sb(sb, NFSD_PIPE_DIR);
  616. if (dir == NULL)
  617. return ERR_PTR(-ENOENT);
  618. dentry = rpc_mkpipe_dentry(dir, NFSD_CLD_PIPE, NULL, pipe);
  619. dput(dir);
  620. return dentry;
  621. }
  622. static void
  623. nfsd4_cld_unregister_sb(struct rpc_pipe *pipe)
  624. {
  625. if (pipe->dentry)
  626. rpc_unlink(pipe->dentry);
  627. }
  628. static struct dentry *
  629. nfsd4_cld_register_net(struct net *net, struct rpc_pipe *pipe)
  630. {
  631. struct super_block *sb;
  632. struct dentry *dentry;
  633. sb = rpc_get_sb_net(net);
  634. if (!sb)
  635. return NULL;
  636. dentry = nfsd4_cld_register_sb(sb, pipe);
  637. rpc_put_sb_net(net);
  638. return dentry;
  639. }
  640. static void
  641. nfsd4_cld_unregister_net(struct net *net, struct rpc_pipe *pipe)
  642. {
  643. struct super_block *sb;
  644. sb = rpc_get_sb_net(net);
  645. if (sb) {
  646. nfsd4_cld_unregister_sb(pipe);
  647. rpc_put_sb_net(net);
  648. }
  649. }
  650. /* Initialize rpc_pipefs pipe for communication with client tracking daemon */
  651. static int
  652. nfsd4_init_cld_pipe(struct net *net)
  653. {
  654. int ret;
  655. struct dentry *dentry;
  656. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  657. struct cld_net *cn;
  658. if (nn->cld_net)
  659. return 0;
  660. cn = kzalloc(sizeof(*cn), GFP_KERNEL);
  661. if (!cn) {
  662. ret = -ENOMEM;
  663. goto err;
  664. }
  665. cn->cn_pipe = rpc_mkpipe_data(&cld_upcall_ops, RPC_PIPE_WAIT_FOR_OPEN);
  666. if (IS_ERR(cn->cn_pipe)) {
  667. ret = PTR_ERR(cn->cn_pipe);
  668. goto err;
  669. }
  670. spin_lock_init(&cn->cn_lock);
  671. INIT_LIST_HEAD(&cn->cn_list);
  672. dentry = nfsd4_cld_register_net(net, cn->cn_pipe);
  673. if (IS_ERR(dentry)) {
  674. ret = PTR_ERR(dentry);
  675. goto err_destroy_data;
  676. }
  677. cn->cn_pipe->dentry = dentry;
  678. nn->cld_net = cn;
  679. return 0;
  680. err_destroy_data:
  681. rpc_destroy_pipe_data(cn->cn_pipe);
  682. err:
  683. kfree(cn);
  684. printk(KERN_ERR "NFSD: unable to create nfsdcld upcall pipe (%d)\n",
  685. ret);
  686. return ret;
  687. }
  688. static void
  689. nfsd4_remove_cld_pipe(struct net *net)
  690. {
  691. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  692. struct cld_net *cn = nn->cld_net;
  693. nfsd4_cld_unregister_net(net, cn->cn_pipe);
  694. rpc_destroy_pipe_data(cn->cn_pipe);
  695. kfree(nn->cld_net);
  696. nn->cld_net = NULL;
  697. }
  698. static struct cld_upcall *
  699. alloc_cld_upcall(struct cld_net *cn)
  700. {
  701. struct cld_upcall *new, *tmp;
  702. new = kzalloc(sizeof(*new), GFP_KERNEL);
  703. if (!new)
  704. return new;
  705. /* FIXME: hard cap on number in flight? */
  706. restart_search:
  707. spin_lock(&cn->cn_lock);
  708. list_for_each_entry(tmp, &cn->cn_list, cu_list) {
  709. if (tmp->cu_msg.cm_xid == cn->cn_xid) {
  710. cn->cn_xid++;
  711. spin_unlock(&cn->cn_lock);
  712. goto restart_search;
  713. }
  714. }
  715. new->cu_task = current;
  716. new->cu_msg.cm_vers = CLD_UPCALL_VERSION;
  717. put_unaligned(cn->cn_xid++, &new->cu_msg.cm_xid);
  718. new->cu_net = cn;
  719. list_add(&new->cu_list, &cn->cn_list);
  720. spin_unlock(&cn->cn_lock);
  721. dprintk("%s: allocated xid %u\n", __func__, new->cu_msg.cm_xid);
  722. return new;
  723. }
  724. static void
  725. free_cld_upcall(struct cld_upcall *victim)
  726. {
  727. struct cld_net *cn = victim->cu_net;
  728. spin_lock(&cn->cn_lock);
  729. list_del(&victim->cu_list);
  730. spin_unlock(&cn->cn_lock);
  731. kfree(victim);
  732. }
  733. /* Ask daemon to create a new record */
  734. static void
  735. nfsd4_cld_create(struct nfs4_client *clp)
  736. {
  737. int ret;
  738. struct cld_upcall *cup;
  739. struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
  740. struct cld_net *cn = nn->cld_net;
  741. /* Don't upcall if it's already stored */
  742. if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
  743. return;
  744. cup = alloc_cld_upcall(cn);
  745. if (!cup) {
  746. ret = -ENOMEM;
  747. goto out_err;
  748. }
  749. cup->cu_msg.cm_cmd = Cld_Create;
  750. cup->cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
  751. memcpy(cup->cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
  752. clp->cl_name.len);
  753. ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
  754. if (!ret) {
  755. ret = cup->cu_msg.cm_status;
  756. set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
  757. }
  758. free_cld_upcall(cup);
  759. out_err:
  760. if (ret)
  761. printk(KERN_ERR "NFSD: Unable to create client "
  762. "record on stable storage: %d\n", ret);
  763. }
  764. /* Ask daemon to create a new record */
  765. static void
  766. nfsd4_cld_remove(struct nfs4_client *clp)
  767. {
  768. int ret;
  769. struct cld_upcall *cup;
  770. struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
  771. struct cld_net *cn = nn->cld_net;
  772. /* Don't upcall if it's already removed */
  773. if (!test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
  774. return;
  775. cup = alloc_cld_upcall(cn);
  776. if (!cup) {
  777. ret = -ENOMEM;
  778. goto out_err;
  779. }
  780. cup->cu_msg.cm_cmd = Cld_Remove;
  781. cup->cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
  782. memcpy(cup->cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
  783. clp->cl_name.len);
  784. ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
  785. if (!ret) {
  786. ret = cup->cu_msg.cm_status;
  787. clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
  788. }
  789. free_cld_upcall(cup);
  790. out_err:
  791. if (ret)
  792. printk(KERN_ERR "NFSD: Unable to remove client "
  793. "record from stable storage: %d\n", ret);
  794. }
  795. /* Check for presence of a record, and update its timestamp */
  796. static int
  797. nfsd4_cld_check(struct nfs4_client *clp)
  798. {
  799. int ret;
  800. struct cld_upcall *cup;
  801. struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
  802. struct cld_net *cn = nn->cld_net;
  803. /* Don't upcall if one was already stored during this grace pd */
  804. if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
  805. return 0;
  806. cup = alloc_cld_upcall(cn);
  807. if (!cup) {
  808. printk(KERN_ERR "NFSD: Unable to check client record on "
  809. "stable storage: %d\n", -ENOMEM);
  810. return -ENOMEM;
  811. }
  812. cup->cu_msg.cm_cmd = Cld_Check;
  813. cup->cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
  814. memcpy(cup->cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
  815. clp->cl_name.len);
  816. ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
  817. if (!ret) {
  818. ret = cup->cu_msg.cm_status;
  819. set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
  820. }
  821. free_cld_upcall(cup);
  822. return ret;
  823. }
  824. static void
  825. nfsd4_cld_grace_done(struct net *net, time_t boot_time)
  826. {
  827. int ret;
  828. struct cld_upcall *cup;
  829. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  830. struct cld_net *cn = nn->cld_net;
  831. cup = alloc_cld_upcall(cn);
  832. if (!cup) {
  833. ret = -ENOMEM;
  834. goto out_err;
  835. }
  836. cup->cu_msg.cm_cmd = Cld_GraceDone;
  837. cup->cu_msg.cm_u.cm_gracetime = (int64_t)boot_time;
  838. ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
  839. if (!ret)
  840. ret = cup->cu_msg.cm_status;
  841. free_cld_upcall(cup);
  842. out_err:
  843. if (ret)
  844. printk(KERN_ERR "NFSD: Unable to end grace period: %d\n", ret);
  845. }
  846. static struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops = {
  847. .init = nfsd4_init_cld_pipe,
  848. .exit = nfsd4_remove_cld_pipe,
  849. .create = nfsd4_cld_create,
  850. .remove = nfsd4_cld_remove,
  851. .check = nfsd4_cld_check,
  852. .grace_done = nfsd4_cld_grace_done,
  853. };
  854. /* upcall via usermodehelper */
  855. static char cltrack_prog[PATH_MAX] = "/sbin/nfsdcltrack";
  856. module_param_string(cltrack_prog, cltrack_prog, sizeof(cltrack_prog),
  857. S_IRUGO|S_IWUSR);
  858. MODULE_PARM_DESC(cltrack_prog, "Path to the nfsdcltrack upcall program");
  859. static bool cltrack_legacy_disable;
  860. module_param(cltrack_legacy_disable, bool, S_IRUGO|S_IWUSR);
  861. MODULE_PARM_DESC(cltrack_legacy_disable,
  862. "Disable legacy recoverydir conversion. Default: false");
  863. #define LEGACY_TOPDIR_ENV_PREFIX "NFSDCLTRACK_LEGACY_TOPDIR="
  864. #define LEGACY_RECDIR_ENV_PREFIX "NFSDCLTRACK_LEGACY_RECDIR="
  865. static char *
  866. nfsd4_cltrack_legacy_topdir(void)
  867. {
  868. int copied;
  869. size_t len;
  870. char *result;
  871. if (cltrack_legacy_disable)
  872. return NULL;
  873. len = strlen(LEGACY_TOPDIR_ENV_PREFIX) +
  874. strlen(nfs4_recoverydir()) + 1;
  875. result = kmalloc(len, GFP_KERNEL);
  876. if (!result)
  877. return result;
  878. copied = snprintf(result, len, LEGACY_TOPDIR_ENV_PREFIX "%s",
  879. nfs4_recoverydir());
  880. if (copied >= len) {
  881. /* just return nothing if output was truncated */
  882. kfree(result);
  883. return NULL;
  884. }
  885. return result;
  886. }
  887. static char *
  888. nfsd4_cltrack_legacy_recdir(const struct xdr_netobj *name)
  889. {
  890. int copied;
  891. size_t len;
  892. char *result;
  893. if (cltrack_legacy_disable)
  894. return NULL;
  895. /* +1 is for '/' between "topdir" and "recdir" */
  896. len = strlen(LEGACY_RECDIR_ENV_PREFIX) +
  897. strlen(nfs4_recoverydir()) + 1 + HEXDIR_LEN;
  898. result = kmalloc(len, GFP_KERNEL);
  899. if (!result)
  900. return result;
  901. copied = snprintf(result, len, LEGACY_RECDIR_ENV_PREFIX "%s/",
  902. nfs4_recoverydir());
  903. if (copied > (len - HEXDIR_LEN)) {
  904. /* just return nothing if output will be truncated */
  905. kfree(result);
  906. return NULL;
  907. }
  908. copied = nfs4_make_rec_clidname(result + copied, name);
  909. if (copied) {
  910. kfree(result);
  911. return NULL;
  912. }
  913. return result;
  914. }
  915. static int
  916. nfsd4_umh_cltrack_upcall(char *cmd, char *arg, char *legacy)
  917. {
  918. char *envp[2];
  919. char *argv[4];
  920. int ret;
  921. if (unlikely(!cltrack_prog[0])) {
  922. dprintk("%s: cltrack_prog is disabled\n", __func__);
  923. return -EACCES;
  924. }
  925. dprintk("%s: cmd: %s\n", __func__, cmd);
  926. dprintk("%s: arg: %s\n", __func__, arg ? arg : "(null)");
  927. dprintk("%s: legacy: %s\n", __func__, legacy ? legacy : "(null)");
  928. envp[0] = legacy;
  929. envp[1] = NULL;
  930. argv[0] = (char *)cltrack_prog;
  931. argv[1] = cmd;
  932. argv[2] = arg;
  933. argv[3] = NULL;
  934. ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
  935. /*
  936. * Disable the upcall mechanism if we're getting an ENOENT or EACCES
  937. * error. The admin can re-enable it on the fly by using sysfs
  938. * once the problem has been fixed.
  939. */
  940. if (ret == -ENOENT || ret == -EACCES) {
  941. dprintk("NFSD: %s was not found or isn't executable (%d). "
  942. "Setting cltrack_prog to blank string!",
  943. cltrack_prog, ret);
  944. cltrack_prog[0] = '\0';
  945. }
  946. dprintk("%s: %s return value: %d\n", __func__, cltrack_prog, ret);
  947. return ret;
  948. }
  949. static char *
  950. bin_to_hex_dup(const unsigned char *src, int srclen)
  951. {
  952. int i;
  953. char *buf, *hex;
  954. /* +1 for terminating NULL */
  955. buf = kmalloc((srclen * 2) + 1, GFP_KERNEL);
  956. if (!buf)
  957. return buf;
  958. hex = buf;
  959. for (i = 0; i < srclen; i++) {
  960. sprintf(hex, "%2.2x", *src++);
  961. hex += 2;
  962. }
  963. return buf;
  964. }
  965. static int
  966. nfsd4_umh_cltrack_init(struct net __attribute__((unused)) *net)
  967. {
  968. return nfsd4_umh_cltrack_upcall("init", NULL, NULL);
  969. }
  970. static void
  971. nfsd4_umh_cltrack_create(struct nfs4_client *clp)
  972. {
  973. char *hexid;
  974. hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
  975. if (!hexid) {
  976. dprintk("%s: can't allocate memory for upcall!\n", __func__);
  977. return;
  978. }
  979. nfsd4_umh_cltrack_upcall("create", hexid, NULL);
  980. kfree(hexid);
  981. }
  982. static void
  983. nfsd4_umh_cltrack_remove(struct nfs4_client *clp)
  984. {
  985. char *hexid;
  986. hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
  987. if (!hexid) {
  988. dprintk("%s: can't allocate memory for upcall!\n", __func__);
  989. return;
  990. }
  991. nfsd4_umh_cltrack_upcall("remove", hexid, NULL);
  992. kfree(hexid);
  993. }
  994. static int
  995. nfsd4_umh_cltrack_check(struct nfs4_client *clp)
  996. {
  997. int ret;
  998. char *hexid, *legacy;
  999. hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
  1000. if (!hexid) {
  1001. dprintk("%s: can't allocate memory for upcall!\n", __func__);
  1002. return -ENOMEM;
  1003. }
  1004. legacy = nfsd4_cltrack_legacy_recdir(&clp->cl_name);
  1005. ret = nfsd4_umh_cltrack_upcall("check", hexid, legacy);
  1006. kfree(legacy);
  1007. kfree(hexid);
  1008. return ret;
  1009. }
  1010. static void
  1011. nfsd4_umh_cltrack_grace_done(struct net __attribute__((unused)) *net,
  1012. time_t boot_time)
  1013. {
  1014. char *legacy;
  1015. char timestr[22]; /* FIXME: better way to determine max size? */
  1016. sprintf(timestr, "%ld", boot_time);
  1017. legacy = nfsd4_cltrack_legacy_topdir();
  1018. nfsd4_umh_cltrack_upcall("gracedone", timestr, legacy);
  1019. kfree(legacy);
  1020. }
  1021. static struct nfsd4_client_tracking_ops nfsd4_umh_tracking_ops = {
  1022. .init = nfsd4_umh_cltrack_init,
  1023. .exit = NULL,
  1024. .create = nfsd4_umh_cltrack_create,
  1025. .remove = nfsd4_umh_cltrack_remove,
  1026. .check = nfsd4_umh_cltrack_check,
  1027. .grace_done = nfsd4_umh_cltrack_grace_done,
  1028. };
  1029. int
  1030. nfsd4_client_tracking_init(struct net *net)
  1031. {
  1032. int status;
  1033. struct path path;
  1034. /* just run the init if it the method is already decided */
  1035. if (client_tracking_ops)
  1036. goto do_init;
  1037. /*
  1038. * First, try a UMH upcall. It should succeed or fail quickly, so
  1039. * there's little harm in trying that first.
  1040. */
  1041. client_tracking_ops = &nfsd4_umh_tracking_ops;
  1042. status = client_tracking_ops->init(net);
  1043. if (!status)
  1044. return status;
  1045. /*
  1046. * See if the recoverydir exists and is a directory. If it is,
  1047. * then use the legacy ops.
  1048. */
  1049. client_tracking_ops = &nfsd4_legacy_tracking_ops;
  1050. status = kern_path(nfs4_recoverydir(), LOOKUP_FOLLOW, &path);
  1051. if (!status) {
  1052. status = S_ISDIR(path.dentry->d_inode->i_mode);
  1053. path_put(&path);
  1054. if (status)
  1055. goto do_init;
  1056. }
  1057. /* Finally, try to use nfsdcld */
  1058. client_tracking_ops = &nfsd4_cld_tracking_ops;
  1059. printk(KERN_WARNING "NFSD: the nfsdcld client tracking upcall will be "
  1060. "removed in 3.10. Please transition to using "
  1061. "nfsdcltrack.\n");
  1062. do_init:
  1063. status = client_tracking_ops->init(net);
  1064. if (status) {
  1065. printk(KERN_WARNING "NFSD: Unable to initialize client "
  1066. "recovery tracking! (%d)\n", status);
  1067. client_tracking_ops = NULL;
  1068. }
  1069. return status;
  1070. }
  1071. void
  1072. nfsd4_client_tracking_exit(struct net *net)
  1073. {
  1074. if (client_tracking_ops) {
  1075. if (client_tracking_ops->exit)
  1076. client_tracking_ops->exit(net);
  1077. client_tracking_ops = NULL;
  1078. }
  1079. }
  1080. void
  1081. nfsd4_client_record_create(struct nfs4_client *clp)
  1082. {
  1083. if (client_tracking_ops)
  1084. client_tracking_ops->create(clp);
  1085. }
  1086. void
  1087. nfsd4_client_record_remove(struct nfs4_client *clp)
  1088. {
  1089. if (client_tracking_ops)
  1090. client_tracking_ops->remove(clp);
  1091. }
  1092. int
  1093. nfsd4_client_record_check(struct nfs4_client *clp)
  1094. {
  1095. if (client_tracking_ops)
  1096. return client_tracking_ops->check(clp);
  1097. return -EOPNOTSUPP;
  1098. }
  1099. void
  1100. nfsd4_record_grace_done(struct net *net, time_t boot_time)
  1101. {
  1102. if (client_tracking_ops)
  1103. client_tracking_ops->grace_done(net, boot_time);
  1104. }
  1105. static int
  1106. rpc_pipefs_event(struct notifier_block *nb, unsigned long event, void *ptr)
  1107. {
  1108. struct super_block *sb = ptr;
  1109. struct net *net = sb->s_fs_info;
  1110. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  1111. struct cld_net *cn = nn->cld_net;
  1112. struct dentry *dentry;
  1113. int ret = 0;
  1114. if (!try_module_get(THIS_MODULE))
  1115. return 0;
  1116. if (!cn) {
  1117. module_put(THIS_MODULE);
  1118. return 0;
  1119. }
  1120. switch (event) {
  1121. case RPC_PIPEFS_MOUNT:
  1122. dentry = nfsd4_cld_register_sb(sb, cn->cn_pipe);
  1123. if (IS_ERR(dentry)) {
  1124. ret = PTR_ERR(dentry);
  1125. break;
  1126. }
  1127. cn->cn_pipe->dentry = dentry;
  1128. break;
  1129. case RPC_PIPEFS_UMOUNT:
  1130. if (cn->cn_pipe->dentry)
  1131. nfsd4_cld_unregister_sb(cn->cn_pipe);
  1132. break;
  1133. default:
  1134. ret = -ENOTSUPP;
  1135. break;
  1136. }
  1137. module_put(THIS_MODULE);
  1138. return ret;
  1139. }
  1140. static struct notifier_block nfsd4_cld_block = {
  1141. .notifier_call = rpc_pipefs_event,
  1142. };
  1143. int
  1144. register_cld_notifier(void)
  1145. {
  1146. return rpc_pipefs_notifier_register(&nfsd4_cld_block);
  1147. }
  1148. void
  1149. unregister_cld_notifier(void)
  1150. {
  1151. rpc_pipefs_notifier_unregister(&nfsd4_cld_block);
  1152. }