export.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. /*
  2. * NFS exporting and validation.
  3. *
  4. * We maintain a list of clients, each of which has a list of
  5. * exports. To export an fs to a given client, you first have
  6. * to create the client entry with NFSCTL_ADDCLIENT, which
  7. * creates a client control block and adds it to the hash
  8. * table. Then, you call NFSCTL_EXPORT for each fs.
  9. *
  10. *
  11. * Copyright (C) 1995, 1996 Olaf Kirch, <okir@monad.swb.de>
  12. */
  13. #include <linux/slab.h>
  14. #include <linux/namei.h>
  15. #include <linux/module.h>
  16. #include <linux/exportfs.h>
  17. #include <linux/sunrpc/svc_xprt.h>
  18. #include <net/ipv6.h>
  19. #include "nfsd.h"
  20. #include "nfsfh.h"
  21. #include "netns.h"
  22. #define NFSDDBG_FACILITY NFSDDBG_EXPORT
  23. typedef struct auth_domain svc_client;
  24. typedef struct svc_export svc_export;
  25. /*
  26. * We have two caches.
  27. * One maps client+vfsmnt+dentry to export options - the export map
  28. * The other maps client+filehandle-fragment to export options. - the expkey map
  29. *
  30. * The export options are actually stored in the first map, and the
  31. * second map contains a reference to the entry in the first map.
  32. */
  33. #define EXPKEY_HASHBITS 8
  34. #define EXPKEY_HASHMAX (1 << EXPKEY_HASHBITS)
  35. #define EXPKEY_HASHMASK (EXPKEY_HASHMAX -1)
  36. static void expkey_put(struct kref *ref)
  37. {
  38. struct svc_expkey *key = container_of(ref, struct svc_expkey, h.ref);
  39. if (test_bit(CACHE_VALID, &key->h.flags) &&
  40. !test_bit(CACHE_NEGATIVE, &key->h.flags))
  41. path_put(&key->ek_path);
  42. auth_domain_put(key->ek_client);
  43. kfree(key);
  44. }
  45. static void expkey_request(struct cache_detail *cd,
  46. struct cache_head *h,
  47. char **bpp, int *blen)
  48. {
  49. /* client fsidtype \xfsid */
  50. struct svc_expkey *ek = container_of(h, struct svc_expkey, h);
  51. char type[5];
  52. qword_add(bpp, blen, ek->ek_client->name);
  53. snprintf(type, 5, "%d", ek->ek_fsidtype);
  54. qword_add(bpp, blen, type);
  55. qword_addhex(bpp, blen, (char*)ek->ek_fsid, key_len(ek->ek_fsidtype));
  56. (*bpp)[-1] = '\n';
  57. }
  58. static int expkey_upcall(struct cache_detail *cd, struct cache_head *h)
  59. {
  60. return sunrpc_cache_pipe_upcall(cd, h, expkey_request);
  61. }
  62. static struct svc_expkey *svc_expkey_update(struct cache_detail *cd, struct svc_expkey *new,
  63. struct svc_expkey *old);
  64. static struct svc_expkey *svc_expkey_lookup(struct cache_detail *cd, struct svc_expkey *);
  65. static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
  66. {
  67. /* client fsidtype fsid [path] */
  68. char *buf;
  69. int len;
  70. struct auth_domain *dom = NULL;
  71. int err;
  72. int fsidtype;
  73. char *ep;
  74. struct svc_expkey key;
  75. struct svc_expkey *ek = NULL;
  76. if (mesg[mlen - 1] != '\n')
  77. return -EINVAL;
  78. mesg[mlen-1] = 0;
  79. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  80. err = -ENOMEM;
  81. if (!buf)
  82. goto out;
  83. err = -EINVAL;
  84. if ((len=qword_get(&mesg, buf, PAGE_SIZE)) <= 0)
  85. goto out;
  86. err = -ENOENT;
  87. dom = auth_domain_find(buf);
  88. if (!dom)
  89. goto out;
  90. dprintk("found domain %s\n", buf);
  91. err = -EINVAL;
  92. if ((len=qword_get(&mesg, buf, PAGE_SIZE)) <= 0)
  93. goto out;
  94. fsidtype = simple_strtoul(buf, &ep, 10);
  95. if (*ep)
  96. goto out;
  97. dprintk("found fsidtype %d\n", fsidtype);
  98. if (key_len(fsidtype)==0) /* invalid type */
  99. goto out;
  100. if ((len=qword_get(&mesg, buf, PAGE_SIZE)) <= 0)
  101. goto out;
  102. dprintk("found fsid length %d\n", len);
  103. if (len != key_len(fsidtype))
  104. goto out;
  105. /* OK, we seem to have a valid key */
  106. key.h.flags = 0;
  107. key.h.expiry_time = get_expiry(&mesg);
  108. if (key.h.expiry_time == 0)
  109. goto out;
  110. key.ek_client = dom;
  111. key.ek_fsidtype = fsidtype;
  112. memcpy(key.ek_fsid, buf, len);
  113. ek = svc_expkey_lookup(cd, &key);
  114. err = -ENOMEM;
  115. if (!ek)
  116. goto out;
  117. /* now we want a pathname, or empty meaning NEGATIVE */
  118. err = -EINVAL;
  119. len = qword_get(&mesg, buf, PAGE_SIZE);
  120. if (len < 0)
  121. goto out;
  122. dprintk("Path seems to be <%s>\n", buf);
  123. err = 0;
  124. if (len == 0) {
  125. set_bit(CACHE_NEGATIVE, &key.h.flags);
  126. ek = svc_expkey_update(cd, &key, ek);
  127. if (!ek)
  128. err = -ENOMEM;
  129. } else {
  130. err = kern_path(buf, 0, &key.ek_path);
  131. if (err)
  132. goto out;
  133. dprintk("Found the path %s\n", buf);
  134. ek = svc_expkey_update(cd, &key, ek);
  135. if (!ek)
  136. err = -ENOMEM;
  137. path_put(&key.ek_path);
  138. }
  139. cache_flush();
  140. out:
  141. if (ek)
  142. cache_put(&ek->h, cd);
  143. if (dom)
  144. auth_domain_put(dom);
  145. kfree(buf);
  146. return err;
  147. }
  148. static int expkey_show(struct seq_file *m,
  149. struct cache_detail *cd,
  150. struct cache_head *h)
  151. {
  152. struct svc_expkey *ek ;
  153. int i;
  154. if (h ==NULL) {
  155. seq_puts(m, "#domain fsidtype fsid [path]\n");
  156. return 0;
  157. }
  158. ek = container_of(h, struct svc_expkey, h);
  159. seq_printf(m, "%s %d 0x", ek->ek_client->name,
  160. ek->ek_fsidtype);
  161. for (i=0; i < key_len(ek->ek_fsidtype)/4; i++)
  162. seq_printf(m, "%08x", ek->ek_fsid[i]);
  163. if (test_bit(CACHE_VALID, &h->flags) &&
  164. !test_bit(CACHE_NEGATIVE, &h->flags)) {
  165. seq_printf(m, " ");
  166. seq_path(m, &ek->ek_path, "\\ \t\n");
  167. }
  168. seq_printf(m, "\n");
  169. return 0;
  170. }
  171. static inline int expkey_match (struct cache_head *a, struct cache_head *b)
  172. {
  173. struct svc_expkey *orig = container_of(a, struct svc_expkey, h);
  174. struct svc_expkey *new = container_of(b, struct svc_expkey, h);
  175. if (orig->ek_fsidtype != new->ek_fsidtype ||
  176. orig->ek_client != new->ek_client ||
  177. memcmp(orig->ek_fsid, new->ek_fsid, key_len(orig->ek_fsidtype)) != 0)
  178. return 0;
  179. return 1;
  180. }
  181. static inline void expkey_init(struct cache_head *cnew,
  182. struct cache_head *citem)
  183. {
  184. struct svc_expkey *new = container_of(cnew, struct svc_expkey, h);
  185. struct svc_expkey *item = container_of(citem, struct svc_expkey, h);
  186. kref_get(&item->ek_client->ref);
  187. new->ek_client = item->ek_client;
  188. new->ek_fsidtype = item->ek_fsidtype;
  189. memcpy(new->ek_fsid, item->ek_fsid, sizeof(new->ek_fsid));
  190. }
  191. static inline void expkey_update(struct cache_head *cnew,
  192. struct cache_head *citem)
  193. {
  194. struct svc_expkey *new = container_of(cnew, struct svc_expkey, h);
  195. struct svc_expkey *item = container_of(citem, struct svc_expkey, h);
  196. new->ek_path = item->ek_path;
  197. path_get(&item->ek_path);
  198. }
  199. static struct cache_head *expkey_alloc(void)
  200. {
  201. struct svc_expkey *i = kmalloc(sizeof(*i), GFP_KERNEL);
  202. if (i)
  203. return &i->h;
  204. else
  205. return NULL;
  206. }
  207. static struct cache_detail svc_expkey_cache_template = {
  208. .owner = THIS_MODULE,
  209. .hash_size = EXPKEY_HASHMAX,
  210. .name = "nfsd.fh",
  211. .cache_put = expkey_put,
  212. .cache_upcall = expkey_upcall,
  213. .cache_parse = expkey_parse,
  214. .cache_show = expkey_show,
  215. .match = expkey_match,
  216. .init = expkey_init,
  217. .update = expkey_update,
  218. .alloc = expkey_alloc,
  219. };
  220. static int
  221. svc_expkey_hash(struct svc_expkey *item)
  222. {
  223. int hash = item->ek_fsidtype;
  224. char * cp = (char*)item->ek_fsid;
  225. int len = key_len(item->ek_fsidtype);
  226. hash ^= hash_mem(cp, len, EXPKEY_HASHBITS);
  227. hash ^= hash_ptr(item->ek_client, EXPKEY_HASHBITS);
  228. hash &= EXPKEY_HASHMASK;
  229. return hash;
  230. }
  231. static struct svc_expkey *
  232. svc_expkey_lookup(struct cache_detail *cd, struct svc_expkey *item)
  233. {
  234. struct cache_head *ch;
  235. int hash = svc_expkey_hash(item);
  236. ch = sunrpc_cache_lookup(cd, &item->h, hash);
  237. if (ch)
  238. return container_of(ch, struct svc_expkey, h);
  239. else
  240. return NULL;
  241. }
  242. static struct svc_expkey *
  243. svc_expkey_update(struct cache_detail *cd, struct svc_expkey *new,
  244. struct svc_expkey *old)
  245. {
  246. struct cache_head *ch;
  247. int hash = svc_expkey_hash(new);
  248. ch = sunrpc_cache_update(cd, &new->h, &old->h, hash);
  249. if (ch)
  250. return container_of(ch, struct svc_expkey, h);
  251. else
  252. return NULL;
  253. }
  254. #define EXPORT_HASHBITS 8
  255. #define EXPORT_HASHMAX (1<< EXPORT_HASHBITS)
  256. static void nfsd4_fslocs_free(struct nfsd4_fs_locations *fsloc)
  257. {
  258. int i;
  259. for (i = 0; i < fsloc->locations_count; i++) {
  260. kfree(fsloc->locations[i].path);
  261. kfree(fsloc->locations[i].hosts);
  262. }
  263. kfree(fsloc->locations);
  264. }
  265. static void svc_export_put(struct kref *ref)
  266. {
  267. struct svc_export *exp = container_of(ref, struct svc_export, h.ref);
  268. path_put(&exp->ex_path);
  269. auth_domain_put(exp->ex_client);
  270. nfsd4_fslocs_free(&exp->ex_fslocs);
  271. kfree(exp);
  272. }
  273. static void svc_export_request(struct cache_detail *cd,
  274. struct cache_head *h,
  275. char **bpp, int *blen)
  276. {
  277. /* client path */
  278. struct svc_export *exp = container_of(h, struct svc_export, h);
  279. char *pth;
  280. qword_add(bpp, blen, exp->ex_client->name);
  281. pth = d_path(&exp->ex_path, *bpp, *blen);
  282. if (IS_ERR(pth)) {
  283. /* is this correct? */
  284. (*bpp)[0] = '\n';
  285. return;
  286. }
  287. qword_add(bpp, blen, pth);
  288. (*bpp)[-1] = '\n';
  289. }
  290. static int svc_export_upcall(struct cache_detail *cd, struct cache_head *h)
  291. {
  292. return sunrpc_cache_pipe_upcall(cd, h, svc_export_request);
  293. }
  294. static struct svc_export *svc_export_update(struct svc_export *new,
  295. struct svc_export *old);
  296. static struct svc_export *svc_export_lookup(struct svc_export *);
  297. static int check_export(struct inode *inode, int *flags, unsigned char *uuid)
  298. {
  299. /*
  300. * We currently export only dirs, regular files, and (for v4
  301. * pseudoroot) symlinks.
  302. */
  303. if (!S_ISDIR(inode->i_mode) &&
  304. !S_ISLNK(inode->i_mode) &&
  305. !S_ISREG(inode->i_mode))
  306. return -ENOTDIR;
  307. /*
  308. * Mountd should never pass down a writeable V4ROOT export, but,
  309. * just to make sure:
  310. */
  311. if (*flags & NFSEXP_V4ROOT)
  312. *flags |= NFSEXP_READONLY;
  313. /* There are two requirements on a filesystem to be exportable.
  314. * 1: We must be able to identify the filesystem from a number.
  315. * either a device number (so FS_REQUIRES_DEV needed)
  316. * or an FSID number (so NFSEXP_FSID or ->uuid is needed).
  317. * 2: We must be able to find an inode from a filehandle.
  318. * This means that s_export_op must be set.
  319. */
  320. if (!(inode->i_sb->s_type->fs_flags & FS_REQUIRES_DEV) &&
  321. !(*flags & NFSEXP_FSID) &&
  322. uuid == NULL) {
  323. dprintk("exp_export: export of non-dev fs without fsid\n");
  324. return -EINVAL;
  325. }
  326. if (!inode->i_sb->s_export_op ||
  327. !inode->i_sb->s_export_op->fh_to_dentry) {
  328. dprintk("exp_export: export of invalid fs type.\n");
  329. return -EINVAL;
  330. }
  331. return 0;
  332. }
  333. #ifdef CONFIG_NFSD_V4
  334. static int
  335. fsloc_parse(char **mesg, char *buf, struct nfsd4_fs_locations *fsloc)
  336. {
  337. int len;
  338. int migrated, i, err;
  339. /* listsize */
  340. err = get_uint(mesg, &fsloc->locations_count);
  341. if (err)
  342. return err;
  343. if (fsloc->locations_count > MAX_FS_LOCATIONS)
  344. return -EINVAL;
  345. if (fsloc->locations_count == 0)
  346. return 0;
  347. fsloc->locations = kzalloc(fsloc->locations_count
  348. * sizeof(struct nfsd4_fs_location), GFP_KERNEL);
  349. if (!fsloc->locations)
  350. return -ENOMEM;
  351. for (i=0; i < fsloc->locations_count; i++) {
  352. /* colon separated host list */
  353. err = -EINVAL;
  354. len = qword_get(mesg, buf, PAGE_SIZE);
  355. if (len <= 0)
  356. goto out_free_all;
  357. err = -ENOMEM;
  358. fsloc->locations[i].hosts = kstrdup(buf, GFP_KERNEL);
  359. if (!fsloc->locations[i].hosts)
  360. goto out_free_all;
  361. err = -EINVAL;
  362. /* slash separated path component list */
  363. len = qword_get(mesg, buf, PAGE_SIZE);
  364. if (len <= 0)
  365. goto out_free_all;
  366. err = -ENOMEM;
  367. fsloc->locations[i].path = kstrdup(buf, GFP_KERNEL);
  368. if (!fsloc->locations[i].path)
  369. goto out_free_all;
  370. }
  371. /* migrated */
  372. err = get_int(mesg, &migrated);
  373. if (err)
  374. goto out_free_all;
  375. err = -EINVAL;
  376. if (migrated < 0 || migrated > 1)
  377. goto out_free_all;
  378. fsloc->migrated = migrated;
  379. return 0;
  380. out_free_all:
  381. nfsd4_fslocs_free(fsloc);
  382. return err;
  383. }
  384. static int secinfo_parse(char **mesg, char *buf, struct svc_export *exp)
  385. {
  386. int listsize, err;
  387. struct exp_flavor_info *f;
  388. err = get_int(mesg, &listsize);
  389. if (err)
  390. return err;
  391. if (listsize < 0 || listsize > MAX_SECINFO_LIST)
  392. return -EINVAL;
  393. for (f = exp->ex_flavors; f < exp->ex_flavors + listsize; f++) {
  394. err = get_uint(mesg, &f->pseudoflavor);
  395. if (err)
  396. return err;
  397. /*
  398. * XXX: It would be nice to also check whether this
  399. * pseudoflavor is supported, so we can discover the
  400. * problem at export time instead of when a client fails
  401. * to authenticate.
  402. */
  403. err = get_uint(mesg, &f->flags);
  404. if (err)
  405. return err;
  406. /* Only some flags are allowed to differ between flavors: */
  407. if (~NFSEXP_SECINFO_FLAGS & (f->flags ^ exp->ex_flags))
  408. return -EINVAL;
  409. }
  410. exp->ex_nflavors = listsize;
  411. return 0;
  412. }
  413. #else /* CONFIG_NFSD_V4 */
  414. static inline int
  415. fsloc_parse(char **mesg, char *buf, struct nfsd4_fs_locations *fsloc){return 0;}
  416. static inline int
  417. secinfo_parse(char **mesg, char *buf, struct svc_export *exp) { return 0; }
  418. #endif
  419. static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
  420. {
  421. /* client path expiry [flags anonuid anongid fsid] */
  422. char *buf;
  423. int len;
  424. int err;
  425. struct auth_domain *dom = NULL;
  426. struct svc_export exp = {}, *expp;
  427. int an_int;
  428. if (mesg[mlen-1] != '\n')
  429. return -EINVAL;
  430. mesg[mlen-1] = 0;
  431. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  432. if (!buf)
  433. return -ENOMEM;
  434. /* client */
  435. err = -EINVAL;
  436. len = qword_get(&mesg, buf, PAGE_SIZE);
  437. if (len <= 0)
  438. goto out;
  439. err = -ENOENT;
  440. dom = auth_domain_find(buf);
  441. if (!dom)
  442. goto out;
  443. /* path */
  444. err = -EINVAL;
  445. if ((len = qword_get(&mesg, buf, PAGE_SIZE)) <= 0)
  446. goto out1;
  447. err = kern_path(buf, 0, &exp.ex_path);
  448. if (err)
  449. goto out1;
  450. exp.ex_client = dom;
  451. exp.cd = cd;
  452. /* expiry */
  453. err = -EINVAL;
  454. exp.h.expiry_time = get_expiry(&mesg);
  455. if (exp.h.expiry_time == 0)
  456. goto out3;
  457. /* flags */
  458. err = get_int(&mesg, &an_int);
  459. if (err == -ENOENT) {
  460. err = 0;
  461. set_bit(CACHE_NEGATIVE, &exp.h.flags);
  462. } else {
  463. if (err || an_int < 0)
  464. goto out3;
  465. exp.ex_flags= an_int;
  466. /* anon uid */
  467. err = get_int(&mesg, &an_int);
  468. if (err)
  469. goto out3;
  470. exp.ex_anon_uid= an_int;
  471. /* anon gid */
  472. err = get_int(&mesg, &an_int);
  473. if (err)
  474. goto out3;
  475. exp.ex_anon_gid= an_int;
  476. /* fsid */
  477. err = get_int(&mesg, &an_int);
  478. if (err)
  479. goto out3;
  480. exp.ex_fsid = an_int;
  481. while ((len = qword_get(&mesg, buf, PAGE_SIZE)) > 0) {
  482. if (strcmp(buf, "fsloc") == 0)
  483. err = fsloc_parse(&mesg, buf, &exp.ex_fslocs);
  484. else if (strcmp(buf, "uuid") == 0) {
  485. /* expect a 16 byte uuid encoded as \xXXXX... */
  486. len = qword_get(&mesg, buf, PAGE_SIZE);
  487. if (len != 16)
  488. err = -EINVAL;
  489. else {
  490. exp.ex_uuid =
  491. kmemdup(buf, 16, GFP_KERNEL);
  492. if (exp.ex_uuid == NULL)
  493. err = -ENOMEM;
  494. }
  495. } else if (strcmp(buf, "secinfo") == 0)
  496. err = secinfo_parse(&mesg, buf, &exp);
  497. else
  498. /* quietly ignore unknown words and anything
  499. * following. Newer user-space can try to set
  500. * new values, then see what the result was.
  501. */
  502. break;
  503. if (err)
  504. goto out4;
  505. }
  506. err = check_export(exp.ex_path.dentry->d_inode, &exp.ex_flags,
  507. exp.ex_uuid);
  508. if (err)
  509. goto out4;
  510. }
  511. expp = svc_export_lookup(&exp);
  512. if (expp)
  513. expp = svc_export_update(&exp, expp);
  514. else
  515. err = -ENOMEM;
  516. cache_flush();
  517. if (expp == NULL)
  518. err = -ENOMEM;
  519. else
  520. exp_put(expp);
  521. out4:
  522. nfsd4_fslocs_free(&exp.ex_fslocs);
  523. kfree(exp.ex_uuid);
  524. out3:
  525. path_put(&exp.ex_path);
  526. out1:
  527. auth_domain_put(dom);
  528. out:
  529. kfree(buf);
  530. return err;
  531. }
  532. static void exp_flags(struct seq_file *m, int flag, int fsid,
  533. uid_t anonu, uid_t anong, struct nfsd4_fs_locations *fslocs);
  534. static void show_secinfo(struct seq_file *m, struct svc_export *exp);
  535. static int svc_export_show(struct seq_file *m,
  536. struct cache_detail *cd,
  537. struct cache_head *h)
  538. {
  539. struct svc_export *exp ;
  540. if (h ==NULL) {
  541. seq_puts(m, "#path domain(flags)\n");
  542. return 0;
  543. }
  544. exp = container_of(h, struct svc_export, h);
  545. seq_path(m, &exp->ex_path, " \t\n\\");
  546. seq_putc(m, '\t');
  547. seq_escape(m, exp->ex_client->name, " \t\n\\");
  548. seq_putc(m, '(');
  549. if (test_bit(CACHE_VALID, &h->flags) &&
  550. !test_bit(CACHE_NEGATIVE, &h->flags)) {
  551. exp_flags(m, exp->ex_flags, exp->ex_fsid,
  552. exp->ex_anon_uid, exp->ex_anon_gid, &exp->ex_fslocs);
  553. if (exp->ex_uuid) {
  554. int i;
  555. seq_puts(m, ",uuid=");
  556. for (i=0; i<16; i++) {
  557. if ((i&3) == 0 && i)
  558. seq_putc(m, ':');
  559. seq_printf(m, "%02x", exp->ex_uuid[i]);
  560. }
  561. }
  562. show_secinfo(m, exp);
  563. }
  564. seq_puts(m, ")\n");
  565. return 0;
  566. }
  567. static int svc_export_match(struct cache_head *a, struct cache_head *b)
  568. {
  569. struct svc_export *orig = container_of(a, struct svc_export, h);
  570. struct svc_export *new = container_of(b, struct svc_export, h);
  571. return orig->ex_client == new->ex_client &&
  572. orig->ex_path.dentry == new->ex_path.dentry &&
  573. orig->ex_path.mnt == new->ex_path.mnt;
  574. }
  575. static void svc_export_init(struct cache_head *cnew, struct cache_head *citem)
  576. {
  577. struct svc_export *new = container_of(cnew, struct svc_export, h);
  578. struct svc_export *item = container_of(citem, struct svc_export, h);
  579. kref_get(&item->ex_client->ref);
  580. new->ex_client = item->ex_client;
  581. new->ex_path.dentry = dget(item->ex_path.dentry);
  582. new->ex_path.mnt = mntget(item->ex_path.mnt);
  583. new->ex_fslocs.locations = NULL;
  584. new->ex_fslocs.locations_count = 0;
  585. new->ex_fslocs.migrated = 0;
  586. new->cd = item->cd;
  587. }
  588. static void export_update(struct cache_head *cnew, struct cache_head *citem)
  589. {
  590. struct svc_export *new = container_of(cnew, struct svc_export, h);
  591. struct svc_export *item = container_of(citem, struct svc_export, h);
  592. int i;
  593. new->ex_flags = item->ex_flags;
  594. new->ex_anon_uid = item->ex_anon_uid;
  595. new->ex_anon_gid = item->ex_anon_gid;
  596. new->ex_fsid = item->ex_fsid;
  597. new->ex_uuid = item->ex_uuid;
  598. item->ex_uuid = NULL;
  599. new->ex_fslocs.locations = item->ex_fslocs.locations;
  600. item->ex_fslocs.locations = NULL;
  601. new->ex_fslocs.locations_count = item->ex_fslocs.locations_count;
  602. item->ex_fslocs.locations_count = 0;
  603. new->ex_fslocs.migrated = item->ex_fslocs.migrated;
  604. item->ex_fslocs.migrated = 0;
  605. new->ex_nflavors = item->ex_nflavors;
  606. for (i = 0; i < MAX_SECINFO_LIST; i++) {
  607. new->ex_flavors[i] = item->ex_flavors[i];
  608. }
  609. }
  610. static struct cache_head *svc_export_alloc(void)
  611. {
  612. struct svc_export *i = kmalloc(sizeof(*i), GFP_KERNEL);
  613. if (i)
  614. return &i->h;
  615. else
  616. return NULL;
  617. }
  618. static struct cache_detail svc_export_cache_template = {
  619. .owner = THIS_MODULE,
  620. .hash_size = EXPORT_HASHMAX,
  621. .name = "nfsd.export",
  622. .cache_put = svc_export_put,
  623. .cache_upcall = svc_export_upcall,
  624. .cache_parse = svc_export_parse,
  625. .cache_show = svc_export_show,
  626. .match = svc_export_match,
  627. .init = svc_export_init,
  628. .update = export_update,
  629. .alloc = svc_export_alloc,
  630. };
  631. static int
  632. svc_export_hash(struct svc_export *exp)
  633. {
  634. int hash;
  635. hash = hash_ptr(exp->ex_client, EXPORT_HASHBITS);
  636. hash ^= hash_ptr(exp->ex_path.dentry, EXPORT_HASHBITS);
  637. hash ^= hash_ptr(exp->ex_path.mnt, EXPORT_HASHBITS);
  638. return hash;
  639. }
  640. static struct svc_export *
  641. svc_export_lookup(struct svc_export *exp)
  642. {
  643. struct cache_head *ch;
  644. int hash = svc_export_hash(exp);
  645. ch = sunrpc_cache_lookup(exp->cd, &exp->h, hash);
  646. if (ch)
  647. return container_of(ch, struct svc_export, h);
  648. else
  649. return NULL;
  650. }
  651. static struct svc_export *
  652. svc_export_update(struct svc_export *new, struct svc_export *old)
  653. {
  654. struct cache_head *ch;
  655. int hash = svc_export_hash(old);
  656. ch = sunrpc_cache_update(old->cd, &new->h, &old->h, hash);
  657. if (ch)
  658. return container_of(ch, struct svc_export, h);
  659. else
  660. return NULL;
  661. }
  662. static struct svc_expkey *
  663. exp_find_key(struct cache_detail *cd, svc_client *clp, int fsid_type,
  664. u32 *fsidv, struct cache_req *reqp)
  665. {
  666. struct svc_expkey key, *ek;
  667. int err;
  668. if (!clp)
  669. return ERR_PTR(-ENOENT);
  670. key.ek_client = clp;
  671. key.ek_fsidtype = fsid_type;
  672. memcpy(key.ek_fsid, fsidv, key_len(fsid_type));
  673. ek = svc_expkey_lookup(cd, &key);
  674. if (ek == NULL)
  675. return ERR_PTR(-ENOMEM);
  676. err = cache_check(cd, &ek->h, reqp);
  677. if (err)
  678. return ERR_PTR(err);
  679. return ek;
  680. }
  681. static svc_export *exp_get_by_name(struct cache_detail *cd, svc_client *clp,
  682. const struct path *path, struct cache_req *reqp)
  683. {
  684. struct svc_export *exp, key;
  685. int err;
  686. if (!clp)
  687. return ERR_PTR(-ENOENT);
  688. key.ex_client = clp;
  689. key.ex_path = *path;
  690. key.cd = cd;
  691. exp = svc_export_lookup(&key);
  692. if (exp == NULL)
  693. return ERR_PTR(-ENOMEM);
  694. err = cache_check(cd, &exp->h, reqp);
  695. if (err)
  696. return ERR_PTR(err);
  697. return exp;
  698. }
  699. /*
  700. * Find the export entry for a given dentry.
  701. */
  702. static struct svc_export *exp_parent(struct cache_detail *cd, svc_client *clp,
  703. struct path *path)
  704. {
  705. struct dentry *saved = dget(path->dentry);
  706. svc_export *exp = exp_get_by_name(cd, clp, path, NULL);
  707. while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(path->dentry)) {
  708. struct dentry *parent = dget_parent(path->dentry);
  709. dput(path->dentry);
  710. path->dentry = parent;
  711. exp = exp_get_by_name(cd, clp, path, NULL);
  712. }
  713. dput(path->dentry);
  714. path->dentry = saved;
  715. return exp;
  716. }
  717. /*
  718. * Obtain the root fh on behalf of a client.
  719. * This could be done in user space, but I feel that it adds some safety
  720. * since its harder to fool a kernel module than a user space program.
  721. */
  722. int
  723. exp_rootfh(struct net *net, svc_client *clp, char *name,
  724. struct knfsd_fh *f, int maxsize)
  725. {
  726. struct svc_export *exp;
  727. struct path path;
  728. struct inode *inode;
  729. struct svc_fh fh;
  730. int err;
  731. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  732. struct cache_detail *cd = nn->svc_export_cache;
  733. err = -EPERM;
  734. /* NB: we probably ought to check that it's NUL-terminated */
  735. if (kern_path(name, 0, &path)) {
  736. printk("nfsd: exp_rootfh path not found %s", name);
  737. return err;
  738. }
  739. inode = path.dentry->d_inode;
  740. dprintk("nfsd: exp_rootfh(%s [%p] %s:%s/%ld)\n",
  741. name, path.dentry, clp->name,
  742. inode->i_sb->s_id, inode->i_ino);
  743. exp = exp_parent(cd, clp, &path);
  744. if (IS_ERR(exp)) {
  745. err = PTR_ERR(exp);
  746. goto out;
  747. }
  748. /*
  749. * fh must be initialized before calling fh_compose
  750. */
  751. fh_init(&fh, maxsize);
  752. if (fh_compose(&fh, exp, path.dentry, NULL))
  753. err = -EINVAL;
  754. else
  755. err = 0;
  756. memcpy(f, &fh.fh_handle, sizeof(struct knfsd_fh));
  757. fh_put(&fh);
  758. exp_put(exp);
  759. out:
  760. path_put(&path);
  761. return err;
  762. }
  763. static struct svc_export *exp_find(struct cache_detail *cd,
  764. struct auth_domain *clp, int fsid_type,
  765. u32 *fsidv, struct cache_req *reqp)
  766. {
  767. struct svc_export *exp;
  768. struct nfsd_net *nn = net_generic(cd->net, nfsd_net_id);
  769. struct svc_expkey *ek = exp_find_key(nn->svc_expkey_cache, clp, fsid_type, fsidv, reqp);
  770. if (IS_ERR(ek))
  771. return ERR_CAST(ek);
  772. exp = exp_get_by_name(cd, clp, &ek->ek_path, reqp);
  773. cache_put(&ek->h, nn->svc_expkey_cache);
  774. if (IS_ERR(exp))
  775. return ERR_CAST(exp);
  776. return exp;
  777. }
  778. __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp)
  779. {
  780. struct exp_flavor_info *f;
  781. struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
  782. /* legacy gss-only clients are always OK: */
  783. if (exp->ex_client == rqstp->rq_gssclient)
  784. return 0;
  785. /* ip-address based client; check sec= export option: */
  786. for (f = exp->ex_flavors; f < end; f++) {
  787. if (f->pseudoflavor == rqstp->rq_cred.cr_flavor)
  788. return 0;
  789. }
  790. /* defaults in absence of sec= options: */
  791. if (exp->ex_nflavors == 0) {
  792. if (rqstp->rq_cred.cr_flavor == RPC_AUTH_NULL ||
  793. rqstp->rq_cred.cr_flavor == RPC_AUTH_UNIX)
  794. return 0;
  795. }
  796. return nfserr_wrongsec;
  797. }
  798. /*
  799. * Uses rq_client and rq_gssclient to find an export; uses rq_client (an
  800. * auth_unix client) if it's available and has secinfo information;
  801. * otherwise, will try to use rq_gssclient.
  802. *
  803. * Called from functions that handle requests; functions that do work on
  804. * behalf of mountd are passed a single client name to use, and should
  805. * use exp_get_by_name() or exp_find().
  806. */
  807. struct svc_export *
  808. rqst_exp_get_by_name(struct svc_rqst *rqstp, struct path *path)
  809. {
  810. struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT);
  811. struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
  812. struct cache_detail *cd = nn->svc_export_cache;
  813. if (rqstp->rq_client == NULL)
  814. goto gss;
  815. /* First try the auth_unix client: */
  816. exp = exp_get_by_name(cd, rqstp->rq_client, path, &rqstp->rq_chandle);
  817. if (PTR_ERR(exp) == -ENOENT)
  818. goto gss;
  819. if (IS_ERR(exp))
  820. return exp;
  821. /* If it has secinfo, assume there are no gss/... clients */
  822. if (exp->ex_nflavors > 0)
  823. return exp;
  824. gss:
  825. /* Otherwise, try falling back on gss client */
  826. if (rqstp->rq_gssclient == NULL)
  827. return exp;
  828. gssexp = exp_get_by_name(cd, rqstp->rq_gssclient, path, &rqstp->rq_chandle);
  829. if (PTR_ERR(gssexp) == -ENOENT)
  830. return exp;
  831. if (!IS_ERR(exp))
  832. exp_put(exp);
  833. return gssexp;
  834. }
  835. struct svc_export *
  836. rqst_exp_find(struct svc_rqst *rqstp, int fsid_type, u32 *fsidv)
  837. {
  838. struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT);
  839. struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
  840. struct cache_detail *cd = nn->svc_export_cache;
  841. if (rqstp->rq_client == NULL)
  842. goto gss;
  843. /* First try the auth_unix client: */
  844. exp = exp_find(cd, rqstp->rq_client, fsid_type,
  845. fsidv, &rqstp->rq_chandle);
  846. if (PTR_ERR(exp) == -ENOENT)
  847. goto gss;
  848. if (IS_ERR(exp))
  849. return exp;
  850. /* If it has secinfo, assume there are no gss/... clients */
  851. if (exp->ex_nflavors > 0)
  852. return exp;
  853. gss:
  854. /* Otherwise, try falling back on gss client */
  855. if (rqstp->rq_gssclient == NULL)
  856. return exp;
  857. gssexp = exp_find(cd, rqstp->rq_gssclient, fsid_type, fsidv,
  858. &rqstp->rq_chandle);
  859. if (PTR_ERR(gssexp) == -ENOENT)
  860. return exp;
  861. if (!IS_ERR(exp))
  862. exp_put(exp);
  863. return gssexp;
  864. }
  865. struct svc_export *
  866. rqst_exp_parent(struct svc_rqst *rqstp, struct path *path)
  867. {
  868. struct dentry *saved = dget(path->dentry);
  869. struct svc_export *exp = rqst_exp_get_by_name(rqstp, path);
  870. while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(path->dentry)) {
  871. struct dentry *parent = dget_parent(path->dentry);
  872. dput(path->dentry);
  873. path->dentry = parent;
  874. exp = rqst_exp_get_by_name(rqstp, path);
  875. }
  876. dput(path->dentry);
  877. path->dentry = saved;
  878. return exp;
  879. }
  880. struct svc_export *rqst_find_fsidzero_export(struct svc_rqst *rqstp)
  881. {
  882. u32 fsidv[2];
  883. mk_fsid(FSID_NUM, fsidv, 0, 0, 0, NULL);
  884. return rqst_exp_find(rqstp, FSID_NUM, fsidv);
  885. }
  886. /*
  887. * Called when we need the filehandle for the root of the pseudofs,
  888. * for a given NFSv4 client. The root is defined to be the
  889. * export point with fsid==0
  890. */
  891. __be32
  892. exp_pseudoroot(struct svc_rqst *rqstp, struct svc_fh *fhp)
  893. {
  894. struct svc_export *exp;
  895. __be32 rv;
  896. exp = rqst_find_fsidzero_export(rqstp);
  897. if (IS_ERR(exp))
  898. return nfserrno(PTR_ERR(exp));
  899. rv = fh_compose(fhp, exp, exp->ex_path.dentry, NULL);
  900. exp_put(exp);
  901. return rv;
  902. }
  903. /* Iterator */
  904. static void *e_start(struct seq_file *m, loff_t *pos)
  905. __acquires(((struct cache_detail *)m->private)->hash_lock)
  906. {
  907. loff_t n = *pos;
  908. unsigned hash, export;
  909. struct cache_head *ch;
  910. struct cache_detail *cd = m->private;
  911. struct cache_head **export_table = cd->hash_table;
  912. read_lock(&cd->hash_lock);
  913. if (!n--)
  914. return SEQ_START_TOKEN;
  915. hash = n >> 32;
  916. export = n & ((1LL<<32) - 1);
  917. for (ch=export_table[hash]; ch; ch=ch->next)
  918. if (!export--)
  919. return ch;
  920. n &= ~((1LL<<32) - 1);
  921. do {
  922. hash++;
  923. n += 1LL<<32;
  924. } while(hash < EXPORT_HASHMAX && export_table[hash]==NULL);
  925. if (hash >= EXPORT_HASHMAX)
  926. return NULL;
  927. *pos = n+1;
  928. return export_table[hash];
  929. }
  930. static void *e_next(struct seq_file *m, void *p, loff_t *pos)
  931. {
  932. struct cache_head *ch = p;
  933. int hash = (*pos >> 32);
  934. struct cache_detail *cd = m->private;
  935. struct cache_head **export_table = cd->hash_table;
  936. if (p == SEQ_START_TOKEN)
  937. hash = 0;
  938. else if (ch->next == NULL) {
  939. hash++;
  940. *pos += 1LL<<32;
  941. } else {
  942. ++*pos;
  943. return ch->next;
  944. }
  945. *pos &= ~((1LL<<32) - 1);
  946. while (hash < EXPORT_HASHMAX && export_table[hash] == NULL) {
  947. hash++;
  948. *pos += 1LL<<32;
  949. }
  950. if (hash >= EXPORT_HASHMAX)
  951. return NULL;
  952. ++*pos;
  953. return export_table[hash];
  954. }
  955. static void e_stop(struct seq_file *m, void *p)
  956. __releases(((struct cache_detail *)m->private)->hash_lock)
  957. {
  958. struct cache_detail *cd = m->private;
  959. read_unlock(&cd->hash_lock);
  960. }
  961. static struct flags {
  962. int flag;
  963. char *name[2];
  964. } expflags[] = {
  965. { NFSEXP_READONLY, {"ro", "rw"}},
  966. { NFSEXP_INSECURE_PORT, {"insecure", ""}},
  967. { NFSEXP_ROOTSQUASH, {"root_squash", "no_root_squash"}},
  968. { NFSEXP_ALLSQUASH, {"all_squash", ""}},
  969. { NFSEXP_ASYNC, {"async", "sync"}},
  970. { NFSEXP_GATHERED_WRITES, {"wdelay", "no_wdelay"}},
  971. { NFSEXP_NOHIDE, {"nohide", ""}},
  972. { NFSEXP_CROSSMOUNT, {"crossmnt", ""}},
  973. { NFSEXP_NOSUBTREECHECK, {"no_subtree_check", ""}},
  974. { NFSEXP_NOAUTHNLM, {"insecure_locks", ""}},
  975. { NFSEXP_V4ROOT, {"v4root", ""}},
  976. { 0, {"", ""}}
  977. };
  978. static void show_expflags(struct seq_file *m, int flags, int mask)
  979. {
  980. struct flags *flg;
  981. int state, first = 0;
  982. for (flg = expflags; flg->flag; flg++) {
  983. if (flg->flag & ~mask)
  984. continue;
  985. state = (flg->flag & flags) ? 0 : 1;
  986. if (*flg->name[state])
  987. seq_printf(m, "%s%s", first++?",":"", flg->name[state]);
  988. }
  989. }
  990. static void show_secinfo_flags(struct seq_file *m, int flags)
  991. {
  992. seq_printf(m, ",");
  993. show_expflags(m, flags, NFSEXP_SECINFO_FLAGS);
  994. }
  995. static bool secinfo_flags_equal(int f, int g)
  996. {
  997. f &= NFSEXP_SECINFO_FLAGS;
  998. g &= NFSEXP_SECINFO_FLAGS;
  999. return f == g;
  1000. }
  1001. static int show_secinfo_run(struct seq_file *m, struct exp_flavor_info **fp, struct exp_flavor_info *end)
  1002. {
  1003. int flags;
  1004. flags = (*fp)->flags;
  1005. seq_printf(m, ",sec=%d", (*fp)->pseudoflavor);
  1006. (*fp)++;
  1007. while (*fp != end && secinfo_flags_equal(flags, (*fp)->flags)) {
  1008. seq_printf(m, ":%d", (*fp)->pseudoflavor);
  1009. (*fp)++;
  1010. }
  1011. return flags;
  1012. }
  1013. static void show_secinfo(struct seq_file *m, struct svc_export *exp)
  1014. {
  1015. struct exp_flavor_info *f;
  1016. struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
  1017. int flags;
  1018. if (exp->ex_nflavors == 0)
  1019. return;
  1020. f = exp->ex_flavors;
  1021. flags = show_secinfo_run(m, &f, end);
  1022. if (!secinfo_flags_equal(flags, exp->ex_flags))
  1023. show_secinfo_flags(m, flags);
  1024. while (f != end) {
  1025. flags = show_secinfo_run(m, &f, end);
  1026. show_secinfo_flags(m, flags);
  1027. }
  1028. }
  1029. static void exp_flags(struct seq_file *m, int flag, int fsid,
  1030. uid_t anonu, uid_t anong, struct nfsd4_fs_locations *fsloc)
  1031. {
  1032. show_expflags(m, flag, NFSEXP_ALLFLAGS);
  1033. if (flag & NFSEXP_FSID)
  1034. seq_printf(m, ",fsid=%d", fsid);
  1035. if (anonu != (uid_t)-2 && anonu != (0x10000-2))
  1036. seq_printf(m, ",anonuid=%u", anonu);
  1037. if (anong != (gid_t)-2 && anong != (0x10000-2))
  1038. seq_printf(m, ",anongid=%u", anong);
  1039. if (fsloc && fsloc->locations_count > 0) {
  1040. char *loctype = (fsloc->migrated) ? "refer" : "replicas";
  1041. int i;
  1042. seq_printf(m, ",%s=", loctype);
  1043. seq_escape(m, fsloc->locations[0].path, ",;@ \t\n\\");
  1044. seq_putc(m, '@');
  1045. seq_escape(m, fsloc->locations[0].hosts, ",;@ \t\n\\");
  1046. for (i = 1; i < fsloc->locations_count; i++) {
  1047. seq_putc(m, ';');
  1048. seq_escape(m, fsloc->locations[i].path, ",;@ \t\n\\");
  1049. seq_putc(m, '@');
  1050. seq_escape(m, fsloc->locations[i].hosts, ",;@ \t\n\\");
  1051. }
  1052. }
  1053. }
  1054. static int e_show(struct seq_file *m, void *p)
  1055. {
  1056. struct cache_head *cp = p;
  1057. struct svc_export *exp = container_of(cp, struct svc_export, h);
  1058. struct cache_detail *cd = m->private;
  1059. if (p == SEQ_START_TOKEN) {
  1060. seq_puts(m, "# Version 1.1\n");
  1061. seq_puts(m, "# Path Client(Flags) # IPs\n");
  1062. return 0;
  1063. }
  1064. cache_get(&exp->h);
  1065. if (cache_check(cd, &exp->h, NULL))
  1066. return 0;
  1067. exp_put(exp);
  1068. return svc_export_show(m, cd, cp);
  1069. }
  1070. const struct seq_operations nfs_exports_op = {
  1071. .start = e_start,
  1072. .next = e_next,
  1073. .stop = e_stop,
  1074. .show = e_show,
  1075. };
  1076. /*
  1077. * Initialize the exports module.
  1078. */
  1079. int
  1080. nfsd_export_init(struct net *net)
  1081. {
  1082. int rv;
  1083. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  1084. dprintk("nfsd: initializing export module (net: %p).\n", net);
  1085. nn->svc_export_cache = cache_create_net(&svc_export_cache_template, net);
  1086. if (IS_ERR(nn->svc_export_cache))
  1087. return PTR_ERR(nn->svc_export_cache);
  1088. rv = cache_register_net(nn->svc_export_cache, net);
  1089. if (rv)
  1090. goto destroy_export_cache;
  1091. nn->svc_expkey_cache = cache_create_net(&svc_expkey_cache_template, net);
  1092. if (IS_ERR(nn->svc_expkey_cache)) {
  1093. rv = PTR_ERR(nn->svc_expkey_cache);
  1094. goto unregister_export_cache;
  1095. }
  1096. rv = cache_register_net(nn->svc_expkey_cache, net);
  1097. if (rv)
  1098. goto destroy_expkey_cache;
  1099. return 0;
  1100. destroy_expkey_cache:
  1101. cache_destroy_net(nn->svc_expkey_cache, net);
  1102. unregister_export_cache:
  1103. cache_unregister_net(nn->svc_export_cache, net);
  1104. destroy_export_cache:
  1105. cache_destroy_net(nn->svc_export_cache, net);
  1106. return rv;
  1107. }
  1108. /*
  1109. * Flush exports table - called when last nfsd thread is killed
  1110. */
  1111. void
  1112. nfsd_export_flush(struct net *net)
  1113. {
  1114. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  1115. cache_purge(nn->svc_expkey_cache);
  1116. cache_purge(nn->svc_export_cache);
  1117. }
  1118. /*
  1119. * Shutdown the exports module.
  1120. */
  1121. void
  1122. nfsd_export_shutdown(struct net *net)
  1123. {
  1124. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  1125. dprintk("nfsd: shutting down export module (net: %p).\n", net);
  1126. cache_unregister_net(nn->svc_expkey_cache, net);
  1127. cache_unregister_net(nn->svc_export_cache, net);
  1128. cache_destroy_net(nn->svc_expkey_cache, net);
  1129. cache_destroy_net(nn->svc_export_cache, net);
  1130. svcauth_unix_purge(net);
  1131. dprintk("nfsd: export shutdown complete (net: %p).\n", net);
  1132. }