nfssvc.c 17 KB

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