export.c 32 KB

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