svc.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  1. /*
  2. * linux/net/sunrpc/svc.c
  3. *
  4. * High-level RPC service routines
  5. *
  6. * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  7. *
  8. * Multiple threads pools and NUMAisation
  9. * Copyright (c) 2006 Silicon Graphics, Inc.
  10. * by Greg Banks <gnb@melbourne.sgi.com>
  11. */
  12. #include <linux/linkage.h>
  13. #include <linux/sched.h>
  14. #include <linux/errno.h>
  15. #include <linux/net.h>
  16. #include <linux/in.h>
  17. #include <linux/mm.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/module.h>
  20. #include <linux/kthread.h>
  21. #include <linux/slab.h>
  22. #include <linux/sunrpc/types.h>
  23. #include <linux/sunrpc/xdr.h>
  24. #include <linux/sunrpc/stats.h>
  25. #include <linux/sunrpc/svcsock.h>
  26. #include <linux/sunrpc/clnt.h>
  27. #include <linux/sunrpc/bc_xprt.h>
  28. #define RPCDBG_FACILITY RPCDBG_SVCDSP
  29. static void svc_unregister(const struct svc_serv *serv);
  30. #define svc_serv_is_pooled(serv) ((serv)->sv_function)
  31. /*
  32. * Mode for mapping cpus to pools.
  33. */
  34. enum {
  35. SVC_POOL_AUTO = -1, /* choose one of the others */
  36. SVC_POOL_GLOBAL, /* no mapping, just a single global pool
  37. * (legacy & UP mode) */
  38. SVC_POOL_PERCPU, /* one pool per cpu */
  39. SVC_POOL_PERNODE /* one pool per numa node */
  40. };
  41. #define SVC_POOL_DEFAULT SVC_POOL_GLOBAL
  42. /*
  43. * Structure for mapping cpus to pools and vice versa.
  44. * Setup once during sunrpc initialisation.
  45. */
  46. static struct svc_pool_map {
  47. int count; /* How many svc_servs use us */
  48. int mode; /* Note: int not enum to avoid
  49. * warnings about "enumeration value
  50. * not handled in switch" */
  51. unsigned int npools;
  52. unsigned int *pool_to; /* maps pool id to cpu or node */
  53. unsigned int *to_pool; /* maps cpu or node to pool id */
  54. } svc_pool_map = {
  55. .count = 0,
  56. .mode = SVC_POOL_DEFAULT
  57. };
  58. static DEFINE_MUTEX(svc_pool_map_mutex);/* protects svc_pool_map.count only */
  59. static int
  60. param_set_pool_mode(const char *val, struct kernel_param *kp)
  61. {
  62. int *ip = (int *)kp->arg;
  63. struct svc_pool_map *m = &svc_pool_map;
  64. int err;
  65. mutex_lock(&svc_pool_map_mutex);
  66. err = -EBUSY;
  67. if (m->count)
  68. goto out;
  69. err = 0;
  70. if (!strncmp(val, "auto", 4))
  71. *ip = SVC_POOL_AUTO;
  72. else if (!strncmp(val, "global", 6))
  73. *ip = SVC_POOL_GLOBAL;
  74. else if (!strncmp(val, "percpu", 6))
  75. *ip = SVC_POOL_PERCPU;
  76. else if (!strncmp(val, "pernode", 7))
  77. *ip = SVC_POOL_PERNODE;
  78. else
  79. err = -EINVAL;
  80. out:
  81. mutex_unlock(&svc_pool_map_mutex);
  82. return err;
  83. }
  84. static int
  85. param_get_pool_mode(char *buf, struct kernel_param *kp)
  86. {
  87. int *ip = (int *)kp->arg;
  88. switch (*ip)
  89. {
  90. case SVC_POOL_AUTO:
  91. return strlcpy(buf, "auto", 20);
  92. case SVC_POOL_GLOBAL:
  93. return strlcpy(buf, "global", 20);
  94. case SVC_POOL_PERCPU:
  95. return strlcpy(buf, "percpu", 20);
  96. case SVC_POOL_PERNODE:
  97. return strlcpy(buf, "pernode", 20);
  98. default:
  99. return sprintf(buf, "%d", *ip);
  100. }
  101. }
  102. module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode,
  103. &svc_pool_map.mode, 0644);
  104. /*
  105. * Detect best pool mapping mode heuristically,
  106. * according to the machine's topology.
  107. */
  108. static int
  109. svc_pool_map_choose_mode(void)
  110. {
  111. unsigned int node;
  112. if (nr_online_nodes > 1) {
  113. /*
  114. * Actually have multiple NUMA nodes,
  115. * so split pools on NUMA node boundaries
  116. */
  117. return SVC_POOL_PERNODE;
  118. }
  119. node = first_online_node;
  120. if (nr_cpus_node(node) > 2) {
  121. /*
  122. * Non-trivial SMP, or CONFIG_NUMA on
  123. * non-NUMA hardware, e.g. with a generic
  124. * x86_64 kernel on Xeons. In this case we
  125. * want to divide the pools on cpu boundaries.
  126. */
  127. return SVC_POOL_PERCPU;
  128. }
  129. /* default: one global pool */
  130. return SVC_POOL_GLOBAL;
  131. }
  132. /*
  133. * Allocate the to_pool[] and pool_to[] arrays.
  134. * Returns 0 on success or an errno.
  135. */
  136. static int
  137. svc_pool_map_alloc_arrays(struct svc_pool_map *m, unsigned int maxpools)
  138. {
  139. m->to_pool = kcalloc(maxpools, sizeof(unsigned int), GFP_KERNEL);
  140. if (!m->to_pool)
  141. goto fail;
  142. m->pool_to = kcalloc(maxpools, sizeof(unsigned int), GFP_KERNEL);
  143. if (!m->pool_to)
  144. goto fail_free;
  145. return 0;
  146. fail_free:
  147. kfree(m->to_pool);
  148. fail:
  149. return -ENOMEM;
  150. }
  151. /*
  152. * Initialise the pool map for SVC_POOL_PERCPU mode.
  153. * Returns number of pools or <0 on error.
  154. */
  155. static int
  156. svc_pool_map_init_percpu(struct svc_pool_map *m)
  157. {
  158. unsigned int maxpools = nr_cpu_ids;
  159. unsigned int pidx = 0;
  160. unsigned int cpu;
  161. int err;
  162. err = svc_pool_map_alloc_arrays(m, maxpools);
  163. if (err)
  164. return err;
  165. for_each_online_cpu(cpu) {
  166. BUG_ON(pidx > maxpools);
  167. m->to_pool[cpu] = pidx;
  168. m->pool_to[pidx] = cpu;
  169. pidx++;
  170. }
  171. /* cpus brought online later all get mapped to pool0, sorry */
  172. return pidx;
  173. };
  174. /*
  175. * Initialise the pool map for SVC_POOL_PERNODE mode.
  176. * Returns number of pools or <0 on error.
  177. */
  178. static int
  179. svc_pool_map_init_pernode(struct svc_pool_map *m)
  180. {
  181. unsigned int maxpools = nr_node_ids;
  182. unsigned int pidx = 0;
  183. unsigned int node;
  184. int err;
  185. err = svc_pool_map_alloc_arrays(m, maxpools);
  186. if (err)
  187. return err;
  188. for_each_node_with_cpus(node) {
  189. /* some architectures (e.g. SN2) have cpuless nodes */
  190. BUG_ON(pidx > maxpools);
  191. m->to_pool[node] = pidx;
  192. m->pool_to[pidx] = node;
  193. pidx++;
  194. }
  195. /* nodes brought online later all get mapped to pool0, sorry */
  196. return pidx;
  197. }
  198. /*
  199. * Add a reference to the global map of cpus to pools (and
  200. * vice versa). Initialise the map if we're the first user.
  201. * Returns the number of pools.
  202. */
  203. static unsigned int
  204. svc_pool_map_get(void)
  205. {
  206. struct svc_pool_map *m = &svc_pool_map;
  207. int npools = -1;
  208. mutex_lock(&svc_pool_map_mutex);
  209. if (m->count++) {
  210. mutex_unlock(&svc_pool_map_mutex);
  211. return m->npools;
  212. }
  213. if (m->mode == SVC_POOL_AUTO)
  214. m->mode = svc_pool_map_choose_mode();
  215. switch (m->mode) {
  216. case SVC_POOL_PERCPU:
  217. npools = svc_pool_map_init_percpu(m);
  218. break;
  219. case SVC_POOL_PERNODE:
  220. npools = svc_pool_map_init_pernode(m);
  221. break;
  222. }
  223. if (npools < 0) {
  224. /* default, or memory allocation failure */
  225. npools = 1;
  226. m->mode = SVC_POOL_GLOBAL;
  227. }
  228. m->npools = npools;
  229. mutex_unlock(&svc_pool_map_mutex);
  230. return m->npools;
  231. }
  232. /*
  233. * Drop a reference to the global map of cpus to pools.
  234. * When the last reference is dropped, the map data is
  235. * freed; this allows the sysadmin to change the pool
  236. * mode using the pool_mode module option without
  237. * rebooting or re-loading sunrpc.ko.
  238. */
  239. static void
  240. svc_pool_map_put(void)
  241. {
  242. struct svc_pool_map *m = &svc_pool_map;
  243. mutex_lock(&svc_pool_map_mutex);
  244. if (!--m->count) {
  245. m->mode = SVC_POOL_DEFAULT;
  246. kfree(m->to_pool);
  247. kfree(m->pool_to);
  248. m->npools = 0;
  249. }
  250. mutex_unlock(&svc_pool_map_mutex);
  251. }
  252. static int svc_pool_map_get_node(unsigned int pidx)
  253. {
  254. const struct svc_pool_map *m = &svc_pool_map;
  255. if (m->count) {
  256. if (m->mode == SVC_POOL_PERCPU)
  257. return cpu_to_node(m->pool_to[pidx]);
  258. if (m->mode == SVC_POOL_PERNODE)
  259. return m->pool_to[pidx];
  260. }
  261. return NUMA_NO_NODE;
  262. }
  263. /*
  264. * Set the given thread's cpus_allowed mask so that it
  265. * will only run on cpus in the given pool.
  266. */
  267. static inline void
  268. svc_pool_map_set_cpumask(struct task_struct *task, unsigned int pidx)
  269. {
  270. struct svc_pool_map *m = &svc_pool_map;
  271. unsigned int node = m->pool_to[pidx];
  272. /*
  273. * The caller checks for sv_nrpools > 1, which
  274. * implies that we've been initialized.
  275. */
  276. BUG_ON(m->count == 0);
  277. switch (m->mode) {
  278. case SVC_POOL_PERCPU:
  279. {
  280. set_cpus_allowed_ptr(task, cpumask_of(node));
  281. break;
  282. }
  283. case SVC_POOL_PERNODE:
  284. {
  285. set_cpus_allowed_ptr(task, cpumask_of_node(node));
  286. break;
  287. }
  288. }
  289. }
  290. /*
  291. * Use the mapping mode to choose a pool for a given CPU.
  292. * Used when enqueueing an incoming RPC. Always returns
  293. * a non-NULL pool pointer.
  294. */
  295. struct svc_pool *
  296. svc_pool_for_cpu(struct svc_serv *serv, int cpu)
  297. {
  298. struct svc_pool_map *m = &svc_pool_map;
  299. unsigned int pidx = 0;
  300. /*
  301. * An uninitialised map happens in a pure client when
  302. * lockd is brought up, so silently treat it the
  303. * same as SVC_POOL_GLOBAL.
  304. */
  305. if (svc_serv_is_pooled(serv)) {
  306. switch (m->mode) {
  307. case SVC_POOL_PERCPU:
  308. pidx = m->to_pool[cpu];
  309. break;
  310. case SVC_POOL_PERNODE:
  311. pidx = m->to_pool[cpu_to_node(cpu)];
  312. break;
  313. }
  314. }
  315. return &serv->sv_pools[pidx % serv->sv_nrpools];
  316. }
  317. /*
  318. * Create an RPC service
  319. */
  320. static struct svc_serv *
  321. __svc_create(struct svc_program *prog, unsigned int bufsize, int npools,
  322. void (*shutdown)(struct svc_serv *serv))
  323. {
  324. struct svc_serv *serv;
  325. unsigned int vers;
  326. unsigned int xdrsize;
  327. unsigned int i;
  328. if (!(serv = kzalloc(sizeof(*serv), GFP_KERNEL)))
  329. return NULL;
  330. serv->sv_name = prog->pg_name;
  331. serv->sv_program = prog;
  332. serv->sv_nrthreads = 1;
  333. serv->sv_stats = prog->pg_stats;
  334. if (bufsize > RPCSVC_MAXPAYLOAD)
  335. bufsize = RPCSVC_MAXPAYLOAD;
  336. serv->sv_max_payload = bufsize? bufsize : 4096;
  337. serv->sv_max_mesg = roundup(serv->sv_max_payload + PAGE_SIZE, PAGE_SIZE);
  338. serv->sv_shutdown = shutdown;
  339. xdrsize = 0;
  340. while (prog) {
  341. prog->pg_lovers = prog->pg_nvers-1;
  342. for (vers=0; vers<prog->pg_nvers ; vers++)
  343. if (prog->pg_vers[vers]) {
  344. prog->pg_hivers = vers;
  345. if (prog->pg_lovers > vers)
  346. prog->pg_lovers = vers;
  347. if (prog->pg_vers[vers]->vs_xdrsize > xdrsize)
  348. xdrsize = prog->pg_vers[vers]->vs_xdrsize;
  349. }
  350. prog = prog->pg_next;
  351. }
  352. serv->sv_xdrsize = xdrsize;
  353. INIT_LIST_HEAD(&serv->sv_tempsocks);
  354. INIT_LIST_HEAD(&serv->sv_permsocks);
  355. init_timer(&serv->sv_temptimer);
  356. spin_lock_init(&serv->sv_lock);
  357. serv->sv_nrpools = npools;
  358. serv->sv_pools =
  359. kcalloc(serv->sv_nrpools, sizeof(struct svc_pool),
  360. GFP_KERNEL);
  361. if (!serv->sv_pools) {
  362. kfree(serv);
  363. return NULL;
  364. }
  365. for (i = 0; i < serv->sv_nrpools; i++) {
  366. struct svc_pool *pool = &serv->sv_pools[i];
  367. dprintk("svc: initialising pool %u for %s\n",
  368. i, serv->sv_name);
  369. pool->sp_id = i;
  370. INIT_LIST_HEAD(&pool->sp_threads);
  371. INIT_LIST_HEAD(&pool->sp_sockets);
  372. INIT_LIST_HEAD(&pool->sp_all_threads);
  373. spin_lock_init(&pool->sp_lock);
  374. }
  375. /* Remove any stale portmap registrations */
  376. svc_unregister(serv);
  377. return serv;
  378. }
  379. struct svc_serv *
  380. svc_create(struct svc_program *prog, unsigned int bufsize,
  381. void (*shutdown)(struct svc_serv *serv))
  382. {
  383. return __svc_create(prog, bufsize, /*npools*/1, shutdown);
  384. }
  385. EXPORT_SYMBOL_GPL(svc_create);
  386. struct svc_serv *
  387. svc_create_pooled(struct svc_program *prog, unsigned int bufsize,
  388. void (*shutdown)(struct svc_serv *serv),
  389. svc_thread_fn func, struct module *mod)
  390. {
  391. struct svc_serv *serv;
  392. unsigned int npools = svc_pool_map_get();
  393. serv = __svc_create(prog, bufsize, npools, shutdown);
  394. if (serv != NULL) {
  395. serv->sv_function = func;
  396. serv->sv_module = mod;
  397. }
  398. return serv;
  399. }
  400. EXPORT_SYMBOL_GPL(svc_create_pooled);
  401. /*
  402. * Destroy an RPC service. Should be called with appropriate locking to
  403. * protect the sv_nrthreads, sv_permsocks and sv_tempsocks.
  404. */
  405. void
  406. svc_destroy(struct svc_serv *serv)
  407. {
  408. dprintk("svc: svc_destroy(%s, %d)\n",
  409. serv->sv_program->pg_name,
  410. serv->sv_nrthreads);
  411. if (serv->sv_nrthreads) {
  412. if (--(serv->sv_nrthreads) != 0) {
  413. svc_sock_update_bufs(serv);
  414. return;
  415. }
  416. } else
  417. printk("svc_destroy: no threads for serv=%p!\n", serv);
  418. del_timer_sync(&serv->sv_temptimer);
  419. svc_close_all(&serv->sv_tempsocks);
  420. if (serv->sv_shutdown)
  421. serv->sv_shutdown(serv);
  422. svc_close_all(&serv->sv_permsocks);
  423. BUG_ON(!list_empty(&serv->sv_permsocks));
  424. BUG_ON(!list_empty(&serv->sv_tempsocks));
  425. cache_clean_deferred(serv);
  426. if (svc_serv_is_pooled(serv))
  427. svc_pool_map_put();
  428. svc_unregister(serv);
  429. kfree(serv->sv_pools);
  430. kfree(serv);
  431. }
  432. EXPORT_SYMBOL_GPL(svc_destroy);
  433. /*
  434. * Allocate an RPC server's buffer space.
  435. * We allocate pages and place them in rq_argpages.
  436. */
  437. static int
  438. svc_init_buffer(struct svc_rqst *rqstp, unsigned int size, int node)
  439. {
  440. unsigned int pages, arghi;
  441. /* bc_xprt uses fore channel allocated buffers */
  442. if (svc_is_backchannel(rqstp))
  443. return 1;
  444. pages = size / PAGE_SIZE + 1; /* extra page as we hold both request and reply.
  445. * We assume one is at most one page
  446. */
  447. arghi = 0;
  448. BUG_ON(pages > RPCSVC_MAXPAGES);
  449. while (pages) {
  450. struct page *p = alloc_pages_node(node, GFP_KERNEL, 0);
  451. if (!p)
  452. break;
  453. rqstp->rq_pages[arghi++] = p;
  454. pages--;
  455. }
  456. return pages == 0;
  457. }
  458. /*
  459. * Release an RPC server buffer
  460. */
  461. static void
  462. svc_release_buffer(struct svc_rqst *rqstp)
  463. {
  464. unsigned int i;
  465. for (i = 0; i < ARRAY_SIZE(rqstp->rq_pages); i++)
  466. if (rqstp->rq_pages[i])
  467. put_page(rqstp->rq_pages[i]);
  468. }
  469. struct svc_rqst *
  470. svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node)
  471. {
  472. struct svc_rqst *rqstp;
  473. rqstp = kzalloc_node(sizeof(*rqstp), GFP_KERNEL, node);
  474. if (!rqstp)
  475. goto out_enomem;
  476. init_waitqueue_head(&rqstp->rq_wait);
  477. serv->sv_nrthreads++;
  478. spin_lock_bh(&pool->sp_lock);
  479. pool->sp_nrthreads++;
  480. list_add(&rqstp->rq_all, &pool->sp_all_threads);
  481. spin_unlock_bh(&pool->sp_lock);
  482. rqstp->rq_server = serv;
  483. rqstp->rq_pool = pool;
  484. rqstp->rq_argp = kmalloc_node(serv->sv_xdrsize, GFP_KERNEL, node);
  485. if (!rqstp->rq_argp)
  486. goto out_thread;
  487. rqstp->rq_resp = kmalloc_node(serv->sv_xdrsize, GFP_KERNEL, node);
  488. if (!rqstp->rq_resp)
  489. goto out_thread;
  490. if (!svc_init_buffer(rqstp, serv->sv_max_mesg, node))
  491. goto out_thread;
  492. return rqstp;
  493. out_thread:
  494. svc_exit_thread(rqstp);
  495. out_enomem:
  496. return ERR_PTR(-ENOMEM);
  497. }
  498. EXPORT_SYMBOL_GPL(svc_prepare_thread);
  499. /*
  500. * Choose a pool in which to create a new thread, for svc_set_num_threads
  501. */
  502. static inline struct svc_pool *
  503. choose_pool(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
  504. {
  505. if (pool != NULL)
  506. return pool;
  507. return &serv->sv_pools[(*state)++ % serv->sv_nrpools];
  508. }
  509. /*
  510. * Choose a thread to kill, for svc_set_num_threads
  511. */
  512. static inline struct task_struct *
  513. choose_victim(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
  514. {
  515. unsigned int i;
  516. struct task_struct *task = NULL;
  517. if (pool != NULL) {
  518. spin_lock_bh(&pool->sp_lock);
  519. } else {
  520. /* choose a pool in round-robin fashion */
  521. for (i = 0; i < serv->sv_nrpools; i++) {
  522. pool = &serv->sv_pools[--(*state) % serv->sv_nrpools];
  523. spin_lock_bh(&pool->sp_lock);
  524. if (!list_empty(&pool->sp_all_threads))
  525. goto found_pool;
  526. spin_unlock_bh(&pool->sp_lock);
  527. }
  528. return NULL;
  529. }
  530. found_pool:
  531. if (!list_empty(&pool->sp_all_threads)) {
  532. struct svc_rqst *rqstp;
  533. /*
  534. * Remove from the pool->sp_all_threads list
  535. * so we don't try to kill it again.
  536. */
  537. rqstp = list_entry(pool->sp_all_threads.next, struct svc_rqst, rq_all);
  538. list_del_init(&rqstp->rq_all);
  539. task = rqstp->rq_task;
  540. }
  541. spin_unlock_bh(&pool->sp_lock);
  542. return task;
  543. }
  544. /*
  545. * Create or destroy enough new threads to make the number
  546. * of threads the given number. If `pool' is non-NULL, applies
  547. * only to threads in that pool, otherwise round-robins between
  548. * all pools. Must be called with a svc_get() reference and
  549. * the BKL or another lock to protect access to svc_serv fields.
  550. *
  551. * Destroying threads relies on the service threads filling in
  552. * rqstp->rq_task, which only the nfs ones do. Assumes the serv
  553. * has been created using svc_create_pooled().
  554. *
  555. * Based on code that used to be in nfsd_svc() but tweaked
  556. * to be pool-aware.
  557. */
  558. int
  559. svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
  560. {
  561. struct svc_rqst *rqstp;
  562. struct task_struct *task;
  563. struct svc_pool *chosen_pool;
  564. int error = 0;
  565. unsigned int state = serv->sv_nrthreads-1;
  566. int node;
  567. if (pool == NULL) {
  568. /* The -1 assumes caller has done a svc_get() */
  569. nrservs -= (serv->sv_nrthreads-1);
  570. } else {
  571. spin_lock_bh(&pool->sp_lock);
  572. nrservs -= pool->sp_nrthreads;
  573. spin_unlock_bh(&pool->sp_lock);
  574. }
  575. /* create new threads */
  576. while (nrservs > 0) {
  577. nrservs--;
  578. chosen_pool = choose_pool(serv, pool, &state);
  579. node = svc_pool_map_get_node(chosen_pool->sp_id);
  580. rqstp = svc_prepare_thread(serv, chosen_pool, node);
  581. if (IS_ERR(rqstp)) {
  582. error = PTR_ERR(rqstp);
  583. break;
  584. }
  585. __module_get(serv->sv_module);
  586. task = kthread_create_on_node(serv->sv_function, rqstp,
  587. node, serv->sv_name);
  588. if (IS_ERR(task)) {
  589. error = PTR_ERR(task);
  590. module_put(serv->sv_module);
  591. svc_exit_thread(rqstp);
  592. break;
  593. }
  594. rqstp->rq_task = task;
  595. if (serv->sv_nrpools > 1)
  596. svc_pool_map_set_cpumask(task, chosen_pool->sp_id);
  597. svc_sock_update_bufs(serv);
  598. wake_up_process(task);
  599. }
  600. /* destroy old threads */
  601. while (nrservs < 0 &&
  602. (task = choose_victim(serv, pool, &state)) != NULL) {
  603. send_sig(SIGINT, task, 1);
  604. nrservs++;
  605. }
  606. return error;
  607. }
  608. EXPORT_SYMBOL_GPL(svc_set_num_threads);
  609. /*
  610. * Called from a server thread as it's exiting. Caller must hold the BKL or
  611. * the "service mutex", whichever is appropriate for the service.
  612. */
  613. void
  614. svc_exit_thread(struct svc_rqst *rqstp)
  615. {
  616. struct svc_serv *serv = rqstp->rq_server;
  617. struct svc_pool *pool = rqstp->rq_pool;
  618. svc_release_buffer(rqstp);
  619. kfree(rqstp->rq_resp);
  620. kfree(rqstp->rq_argp);
  621. kfree(rqstp->rq_auth_data);
  622. spin_lock_bh(&pool->sp_lock);
  623. pool->sp_nrthreads--;
  624. list_del(&rqstp->rq_all);
  625. spin_unlock_bh(&pool->sp_lock);
  626. kfree(rqstp);
  627. /* Release the server */
  628. if (serv)
  629. svc_destroy(serv);
  630. }
  631. EXPORT_SYMBOL_GPL(svc_exit_thread);
  632. /*
  633. * Register an "inet" protocol family netid with the local
  634. * rpcbind daemon via an rpcbind v4 SET request.
  635. *
  636. * No netconfig infrastructure is available in the kernel, so
  637. * we map IP_ protocol numbers to netids by hand.
  638. *
  639. * Returns zero on success; a negative errno value is returned
  640. * if any error occurs.
  641. */
  642. static int __svc_rpcb_register4(const u32 program, const u32 version,
  643. const unsigned short protocol,
  644. const unsigned short port)
  645. {
  646. const struct sockaddr_in sin = {
  647. .sin_family = AF_INET,
  648. .sin_addr.s_addr = htonl(INADDR_ANY),
  649. .sin_port = htons(port),
  650. };
  651. const char *netid;
  652. int error;
  653. switch (protocol) {
  654. case IPPROTO_UDP:
  655. netid = RPCBIND_NETID_UDP;
  656. break;
  657. case IPPROTO_TCP:
  658. netid = RPCBIND_NETID_TCP;
  659. break;
  660. default:
  661. return -ENOPROTOOPT;
  662. }
  663. error = rpcb_v4_register(program, version,
  664. (const struct sockaddr *)&sin, netid);
  665. /*
  666. * User space didn't support rpcbind v4, so retry this
  667. * registration request with the legacy rpcbind v2 protocol.
  668. */
  669. if (error == -EPROTONOSUPPORT)
  670. error = rpcb_register(program, version, protocol, port);
  671. return error;
  672. }
  673. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  674. /*
  675. * Register an "inet6" protocol family netid with the local
  676. * rpcbind daemon via an rpcbind v4 SET request.
  677. *
  678. * No netconfig infrastructure is available in the kernel, so
  679. * we map IP_ protocol numbers to netids by hand.
  680. *
  681. * Returns zero on success; a negative errno value is returned
  682. * if any error occurs.
  683. */
  684. static int __svc_rpcb_register6(const u32 program, const u32 version,
  685. const unsigned short protocol,
  686. const unsigned short port)
  687. {
  688. const struct sockaddr_in6 sin6 = {
  689. .sin6_family = AF_INET6,
  690. .sin6_addr = IN6ADDR_ANY_INIT,
  691. .sin6_port = htons(port),
  692. };
  693. const char *netid;
  694. int error;
  695. switch (protocol) {
  696. case IPPROTO_UDP:
  697. netid = RPCBIND_NETID_UDP6;
  698. break;
  699. case IPPROTO_TCP:
  700. netid = RPCBIND_NETID_TCP6;
  701. break;
  702. default:
  703. return -ENOPROTOOPT;
  704. }
  705. error = rpcb_v4_register(program, version,
  706. (const struct sockaddr *)&sin6, netid);
  707. /*
  708. * User space didn't support rpcbind version 4, so we won't
  709. * use a PF_INET6 listener.
  710. */
  711. if (error == -EPROTONOSUPPORT)
  712. error = -EAFNOSUPPORT;
  713. return error;
  714. }
  715. #endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
  716. /*
  717. * Register a kernel RPC service via rpcbind version 4.
  718. *
  719. * Returns zero on success; a negative errno value is returned
  720. * if any error occurs.
  721. */
  722. static int __svc_register(const char *progname,
  723. const u32 program, const u32 version,
  724. const int family,
  725. const unsigned short protocol,
  726. const unsigned short port)
  727. {
  728. int error = -EAFNOSUPPORT;
  729. switch (family) {
  730. case PF_INET:
  731. error = __svc_rpcb_register4(program, version,
  732. protocol, port);
  733. break;
  734. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  735. case PF_INET6:
  736. error = __svc_rpcb_register6(program, version,
  737. protocol, port);
  738. #endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
  739. }
  740. if (error < 0)
  741. printk(KERN_WARNING "svc: failed to register %sv%u RPC "
  742. "service (errno %d).\n", progname, version, -error);
  743. return error;
  744. }
  745. /**
  746. * svc_register - register an RPC service with the local portmapper
  747. * @serv: svc_serv struct for the service to register
  748. * @family: protocol family of service's listener socket
  749. * @proto: transport protocol number to advertise
  750. * @port: port to advertise
  751. *
  752. * Service is registered for any address in the passed-in protocol family
  753. */
  754. int svc_register(const struct svc_serv *serv, const int family,
  755. const unsigned short proto, const unsigned short port)
  756. {
  757. struct svc_program *progp;
  758. unsigned int i;
  759. int error = 0;
  760. BUG_ON(proto == 0 && port == 0);
  761. for (progp = serv->sv_program; progp; progp = progp->pg_next) {
  762. for (i = 0; i < progp->pg_nvers; i++) {
  763. if (progp->pg_vers[i] == NULL)
  764. continue;
  765. dprintk("svc: svc_register(%sv%d, %s, %u, %u)%s\n",
  766. progp->pg_name,
  767. i,
  768. proto == IPPROTO_UDP? "udp" : "tcp",
  769. port,
  770. family,
  771. progp->pg_vers[i]->vs_hidden?
  772. " (but not telling portmap)" : "");
  773. if (progp->pg_vers[i]->vs_hidden)
  774. continue;
  775. error = __svc_register(progp->pg_name, progp->pg_prog,
  776. i, family, proto, port);
  777. if (error < 0)
  778. break;
  779. }
  780. }
  781. return error;
  782. }
  783. /*
  784. * If user space is running rpcbind, it should take the v4 UNSET
  785. * and clear everything for this [program, version]. If user space
  786. * is running portmap, it will reject the v4 UNSET, but won't have
  787. * any "inet6" entries anyway. So a PMAP_UNSET should be sufficient
  788. * in this case to clear all existing entries for [program, version].
  789. */
  790. static void __svc_unregister(const u32 program, const u32 version,
  791. const char *progname)
  792. {
  793. int error;
  794. error = rpcb_v4_register(program, version, NULL, "");
  795. /*
  796. * User space didn't support rpcbind v4, so retry this
  797. * request with the legacy rpcbind v2 protocol.
  798. */
  799. if (error == -EPROTONOSUPPORT)
  800. error = rpcb_register(program, version, 0, 0);
  801. dprintk("svc: %s(%sv%u), error %d\n",
  802. __func__, progname, version, error);
  803. }
  804. /*
  805. * All netids, bind addresses and ports registered for [program, version]
  806. * are removed from the local rpcbind database (if the service is not
  807. * hidden) to make way for a new instance of the service.
  808. *
  809. * The result of unregistration is reported via dprintk for those who want
  810. * verification of the result, but is otherwise not important.
  811. */
  812. static void svc_unregister(const struct svc_serv *serv)
  813. {
  814. struct svc_program *progp;
  815. unsigned long flags;
  816. unsigned int i;
  817. clear_thread_flag(TIF_SIGPENDING);
  818. for (progp = serv->sv_program; progp; progp = progp->pg_next) {
  819. for (i = 0; i < progp->pg_nvers; i++) {
  820. if (progp->pg_vers[i] == NULL)
  821. continue;
  822. if (progp->pg_vers[i]->vs_hidden)
  823. continue;
  824. dprintk("svc: attempting to unregister %sv%u\n",
  825. progp->pg_name, i);
  826. __svc_unregister(progp->pg_prog, i, progp->pg_name);
  827. }
  828. }
  829. spin_lock_irqsave(&current->sighand->siglock, flags);
  830. recalc_sigpending();
  831. spin_unlock_irqrestore(&current->sighand->siglock, flags);
  832. }
  833. /*
  834. * Printk the given error with the address of the client that caused it.
  835. */
  836. static __printf(2, 3)
  837. int svc_printk(struct svc_rqst *rqstp, const char *fmt, ...)
  838. {
  839. va_list args;
  840. int r;
  841. char buf[RPC_MAX_ADDRBUFLEN];
  842. if (!net_ratelimit())
  843. return 0;
  844. printk(KERN_WARNING "svc: %s: ",
  845. svc_print_addr(rqstp, buf, sizeof(buf)));
  846. va_start(args, fmt);
  847. r = vprintk(fmt, args);
  848. va_end(args);
  849. return r;
  850. }
  851. /*
  852. * Common routine for processing the RPC request.
  853. */
  854. static int
  855. svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
  856. {
  857. struct svc_program *progp;
  858. struct svc_version *versp = NULL; /* compiler food */
  859. struct svc_procedure *procp = NULL;
  860. struct svc_serv *serv = rqstp->rq_server;
  861. kxdrproc_t xdr;
  862. __be32 *statp;
  863. u32 prog, vers, proc;
  864. __be32 auth_stat, rpc_stat;
  865. int auth_res;
  866. __be32 *reply_statp;
  867. rpc_stat = rpc_success;
  868. if (argv->iov_len < 6*4)
  869. goto err_short_len;
  870. /* Will be turned off only in gss privacy case: */
  871. rqstp->rq_splice_ok = 1;
  872. /* Will be turned off only when NFSv4 Sessions are used */
  873. rqstp->rq_usedeferral = 1;
  874. rqstp->rq_dropme = false;
  875. /* Setup reply header */
  876. rqstp->rq_xprt->xpt_ops->xpo_prep_reply_hdr(rqstp);
  877. svc_putu32(resv, rqstp->rq_xid);
  878. vers = svc_getnl(argv);
  879. /* First words of reply: */
  880. svc_putnl(resv, 1); /* REPLY */
  881. if (vers != 2) /* RPC version number */
  882. goto err_bad_rpc;
  883. /* Save position in case we later decide to reject: */
  884. reply_statp = resv->iov_base + resv->iov_len;
  885. svc_putnl(resv, 0); /* ACCEPT */
  886. rqstp->rq_prog = prog = svc_getnl(argv); /* program number */
  887. rqstp->rq_vers = vers = svc_getnl(argv); /* version number */
  888. rqstp->rq_proc = proc = svc_getnl(argv); /* procedure number */
  889. progp = serv->sv_program;
  890. for (progp = serv->sv_program; progp; progp = progp->pg_next)
  891. if (prog == progp->pg_prog)
  892. break;
  893. /*
  894. * Decode auth data, and add verifier to reply buffer.
  895. * We do this before anything else in order to get a decent
  896. * auth verifier.
  897. */
  898. auth_res = svc_authenticate(rqstp, &auth_stat);
  899. /* Also give the program a chance to reject this call: */
  900. if (auth_res == SVC_OK && progp) {
  901. auth_stat = rpc_autherr_badcred;
  902. auth_res = progp->pg_authenticate(rqstp);
  903. }
  904. switch (auth_res) {
  905. case SVC_OK:
  906. break;
  907. case SVC_GARBAGE:
  908. goto err_garbage;
  909. case SVC_SYSERR:
  910. rpc_stat = rpc_system_err;
  911. goto err_bad;
  912. case SVC_DENIED:
  913. goto err_bad_auth;
  914. case SVC_CLOSE:
  915. if (test_bit(XPT_TEMP, &rqstp->rq_xprt->xpt_flags))
  916. svc_close_xprt(rqstp->rq_xprt);
  917. case SVC_DROP:
  918. goto dropit;
  919. case SVC_COMPLETE:
  920. goto sendit;
  921. }
  922. if (progp == NULL)
  923. goto err_bad_prog;
  924. if (vers >= progp->pg_nvers ||
  925. !(versp = progp->pg_vers[vers]))
  926. goto err_bad_vers;
  927. procp = versp->vs_proc + proc;
  928. if (proc >= versp->vs_nproc || !procp->pc_func)
  929. goto err_bad_proc;
  930. rqstp->rq_procinfo = procp;
  931. /* Syntactic check complete */
  932. serv->sv_stats->rpccnt++;
  933. /* Build the reply header. */
  934. statp = resv->iov_base +resv->iov_len;
  935. svc_putnl(resv, RPC_SUCCESS);
  936. /* Bump per-procedure stats counter */
  937. procp->pc_count++;
  938. /* Initialize storage for argp and resp */
  939. memset(rqstp->rq_argp, 0, procp->pc_argsize);
  940. memset(rqstp->rq_resp, 0, procp->pc_ressize);
  941. /* un-reserve some of the out-queue now that we have a
  942. * better idea of reply size
  943. */
  944. if (procp->pc_xdrressize)
  945. svc_reserve_auth(rqstp, procp->pc_xdrressize<<2);
  946. /* Call the function that processes the request. */
  947. if (!versp->vs_dispatch) {
  948. /* Decode arguments */
  949. xdr = procp->pc_decode;
  950. if (xdr && !xdr(rqstp, argv->iov_base, rqstp->rq_argp))
  951. goto err_garbage;
  952. *statp = procp->pc_func(rqstp, rqstp->rq_argp, rqstp->rq_resp);
  953. /* Encode reply */
  954. if (rqstp->rq_dropme) {
  955. if (procp->pc_release)
  956. procp->pc_release(rqstp, NULL, rqstp->rq_resp);
  957. goto dropit;
  958. }
  959. if (*statp == rpc_success &&
  960. (xdr = procp->pc_encode) &&
  961. !xdr(rqstp, resv->iov_base+resv->iov_len, rqstp->rq_resp)) {
  962. dprintk("svc: failed to encode reply\n");
  963. /* serv->sv_stats->rpcsystemerr++; */
  964. *statp = rpc_system_err;
  965. }
  966. } else {
  967. dprintk("svc: calling dispatcher\n");
  968. if (!versp->vs_dispatch(rqstp, statp)) {
  969. /* Release reply info */
  970. if (procp->pc_release)
  971. procp->pc_release(rqstp, NULL, rqstp->rq_resp);
  972. goto dropit;
  973. }
  974. }
  975. /* Check RPC status result */
  976. if (*statp != rpc_success)
  977. resv->iov_len = ((void*)statp) - resv->iov_base + 4;
  978. /* Release reply info */
  979. if (procp->pc_release)
  980. procp->pc_release(rqstp, NULL, rqstp->rq_resp);
  981. if (procp->pc_encode == NULL)
  982. goto dropit;
  983. sendit:
  984. if (svc_authorise(rqstp))
  985. goto dropit;
  986. return 1; /* Caller can now send it */
  987. dropit:
  988. svc_authorise(rqstp); /* doesn't hurt to call this twice */
  989. dprintk("svc: svc_process dropit\n");
  990. return 0;
  991. err_short_len:
  992. svc_printk(rqstp, "short len %Zd, dropping request\n",
  993. argv->iov_len);
  994. goto dropit; /* drop request */
  995. err_bad_rpc:
  996. serv->sv_stats->rpcbadfmt++;
  997. svc_putnl(resv, 1); /* REJECT */
  998. svc_putnl(resv, 0); /* RPC_MISMATCH */
  999. svc_putnl(resv, 2); /* Only RPCv2 supported */
  1000. svc_putnl(resv, 2);
  1001. goto sendit;
  1002. err_bad_auth:
  1003. dprintk("svc: authentication failed (%d)\n", ntohl(auth_stat));
  1004. serv->sv_stats->rpcbadauth++;
  1005. /* Restore write pointer to location of accept status: */
  1006. xdr_ressize_check(rqstp, reply_statp);
  1007. svc_putnl(resv, 1); /* REJECT */
  1008. svc_putnl(resv, 1); /* AUTH_ERROR */
  1009. svc_putnl(resv, ntohl(auth_stat)); /* status */
  1010. goto sendit;
  1011. err_bad_prog:
  1012. dprintk("svc: unknown program %d\n", prog);
  1013. serv->sv_stats->rpcbadfmt++;
  1014. svc_putnl(resv, RPC_PROG_UNAVAIL);
  1015. goto sendit;
  1016. err_bad_vers:
  1017. svc_printk(rqstp, "unknown version (%d for prog %d, %s)\n",
  1018. vers, prog, progp->pg_name);
  1019. serv->sv_stats->rpcbadfmt++;
  1020. svc_putnl(resv, RPC_PROG_MISMATCH);
  1021. svc_putnl(resv, progp->pg_lovers);
  1022. svc_putnl(resv, progp->pg_hivers);
  1023. goto sendit;
  1024. err_bad_proc:
  1025. svc_printk(rqstp, "unknown procedure (%d)\n", proc);
  1026. serv->sv_stats->rpcbadfmt++;
  1027. svc_putnl(resv, RPC_PROC_UNAVAIL);
  1028. goto sendit;
  1029. err_garbage:
  1030. svc_printk(rqstp, "failed to decode args\n");
  1031. rpc_stat = rpc_garbage_args;
  1032. err_bad:
  1033. serv->sv_stats->rpcbadfmt++;
  1034. svc_putnl(resv, ntohl(rpc_stat));
  1035. goto sendit;
  1036. }
  1037. EXPORT_SYMBOL_GPL(svc_process);
  1038. /*
  1039. * Process the RPC request.
  1040. */
  1041. int
  1042. svc_process(struct svc_rqst *rqstp)
  1043. {
  1044. struct kvec *argv = &rqstp->rq_arg.head[0];
  1045. struct kvec *resv = &rqstp->rq_res.head[0];
  1046. struct svc_serv *serv = rqstp->rq_server;
  1047. u32 dir;
  1048. /*
  1049. * Setup response xdr_buf.
  1050. * Initially it has just one page
  1051. */
  1052. rqstp->rq_resused = 1;
  1053. resv->iov_base = page_address(rqstp->rq_respages[0]);
  1054. resv->iov_len = 0;
  1055. rqstp->rq_res.pages = rqstp->rq_respages + 1;
  1056. rqstp->rq_res.len = 0;
  1057. rqstp->rq_res.page_base = 0;
  1058. rqstp->rq_res.page_len = 0;
  1059. rqstp->rq_res.buflen = PAGE_SIZE;
  1060. rqstp->rq_res.tail[0].iov_base = NULL;
  1061. rqstp->rq_res.tail[0].iov_len = 0;
  1062. rqstp->rq_xid = svc_getu32(argv);
  1063. dir = svc_getnl(argv);
  1064. if (dir != 0) {
  1065. /* direction != CALL */
  1066. svc_printk(rqstp, "bad direction %d, dropping request\n", dir);
  1067. serv->sv_stats->rpcbadfmt++;
  1068. svc_drop(rqstp);
  1069. return 0;
  1070. }
  1071. /* Returns 1 for send, 0 for drop */
  1072. if (svc_process_common(rqstp, argv, resv))
  1073. return svc_send(rqstp);
  1074. else {
  1075. svc_drop(rqstp);
  1076. return 0;
  1077. }
  1078. }
  1079. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  1080. /*
  1081. * Process a backchannel RPC request that arrived over an existing
  1082. * outbound connection
  1083. */
  1084. int
  1085. bc_svc_process(struct svc_serv *serv, struct rpc_rqst *req,
  1086. struct svc_rqst *rqstp)
  1087. {
  1088. struct kvec *argv = &rqstp->rq_arg.head[0];
  1089. struct kvec *resv = &rqstp->rq_res.head[0];
  1090. /* Build the svc_rqst used by the common processing routine */
  1091. rqstp->rq_xprt = serv->sv_bc_xprt;
  1092. rqstp->rq_xid = req->rq_xid;
  1093. rqstp->rq_prot = req->rq_xprt->prot;
  1094. rqstp->rq_server = serv;
  1095. rqstp->rq_addrlen = sizeof(req->rq_xprt->addr);
  1096. memcpy(&rqstp->rq_addr, &req->rq_xprt->addr, rqstp->rq_addrlen);
  1097. memcpy(&rqstp->rq_arg, &req->rq_rcv_buf, sizeof(rqstp->rq_arg));
  1098. memcpy(&rqstp->rq_res, &req->rq_snd_buf, sizeof(rqstp->rq_res));
  1099. /* reset result send buffer "put" position */
  1100. resv->iov_len = 0;
  1101. if (rqstp->rq_prot != IPPROTO_TCP) {
  1102. printk(KERN_ERR "No support for Non-TCP transports!\n");
  1103. BUG();
  1104. }
  1105. /*
  1106. * Skip the next two words because they've already been
  1107. * processed in the trasport
  1108. */
  1109. svc_getu32(argv); /* XID */
  1110. svc_getnl(argv); /* CALLDIR */
  1111. /* Returns 1 for send, 0 for drop */
  1112. if (svc_process_common(rqstp, argv, resv)) {
  1113. memcpy(&req->rq_snd_buf, &rqstp->rq_res,
  1114. sizeof(req->rq_snd_buf));
  1115. return bc_send(req);
  1116. } else {
  1117. /* Nothing to do to drop request */
  1118. return 0;
  1119. }
  1120. }
  1121. EXPORT_SYMBOL_GPL(bc_svc_process);
  1122. #endif /* CONFIG_SUNRPC_BACKCHANNEL */
  1123. /*
  1124. * Return (transport-specific) limit on the rpc payload.
  1125. */
  1126. u32 svc_max_payload(const struct svc_rqst *rqstp)
  1127. {
  1128. u32 max = rqstp->rq_xprt->xpt_class->xcl_max_payload;
  1129. if (rqstp->rq_server->sv_max_payload < max)
  1130. max = rqstp->rq_server->sv_max_payload;
  1131. return max;
  1132. }
  1133. EXPORT_SYMBOL_GPL(svc_max_payload);