export.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289
  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_types = 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_types = item->ex_layout_types;
  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. /* If the compound op contains a spo_must_allowed op,
  833. * it will be sent with integrity/protection which
  834. * will have to be expressly allowed on mounts that
  835. * don't support it
  836. */
  837. if (nfsd4_spo_must_allow(rqstp))
  838. return 0;
  839. return nfserr_wrongsec;
  840. }
  841. /*
  842. * Uses rq_client and rq_gssclient to find an export; uses rq_client (an
  843. * auth_unix client) if it's available and has secinfo information;
  844. * otherwise, will try to use rq_gssclient.
  845. *
  846. * Called from functions that handle requests; functions that do work on
  847. * behalf of mountd are passed a single client name to use, and should
  848. * use exp_get_by_name() or exp_find().
  849. */
  850. struct svc_export *
  851. rqst_exp_get_by_name(struct svc_rqst *rqstp, struct path *path)
  852. {
  853. struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT);
  854. struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
  855. struct cache_detail *cd = nn->svc_export_cache;
  856. if (rqstp->rq_client == NULL)
  857. goto gss;
  858. /* First try the auth_unix client: */
  859. exp = exp_get_by_name(cd, rqstp->rq_client, path, &rqstp->rq_chandle);
  860. if (PTR_ERR(exp) == -ENOENT)
  861. goto gss;
  862. if (IS_ERR(exp))
  863. return exp;
  864. /* If it has secinfo, assume there are no gss/... clients */
  865. if (exp->ex_nflavors > 0)
  866. return exp;
  867. gss:
  868. /* Otherwise, try falling back on gss client */
  869. if (rqstp->rq_gssclient == NULL)
  870. return exp;
  871. gssexp = exp_get_by_name(cd, rqstp->rq_gssclient, path, &rqstp->rq_chandle);
  872. if (PTR_ERR(gssexp) == -ENOENT)
  873. return exp;
  874. if (!IS_ERR(exp))
  875. exp_put(exp);
  876. return gssexp;
  877. }
  878. struct svc_export *
  879. rqst_exp_find(struct svc_rqst *rqstp, int fsid_type, u32 *fsidv)
  880. {
  881. struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT);
  882. struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
  883. struct cache_detail *cd = nn->svc_export_cache;
  884. if (rqstp->rq_client == NULL)
  885. goto gss;
  886. /* First try the auth_unix client: */
  887. exp = exp_find(cd, rqstp->rq_client, fsid_type,
  888. fsidv, &rqstp->rq_chandle);
  889. if (PTR_ERR(exp) == -ENOENT)
  890. goto gss;
  891. if (IS_ERR(exp))
  892. return exp;
  893. /* If it has secinfo, assume there are no gss/... clients */
  894. if (exp->ex_nflavors > 0)
  895. return exp;
  896. gss:
  897. /* Otherwise, try falling back on gss client */
  898. if (rqstp->rq_gssclient == NULL)
  899. return exp;
  900. gssexp = exp_find(cd, rqstp->rq_gssclient, fsid_type, fsidv,
  901. &rqstp->rq_chandle);
  902. if (PTR_ERR(gssexp) == -ENOENT)
  903. return exp;
  904. if (!IS_ERR(exp))
  905. exp_put(exp);
  906. return gssexp;
  907. }
  908. struct svc_export *
  909. rqst_exp_parent(struct svc_rqst *rqstp, struct path *path)
  910. {
  911. struct dentry *saved = dget(path->dentry);
  912. struct svc_export *exp = rqst_exp_get_by_name(rqstp, path);
  913. while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(path->dentry)) {
  914. struct dentry *parent = dget_parent(path->dentry);
  915. dput(path->dentry);
  916. path->dentry = parent;
  917. exp = rqst_exp_get_by_name(rqstp, path);
  918. }
  919. dput(path->dentry);
  920. path->dentry = saved;
  921. return exp;
  922. }
  923. struct svc_export *rqst_find_fsidzero_export(struct svc_rqst *rqstp)
  924. {
  925. u32 fsidv[2];
  926. mk_fsid(FSID_NUM, fsidv, 0, 0, 0, NULL);
  927. return rqst_exp_find(rqstp, FSID_NUM, fsidv);
  928. }
  929. /*
  930. * Called when we need the filehandle for the root of the pseudofs,
  931. * for a given NFSv4 client. The root is defined to be the
  932. * export point with fsid==0
  933. */
  934. __be32
  935. exp_pseudoroot(struct svc_rqst *rqstp, struct svc_fh *fhp)
  936. {
  937. struct svc_export *exp;
  938. __be32 rv;
  939. exp = rqst_find_fsidzero_export(rqstp);
  940. if (IS_ERR(exp))
  941. return nfserrno(PTR_ERR(exp));
  942. rv = fh_compose(fhp, exp, exp->ex_path.dentry, NULL);
  943. exp_put(exp);
  944. return rv;
  945. }
  946. static struct flags {
  947. int flag;
  948. char *name[2];
  949. } expflags[] = {
  950. { NFSEXP_READONLY, {"ro", "rw"}},
  951. { NFSEXP_INSECURE_PORT, {"insecure", ""}},
  952. { NFSEXP_ROOTSQUASH, {"root_squash", "no_root_squash"}},
  953. { NFSEXP_ALLSQUASH, {"all_squash", ""}},
  954. { NFSEXP_ASYNC, {"async", "sync"}},
  955. { NFSEXP_GATHERED_WRITES, {"wdelay", "no_wdelay"}},
  956. { NFSEXP_NOREADDIRPLUS, {"nordirplus", ""}},
  957. { NFSEXP_NOHIDE, {"nohide", ""}},
  958. { NFSEXP_CROSSMOUNT, {"crossmnt", ""}},
  959. { NFSEXP_NOSUBTREECHECK, {"no_subtree_check", ""}},
  960. { NFSEXP_NOAUTHNLM, {"insecure_locks", ""}},
  961. { NFSEXP_V4ROOT, {"v4root", ""}},
  962. { NFSEXP_PNFS, {"pnfs", ""}},
  963. { 0, {"", ""}}
  964. };
  965. static void show_expflags(struct seq_file *m, int flags, int mask)
  966. {
  967. struct flags *flg;
  968. int state, first = 0;
  969. for (flg = expflags; flg->flag; flg++) {
  970. if (flg->flag & ~mask)
  971. continue;
  972. state = (flg->flag & flags) ? 0 : 1;
  973. if (*flg->name[state])
  974. seq_printf(m, "%s%s", first++?",":"", flg->name[state]);
  975. }
  976. }
  977. static void show_secinfo_flags(struct seq_file *m, int flags)
  978. {
  979. seq_printf(m, ",");
  980. show_expflags(m, flags, NFSEXP_SECINFO_FLAGS);
  981. }
  982. static bool secinfo_flags_equal(int f, int g)
  983. {
  984. f &= NFSEXP_SECINFO_FLAGS;
  985. g &= NFSEXP_SECINFO_FLAGS;
  986. return f == g;
  987. }
  988. static int show_secinfo_run(struct seq_file *m, struct exp_flavor_info **fp, struct exp_flavor_info *end)
  989. {
  990. int flags;
  991. flags = (*fp)->flags;
  992. seq_printf(m, ",sec=%d", (*fp)->pseudoflavor);
  993. (*fp)++;
  994. while (*fp != end && secinfo_flags_equal(flags, (*fp)->flags)) {
  995. seq_printf(m, ":%d", (*fp)->pseudoflavor);
  996. (*fp)++;
  997. }
  998. return flags;
  999. }
  1000. static void show_secinfo(struct seq_file *m, struct svc_export *exp)
  1001. {
  1002. struct exp_flavor_info *f;
  1003. struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
  1004. int flags;
  1005. if (exp->ex_nflavors == 0)
  1006. return;
  1007. f = exp->ex_flavors;
  1008. flags = show_secinfo_run(m, &f, end);
  1009. if (!secinfo_flags_equal(flags, exp->ex_flags))
  1010. show_secinfo_flags(m, flags);
  1011. while (f != end) {
  1012. flags = show_secinfo_run(m, &f, end);
  1013. show_secinfo_flags(m, flags);
  1014. }
  1015. }
  1016. static void exp_flags(struct seq_file *m, int flag, int fsid,
  1017. kuid_t anonu, kgid_t anong, struct nfsd4_fs_locations *fsloc)
  1018. {
  1019. show_expflags(m, flag, NFSEXP_ALLFLAGS);
  1020. if (flag & NFSEXP_FSID)
  1021. seq_printf(m, ",fsid=%d", fsid);
  1022. if (!uid_eq(anonu, make_kuid(&init_user_ns, (uid_t)-2)) &&
  1023. !uid_eq(anonu, make_kuid(&init_user_ns, 0x10000-2)))
  1024. seq_printf(m, ",anonuid=%u", from_kuid(&init_user_ns, anonu));
  1025. if (!gid_eq(anong, make_kgid(&init_user_ns, (gid_t)-2)) &&
  1026. !gid_eq(anong, make_kgid(&init_user_ns, 0x10000-2)))
  1027. seq_printf(m, ",anongid=%u", from_kgid(&init_user_ns, anong));
  1028. if (fsloc && fsloc->locations_count > 0) {
  1029. char *loctype = (fsloc->migrated) ? "refer" : "replicas";
  1030. int i;
  1031. seq_printf(m, ",%s=", loctype);
  1032. seq_escape(m, fsloc->locations[0].path, ",;@ \t\n\\");
  1033. seq_putc(m, '@');
  1034. seq_escape(m, fsloc->locations[0].hosts, ",;@ \t\n\\");
  1035. for (i = 1; i < fsloc->locations_count; i++) {
  1036. seq_putc(m, ';');
  1037. seq_escape(m, fsloc->locations[i].path, ",;@ \t\n\\");
  1038. seq_putc(m, '@');
  1039. seq_escape(m, fsloc->locations[i].hosts, ",;@ \t\n\\");
  1040. }
  1041. }
  1042. }
  1043. static int e_show(struct seq_file *m, void *p)
  1044. {
  1045. struct cache_head *cp = p;
  1046. struct svc_export *exp = container_of(cp, struct svc_export, h);
  1047. struct cache_detail *cd = m->private;
  1048. if (p == SEQ_START_TOKEN) {
  1049. seq_puts(m, "# Version 1.1\n");
  1050. seq_puts(m, "# Path Client(Flags) # IPs\n");
  1051. return 0;
  1052. }
  1053. exp_get(exp);
  1054. if (cache_check(cd, &exp->h, NULL))
  1055. return 0;
  1056. exp_put(exp);
  1057. return svc_export_show(m, cd, cp);
  1058. }
  1059. const struct seq_operations nfs_exports_op = {
  1060. .start = cache_seq_start,
  1061. .next = cache_seq_next,
  1062. .stop = cache_seq_stop,
  1063. .show = e_show,
  1064. };
  1065. /*
  1066. * Initialize the exports module.
  1067. */
  1068. int
  1069. nfsd_export_init(struct net *net)
  1070. {
  1071. int rv;
  1072. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  1073. dprintk("nfsd: initializing export module (net: %p).\n", net);
  1074. nn->svc_export_cache = cache_create_net(&svc_export_cache_template, net);
  1075. if (IS_ERR(nn->svc_export_cache))
  1076. return PTR_ERR(nn->svc_export_cache);
  1077. rv = cache_register_net(nn->svc_export_cache, net);
  1078. if (rv)
  1079. goto destroy_export_cache;
  1080. nn->svc_expkey_cache = cache_create_net(&svc_expkey_cache_template, net);
  1081. if (IS_ERR(nn->svc_expkey_cache)) {
  1082. rv = PTR_ERR(nn->svc_expkey_cache);
  1083. goto unregister_export_cache;
  1084. }
  1085. rv = cache_register_net(nn->svc_expkey_cache, net);
  1086. if (rv)
  1087. goto destroy_expkey_cache;
  1088. return 0;
  1089. destroy_expkey_cache:
  1090. cache_destroy_net(nn->svc_expkey_cache, net);
  1091. unregister_export_cache:
  1092. cache_unregister_net(nn->svc_export_cache, net);
  1093. destroy_export_cache:
  1094. cache_destroy_net(nn->svc_export_cache, net);
  1095. return rv;
  1096. }
  1097. /*
  1098. * Flush exports table - called when last nfsd thread is killed
  1099. */
  1100. void
  1101. nfsd_export_flush(struct net *net)
  1102. {
  1103. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  1104. cache_purge(nn->svc_expkey_cache);
  1105. cache_purge(nn->svc_export_cache);
  1106. }
  1107. /*
  1108. * Shutdown the exports module.
  1109. */
  1110. void
  1111. nfsd_export_shutdown(struct net *net)
  1112. {
  1113. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  1114. dprintk("nfsd: shutting down export module (net: %p).\n", net);
  1115. cache_unregister_net(nn->svc_expkey_cache, net);
  1116. cache_unregister_net(nn->svc_export_cache, net);
  1117. cache_destroy_net(nn->svc_expkey_cache, net);
  1118. cache_destroy_net(nn->svc_export_cache, net);
  1119. svcauth_unix_purge(net);
  1120. dprintk("nfsd: export shutdown complete (net: %p).\n", net);
  1121. }