nfs4recover.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  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. if (status)
  356. printk("nfsd4: failed to purge old clients from recovery"
  357. " directory %s\n", rec_file->f_path.dentry->d_name.name);
  358. }
  359. static int
  360. load_recdir(struct dentry *parent, struct dentry *child)
  361. {
  362. if (child->d_name.len != HEXDIR_LEN - 1) {
  363. printk("nfsd4: illegal name %s in recovery directory\n",
  364. child->d_name.name);
  365. /* Keep trying; maybe the others are OK: */
  366. return 0;
  367. }
  368. nfs4_client_to_reclaim(child->d_name.name);
  369. return 0;
  370. }
  371. static int
  372. nfsd4_recdir_load(void) {
  373. int status;
  374. if (!rec_file)
  375. return 0;
  376. status = nfsd4_list_rec_dir(load_recdir);
  377. if (status)
  378. printk("nfsd4: failed loading clients from recovery"
  379. " directory %s\n", rec_file->f_path.dentry->d_name.name);
  380. return status;
  381. }
  382. /*
  383. * Hold reference to the recovery directory.
  384. */
  385. static int
  386. nfsd4_init_recdir(void)
  387. {
  388. const struct cred *original_cred;
  389. int status;
  390. printk("NFSD: Using %s as the NFSv4 state recovery directory\n",
  391. user_recovery_dirname);
  392. BUG_ON(rec_file);
  393. status = nfs4_save_creds(&original_cred);
  394. if (status < 0) {
  395. printk("NFSD: Unable to change credentials to find recovery"
  396. " directory: error %d\n",
  397. status);
  398. return status;
  399. }
  400. rec_file = filp_open(user_recovery_dirname, O_RDONLY | O_DIRECTORY, 0);
  401. if (IS_ERR(rec_file)) {
  402. printk("NFSD: unable to find recovery directory %s\n",
  403. user_recovery_dirname);
  404. status = PTR_ERR(rec_file);
  405. rec_file = NULL;
  406. }
  407. nfs4_reset_creds(original_cred);
  408. if (!status)
  409. in_grace = true;
  410. return status;
  411. }
  412. static int
  413. nfsd4_load_reboot_recovery_data(struct net *net)
  414. {
  415. int status;
  416. /* XXX: The legacy code won't work in a container */
  417. if (net != &init_net) {
  418. WARN(1, KERN_ERR "NFSD: attempt to initialize legacy client "
  419. "tracking in a container!\n");
  420. return -EINVAL;
  421. }
  422. nfs4_lock_state();
  423. status = nfsd4_init_recdir();
  424. if (!status)
  425. status = nfsd4_recdir_load();
  426. nfs4_unlock_state();
  427. if (status)
  428. printk(KERN_ERR "NFSD: Failure reading reboot recovery data\n");
  429. return status;
  430. }
  431. static void
  432. nfsd4_shutdown_recdir(void)
  433. {
  434. if (!rec_file)
  435. return;
  436. fput(rec_file);
  437. rec_file = NULL;
  438. }
  439. static void
  440. nfsd4_legacy_tracking_exit(struct net *net)
  441. {
  442. nfs4_release_reclaim();
  443. nfsd4_shutdown_recdir();
  444. }
  445. /*
  446. * Change the NFSv4 recovery directory to recdir.
  447. */
  448. int
  449. nfs4_reset_recoverydir(char *recdir)
  450. {
  451. int status;
  452. struct path path;
  453. status = kern_path(recdir, LOOKUP_FOLLOW, &path);
  454. if (status)
  455. return status;
  456. status = -ENOTDIR;
  457. if (S_ISDIR(path.dentry->d_inode->i_mode)) {
  458. strcpy(user_recovery_dirname, recdir);
  459. status = 0;
  460. }
  461. path_put(&path);
  462. return status;
  463. }
  464. char *
  465. nfs4_recoverydir(void)
  466. {
  467. return user_recovery_dirname;
  468. }
  469. static int
  470. nfsd4_check_legacy_client(struct nfs4_client *clp)
  471. {
  472. int status;
  473. char dname[HEXDIR_LEN];
  474. struct nfs4_client_reclaim *crp;
  475. /* did we already find that this client is stable? */
  476. if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
  477. return 0;
  478. status = nfs4_make_rec_clidname(dname, &clp->cl_name);
  479. if (status) {
  480. legacy_recdir_name_error(status);
  481. return status;
  482. }
  483. /* look for it in the reclaim hashtable otherwise */
  484. crp = nfsd4_find_reclaim_client(dname);
  485. if (crp) {
  486. set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
  487. crp->cr_clp = clp;
  488. return 0;
  489. }
  490. return -ENOENT;
  491. }
  492. static struct nfsd4_client_tracking_ops nfsd4_legacy_tracking_ops = {
  493. .init = nfsd4_load_reboot_recovery_data,
  494. .exit = nfsd4_legacy_tracking_exit,
  495. .create = nfsd4_create_clid_dir,
  496. .remove = nfsd4_remove_clid_dir,
  497. .check = nfsd4_check_legacy_client,
  498. .grace_done = nfsd4_recdir_purge_old,
  499. };
  500. /* Globals */
  501. #define NFSD_PIPE_DIR "nfsd"
  502. #define NFSD_CLD_PIPE "cld"
  503. /* per-net-ns structure for holding cld upcall info */
  504. struct cld_net {
  505. struct rpc_pipe *cn_pipe;
  506. spinlock_t cn_lock;
  507. struct list_head cn_list;
  508. unsigned int cn_xid;
  509. };
  510. struct cld_upcall {
  511. struct list_head cu_list;
  512. struct cld_net *cu_net;
  513. struct task_struct *cu_task;
  514. struct cld_msg cu_msg;
  515. };
  516. static int
  517. __cld_pipe_upcall(struct rpc_pipe *pipe, struct cld_msg *cmsg)
  518. {
  519. int ret;
  520. struct rpc_pipe_msg msg;
  521. memset(&msg, 0, sizeof(msg));
  522. msg.data = cmsg;
  523. msg.len = sizeof(*cmsg);
  524. /*
  525. * Set task state before we queue the upcall. That prevents
  526. * wake_up_process in the downcall from racing with schedule.
  527. */
  528. set_current_state(TASK_UNINTERRUPTIBLE);
  529. ret = rpc_queue_upcall(pipe, &msg);
  530. if (ret < 0) {
  531. set_current_state(TASK_RUNNING);
  532. goto out;
  533. }
  534. schedule();
  535. set_current_state(TASK_RUNNING);
  536. if (msg.errno < 0)
  537. ret = msg.errno;
  538. out:
  539. return ret;
  540. }
  541. static int
  542. cld_pipe_upcall(struct rpc_pipe *pipe, struct cld_msg *cmsg)
  543. {
  544. int ret;
  545. /*
  546. * -EAGAIN occurs when pipe is closed and reopened while there are
  547. * upcalls queued.
  548. */
  549. do {
  550. ret = __cld_pipe_upcall(pipe, cmsg);
  551. } while (ret == -EAGAIN);
  552. return ret;
  553. }
  554. static ssize_t
  555. cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
  556. {
  557. struct cld_upcall *tmp, *cup;
  558. struct cld_msg __user *cmsg = (struct cld_msg __user *)src;
  559. uint32_t xid;
  560. struct nfsd_net *nn = net_generic(filp->f_dentry->d_sb->s_fs_info,
  561. nfsd_net_id);
  562. struct cld_net *cn = nn->cld_net;
  563. if (mlen != sizeof(*cmsg)) {
  564. dprintk("%s: got %zu bytes, expected %zu\n", __func__, mlen,
  565. sizeof(*cmsg));
  566. return -EINVAL;
  567. }
  568. /* copy just the xid so we can try to find that */
  569. if (copy_from_user(&xid, &cmsg->cm_xid, sizeof(xid)) != 0) {
  570. dprintk("%s: error when copying xid from userspace", __func__);
  571. return -EFAULT;
  572. }
  573. /* walk the list and find corresponding xid */
  574. cup = NULL;
  575. spin_lock(&cn->cn_lock);
  576. list_for_each_entry(tmp, &cn->cn_list, cu_list) {
  577. if (get_unaligned(&tmp->cu_msg.cm_xid) == xid) {
  578. cup = tmp;
  579. list_del_init(&cup->cu_list);
  580. break;
  581. }
  582. }
  583. spin_unlock(&cn->cn_lock);
  584. /* couldn't find upcall? */
  585. if (!cup) {
  586. dprintk("%s: couldn't find upcall -- xid=%u\n", __func__, xid);
  587. return -EINVAL;
  588. }
  589. if (copy_from_user(&cup->cu_msg, src, mlen) != 0)
  590. return -EFAULT;
  591. wake_up_process(cup->cu_task);
  592. return mlen;
  593. }
  594. static void
  595. cld_pipe_destroy_msg(struct rpc_pipe_msg *msg)
  596. {
  597. struct cld_msg *cmsg = msg->data;
  598. struct cld_upcall *cup = container_of(cmsg, struct cld_upcall,
  599. cu_msg);
  600. /* errno >= 0 means we got a downcall */
  601. if (msg->errno >= 0)
  602. return;
  603. wake_up_process(cup->cu_task);
  604. }
  605. static const struct rpc_pipe_ops cld_upcall_ops = {
  606. .upcall = rpc_pipe_generic_upcall,
  607. .downcall = cld_pipe_downcall,
  608. .destroy_msg = cld_pipe_destroy_msg,
  609. };
  610. static struct dentry *
  611. nfsd4_cld_register_sb(struct super_block *sb, struct rpc_pipe *pipe)
  612. {
  613. struct dentry *dir, *dentry;
  614. dir = rpc_d_lookup_sb(sb, NFSD_PIPE_DIR);
  615. if (dir == NULL)
  616. return ERR_PTR(-ENOENT);
  617. dentry = rpc_mkpipe_dentry(dir, NFSD_CLD_PIPE, NULL, pipe);
  618. dput(dir);
  619. return dentry;
  620. }
  621. static void
  622. nfsd4_cld_unregister_sb(struct rpc_pipe *pipe)
  623. {
  624. if (pipe->dentry)
  625. rpc_unlink(pipe->dentry);
  626. }
  627. static struct dentry *
  628. nfsd4_cld_register_net(struct net *net, struct rpc_pipe *pipe)
  629. {
  630. struct super_block *sb;
  631. struct dentry *dentry;
  632. sb = rpc_get_sb_net(net);
  633. if (!sb)
  634. return NULL;
  635. dentry = nfsd4_cld_register_sb(sb, pipe);
  636. rpc_put_sb_net(net);
  637. return dentry;
  638. }
  639. static void
  640. nfsd4_cld_unregister_net(struct net *net, struct rpc_pipe *pipe)
  641. {
  642. struct super_block *sb;
  643. sb = rpc_get_sb_net(net);
  644. if (sb) {
  645. nfsd4_cld_unregister_sb(pipe);
  646. rpc_put_sb_net(net);
  647. }
  648. }
  649. /* Initialize rpc_pipefs pipe for communication with client tracking daemon */
  650. static int
  651. nfsd4_init_cld_pipe(struct net *net)
  652. {
  653. int ret;
  654. struct dentry *dentry;
  655. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  656. struct cld_net *cn;
  657. if (nn->cld_net)
  658. return 0;
  659. cn = kzalloc(sizeof(*cn), GFP_KERNEL);
  660. if (!cn) {
  661. ret = -ENOMEM;
  662. goto err;
  663. }
  664. cn->cn_pipe = rpc_mkpipe_data(&cld_upcall_ops, RPC_PIPE_WAIT_FOR_OPEN);
  665. if (IS_ERR(cn->cn_pipe)) {
  666. ret = PTR_ERR(cn->cn_pipe);
  667. goto err;
  668. }
  669. spin_lock_init(&cn->cn_lock);
  670. INIT_LIST_HEAD(&cn->cn_list);
  671. dentry = nfsd4_cld_register_net(net, cn->cn_pipe);
  672. if (IS_ERR(dentry)) {
  673. ret = PTR_ERR(dentry);
  674. goto err_destroy_data;
  675. }
  676. cn->cn_pipe->dentry = dentry;
  677. nn->cld_net = cn;
  678. return 0;
  679. err_destroy_data:
  680. rpc_destroy_pipe_data(cn->cn_pipe);
  681. err:
  682. kfree(cn);
  683. printk(KERN_ERR "NFSD: unable to create nfsdcld upcall pipe (%d)\n",
  684. ret);
  685. return ret;
  686. }
  687. static void
  688. nfsd4_remove_cld_pipe(struct net *net)
  689. {
  690. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  691. struct cld_net *cn = nn->cld_net;
  692. nfsd4_cld_unregister_net(net, cn->cn_pipe);
  693. rpc_destroy_pipe_data(cn->cn_pipe);
  694. kfree(nn->cld_net);
  695. nn->cld_net = NULL;
  696. }
  697. static struct cld_upcall *
  698. alloc_cld_upcall(struct cld_net *cn)
  699. {
  700. struct cld_upcall *new, *tmp;
  701. new = kzalloc(sizeof(*new), GFP_KERNEL);
  702. if (!new)
  703. return new;
  704. /* FIXME: hard cap on number in flight? */
  705. restart_search:
  706. spin_lock(&cn->cn_lock);
  707. list_for_each_entry(tmp, &cn->cn_list, cu_list) {
  708. if (tmp->cu_msg.cm_xid == cn->cn_xid) {
  709. cn->cn_xid++;
  710. spin_unlock(&cn->cn_lock);
  711. goto restart_search;
  712. }
  713. }
  714. new->cu_task = current;
  715. new->cu_msg.cm_vers = CLD_UPCALL_VERSION;
  716. put_unaligned(cn->cn_xid++, &new->cu_msg.cm_xid);
  717. new->cu_net = cn;
  718. list_add(&new->cu_list, &cn->cn_list);
  719. spin_unlock(&cn->cn_lock);
  720. dprintk("%s: allocated xid %u\n", __func__, new->cu_msg.cm_xid);
  721. return new;
  722. }
  723. static void
  724. free_cld_upcall(struct cld_upcall *victim)
  725. {
  726. struct cld_net *cn = victim->cu_net;
  727. spin_lock(&cn->cn_lock);
  728. list_del(&victim->cu_list);
  729. spin_unlock(&cn->cn_lock);
  730. kfree(victim);
  731. }
  732. /* Ask daemon to create a new record */
  733. static void
  734. nfsd4_cld_create(struct nfs4_client *clp)
  735. {
  736. int ret;
  737. struct cld_upcall *cup;
  738. /* FIXME: determine net from clp */
  739. struct nfsd_net *nn = net_generic(&init_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. /* FIXME: determine net from clp */
  771. struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
  772. struct cld_net *cn = nn->cld_net;
  773. /* Don't upcall if it's already removed */
  774. if (!test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
  775. return;
  776. cup = alloc_cld_upcall(cn);
  777. if (!cup) {
  778. ret = -ENOMEM;
  779. goto out_err;
  780. }
  781. cup->cu_msg.cm_cmd = Cld_Remove;
  782. cup->cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
  783. memcpy(cup->cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
  784. clp->cl_name.len);
  785. ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
  786. if (!ret) {
  787. ret = cup->cu_msg.cm_status;
  788. clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
  789. }
  790. free_cld_upcall(cup);
  791. out_err:
  792. if (ret)
  793. printk(KERN_ERR "NFSD: Unable to remove client "
  794. "record from stable storage: %d\n", ret);
  795. }
  796. /* Check for presence of a record, and update its timestamp */
  797. static int
  798. nfsd4_cld_check(struct nfs4_client *clp)
  799. {
  800. int ret;
  801. struct cld_upcall *cup;
  802. /* FIXME: determine net from clp */
  803. struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
  804. struct cld_net *cn = nn->cld_net;
  805. /* Don't upcall if one was already stored during this grace pd */
  806. if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
  807. return 0;
  808. cup = alloc_cld_upcall(cn);
  809. if (!cup) {
  810. printk(KERN_ERR "NFSD: Unable to check client record on "
  811. "stable storage: %d\n", -ENOMEM);
  812. return -ENOMEM;
  813. }
  814. cup->cu_msg.cm_cmd = Cld_Check;
  815. cup->cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
  816. memcpy(cup->cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
  817. clp->cl_name.len);
  818. ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
  819. if (!ret) {
  820. ret = cup->cu_msg.cm_status;
  821. set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
  822. }
  823. free_cld_upcall(cup);
  824. return ret;
  825. }
  826. static void
  827. nfsd4_cld_grace_done(struct net *net, time_t boot_time)
  828. {
  829. int ret;
  830. struct cld_upcall *cup;
  831. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  832. struct cld_net *cn = nn->cld_net;
  833. cup = alloc_cld_upcall(cn);
  834. if (!cup) {
  835. ret = -ENOMEM;
  836. goto out_err;
  837. }
  838. cup->cu_msg.cm_cmd = Cld_GraceDone;
  839. cup->cu_msg.cm_u.cm_gracetime = (int64_t)boot_time;
  840. ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
  841. if (!ret)
  842. ret = cup->cu_msg.cm_status;
  843. free_cld_upcall(cup);
  844. out_err:
  845. if (ret)
  846. printk(KERN_ERR "NFSD: Unable to end grace period: %d\n", ret);
  847. }
  848. static struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops = {
  849. .init = nfsd4_init_cld_pipe,
  850. .exit = nfsd4_remove_cld_pipe,
  851. .create = nfsd4_cld_create,
  852. .remove = nfsd4_cld_remove,
  853. .check = nfsd4_cld_check,
  854. .grace_done = nfsd4_cld_grace_done,
  855. };
  856. /* upcall via usermodehelper */
  857. static char cltrack_prog[PATH_MAX] = "/sbin/nfsdcltrack";
  858. module_param_string(cltrack_prog, cltrack_prog, sizeof(cltrack_prog),
  859. S_IRUGO|S_IWUSR);
  860. MODULE_PARM_DESC(cltrack_prog, "Path to the nfsdcltrack upcall program");
  861. static bool cltrack_legacy_disable;
  862. module_param(cltrack_legacy_disable, bool, S_IRUGO|S_IWUSR);
  863. MODULE_PARM_DESC(cltrack_legacy_disable,
  864. "Disable legacy recoverydir conversion. Default: false");
  865. #define LEGACY_TOPDIR_ENV_PREFIX "NFSDCLTRACK_LEGACY_TOPDIR="
  866. #define LEGACY_RECDIR_ENV_PREFIX "NFSDCLTRACK_LEGACY_RECDIR="
  867. static char *
  868. nfsd4_cltrack_legacy_topdir(void)
  869. {
  870. int copied;
  871. size_t len;
  872. char *result;
  873. if (cltrack_legacy_disable)
  874. return NULL;
  875. len = strlen(LEGACY_TOPDIR_ENV_PREFIX) +
  876. strlen(nfs4_recoverydir()) + 1;
  877. result = kmalloc(len, GFP_KERNEL);
  878. if (!result)
  879. return result;
  880. copied = snprintf(result, len, LEGACY_TOPDIR_ENV_PREFIX "%s",
  881. nfs4_recoverydir());
  882. if (copied >= len) {
  883. /* just return nothing if output was truncated */
  884. kfree(result);
  885. return NULL;
  886. }
  887. return result;
  888. }
  889. static char *
  890. nfsd4_cltrack_legacy_recdir(const struct xdr_netobj *name)
  891. {
  892. int copied;
  893. size_t len;
  894. char *result;
  895. if (cltrack_legacy_disable)
  896. return NULL;
  897. /* +1 is for '/' between "topdir" and "recdir" */
  898. len = strlen(LEGACY_RECDIR_ENV_PREFIX) +
  899. strlen(nfs4_recoverydir()) + 1 + HEXDIR_LEN;
  900. result = kmalloc(len, GFP_KERNEL);
  901. if (!result)
  902. return result;
  903. copied = snprintf(result, len, LEGACY_RECDIR_ENV_PREFIX "%s/",
  904. nfs4_recoverydir());
  905. if (copied > (len - HEXDIR_LEN)) {
  906. /* just return nothing if output will be truncated */
  907. kfree(result);
  908. return NULL;
  909. }
  910. copied = nfs4_make_rec_clidname(result + copied, name);
  911. if (copied) {
  912. kfree(result);
  913. return NULL;
  914. }
  915. return result;
  916. }
  917. static int
  918. nfsd4_umh_cltrack_upcall(char *cmd, char *arg, char *legacy)
  919. {
  920. char *envp[2];
  921. char *argv[4];
  922. int ret;
  923. if (unlikely(!cltrack_prog[0])) {
  924. dprintk("%s: cltrack_prog is disabled\n", __func__);
  925. return -EACCES;
  926. }
  927. dprintk("%s: cmd: %s\n", __func__, cmd);
  928. dprintk("%s: arg: %s\n", __func__, arg ? arg : "(null)");
  929. dprintk("%s: legacy: %s\n", __func__, legacy ? legacy : "(null)");
  930. envp[0] = legacy;
  931. envp[1] = NULL;
  932. argv[0] = (char *)cltrack_prog;
  933. argv[1] = cmd;
  934. argv[2] = arg;
  935. argv[3] = NULL;
  936. ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
  937. /*
  938. * Disable the upcall mechanism if we're getting an ENOENT or EACCES
  939. * error. The admin can re-enable it on the fly by using sysfs
  940. * once the problem has been fixed.
  941. */
  942. if (ret == -ENOENT || ret == -EACCES) {
  943. dprintk("NFSD: %s was not found or isn't executable (%d). "
  944. "Setting cltrack_prog to blank string!",
  945. cltrack_prog, ret);
  946. cltrack_prog[0] = '\0';
  947. }
  948. dprintk("%s: %s return value: %d\n", __func__, cltrack_prog, ret);
  949. return ret;
  950. }
  951. static char *
  952. bin_to_hex_dup(const unsigned char *src, int srclen)
  953. {
  954. int i;
  955. char *buf, *hex;
  956. /* +1 for terminating NULL */
  957. buf = kmalloc((srclen * 2) + 1, GFP_KERNEL);
  958. if (!buf)
  959. return buf;
  960. hex = buf;
  961. for (i = 0; i < srclen; i++) {
  962. sprintf(hex, "%2.2x", *src++);
  963. hex += 2;
  964. }
  965. return buf;
  966. }
  967. static int
  968. nfsd4_umh_cltrack_init(struct net __attribute__((unused)) *net)
  969. {
  970. return nfsd4_umh_cltrack_upcall("init", NULL, NULL);
  971. }
  972. static void
  973. nfsd4_umh_cltrack_create(struct nfs4_client *clp)
  974. {
  975. char *hexid;
  976. hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
  977. if (!hexid) {
  978. dprintk("%s: can't allocate memory for upcall!\n", __func__);
  979. return;
  980. }
  981. nfsd4_umh_cltrack_upcall("create", hexid, NULL);
  982. kfree(hexid);
  983. }
  984. static void
  985. nfsd4_umh_cltrack_remove(struct nfs4_client *clp)
  986. {
  987. char *hexid;
  988. hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
  989. if (!hexid) {
  990. dprintk("%s: can't allocate memory for upcall!\n", __func__);
  991. return;
  992. }
  993. nfsd4_umh_cltrack_upcall("remove", hexid, NULL);
  994. kfree(hexid);
  995. }
  996. static int
  997. nfsd4_umh_cltrack_check(struct nfs4_client *clp)
  998. {
  999. int ret;
  1000. char *hexid, *legacy;
  1001. hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
  1002. if (!hexid) {
  1003. dprintk("%s: can't allocate memory for upcall!\n", __func__);
  1004. return -ENOMEM;
  1005. }
  1006. legacy = nfsd4_cltrack_legacy_recdir(&clp->cl_name);
  1007. ret = nfsd4_umh_cltrack_upcall("check", hexid, legacy);
  1008. kfree(legacy);
  1009. kfree(hexid);
  1010. return ret;
  1011. }
  1012. static void
  1013. nfsd4_umh_cltrack_grace_done(struct net __attribute__((unused)) *net,
  1014. time_t boot_time)
  1015. {
  1016. char *legacy;
  1017. char timestr[22]; /* FIXME: better way to determine max size? */
  1018. sprintf(timestr, "%ld", boot_time);
  1019. legacy = nfsd4_cltrack_legacy_topdir();
  1020. nfsd4_umh_cltrack_upcall("gracedone", timestr, legacy);
  1021. kfree(legacy);
  1022. }
  1023. static struct nfsd4_client_tracking_ops nfsd4_umh_tracking_ops = {
  1024. .init = nfsd4_umh_cltrack_init,
  1025. .exit = NULL,
  1026. .create = nfsd4_umh_cltrack_create,
  1027. .remove = nfsd4_umh_cltrack_remove,
  1028. .check = nfsd4_umh_cltrack_check,
  1029. .grace_done = nfsd4_umh_cltrack_grace_done,
  1030. };
  1031. int
  1032. nfsd4_client_tracking_init(struct net *net)
  1033. {
  1034. int status;
  1035. struct path path;
  1036. /* just run the init if it the method is already decided */
  1037. if (client_tracking_ops)
  1038. goto do_init;
  1039. /*
  1040. * First, try a UMH upcall. It should succeed or fail quickly, so
  1041. * there's little harm in trying that first.
  1042. */
  1043. client_tracking_ops = &nfsd4_umh_tracking_ops;
  1044. status = client_tracking_ops->init(net);
  1045. if (!status)
  1046. return status;
  1047. /*
  1048. * See if the recoverydir exists and is a directory. If it is,
  1049. * then use the legacy ops.
  1050. */
  1051. client_tracking_ops = &nfsd4_legacy_tracking_ops;
  1052. status = kern_path(nfs4_recoverydir(), LOOKUP_FOLLOW, &path);
  1053. if (!status) {
  1054. status = S_ISDIR(path.dentry->d_inode->i_mode);
  1055. path_put(&path);
  1056. if (status)
  1057. goto do_init;
  1058. }
  1059. /* Finally, try to use nfsdcld */
  1060. client_tracking_ops = &nfsd4_cld_tracking_ops;
  1061. printk(KERN_WARNING "NFSD: the nfsdcld client tracking upcall will be "
  1062. "removed in 3.10. Please transition to using "
  1063. "nfsdcltrack.\n");
  1064. do_init:
  1065. status = client_tracking_ops->init(net);
  1066. if (status) {
  1067. printk(KERN_WARNING "NFSD: Unable to initialize client "
  1068. "recovery tracking! (%d)\n", status);
  1069. client_tracking_ops = NULL;
  1070. }
  1071. return status;
  1072. }
  1073. void
  1074. nfsd4_client_tracking_exit(struct net *net)
  1075. {
  1076. if (client_tracking_ops) {
  1077. if (client_tracking_ops->exit)
  1078. client_tracking_ops->exit(net);
  1079. client_tracking_ops = NULL;
  1080. }
  1081. }
  1082. void
  1083. nfsd4_client_record_create(struct nfs4_client *clp)
  1084. {
  1085. if (client_tracking_ops)
  1086. client_tracking_ops->create(clp);
  1087. }
  1088. void
  1089. nfsd4_client_record_remove(struct nfs4_client *clp)
  1090. {
  1091. if (client_tracking_ops)
  1092. client_tracking_ops->remove(clp);
  1093. }
  1094. int
  1095. nfsd4_client_record_check(struct nfs4_client *clp)
  1096. {
  1097. if (client_tracking_ops)
  1098. return client_tracking_ops->check(clp);
  1099. return -EOPNOTSUPP;
  1100. }
  1101. void
  1102. nfsd4_record_grace_done(struct net *net, time_t boot_time)
  1103. {
  1104. if (client_tracking_ops)
  1105. client_tracking_ops->grace_done(net, boot_time);
  1106. }
  1107. static int
  1108. rpc_pipefs_event(struct notifier_block *nb, unsigned long event, void *ptr)
  1109. {
  1110. struct super_block *sb = ptr;
  1111. struct net *net = sb->s_fs_info;
  1112. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  1113. struct cld_net *cn = nn->cld_net;
  1114. struct dentry *dentry;
  1115. int ret = 0;
  1116. if (!try_module_get(THIS_MODULE))
  1117. return 0;
  1118. if (!cn) {
  1119. module_put(THIS_MODULE);
  1120. return 0;
  1121. }
  1122. switch (event) {
  1123. case RPC_PIPEFS_MOUNT:
  1124. dentry = nfsd4_cld_register_sb(sb, cn->cn_pipe);
  1125. if (IS_ERR(dentry)) {
  1126. ret = PTR_ERR(dentry);
  1127. break;
  1128. }
  1129. cn->cn_pipe->dentry = dentry;
  1130. break;
  1131. case RPC_PIPEFS_UMOUNT:
  1132. if (cn->cn_pipe->dentry)
  1133. nfsd4_cld_unregister_sb(cn->cn_pipe);
  1134. break;
  1135. default:
  1136. ret = -ENOTSUPP;
  1137. break;
  1138. }
  1139. module_put(THIS_MODULE);
  1140. return ret;
  1141. }
  1142. static struct notifier_block nfsd4_cld_block = {
  1143. .notifier_call = rpc_pipefs_event,
  1144. };
  1145. int
  1146. register_cld_notifier(void)
  1147. {
  1148. return rpc_pipefs_notifier_register(&nfsd4_cld_block);
  1149. }
  1150. void
  1151. unregister_cld_notifier(void)
  1152. {
  1153. rpc_pipefs_notifier_unregister(&nfsd4_cld_block);
  1154. }