nfssvc.c 17 KB

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