export.c 31 KB

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