export.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  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= make_kuid(&init_user_ns, an_int);
  471. if (!uid_valid(exp.ex_anon_uid))
  472. goto out3;
  473. /* anon gid */
  474. err = get_int(&mesg, &an_int);
  475. if (err)
  476. goto out3;
  477. exp.ex_anon_gid= make_kgid(&init_user_ns, an_int);
  478. if (!gid_valid(exp.ex_anon_gid))
  479. goto out3;
  480. /* fsid */
  481. err = get_int(&mesg, &an_int);
  482. if (err)
  483. goto out3;
  484. exp.ex_fsid = an_int;
  485. while ((len = qword_get(&mesg, buf, PAGE_SIZE)) > 0) {
  486. if (strcmp(buf, "fsloc") == 0)
  487. err = fsloc_parse(&mesg, buf, &exp.ex_fslocs);
  488. else if (strcmp(buf, "uuid") == 0) {
  489. /* expect a 16 byte uuid encoded as \xXXXX... */
  490. len = qword_get(&mesg, buf, PAGE_SIZE);
  491. if (len != 16)
  492. err = -EINVAL;
  493. else {
  494. exp.ex_uuid =
  495. kmemdup(buf, 16, GFP_KERNEL);
  496. if (exp.ex_uuid == NULL)
  497. err = -ENOMEM;
  498. }
  499. } else if (strcmp(buf, "secinfo") == 0)
  500. err = secinfo_parse(&mesg, buf, &exp);
  501. else
  502. /* quietly ignore unknown words and anything
  503. * following. Newer user-space can try to set
  504. * new values, then see what the result was.
  505. */
  506. break;
  507. if (err)
  508. goto out4;
  509. }
  510. err = check_export(exp.ex_path.dentry->d_inode, &exp.ex_flags,
  511. exp.ex_uuid);
  512. if (err)
  513. goto out4;
  514. }
  515. expp = svc_export_lookup(&exp);
  516. if (expp)
  517. expp = svc_export_update(&exp, expp);
  518. else
  519. err = -ENOMEM;
  520. cache_flush();
  521. if (expp == NULL)
  522. err = -ENOMEM;
  523. else
  524. exp_put(expp);
  525. out4:
  526. nfsd4_fslocs_free(&exp.ex_fslocs);
  527. kfree(exp.ex_uuid);
  528. out3:
  529. path_put(&exp.ex_path);
  530. out1:
  531. auth_domain_put(dom);
  532. out:
  533. kfree(buf);
  534. return err;
  535. }
  536. static void exp_flags(struct seq_file *m, int flag, int fsid,
  537. kuid_t anonu, kgid_t anong, struct nfsd4_fs_locations *fslocs);
  538. static void show_secinfo(struct seq_file *m, struct svc_export *exp);
  539. static int svc_export_show(struct seq_file *m,
  540. struct cache_detail *cd,
  541. struct cache_head *h)
  542. {
  543. struct svc_export *exp ;
  544. if (h ==NULL) {
  545. seq_puts(m, "#path domain(flags)\n");
  546. return 0;
  547. }
  548. exp = container_of(h, struct svc_export, h);
  549. seq_path(m, &exp->ex_path, " \t\n\\");
  550. seq_putc(m, '\t');
  551. seq_escape(m, exp->ex_client->name, " \t\n\\");
  552. seq_putc(m, '(');
  553. if (test_bit(CACHE_VALID, &h->flags) &&
  554. !test_bit(CACHE_NEGATIVE, &h->flags)) {
  555. exp_flags(m, exp->ex_flags, exp->ex_fsid,
  556. exp->ex_anon_uid, exp->ex_anon_gid, &exp->ex_fslocs);
  557. if (exp->ex_uuid) {
  558. int i;
  559. seq_puts(m, ",uuid=");
  560. for (i=0; i<16; i++) {
  561. if ((i&3) == 0 && i)
  562. seq_putc(m, ':');
  563. seq_printf(m, "%02x", exp->ex_uuid[i]);
  564. }
  565. }
  566. show_secinfo(m, exp);
  567. }
  568. seq_puts(m, ")\n");
  569. return 0;
  570. }
  571. static int svc_export_match(struct cache_head *a, struct cache_head *b)
  572. {
  573. struct svc_export *orig = container_of(a, struct svc_export, h);
  574. struct svc_export *new = container_of(b, struct svc_export, h);
  575. return orig->ex_client == new->ex_client &&
  576. orig->ex_path.dentry == new->ex_path.dentry &&
  577. orig->ex_path.mnt == new->ex_path.mnt;
  578. }
  579. static void svc_export_init(struct cache_head *cnew, struct cache_head *citem)
  580. {
  581. struct svc_export *new = container_of(cnew, struct svc_export, h);
  582. struct svc_export *item = container_of(citem, struct svc_export, h);
  583. kref_get(&item->ex_client->ref);
  584. new->ex_client = item->ex_client;
  585. new->ex_path.dentry = dget(item->ex_path.dentry);
  586. new->ex_path.mnt = mntget(item->ex_path.mnt);
  587. new->ex_fslocs.locations = NULL;
  588. new->ex_fslocs.locations_count = 0;
  589. new->ex_fslocs.migrated = 0;
  590. new->cd = item->cd;
  591. }
  592. static void export_update(struct cache_head *cnew, struct cache_head *citem)
  593. {
  594. struct svc_export *new = container_of(cnew, struct svc_export, h);
  595. struct svc_export *item = container_of(citem, struct svc_export, h);
  596. int i;
  597. new->ex_flags = item->ex_flags;
  598. new->ex_anon_uid = item->ex_anon_uid;
  599. new->ex_anon_gid = item->ex_anon_gid;
  600. new->ex_fsid = item->ex_fsid;
  601. new->ex_uuid = item->ex_uuid;
  602. item->ex_uuid = NULL;
  603. new->ex_fslocs.locations = item->ex_fslocs.locations;
  604. item->ex_fslocs.locations = NULL;
  605. new->ex_fslocs.locations_count = item->ex_fslocs.locations_count;
  606. item->ex_fslocs.locations_count = 0;
  607. new->ex_fslocs.migrated = item->ex_fslocs.migrated;
  608. item->ex_fslocs.migrated = 0;
  609. new->ex_nflavors = item->ex_nflavors;
  610. for (i = 0; i < MAX_SECINFO_LIST; i++) {
  611. new->ex_flavors[i] = item->ex_flavors[i];
  612. }
  613. }
  614. static struct cache_head *svc_export_alloc(void)
  615. {
  616. struct svc_export *i = kmalloc(sizeof(*i), GFP_KERNEL);
  617. if (i)
  618. return &i->h;
  619. else
  620. return NULL;
  621. }
  622. static struct cache_detail svc_export_cache_template = {
  623. .owner = THIS_MODULE,
  624. .hash_size = EXPORT_HASHMAX,
  625. .name = "nfsd.export",
  626. .cache_put = svc_export_put,
  627. .cache_upcall = svc_export_upcall,
  628. .cache_parse = svc_export_parse,
  629. .cache_show = svc_export_show,
  630. .match = svc_export_match,
  631. .init = svc_export_init,
  632. .update = export_update,
  633. .alloc = svc_export_alloc,
  634. };
  635. static int
  636. svc_export_hash(struct svc_export *exp)
  637. {
  638. int hash;
  639. hash = hash_ptr(exp->ex_client, EXPORT_HASHBITS);
  640. hash ^= hash_ptr(exp->ex_path.dentry, EXPORT_HASHBITS);
  641. hash ^= hash_ptr(exp->ex_path.mnt, EXPORT_HASHBITS);
  642. return hash;
  643. }
  644. static struct svc_export *
  645. svc_export_lookup(struct svc_export *exp)
  646. {
  647. struct cache_head *ch;
  648. int hash = svc_export_hash(exp);
  649. ch = sunrpc_cache_lookup(exp->cd, &exp->h, hash);
  650. if (ch)
  651. return container_of(ch, struct svc_export, h);
  652. else
  653. return NULL;
  654. }
  655. static struct svc_export *
  656. svc_export_update(struct svc_export *new, struct svc_export *old)
  657. {
  658. struct cache_head *ch;
  659. int hash = svc_export_hash(old);
  660. ch = sunrpc_cache_update(old->cd, &new->h, &old->h, hash);
  661. if (ch)
  662. return container_of(ch, struct svc_export, h);
  663. else
  664. return NULL;
  665. }
  666. static struct svc_expkey *
  667. exp_find_key(struct cache_detail *cd, svc_client *clp, int fsid_type,
  668. u32 *fsidv, struct cache_req *reqp)
  669. {
  670. struct svc_expkey key, *ek;
  671. int err;
  672. if (!clp)
  673. return ERR_PTR(-ENOENT);
  674. key.ek_client = clp;
  675. key.ek_fsidtype = fsid_type;
  676. memcpy(key.ek_fsid, fsidv, key_len(fsid_type));
  677. ek = svc_expkey_lookup(cd, &key);
  678. if (ek == NULL)
  679. return ERR_PTR(-ENOMEM);
  680. err = cache_check(cd, &ek->h, reqp);
  681. if (err)
  682. return ERR_PTR(err);
  683. return ek;
  684. }
  685. static svc_export *exp_get_by_name(struct cache_detail *cd, svc_client *clp,
  686. const struct path *path, struct cache_req *reqp)
  687. {
  688. struct svc_export *exp, key;
  689. int err;
  690. if (!clp)
  691. return ERR_PTR(-ENOENT);
  692. key.ex_client = clp;
  693. key.ex_path = *path;
  694. key.cd = cd;
  695. exp = svc_export_lookup(&key);
  696. if (exp == NULL)
  697. return ERR_PTR(-ENOMEM);
  698. err = cache_check(cd, &exp->h, reqp);
  699. if (err)
  700. return ERR_PTR(err);
  701. return exp;
  702. }
  703. /*
  704. * Find the export entry for a given dentry.
  705. */
  706. static struct svc_export *exp_parent(struct cache_detail *cd, svc_client *clp,
  707. struct path *path)
  708. {
  709. struct dentry *saved = dget(path->dentry);
  710. svc_export *exp = exp_get_by_name(cd, clp, path, NULL);
  711. while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(path->dentry)) {
  712. struct dentry *parent = dget_parent(path->dentry);
  713. dput(path->dentry);
  714. path->dentry = parent;
  715. exp = exp_get_by_name(cd, clp, path, NULL);
  716. }
  717. dput(path->dentry);
  718. path->dentry = saved;
  719. return exp;
  720. }
  721. /*
  722. * Obtain the root fh on behalf of a client.
  723. * This could be done in user space, but I feel that it adds some safety
  724. * since its harder to fool a kernel module than a user space program.
  725. */
  726. int
  727. exp_rootfh(struct net *net, svc_client *clp, char *name,
  728. struct knfsd_fh *f, int maxsize)
  729. {
  730. struct svc_export *exp;
  731. struct path path;
  732. struct inode *inode;
  733. struct svc_fh fh;
  734. int err;
  735. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  736. struct cache_detail *cd = nn->svc_export_cache;
  737. err = -EPERM;
  738. /* NB: we probably ought to check that it's NUL-terminated */
  739. if (kern_path(name, 0, &path)) {
  740. printk("nfsd: exp_rootfh path not found %s", name);
  741. return err;
  742. }
  743. inode = path.dentry->d_inode;
  744. dprintk("nfsd: exp_rootfh(%s [%p] %s:%s/%ld)\n",
  745. name, path.dentry, clp->name,
  746. inode->i_sb->s_id, inode->i_ino);
  747. exp = exp_parent(cd, clp, &path);
  748. if (IS_ERR(exp)) {
  749. err = PTR_ERR(exp);
  750. goto out;
  751. }
  752. /*
  753. * fh must be initialized before calling fh_compose
  754. */
  755. fh_init(&fh, maxsize);
  756. if (fh_compose(&fh, exp, path.dentry, NULL))
  757. err = -EINVAL;
  758. else
  759. err = 0;
  760. memcpy(f, &fh.fh_handle, sizeof(struct knfsd_fh));
  761. fh_put(&fh);
  762. exp_put(exp);
  763. out:
  764. path_put(&path);
  765. return err;
  766. }
  767. static struct svc_export *exp_find(struct cache_detail *cd,
  768. struct auth_domain *clp, int fsid_type,
  769. u32 *fsidv, struct cache_req *reqp)
  770. {
  771. struct svc_export *exp;
  772. struct nfsd_net *nn = net_generic(cd->net, nfsd_net_id);
  773. struct svc_expkey *ek = exp_find_key(nn->svc_expkey_cache, clp, fsid_type, fsidv, reqp);
  774. if (IS_ERR(ek))
  775. return ERR_CAST(ek);
  776. exp = exp_get_by_name(cd, clp, &ek->ek_path, reqp);
  777. cache_put(&ek->h, nn->svc_expkey_cache);
  778. if (IS_ERR(exp))
  779. return ERR_CAST(exp);
  780. return exp;
  781. }
  782. __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp)
  783. {
  784. struct exp_flavor_info *f;
  785. struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
  786. /* legacy gss-only clients are always OK: */
  787. if (exp->ex_client == rqstp->rq_gssclient)
  788. return 0;
  789. /* ip-address based client; check sec= export option: */
  790. for (f = exp->ex_flavors; f < end; f++) {
  791. if (f->pseudoflavor == rqstp->rq_cred.cr_flavor)
  792. return 0;
  793. }
  794. /* defaults in absence of sec= options: */
  795. if (exp->ex_nflavors == 0) {
  796. if (rqstp->rq_cred.cr_flavor == RPC_AUTH_NULL ||
  797. rqstp->rq_cred.cr_flavor == RPC_AUTH_UNIX)
  798. return 0;
  799. }
  800. return nfserr_wrongsec;
  801. }
  802. /*
  803. * Uses rq_client and rq_gssclient to find an export; uses rq_client (an
  804. * auth_unix client) if it's available and has secinfo information;
  805. * otherwise, will try to use rq_gssclient.
  806. *
  807. * Called from functions that handle requests; functions that do work on
  808. * behalf of mountd are passed a single client name to use, and should
  809. * use exp_get_by_name() or exp_find().
  810. */
  811. struct svc_export *
  812. rqst_exp_get_by_name(struct svc_rqst *rqstp, struct path *path)
  813. {
  814. struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT);
  815. struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
  816. struct cache_detail *cd = nn->svc_export_cache;
  817. if (rqstp->rq_client == NULL)
  818. goto gss;
  819. /* First try the auth_unix client: */
  820. exp = exp_get_by_name(cd, rqstp->rq_client, path, &rqstp->rq_chandle);
  821. if (PTR_ERR(exp) == -ENOENT)
  822. goto gss;
  823. if (IS_ERR(exp))
  824. return exp;
  825. /* If it has secinfo, assume there are no gss/... clients */
  826. if (exp->ex_nflavors > 0)
  827. return exp;
  828. gss:
  829. /* Otherwise, try falling back on gss client */
  830. if (rqstp->rq_gssclient == NULL)
  831. return exp;
  832. gssexp = exp_get_by_name(cd, rqstp->rq_gssclient, path, &rqstp->rq_chandle);
  833. if (PTR_ERR(gssexp) == -ENOENT)
  834. return exp;
  835. if (!IS_ERR(exp))
  836. exp_put(exp);
  837. return gssexp;
  838. }
  839. struct svc_export *
  840. rqst_exp_find(struct svc_rqst *rqstp, int fsid_type, u32 *fsidv)
  841. {
  842. struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT);
  843. struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
  844. struct cache_detail *cd = nn->svc_export_cache;
  845. if (rqstp->rq_client == NULL)
  846. goto gss;
  847. /* First try the auth_unix client: */
  848. exp = exp_find(cd, rqstp->rq_client, fsid_type,
  849. fsidv, &rqstp->rq_chandle);
  850. if (PTR_ERR(exp) == -ENOENT)
  851. goto gss;
  852. if (IS_ERR(exp))
  853. return exp;
  854. /* If it has secinfo, assume there are no gss/... clients */
  855. if (exp->ex_nflavors > 0)
  856. return exp;
  857. gss:
  858. /* Otherwise, try falling back on gss client */
  859. if (rqstp->rq_gssclient == NULL)
  860. return exp;
  861. gssexp = exp_find(cd, rqstp->rq_gssclient, fsid_type, fsidv,
  862. &rqstp->rq_chandle);
  863. if (PTR_ERR(gssexp) == -ENOENT)
  864. return exp;
  865. if (!IS_ERR(exp))
  866. exp_put(exp);
  867. return gssexp;
  868. }
  869. struct svc_export *
  870. rqst_exp_parent(struct svc_rqst *rqstp, struct path *path)
  871. {
  872. struct dentry *saved = dget(path->dentry);
  873. struct svc_export *exp = rqst_exp_get_by_name(rqstp, path);
  874. while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(path->dentry)) {
  875. struct dentry *parent = dget_parent(path->dentry);
  876. dput(path->dentry);
  877. path->dentry = parent;
  878. exp = rqst_exp_get_by_name(rqstp, path);
  879. }
  880. dput(path->dentry);
  881. path->dentry = saved;
  882. return exp;
  883. }
  884. struct svc_export *rqst_find_fsidzero_export(struct svc_rqst *rqstp)
  885. {
  886. u32 fsidv[2];
  887. mk_fsid(FSID_NUM, fsidv, 0, 0, 0, NULL);
  888. return rqst_exp_find(rqstp, FSID_NUM, fsidv);
  889. }
  890. /*
  891. * Called when we need the filehandle for the root of the pseudofs,
  892. * for a given NFSv4 client. The root is defined to be the
  893. * export point with fsid==0
  894. */
  895. __be32
  896. exp_pseudoroot(struct svc_rqst *rqstp, struct svc_fh *fhp)
  897. {
  898. struct svc_export *exp;
  899. __be32 rv;
  900. exp = rqst_find_fsidzero_export(rqstp);
  901. if (IS_ERR(exp))
  902. return nfserrno(PTR_ERR(exp));
  903. rv = fh_compose(fhp, exp, exp->ex_path.dentry, NULL);
  904. exp_put(exp);
  905. return rv;
  906. }
  907. /* Iterator */
  908. static void *e_start(struct seq_file *m, loff_t *pos)
  909. __acquires(((struct cache_detail *)m->private)->hash_lock)
  910. {
  911. loff_t n = *pos;
  912. unsigned hash, export;
  913. struct cache_head *ch;
  914. struct cache_detail *cd = m->private;
  915. struct cache_head **export_table = cd->hash_table;
  916. read_lock(&cd->hash_lock);
  917. if (!n--)
  918. return SEQ_START_TOKEN;
  919. hash = n >> 32;
  920. export = n & ((1LL<<32) - 1);
  921. for (ch=export_table[hash]; ch; ch=ch->next)
  922. if (!export--)
  923. return ch;
  924. n &= ~((1LL<<32) - 1);
  925. do {
  926. hash++;
  927. n += 1LL<<32;
  928. } while(hash < EXPORT_HASHMAX && export_table[hash]==NULL);
  929. if (hash >= EXPORT_HASHMAX)
  930. return NULL;
  931. *pos = n+1;
  932. return export_table[hash];
  933. }
  934. static void *e_next(struct seq_file *m, void *p, loff_t *pos)
  935. {
  936. struct cache_head *ch = p;
  937. int hash = (*pos >> 32);
  938. struct cache_detail *cd = m->private;
  939. struct cache_head **export_table = cd->hash_table;
  940. if (p == SEQ_START_TOKEN)
  941. hash = 0;
  942. else if (ch->next == NULL) {
  943. hash++;
  944. *pos += 1LL<<32;
  945. } else {
  946. ++*pos;
  947. return ch->next;
  948. }
  949. *pos &= ~((1LL<<32) - 1);
  950. while (hash < EXPORT_HASHMAX && export_table[hash] == NULL) {
  951. hash++;
  952. *pos += 1LL<<32;
  953. }
  954. if (hash >= EXPORT_HASHMAX)
  955. return NULL;
  956. ++*pos;
  957. return export_table[hash];
  958. }
  959. static void e_stop(struct seq_file *m, void *p)
  960. __releases(((struct cache_detail *)m->private)->hash_lock)
  961. {
  962. struct cache_detail *cd = m->private;
  963. read_unlock(&cd->hash_lock);
  964. }
  965. static struct flags {
  966. int flag;
  967. char *name[2];
  968. } expflags[] = {
  969. { NFSEXP_READONLY, {"ro", "rw"}},
  970. { NFSEXP_INSECURE_PORT, {"insecure", ""}},
  971. { NFSEXP_ROOTSQUASH, {"root_squash", "no_root_squash"}},
  972. { NFSEXP_ALLSQUASH, {"all_squash", ""}},
  973. { NFSEXP_ASYNC, {"async", "sync"}},
  974. { NFSEXP_GATHERED_WRITES, {"wdelay", "no_wdelay"}},
  975. { NFSEXP_NOHIDE, {"nohide", ""}},
  976. { NFSEXP_CROSSMOUNT, {"crossmnt", ""}},
  977. { NFSEXP_NOSUBTREECHECK, {"no_subtree_check", ""}},
  978. { NFSEXP_NOAUTHNLM, {"insecure_locks", ""}},
  979. { NFSEXP_V4ROOT, {"v4root", ""}},
  980. { 0, {"", ""}}
  981. };
  982. static void show_expflags(struct seq_file *m, int flags, int mask)
  983. {
  984. struct flags *flg;
  985. int state, first = 0;
  986. for (flg = expflags; flg->flag; flg++) {
  987. if (flg->flag & ~mask)
  988. continue;
  989. state = (flg->flag & flags) ? 0 : 1;
  990. if (*flg->name[state])
  991. seq_printf(m, "%s%s", first++?",":"", flg->name[state]);
  992. }
  993. }
  994. static void show_secinfo_flags(struct seq_file *m, int flags)
  995. {
  996. seq_printf(m, ",");
  997. show_expflags(m, flags, NFSEXP_SECINFO_FLAGS);
  998. }
  999. static bool secinfo_flags_equal(int f, int g)
  1000. {
  1001. f &= NFSEXP_SECINFO_FLAGS;
  1002. g &= NFSEXP_SECINFO_FLAGS;
  1003. return f == g;
  1004. }
  1005. static int show_secinfo_run(struct seq_file *m, struct exp_flavor_info **fp, struct exp_flavor_info *end)
  1006. {
  1007. int flags;
  1008. flags = (*fp)->flags;
  1009. seq_printf(m, ",sec=%d", (*fp)->pseudoflavor);
  1010. (*fp)++;
  1011. while (*fp != end && secinfo_flags_equal(flags, (*fp)->flags)) {
  1012. seq_printf(m, ":%d", (*fp)->pseudoflavor);
  1013. (*fp)++;
  1014. }
  1015. return flags;
  1016. }
  1017. static void show_secinfo(struct seq_file *m, struct svc_export *exp)
  1018. {
  1019. struct exp_flavor_info *f;
  1020. struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
  1021. int flags;
  1022. if (exp->ex_nflavors == 0)
  1023. return;
  1024. f = exp->ex_flavors;
  1025. flags = show_secinfo_run(m, &f, end);
  1026. if (!secinfo_flags_equal(flags, exp->ex_flags))
  1027. show_secinfo_flags(m, flags);
  1028. while (f != end) {
  1029. flags = show_secinfo_run(m, &f, end);
  1030. show_secinfo_flags(m, flags);
  1031. }
  1032. }
  1033. static void exp_flags(struct seq_file *m, int flag, int fsid,
  1034. kuid_t anonu, kgid_t anong, struct nfsd4_fs_locations *fsloc)
  1035. {
  1036. show_expflags(m, flag, NFSEXP_ALLFLAGS);
  1037. if (flag & NFSEXP_FSID)
  1038. seq_printf(m, ",fsid=%d", fsid);
  1039. if (!uid_eq(anonu, make_kuid(&init_user_ns, (uid_t)-2)) &&
  1040. !uid_eq(anonu, make_kuid(&init_user_ns, 0x10000-2)))
  1041. seq_printf(m, ",anonuid=%u", from_kuid(&init_user_ns, anonu));
  1042. if (!gid_eq(anong, make_kgid(&init_user_ns, (gid_t)-2)) &&
  1043. !gid_eq(anong, make_kgid(&init_user_ns, 0x10000-2)))
  1044. seq_printf(m, ",anongid=%u", from_kgid(&init_user_ns, anong));
  1045. if (fsloc && fsloc->locations_count > 0) {
  1046. char *loctype = (fsloc->migrated) ? "refer" : "replicas";
  1047. int i;
  1048. seq_printf(m, ",%s=", loctype);
  1049. seq_escape(m, fsloc->locations[0].path, ",;@ \t\n\\");
  1050. seq_putc(m, '@');
  1051. seq_escape(m, fsloc->locations[0].hosts, ",;@ \t\n\\");
  1052. for (i = 1; i < fsloc->locations_count; i++) {
  1053. seq_putc(m, ';');
  1054. seq_escape(m, fsloc->locations[i].path, ",;@ \t\n\\");
  1055. seq_putc(m, '@');
  1056. seq_escape(m, fsloc->locations[i].hosts, ",;@ \t\n\\");
  1057. }
  1058. }
  1059. }
  1060. static int e_show(struct seq_file *m, void *p)
  1061. {
  1062. struct cache_head *cp = p;
  1063. struct svc_export *exp = container_of(cp, struct svc_export, h);
  1064. struct cache_detail *cd = m->private;
  1065. if (p == SEQ_START_TOKEN) {
  1066. seq_puts(m, "# Version 1.1\n");
  1067. seq_puts(m, "# Path Client(Flags) # IPs\n");
  1068. return 0;
  1069. }
  1070. cache_get(&exp->h);
  1071. if (cache_check(cd, &exp->h, NULL))
  1072. return 0;
  1073. exp_put(exp);
  1074. return svc_export_show(m, cd, cp);
  1075. }
  1076. const struct seq_operations nfs_exports_op = {
  1077. .start = e_start,
  1078. .next = e_next,
  1079. .stop = e_stop,
  1080. .show = e_show,
  1081. };
  1082. /*
  1083. * Initialize the exports module.
  1084. */
  1085. int
  1086. nfsd_export_init(struct net *net)
  1087. {
  1088. int rv;
  1089. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  1090. dprintk("nfsd: initializing export module (net: %p).\n", net);
  1091. nn->svc_export_cache = cache_create_net(&svc_export_cache_template, net);
  1092. if (IS_ERR(nn->svc_export_cache))
  1093. return PTR_ERR(nn->svc_export_cache);
  1094. rv = cache_register_net(nn->svc_export_cache, net);
  1095. if (rv)
  1096. goto destroy_export_cache;
  1097. nn->svc_expkey_cache = cache_create_net(&svc_expkey_cache_template, net);
  1098. if (IS_ERR(nn->svc_expkey_cache)) {
  1099. rv = PTR_ERR(nn->svc_expkey_cache);
  1100. goto unregister_export_cache;
  1101. }
  1102. rv = cache_register_net(nn->svc_expkey_cache, net);
  1103. if (rv)
  1104. goto destroy_expkey_cache;
  1105. return 0;
  1106. destroy_expkey_cache:
  1107. cache_destroy_net(nn->svc_expkey_cache, net);
  1108. unregister_export_cache:
  1109. cache_unregister_net(nn->svc_export_cache, net);
  1110. destroy_export_cache:
  1111. cache_destroy_net(nn->svc_export_cache, net);
  1112. return rv;
  1113. }
  1114. /*
  1115. * Flush exports table - called when last nfsd thread is killed
  1116. */
  1117. void
  1118. nfsd_export_flush(struct net *net)
  1119. {
  1120. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  1121. cache_purge(nn->svc_expkey_cache);
  1122. cache_purge(nn->svc_export_cache);
  1123. }
  1124. /*
  1125. * Shutdown the exports module.
  1126. */
  1127. void
  1128. nfsd_export_shutdown(struct net *net)
  1129. {
  1130. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  1131. dprintk("nfsd: shutting down export module (net: %p).\n", net);
  1132. cache_unregister_net(nn->svc_expkey_cache, net);
  1133. cache_unregister_net(nn->svc_export_cache, net);
  1134. cache_destroy_net(nn->svc_expkey_cache, net);
  1135. cache_destroy_net(nn->svc_export_cache, net);
  1136. svcauth_unix_purge(net);
  1137. dprintk("nfsd: export shutdown complete (net: %p).\n", net);
  1138. }