export.c 32 KB

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