export.c 32 KB

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