nfssvc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /*
  2. * Central processing for nfsd.
  3. *
  4. * Authors: Olaf Kirch (okir@monad.swb.de)
  5. *
  6. * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
  7. */
  8. #include <linux/sched.h>
  9. #include <linux/freezer.h>
  10. #include <linux/module.h>
  11. #include <linux/fs_struct.h>
  12. #include <linux/swap.h>
  13. #include <linux/sunrpc/stats.h>
  14. #include <linux/sunrpc/svcsock.h>
  15. #include <linux/lockd/bind.h>
  16. #include <linux/nfsacl.h>
  17. #include <linux/seq_file.h>
  18. #include <net/net_namespace.h>
  19. #include "nfsd.h"
  20. #include "cache.h"
  21. #include "vfs.h"
  22. #define NFSDDBG_FACILITY NFSDDBG_SVC
  23. extern struct svc_program nfsd_program;
  24. static int nfsd(void *vrqstp);
  25. struct timeval nfssvc_boot;
  26. /*
  27. * nfsd_mutex protects nfsd_serv -- both the pointer itself and the members
  28. * of the svc_serv struct. In particular, ->sv_nrthreads but also to some
  29. * extent ->sv_temp_socks and ->sv_permsocks. It also protects nfsdstats.th_cnt
  30. *
  31. * If (out side the lock) nfsd_serv is non-NULL, then it must point to a
  32. * properly initialised 'struct svc_serv' with ->sv_nrthreads > 0. That number
  33. * of nfsd threads must exist and each must listed in ->sp_all_threads in each
  34. * entry of ->sv_pools[].
  35. *
  36. * Transitions of the thread count between zero and non-zero are of particular
  37. * interest since the svc_serv needs to be created and initialized at that
  38. * point, or freed.
  39. *
  40. * Finally, the nfsd_mutex also protects some of the global variables that are
  41. * accessed when nfsd starts and that are settable via the write_* routines in
  42. * nfsctl.c. In particular:
  43. *
  44. * user_recovery_dirname
  45. * user_lease_time
  46. * nfsd_versions
  47. */
  48. DEFINE_MUTEX(nfsd_mutex);
  49. struct svc_serv *nfsd_serv;
  50. /*
  51. * nfsd_drc_lock protects nfsd_drc_max_pages and nfsd_drc_pages_used.
  52. * nfsd_drc_max_pages limits the total amount of memory available for
  53. * version 4.1 DRC caches.
  54. * nfsd_drc_pages_used tracks the current version 4.1 DRC memory usage.
  55. */
  56. spinlock_t nfsd_drc_lock;
  57. unsigned int nfsd_drc_max_mem;
  58. unsigned int nfsd_drc_mem_used;
  59. #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
  60. static struct svc_stat nfsd_acl_svcstats;
  61. static struct svc_version * nfsd_acl_version[] = {
  62. [2] = &nfsd_acl_version2,
  63. [3] = &nfsd_acl_version3,
  64. };
  65. #define NFSD_ACL_MINVERS 2
  66. #define NFSD_ACL_NRVERS ARRAY_SIZE(nfsd_acl_version)
  67. static struct svc_version *nfsd_acl_versions[NFSD_ACL_NRVERS];
  68. static struct svc_program nfsd_acl_program = {
  69. .pg_prog = NFS_ACL_PROGRAM,
  70. .pg_nvers = NFSD_ACL_NRVERS,
  71. .pg_vers = nfsd_acl_versions,
  72. .pg_name = "nfsacl",
  73. .pg_class = "nfsd",
  74. .pg_stats = &nfsd_acl_svcstats,
  75. .pg_authenticate = &svc_set_client,
  76. };
  77. static struct svc_stat nfsd_acl_svcstats = {
  78. .program = &nfsd_acl_program,
  79. };
  80. #endif /* defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL) */
  81. static struct svc_version * nfsd_version[] = {
  82. [2] = &nfsd_version2,
  83. #if defined(CONFIG_NFSD_V3)
  84. [3] = &nfsd_version3,
  85. #endif
  86. #if defined(CONFIG_NFSD_V4)
  87. [4] = &nfsd_version4,
  88. #endif
  89. };
  90. #define NFSD_MINVERS 2
  91. #define NFSD_NRVERS ARRAY_SIZE(nfsd_version)
  92. static struct svc_version *nfsd_versions[NFSD_NRVERS];
  93. struct svc_program nfsd_program = {
  94. #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
  95. .pg_next = &nfsd_acl_program,
  96. #endif
  97. .pg_prog = NFS_PROGRAM, /* program number */
  98. .pg_nvers = NFSD_NRVERS, /* nr of entries in nfsd_version */
  99. .pg_vers = nfsd_versions, /* version table */
  100. .pg_name = "nfsd", /* program name */
  101. .pg_class = "nfsd", /* authentication class */
  102. .pg_stats = &nfsd_svcstats, /* version table */
  103. .pg_authenticate = &svc_set_client, /* export authentication */
  104. };
  105. u32 nfsd_supported_minorversion;
  106. int nfsd_vers(int vers, enum vers_op change)
  107. {
  108. if (vers < NFSD_MINVERS || vers >= NFSD_NRVERS)
  109. return 0;
  110. switch(change) {
  111. case NFSD_SET:
  112. nfsd_versions[vers] = nfsd_version[vers];
  113. #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
  114. if (vers < NFSD_ACL_NRVERS)
  115. nfsd_acl_versions[vers] = nfsd_acl_version[vers];
  116. #endif
  117. break;
  118. case NFSD_CLEAR:
  119. nfsd_versions[vers] = NULL;
  120. #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
  121. if (vers < NFSD_ACL_NRVERS)
  122. nfsd_acl_versions[vers] = NULL;
  123. #endif
  124. break;
  125. case NFSD_TEST:
  126. return nfsd_versions[vers] != NULL;
  127. case NFSD_AVAIL:
  128. return nfsd_version[vers] != NULL;
  129. }
  130. return 0;
  131. }
  132. int nfsd_minorversion(u32 minorversion, enum vers_op change)
  133. {
  134. if (minorversion > NFSD_SUPPORTED_MINOR_VERSION)
  135. return -1;
  136. switch(change) {
  137. case NFSD_SET:
  138. nfsd_supported_minorversion = minorversion;
  139. break;
  140. case NFSD_CLEAR:
  141. if (minorversion == 0)
  142. return -1;
  143. nfsd_supported_minorversion = minorversion - 1;
  144. break;
  145. case NFSD_TEST:
  146. return minorversion <= nfsd_supported_minorversion;
  147. case NFSD_AVAIL:
  148. return minorversion <= NFSD_SUPPORTED_MINOR_VERSION;
  149. }
  150. return 0;
  151. }
  152. /*
  153. * Maximum number of nfsd processes
  154. */
  155. #define NFSD_MAXSERVS 8192
  156. int nfsd_nrthreads(void)
  157. {
  158. int rv = 0;
  159. mutex_lock(&nfsd_mutex);
  160. if (nfsd_serv)
  161. rv = nfsd_serv->sv_nrthreads;
  162. mutex_unlock(&nfsd_mutex);
  163. return rv;
  164. }
  165. static int nfsd_init_socks(struct net *net)
  166. {
  167. int error;
  168. if (!list_empty(&nfsd_serv->sv_permsocks))
  169. return 0;
  170. error = svc_create_xprt(nfsd_serv, "udp", net, PF_INET, NFS_PORT,
  171. SVC_SOCK_DEFAULTS);
  172. if (error < 0)
  173. return error;
  174. error = svc_create_xprt(nfsd_serv, "tcp", net, PF_INET, NFS_PORT,
  175. SVC_SOCK_DEFAULTS);
  176. if (error < 0)
  177. return error;
  178. return 0;
  179. }
  180. static bool nfsd_up = false;
  181. static int nfsd_startup_net(struct net *net)
  182. {
  183. int ret;
  184. ret = nfsd_init_socks(net);
  185. if (ret)
  186. return ret;
  187. ret = lockd_up(net);
  188. if (ret)
  189. return ret;
  190. ret = nfs4_state_start_net(net);
  191. if (ret)
  192. goto out_lockd;
  193. return 0;
  194. out_lockd:
  195. lockd_down(net);
  196. return ret;
  197. }
  198. static int nfsd_startup(int nrservs, struct net *net)
  199. {
  200. int ret;
  201. if (nfsd_up)
  202. return 0;
  203. /*
  204. * Readahead param cache - will no-op if it already exists.
  205. * (Note therefore results will be suboptimal if number of
  206. * threads is modified after nfsd start.)
  207. */
  208. ret = nfsd_racache_init(2*nrservs);
  209. if (ret)
  210. return ret;
  211. ret = nfs4_state_start();
  212. if (ret)
  213. goto out_racache;
  214. ret = nfsd_startup_net(net);
  215. if (ret)
  216. goto out_net;
  217. nfsd_up = true;
  218. return 0;
  219. out_net:
  220. nfs4_state_shutdown();
  221. out_racache:
  222. nfsd_racache_shutdown();
  223. return ret;
  224. }
  225. static void nfsd_shutdown_net(struct net *net)
  226. {
  227. nfs4_state_shutdown_net(net);
  228. lockd_down(net);
  229. }
  230. static void nfsd_shutdown(struct net *net)
  231. {
  232. /*
  233. * write_ports can create the server without actually starting
  234. * any threads--if we get shut down before any threads are
  235. * started, then nfsd_last_thread will be run before any of this
  236. * other initialization has been done.
  237. */
  238. if (!nfsd_up)
  239. return;
  240. nfsd_shutdown_net(net);
  241. nfs4_state_shutdown();
  242. nfsd_racache_shutdown();
  243. nfsd_up = false;
  244. }
  245. static void nfsd_last_thread(struct svc_serv *serv, struct net *net)
  246. {
  247. nfsd_shutdown(net);
  248. svc_rpcb_cleanup(serv, net);
  249. printk(KERN_WARNING "nfsd: last server has exited, flushing export "
  250. "cache\n");
  251. nfsd_export_flush(net);
  252. }
  253. void nfsd_reset_versions(void)
  254. {
  255. int found_one = 0;
  256. int i;
  257. for (i = NFSD_MINVERS; i < NFSD_NRVERS; i++) {
  258. if (nfsd_program.pg_vers[i])
  259. found_one = 1;
  260. }
  261. if (!found_one) {
  262. for (i = NFSD_MINVERS; i < NFSD_NRVERS; i++)
  263. nfsd_program.pg_vers[i] = nfsd_version[i];
  264. #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
  265. for (i = NFSD_ACL_MINVERS; i < NFSD_ACL_NRVERS; i++)
  266. nfsd_acl_program.pg_vers[i] =
  267. nfsd_acl_version[i];
  268. #endif
  269. }
  270. }
  271. /*
  272. * Each session guarantees a negotiated per slot memory cache for replies
  273. * which in turn consumes memory beyond the v2/v3/v4.0 server. A dedicated
  274. * NFSv4.1 server might want to use more memory for a DRC than a machine
  275. * with mutiple services.
  276. *
  277. * Impose a hard limit on the number of pages for the DRC which varies
  278. * according to the machines free pages. This is of course only a default.
  279. *
  280. * For now this is a #defined shift which could be under admin control
  281. * in the future.
  282. */
  283. static void set_max_drc(void)
  284. {
  285. #define NFSD_DRC_SIZE_SHIFT 10
  286. nfsd_drc_max_mem = (nr_free_buffer_pages()
  287. >> NFSD_DRC_SIZE_SHIFT) * PAGE_SIZE;
  288. nfsd_drc_mem_used = 0;
  289. spin_lock_init(&nfsd_drc_lock);
  290. dprintk("%s nfsd_drc_max_mem %u \n", __func__, nfsd_drc_max_mem);
  291. }
  292. static int nfsd_get_default_max_blksize(void)
  293. {
  294. struct sysinfo i;
  295. unsigned long long target;
  296. unsigned long ret;
  297. si_meminfo(&i);
  298. target = (i.totalram - i.totalhigh) << PAGE_SHIFT;
  299. /*
  300. * Aim for 1/4096 of memory per thread This gives 1MB on 4Gig
  301. * machines, but only uses 32K on 128M machines. Bottom out at
  302. * 8K on 32M and smaller. Of course, this is only a default.
  303. */
  304. target >>= 12;
  305. ret = NFSSVC_MAXBLKSIZE;
  306. while (ret > target && ret >= 8*1024*2)
  307. ret /= 2;
  308. return ret;
  309. }
  310. int nfsd_create_serv(struct net *net)
  311. {
  312. int error;
  313. WARN_ON(!mutex_is_locked(&nfsd_mutex));
  314. if (nfsd_serv) {
  315. svc_get(nfsd_serv);
  316. return 0;
  317. }
  318. if (nfsd_max_blksize == 0)
  319. nfsd_max_blksize = nfsd_get_default_max_blksize();
  320. nfsd_reset_versions();
  321. nfsd_serv = svc_create_pooled(&nfsd_program, nfsd_max_blksize,
  322. nfsd_last_thread, nfsd, THIS_MODULE);
  323. if (nfsd_serv == NULL)
  324. return -ENOMEM;
  325. error = svc_bind(nfsd_serv, net);
  326. if (error < 0) {
  327. svc_destroy(nfsd_serv);
  328. return error;
  329. }
  330. set_max_drc();
  331. do_gettimeofday(&nfssvc_boot); /* record boot time */
  332. return 0;
  333. }
  334. int nfsd_nrpools(void)
  335. {
  336. if (nfsd_serv == NULL)
  337. return 0;
  338. else
  339. return nfsd_serv->sv_nrpools;
  340. }
  341. int nfsd_get_nrthreads(int n, int *nthreads)
  342. {
  343. int i = 0;
  344. if (nfsd_serv != NULL) {
  345. for (i = 0; i < nfsd_serv->sv_nrpools && i < n; i++)
  346. nthreads[i] = nfsd_serv->sv_pools[i].sp_nrthreads;
  347. }
  348. return 0;
  349. }
  350. int nfsd_set_nrthreads(int n, int *nthreads, struct net *net)
  351. {
  352. int i = 0;
  353. int tot = 0;
  354. int err = 0;
  355. WARN_ON(!mutex_is_locked(&nfsd_mutex));
  356. if (nfsd_serv == NULL || n <= 0)
  357. return 0;
  358. if (n > nfsd_serv->sv_nrpools)
  359. n = nfsd_serv->sv_nrpools;
  360. /* enforce a global maximum number of threads */
  361. tot = 0;
  362. for (i = 0; i < n; i++) {
  363. if (nthreads[i] > NFSD_MAXSERVS)
  364. nthreads[i] = NFSD_MAXSERVS;
  365. tot += nthreads[i];
  366. }
  367. if (tot > NFSD_MAXSERVS) {
  368. /* total too large: scale down requested numbers */
  369. for (i = 0; i < n && tot > 0; i++) {
  370. int new = nthreads[i] * NFSD_MAXSERVS / tot;
  371. tot -= (nthreads[i] - new);
  372. nthreads[i] = new;
  373. }
  374. for (i = 0; i < n && tot > 0; i++) {
  375. nthreads[i]--;
  376. tot--;
  377. }
  378. }
  379. /*
  380. * There must always be a thread in pool 0; the admin
  381. * can't shut down NFS completely using pool_threads.
  382. */
  383. if (nthreads[0] == 0)
  384. nthreads[0] = 1;
  385. /* apply the new numbers */
  386. svc_get(nfsd_serv);
  387. for (i = 0; i < n; i++) {
  388. err = svc_set_num_threads(nfsd_serv, &nfsd_serv->sv_pools[i],
  389. nthreads[i]);
  390. if (err)
  391. break;
  392. }
  393. nfsd_destroy(net);
  394. return err;
  395. }
  396. /*
  397. * Adjust the number of threads and return the new number of threads.
  398. * This is also the function that starts the server if necessary, if
  399. * this is the first time nrservs is nonzero.
  400. */
  401. int
  402. nfsd_svc(int nrservs, struct net *net)
  403. {
  404. int error;
  405. bool nfsd_up_before;
  406. mutex_lock(&nfsd_mutex);
  407. dprintk("nfsd: creating service\n");
  408. if (nrservs <= 0)
  409. nrservs = 0;
  410. if (nrservs > NFSD_MAXSERVS)
  411. nrservs = NFSD_MAXSERVS;
  412. error = 0;
  413. if (nrservs == 0 && nfsd_serv == NULL)
  414. goto out;
  415. error = nfsd_create_serv(net);
  416. if (error)
  417. goto out;
  418. nfsd_up_before = nfsd_up;
  419. error = nfsd_startup(nrservs, net);
  420. if (error)
  421. goto out_destroy;
  422. error = svc_set_num_threads(nfsd_serv, NULL, nrservs);
  423. if (error)
  424. goto out_shutdown;
  425. /* We are holding a reference to nfsd_serv which
  426. * we don't want to count in the return value,
  427. * so subtract 1
  428. */
  429. error = nfsd_serv->sv_nrthreads - 1;
  430. out_shutdown:
  431. if (error < 0 && !nfsd_up_before)
  432. nfsd_shutdown(net);
  433. out_destroy:
  434. nfsd_destroy(net); /* Release server */
  435. out:
  436. mutex_unlock(&nfsd_mutex);
  437. return error;
  438. }
  439. /*
  440. * This is the NFS server kernel thread
  441. */
  442. static int
  443. nfsd(void *vrqstp)
  444. {
  445. struct svc_rqst *rqstp = (struct svc_rqst *) vrqstp;
  446. int err;
  447. /* Lock module and set up kernel thread */
  448. mutex_lock(&nfsd_mutex);
  449. /* At this point, the thread shares current->fs
  450. * with the init process. We need to create files with a
  451. * umask of 0 instead of init's umask. */
  452. if (unshare_fs_struct() < 0) {
  453. printk("Unable to start nfsd thread: out of memory\n");
  454. goto out;
  455. }
  456. current->fs->umask = 0;
  457. /*
  458. * thread is spawned with all signals set to SIG_IGN, re-enable
  459. * the ones that will bring down the thread
  460. */
  461. allow_signal(SIGKILL);
  462. allow_signal(SIGHUP);
  463. allow_signal(SIGINT);
  464. allow_signal(SIGQUIT);
  465. nfsdstats.th_cnt++;
  466. mutex_unlock(&nfsd_mutex);
  467. /*
  468. * We want less throttling in balance_dirty_pages() so that nfs to
  469. * localhost doesn't cause nfsd to lock up due to all the client's
  470. * dirty pages.
  471. */
  472. current->flags |= PF_LESS_THROTTLE;
  473. set_freezable();
  474. /*
  475. * The main request loop
  476. */
  477. for (;;) {
  478. /*
  479. * Find a socket with data available and call its
  480. * recvfrom routine.
  481. */
  482. while ((err = svc_recv(rqstp, 60*60*HZ)) == -EAGAIN)
  483. ;
  484. if (err == -EINTR)
  485. break;
  486. validate_process_creds();
  487. svc_process(rqstp);
  488. validate_process_creds();
  489. }
  490. /* Clear signals before calling svc_exit_thread() */
  491. flush_signals(current);
  492. mutex_lock(&nfsd_mutex);
  493. nfsdstats.th_cnt --;
  494. out:
  495. rqstp->rq_server = NULL;
  496. /* Release the thread */
  497. svc_exit_thread(rqstp);
  498. nfsd_destroy(&init_net);
  499. /* Release module */
  500. mutex_unlock(&nfsd_mutex);
  501. module_put_and_exit(0);
  502. return 0;
  503. }
  504. static __be32 map_new_errors(u32 vers, __be32 nfserr)
  505. {
  506. if (nfserr == nfserr_jukebox && vers == 2)
  507. return nfserr_dropit;
  508. if (nfserr == nfserr_wrongsec && vers < 4)
  509. return nfserr_acces;
  510. return nfserr;
  511. }
  512. int
  513. nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp)
  514. {
  515. struct svc_procedure *proc;
  516. kxdrproc_t xdr;
  517. __be32 nfserr;
  518. __be32 *nfserrp;
  519. dprintk("nfsd_dispatch: vers %d proc %d\n",
  520. rqstp->rq_vers, rqstp->rq_proc);
  521. proc = rqstp->rq_procinfo;
  522. /*
  523. * Give the xdr decoder a chance to change this if it wants
  524. * (necessary in the NFSv4.0 compound case)
  525. */
  526. rqstp->rq_cachetype = proc->pc_cachetype;
  527. /* Decode arguments */
  528. xdr = proc->pc_decode;
  529. if (xdr && !xdr(rqstp, (__be32*)rqstp->rq_arg.head[0].iov_base,
  530. rqstp->rq_argp)) {
  531. dprintk("nfsd: failed to decode arguments!\n");
  532. *statp = rpc_garbage_args;
  533. return 1;
  534. }
  535. /* Check whether we have this call in the cache. */
  536. switch (nfsd_cache_lookup(rqstp)) {
  537. case RC_INTR:
  538. case RC_DROPIT:
  539. return 0;
  540. case RC_REPLY:
  541. return 1;
  542. case RC_DOIT:;
  543. /* do it */
  544. }
  545. /* need to grab the location to store the status, as
  546. * nfsv4 does some encoding while processing
  547. */
  548. nfserrp = rqstp->rq_res.head[0].iov_base
  549. + rqstp->rq_res.head[0].iov_len;
  550. rqstp->rq_res.head[0].iov_len += sizeof(__be32);
  551. /* Now call the procedure handler, and encode NFS status. */
  552. nfserr = proc->pc_func(rqstp, rqstp->rq_argp, rqstp->rq_resp);
  553. nfserr = map_new_errors(rqstp->rq_vers, nfserr);
  554. if (nfserr == nfserr_dropit || rqstp->rq_dropme) {
  555. dprintk("nfsd: Dropping request; may be revisited later\n");
  556. nfsd_cache_update(rqstp, RC_NOCACHE, NULL);
  557. return 0;
  558. }
  559. if (rqstp->rq_proc != 0)
  560. *nfserrp++ = nfserr;
  561. /* Encode result.
  562. * For NFSv2, additional info is never returned in case of an error.
  563. */
  564. if (!(nfserr && rqstp->rq_vers == 2)) {
  565. xdr = proc->pc_encode;
  566. if (xdr && !xdr(rqstp, nfserrp,
  567. rqstp->rq_resp)) {
  568. /* Failed to encode result. Release cache entry */
  569. dprintk("nfsd: failed to encode result!\n");
  570. nfsd_cache_update(rqstp, RC_NOCACHE, NULL);
  571. *statp = rpc_system_err;
  572. return 1;
  573. }
  574. }
  575. /* Store reply in cache. */
  576. nfsd_cache_update(rqstp, rqstp->rq_cachetype, statp + 1);
  577. return 1;
  578. }
  579. int nfsd_pool_stats_open(struct inode *inode, struct file *file)
  580. {
  581. int ret;
  582. mutex_lock(&nfsd_mutex);
  583. if (nfsd_serv == NULL) {
  584. mutex_unlock(&nfsd_mutex);
  585. return -ENODEV;
  586. }
  587. /* bump up the psudo refcount while traversing */
  588. svc_get(nfsd_serv);
  589. ret = svc_pool_stats_open(nfsd_serv, file);
  590. mutex_unlock(&nfsd_mutex);
  591. return ret;
  592. }
  593. int nfsd_pool_stats_release(struct inode *inode, struct file *file)
  594. {
  595. int ret = seq_release(inode, file);
  596. struct net *net = &init_net;
  597. mutex_lock(&nfsd_mutex);
  598. /* this function really, really should have been called svc_put() */
  599. nfsd_destroy(net);
  600. mutex_unlock(&nfsd_mutex);
  601. return ret;
  602. }