svc.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359
  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. /*
  253. * Set the given thread's cpus_allowed mask so that it
  254. * will only run on cpus in the given pool.
  255. */
  256. static inline void
  257. svc_pool_map_set_cpumask(struct task_struct *task, unsigned int pidx)
  258. {
  259. struct svc_pool_map *m = &svc_pool_map;
  260. unsigned int node = m->pool_to[pidx];
  261. /*
  262. * The caller checks for sv_nrpools > 1, which
  263. * implies that we've been initialized.
  264. */
  265. BUG_ON(m->count == 0);
  266. switch (m->mode) {
  267. case SVC_POOL_PERCPU:
  268. {
  269. set_cpus_allowed_ptr(task, cpumask_of(node));
  270. break;
  271. }
  272. case SVC_POOL_PERNODE:
  273. {
  274. set_cpus_allowed_ptr(task, cpumask_of_node(node));
  275. break;
  276. }
  277. }
  278. }
  279. /*
  280. * Use the mapping mode to choose a pool for a given CPU.
  281. * Used when enqueueing an incoming RPC. Always returns
  282. * a non-NULL pool pointer.
  283. */
  284. struct svc_pool *
  285. svc_pool_for_cpu(struct svc_serv *serv, int cpu)
  286. {
  287. struct svc_pool_map *m = &svc_pool_map;
  288. unsigned int pidx = 0;
  289. /*
  290. * An uninitialised map happens in a pure client when
  291. * lockd is brought up, so silently treat it the
  292. * same as SVC_POOL_GLOBAL.
  293. */
  294. if (svc_serv_is_pooled(serv)) {
  295. switch (m->mode) {
  296. case SVC_POOL_PERCPU:
  297. pidx = m->to_pool[cpu];
  298. break;
  299. case SVC_POOL_PERNODE:
  300. pidx = m->to_pool[cpu_to_node(cpu)];
  301. break;
  302. }
  303. }
  304. return &serv->sv_pools[pidx % serv->sv_nrpools];
  305. }
  306. static int svc_rpcb_setup(struct svc_serv *serv)
  307. {
  308. int err;
  309. err = rpcb_create_local();
  310. if (err)
  311. return err;
  312. /* Remove any stale portmap registrations */
  313. svc_unregister(serv);
  314. return 0;
  315. }
  316. static void svc_rpcb_cleanup(struct svc_serv *serv)
  317. {
  318. svc_unregister(serv);
  319. rpcb_put_local();
  320. }
  321. static int svc_uses_rpcbind(struct svc_serv *serv)
  322. {
  323. struct svc_program *progp;
  324. unsigned int i;
  325. for (progp = serv->sv_program; progp; progp = progp->pg_next) {
  326. for (i = 0; i < progp->pg_nvers; i++) {
  327. if (progp->pg_vers[i] == NULL)
  328. continue;
  329. if (progp->pg_vers[i]->vs_hidden == 0)
  330. return 1;
  331. }
  332. }
  333. return 0;
  334. }
  335. /*
  336. * Create an RPC service
  337. */
  338. static struct svc_serv *
  339. __svc_create(struct svc_program *prog, unsigned int bufsize, int npools,
  340. void (*shutdown)(struct svc_serv *serv))
  341. {
  342. struct svc_serv *serv;
  343. unsigned int vers;
  344. unsigned int xdrsize;
  345. unsigned int i;
  346. if (!(serv = kzalloc(sizeof(*serv), GFP_KERNEL)))
  347. return NULL;
  348. serv->sv_name = prog->pg_name;
  349. serv->sv_program = prog;
  350. serv->sv_nrthreads = 1;
  351. serv->sv_stats = prog->pg_stats;
  352. if (bufsize > RPCSVC_MAXPAYLOAD)
  353. bufsize = RPCSVC_MAXPAYLOAD;
  354. serv->sv_max_payload = bufsize? bufsize : 4096;
  355. serv->sv_max_mesg = roundup(serv->sv_max_payload + PAGE_SIZE, PAGE_SIZE);
  356. serv->sv_shutdown = shutdown;
  357. xdrsize = 0;
  358. while (prog) {
  359. prog->pg_lovers = prog->pg_nvers-1;
  360. for (vers=0; vers<prog->pg_nvers ; vers++)
  361. if (prog->pg_vers[vers]) {
  362. prog->pg_hivers = vers;
  363. if (prog->pg_lovers > vers)
  364. prog->pg_lovers = vers;
  365. if (prog->pg_vers[vers]->vs_xdrsize > xdrsize)
  366. xdrsize = prog->pg_vers[vers]->vs_xdrsize;
  367. }
  368. prog = prog->pg_next;
  369. }
  370. serv->sv_xdrsize = xdrsize;
  371. INIT_LIST_HEAD(&serv->sv_tempsocks);
  372. INIT_LIST_HEAD(&serv->sv_permsocks);
  373. init_timer(&serv->sv_temptimer);
  374. spin_lock_init(&serv->sv_lock);
  375. serv->sv_nrpools = npools;
  376. serv->sv_pools =
  377. kcalloc(serv->sv_nrpools, sizeof(struct svc_pool),
  378. GFP_KERNEL);
  379. if (!serv->sv_pools) {
  380. kfree(serv);
  381. return NULL;
  382. }
  383. for (i = 0; i < serv->sv_nrpools; i++) {
  384. struct svc_pool *pool = &serv->sv_pools[i];
  385. dprintk("svc: initialising pool %u for %s\n",
  386. i, serv->sv_name);
  387. pool->sp_id = i;
  388. INIT_LIST_HEAD(&pool->sp_threads);
  389. INIT_LIST_HEAD(&pool->sp_sockets);
  390. INIT_LIST_HEAD(&pool->sp_all_threads);
  391. spin_lock_init(&pool->sp_lock);
  392. }
  393. if (svc_uses_rpcbind(serv)) {
  394. if (svc_rpcb_setup(serv) < 0) {
  395. kfree(serv->sv_pools);
  396. kfree(serv);
  397. return NULL;
  398. }
  399. if (!serv->sv_shutdown)
  400. serv->sv_shutdown = svc_rpcb_cleanup;
  401. }
  402. return serv;
  403. }
  404. struct svc_serv *
  405. svc_create(struct svc_program *prog, unsigned int bufsize,
  406. void (*shutdown)(struct svc_serv *serv))
  407. {
  408. return __svc_create(prog, bufsize, /*npools*/1, shutdown);
  409. }
  410. EXPORT_SYMBOL_GPL(svc_create);
  411. struct svc_serv *
  412. svc_create_pooled(struct svc_program *prog, unsigned int bufsize,
  413. void (*shutdown)(struct svc_serv *serv),
  414. svc_thread_fn func, struct module *mod)
  415. {
  416. struct svc_serv *serv;
  417. unsigned int npools = svc_pool_map_get();
  418. serv = __svc_create(prog, bufsize, npools, shutdown);
  419. if (serv != NULL) {
  420. serv->sv_function = func;
  421. serv->sv_module = mod;
  422. }
  423. return serv;
  424. }
  425. EXPORT_SYMBOL_GPL(svc_create_pooled);
  426. /*
  427. * Destroy an RPC service. Should be called with appropriate locking to
  428. * protect the sv_nrthreads, sv_permsocks and sv_tempsocks.
  429. */
  430. void
  431. svc_destroy(struct svc_serv *serv)
  432. {
  433. dprintk("svc: svc_destroy(%s, %d)\n",
  434. serv->sv_program->pg_name,
  435. serv->sv_nrthreads);
  436. if (serv->sv_nrthreads) {
  437. if (--(serv->sv_nrthreads) != 0) {
  438. svc_sock_update_bufs(serv);
  439. return;
  440. }
  441. } else
  442. printk("svc_destroy: no threads for serv=%p!\n", serv);
  443. del_timer_sync(&serv->sv_temptimer);
  444. svc_close_all(&serv->sv_tempsocks);
  445. if (serv->sv_shutdown)
  446. serv->sv_shutdown(serv);
  447. svc_close_all(&serv->sv_permsocks);
  448. BUG_ON(!list_empty(&serv->sv_permsocks));
  449. BUG_ON(!list_empty(&serv->sv_tempsocks));
  450. cache_clean_deferred(serv);
  451. if (svc_serv_is_pooled(serv))
  452. svc_pool_map_put();
  453. svc_unregister(serv);
  454. kfree(serv->sv_pools);
  455. kfree(serv);
  456. }
  457. EXPORT_SYMBOL_GPL(svc_destroy);
  458. /*
  459. * Allocate an RPC server's buffer space.
  460. * We allocate pages and place them in rq_argpages.
  461. */
  462. static int
  463. svc_init_buffer(struct svc_rqst *rqstp, unsigned int size)
  464. {
  465. unsigned int pages, arghi;
  466. /* bc_xprt uses fore channel allocated buffers */
  467. if (svc_is_backchannel(rqstp))
  468. return 1;
  469. pages = size / PAGE_SIZE + 1; /* extra page as we hold both request and reply.
  470. * We assume one is at most one page
  471. */
  472. arghi = 0;
  473. BUG_ON(pages > RPCSVC_MAXPAGES);
  474. while (pages) {
  475. struct page *p = alloc_page(GFP_KERNEL);
  476. if (!p)
  477. break;
  478. rqstp->rq_pages[arghi++] = p;
  479. pages--;
  480. }
  481. return pages == 0;
  482. }
  483. /*
  484. * Release an RPC server buffer
  485. */
  486. static void
  487. svc_release_buffer(struct svc_rqst *rqstp)
  488. {
  489. unsigned int i;
  490. for (i = 0; i < ARRAY_SIZE(rqstp->rq_pages); i++)
  491. if (rqstp->rq_pages[i])
  492. put_page(rqstp->rq_pages[i]);
  493. }
  494. struct svc_rqst *
  495. svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool)
  496. {
  497. struct svc_rqst *rqstp;
  498. rqstp = kzalloc(sizeof(*rqstp), GFP_KERNEL);
  499. if (!rqstp)
  500. goto out_enomem;
  501. init_waitqueue_head(&rqstp->rq_wait);
  502. serv->sv_nrthreads++;
  503. spin_lock_bh(&pool->sp_lock);
  504. pool->sp_nrthreads++;
  505. list_add(&rqstp->rq_all, &pool->sp_all_threads);
  506. spin_unlock_bh(&pool->sp_lock);
  507. rqstp->rq_server = serv;
  508. rqstp->rq_pool = pool;
  509. rqstp->rq_argp = kmalloc(serv->sv_xdrsize, GFP_KERNEL);
  510. if (!rqstp->rq_argp)
  511. goto out_thread;
  512. rqstp->rq_resp = kmalloc(serv->sv_xdrsize, GFP_KERNEL);
  513. if (!rqstp->rq_resp)
  514. goto out_thread;
  515. if (!svc_init_buffer(rqstp, serv->sv_max_mesg))
  516. goto out_thread;
  517. return rqstp;
  518. out_thread:
  519. svc_exit_thread(rqstp);
  520. out_enomem:
  521. return ERR_PTR(-ENOMEM);
  522. }
  523. EXPORT_SYMBOL_GPL(svc_prepare_thread);
  524. /*
  525. * Choose a pool in which to create a new thread, for svc_set_num_threads
  526. */
  527. static inline struct svc_pool *
  528. choose_pool(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
  529. {
  530. if (pool != NULL)
  531. return pool;
  532. return &serv->sv_pools[(*state)++ % serv->sv_nrpools];
  533. }
  534. /*
  535. * Choose a thread to kill, for svc_set_num_threads
  536. */
  537. static inline struct task_struct *
  538. choose_victim(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
  539. {
  540. unsigned int i;
  541. struct task_struct *task = NULL;
  542. if (pool != NULL) {
  543. spin_lock_bh(&pool->sp_lock);
  544. } else {
  545. /* choose a pool in round-robin fashion */
  546. for (i = 0; i < serv->sv_nrpools; i++) {
  547. pool = &serv->sv_pools[--(*state) % serv->sv_nrpools];
  548. spin_lock_bh(&pool->sp_lock);
  549. if (!list_empty(&pool->sp_all_threads))
  550. goto found_pool;
  551. spin_unlock_bh(&pool->sp_lock);
  552. }
  553. return NULL;
  554. }
  555. found_pool:
  556. if (!list_empty(&pool->sp_all_threads)) {
  557. struct svc_rqst *rqstp;
  558. /*
  559. * Remove from the pool->sp_all_threads list
  560. * so we don't try to kill it again.
  561. */
  562. rqstp = list_entry(pool->sp_all_threads.next, struct svc_rqst, rq_all);
  563. list_del_init(&rqstp->rq_all);
  564. task = rqstp->rq_task;
  565. }
  566. spin_unlock_bh(&pool->sp_lock);
  567. return task;
  568. }
  569. /*
  570. * Create or destroy enough new threads to make the number
  571. * of threads the given number. If `pool' is non-NULL, applies
  572. * only to threads in that pool, otherwise round-robins between
  573. * all pools. Must be called with a svc_get() reference and
  574. * the BKL or another lock to protect access to svc_serv fields.
  575. *
  576. * Destroying threads relies on the service threads filling in
  577. * rqstp->rq_task, which only the nfs ones do. Assumes the serv
  578. * has been created using svc_create_pooled().
  579. *
  580. * Based on code that used to be in nfsd_svc() but tweaked
  581. * to be pool-aware.
  582. */
  583. int
  584. svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
  585. {
  586. struct svc_rqst *rqstp;
  587. struct task_struct *task;
  588. struct svc_pool *chosen_pool;
  589. int error = 0;
  590. unsigned int state = serv->sv_nrthreads-1;
  591. if (pool == NULL) {
  592. /* The -1 assumes caller has done a svc_get() */
  593. nrservs -= (serv->sv_nrthreads-1);
  594. } else {
  595. spin_lock_bh(&pool->sp_lock);
  596. nrservs -= pool->sp_nrthreads;
  597. spin_unlock_bh(&pool->sp_lock);
  598. }
  599. /* create new threads */
  600. while (nrservs > 0) {
  601. nrservs--;
  602. chosen_pool = choose_pool(serv, pool, &state);
  603. rqstp = svc_prepare_thread(serv, chosen_pool);
  604. if (IS_ERR(rqstp)) {
  605. error = PTR_ERR(rqstp);
  606. break;
  607. }
  608. __module_get(serv->sv_module);
  609. task = kthread_create(serv->sv_function, rqstp, serv->sv_name);
  610. if (IS_ERR(task)) {
  611. error = PTR_ERR(task);
  612. module_put(serv->sv_module);
  613. svc_exit_thread(rqstp);
  614. break;
  615. }
  616. rqstp->rq_task = task;
  617. if (serv->sv_nrpools > 1)
  618. svc_pool_map_set_cpumask(task, chosen_pool->sp_id);
  619. svc_sock_update_bufs(serv);
  620. wake_up_process(task);
  621. }
  622. /* destroy old threads */
  623. while (nrservs < 0 &&
  624. (task = choose_victim(serv, pool, &state)) != NULL) {
  625. send_sig(SIGINT, task, 1);
  626. nrservs++;
  627. }
  628. return error;
  629. }
  630. EXPORT_SYMBOL_GPL(svc_set_num_threads);
  631. /*
  632. * Called from a server thread as it's exiting. Caller must hold the BKL or
  633. * the "service mutex", whichever is appropriate for the service.
  634. */
  635. void
  636. svc_exit_thread(struct svc_rqst *rqstp)
  637. {
  638. struct svc_serv *serv = rqstp->rq_server;
  639. struct svc_pool *pool = rqstp->rq_pool;
  640. svc_release_buffer(rqstp);
  641. kfree(rqstp->rq_resp);
  642. kfree(rqstp->rq_argp);
  643. kfree(rqstp->rq_auth_data);
  644. spin_lock_bh(&pool->sp_lock);
  645. pool->sp_nrthreads--;
  646. list_del(&rqstp->rq_all);
  647. spin_unlock_bh(&pool->sp_lock);
  648. kfree(rqstp);
  649. /* Release the server */
  650. if (serv)
  651. svc_destroy(serv);
  652. }
  653. EXPORT_SYMBOL_GPL(svc_exit_thread);
  654. /*
  655. * Register an "inet" protocol family netid with the local
  656. * rpcbind daemon via an rpcbind v4 SET request.
  657. *
  658. * No netconfig infrastructure is available in the kernel, so
  659. * we map IP_ protocol numbers to netids by hand.
  660. *
  661. * Returns zero on success; a negative errno value is returned
  662. * if any error occurs.
  663. */
  664. static int __svc_rpcb_register4(const u32 program, const u32 version,
  665. const unsigned short protocol,
  666. const unsigned short port)
  667. {
  668. const struct sockaddr_in sin = {
  669. .sin_family = AF_INET,
  670. .sin_addr.s_addr = htonl(INADDR_ANY),
  671. .sin_port = htons(port),
  672. };
  673. const char *netid;
  674. int error;
  675. switch (protocol) {
  676. case IPPROTO_UDP:
  677. netid = RPCBIND_NETID_UDP;
  678. break;
  679. case IPPROTO_TCP:
  680. netid = RPCBIND_NETID_TCP;
  681. break;
  682. default:
  683. return -ENOPROTOOPT;
  684. }
  685. error = rpcb_v4_register(program, version,
  686. (const struct sockaddr *)&sin, netid);
  687. /*
  688. * User space didn't support rpcbind v4, so retry this
  689. * registration request with the legacy rpcbind v2 protocol.
  690. */
  691. if (error == -EPROTONOSUPPORT)
  692. error = rpcb_register(program, version, protocol, port);
  693. return error;
  694. }
  695. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  696. /*
  697. * Register an "inet6" protocol family netid with the local
  698. * rpcbind daemon via an rpcbind v4 SET request.
  699. *
  700. * No netconfig infrastructure is available in the kernel, so
  701. * we map IP_ protocol numbers to netids by hand.
  702. *
  703. * Returns zero on success; a negative errno value is returned
  704. * if any error occurs.
  705. */
  706. static int __svc_rpcb_register6(const u32 program, const u32 version,
  707. const unsigned short protocol,
  708. const unsigned short port)
  709. {
  710. const struct sockaddr_in6 sin6 = {
  711. .sin6_family = AF_INET6,
  712. .sin6_addr = IN6ADDR_ANY_INIT,
  713. .sin6_port = htons(port),
  714. };
  715. const char *netid;
  716. int error;
  717. switch (protocol) {
  718. case IPPROTO_UDP:
  719. netid = RPCBIND_NETID_UDP6;
  720. break;
  721. case IPPROTO_TCP:
  722. netid = RPCBIND_NETID_TCP6;
  723. break;
  724. default:
  725. return -ENOPROTOOPT;
  726. }
  727. error = rpcb_v4_register(program, version,
  728. (const struct sockaddr *)&sin6, netid);
  729. /*
  730. * User space didn't support rpcbind version 4, so we won't
  731. * use a PF_INET6 listener.
  732. */
  733. if (error == -EPROTONOSUPPORT)
  734. error = -EAFNOSUPPORT;
  735. return error;
  736. }
  737. #endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
  738. /*
  739. * Register a kernel RPC service via rpcbind version 4.
  740. *
  741. * Returns zero on success; a negative errno value is returned
  742. * if any error occurs.
  743. */
  744. static int __svc_register(const char *progname,
  745. const u32 program, const u32 version,
  746. const int family,
  747. const unsigned short protocol,
  748. const unsigned short port)
  749. {
  750. int error = -EAFNOSUPPORT;
  751. switch (family) {
  752. case PF_INET:
  753. error = __svc_rpcb_register4(program, version,
  754. protocol, port);
  755. break;
  756. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  757. case PF_INET6:
  758. error = __svc_rpcb_register6(program, version,
  759. protocol, port);
  760. #endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
  761. }
  762. if (error < 0)
  763. printk(KERN_WARNING "svc: failed to register %sv%u RPC "
  764. "service (errno %d).\n", progname, version, -error);
  765. return error;
  766. }
  767. /**
  768. * svc_register - register an RPC service with the local portmapper
  769. * @serv: svc_serv struct for the service to register
  770. * @family: protocol family of service's listener socket
  771. * @proto: transport protocol number to advertise
  772. * @port: port to advertise
  773. *
  774. * Service is registered for any address in the passed-in protocol family
  775. */
  776. int svc_register(const struct svc_serv *serv, const int family,
  777. const unsigned short proto, const unsigned short port)
  778. {
  779. struct svc_program *progp;
  780. unsigned int i;
  781. int error = 0;
  782. BUG_ON(proto == 0 && port == 0);
  783. for (progp = serv->sv_program; progp; progp = progp->pg_next) {
  784. for (i = 0; i < progp->pg_nvers; i++) {
  785. if (progp->pg_vers[i] == NULL)
  786. continue;
  787. dprintk("svc: svc_register(%sv%d, %s, %u, %u)%s\n",
  788. progp->pg_name,
  789. i,
  790. proto == IPPROTO_UDP? "udp" : "tcp",
  791. port,
  792. family,
  793. progp->pg_vers[i]->vs_hidden?
  794. " (but not telling portmap)" : "");
  795. if (progp->pg_vers[i]->vs_hidden)
  796. continue;
  797. error = __svc_register(progp->pg_name, progp->pg_prog,
  798. i, family, proto, port);
  799. if (error < 0)
  800. break;
  801. }
  802. }
  803. return error;
  804. }
  805. /*
  806. * If user space is running rpcbind, it should take the v4 UNSET
  807. * and clear everything for this [program, version]. If user space
  808. * is running portmap, it will reject the v4 UNSET, but won't have
  809. * any "inet6" entries anyway. So a PMAP_UNSET should be sufficient
  810. * in this case to clear all existing entries for [program, version].
  811. */
  812. static void __svc_unregister(const u32 program, const u32 version,
  813. const char *progname)
  814. {
  815. int error;
  816. error = rpcb_v4_register(program, version, NULL, "");
  817. /*
  818. * User space didn't support rpcbind v4, so retry this
  819. * request with the legacy rpcbind v2 protocol.
  820. */
  821. if (error == -EPROTONOSUPPORT)
  822. error = rpcb_register(program, version, 0, 0);
  823. dprintk("svc: %s(%sv%u), error %d\n",
  824. __func__, progname, version, error);
  825. }
  826. /*
  827. * All netids, bind addresses and ports registered for [program, version]
  828. * are removed from the local rpcbind database (if the service is not
  829. * hidden) to make way for a new instance of the service.
  830. *
  831. * The result of unregistration is reported via dprintk for those who want
  832. * verification of the result, but is otherwise not important.
  833. */
  834. static void svc_unregister(const struct svc_serv *serv)
  835. {
  836. struct svc_program *progp;
  837. unsigned long flags;
  838. unsigned int i;
  839. clear_thread_flag(TIF_SIGPENDING);
  840. for (progp = serv->sv_program; progp; progp = progp->pg_next) {
  841. for (i = 0; i < progp->pg_nvers; i++) {
  842. if (progp->pg_vers[i] == NULL)
  843. continue;
  844. if (progp->pg_vers[i]->vs_hidden)
  845. continue;
  846. dprintk("svc: attempting to unregister %sv%u\n",
  847. progp->pg_name, i);
  848. __svc_unregister(progp->pg_prog, i, progp->pg_name);
  849. }
  850. }
  851. spin_lock_irqsave(&current->sighand->siglock, flags);
  852. recalc_sigpending();
  853. spin_unlock_irqrestore(&current->sighand->siglock, flags);
  854. }
  855. /*
  856. * Printk the given error with the address of the client that caused it.
  857. */
  858. static int
  859. __attribute__ ((format (printf, 2, 3)))
  860. svc_printk(struct svc_rqst *rqstp, const char *fmt, ...)
  861. {
  862. va_list args;
  863. int r;
  864. char buf[RPC_MAX_ADDRBUFLEN];
  865. if (!net_ratelimit())
  866. return 0;
  867. printk(KERN_WARNING "svc: %s: ",
  868. svc_print_addr(rqstp, buf, sizeof(buf)));
  869. va_start(args, fmt);
  870. r = vprintk(fmt, args);
  871. va_end(args);
  872. return r;
  873. }
  874. /*
  875. * Common routine for processing the RPC request.
  876. */
  877. static int
  878. svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
  879. {
  880. struct svc_program *progp;
  881. struct svc_version *versp = NULL; /* compiler food */
  882. struct svc_procedure *procp = NULL;
  883. struct svc_serv *serv = rqstp->rq_server;
  884. kxdrproc_t xdr;
  885. __be32 *statp;
  886. u32 prog, vers, proc;
  887. __be32 auth_stat, rpc_stat;
  888. int auth_res;
  889. __be32 *reply_statp;
  890. rpc_stat = rpc_success;
  891. if (argv->iov_len < 6*4)
  892. goto err_short_len;
  893. /* Will be turned off only in gss privacy case: */
  894. rqstp->rq_splice_ok = 1;
  895. /* Will be turned off only when NFSv4 Sessions are used */
  896. rqstp->rq_usedeferral = 1;
  897. rqstp->rq_dropme = false;
  898. /* Setup reply header */
  899. rqstp->rq_xprt->xpt_ops->xpo_prep_reply_hdr(rqstp);
  900. svc_putu32(resv, rqstp->rq_xid);
  901. vers = svc_getnl(argv);
  902. /* First words of reply: */
  903. svc_putnl(resv, 1); /* REPLY */
  904. if (vers != 2) /* RPC version number */
  905. goto err_bad_rpc;
  906. /* Save position in case we later decide to reject: */
  907. reply_statp = resv->iov_base + resv->iov_len;
  908. svc_putnl(resv, 0); /* ACCEPT */
  909. rqstp->rq_prog = prog = svc_getnl(argv); /* program number */
  910. rqstp->rq_vers = vers = svc_getnl(argv); /* version number */
  911. rqstp->rq_proc = proc = svc_getnl(argv); /* procedure number */
  912. progp = serv->sv_program;
  913. for (progp = serv->sv_program; progp; progp = progp->pg_next)
  914. if (prog == progp->pg_prog)
  915. break;
  916. /*
  917. * Decode auth data, and add verifier to reply buffer.
  918. * We do this before anything else in order to get a decent
  919. * auth verifier.
  920. */
  921. auth_res = svc_authenticate(rqstp, &auth_stat);
  922. /* Also give the program a chance to reject this call: */
  923. if (auth_res == SVC_OK && progp) {
  924. auth_stat = rpc_autherr_badcred;
  925. auth_res = progp->pg_authenticate(rqstp);
  926. }
  927. switch (auth_res) {
  928. case SVC_OK:
  929. break;
  930. case SVC_GARBAGE:
  931. goto err_garbage;
  932. case SVC_SYSERR:
  933. rpc_stat = rpc_system_err;
  934. goto err_bad;
  935. case SVC_DENIED:
  936. goto err_bad_auth;
  937. case SVC_CLOSE:
  938. if (test_bit(XPT_TEMP, &rqstp->rq_xprt->xpt_flags))
  939. svc_close_xprt(rqstp->rq_xprt);
  940. case SVC_DROP:
  941. goto dropit;
  942. case SVC_COMPLETE:
  943. goto sendit;
  944. }
  945. if (progp == NULL)
  946. goto err_bad_prog;
  947. if (vers >= progp->pg_nvers ||
  948. !(versp = progp->pg_vers[vers]))
  949. goto err_bad_vers;
  950. procp = versp->vs_proc + proc;
  951. if (proc >= versp->vs_nproc || !procp->pc_func)
  952. goto err_bad_proc;
  953. rqstp->rq_procinfo = procp;
  954. /* Syntactic check complete */
  955. serv->sv_stats->rpccnt++;
  956. /* Build the reply header. */
  957. statp = resv->iov_base +resv->iov_len;
  958. svc_putnl(resv, RPC_SUCCESS);
  959. /* Bump per-procedure stats counter */
  960. procp->pc_count++;
  961. /* Initialize storage for argp and resp */
  962. memset(rqstp->rq_argp, 0, procp->pc_argsize);
  963. memset(rqstp->rq_resp, 0, procp->pc_ressize);
  964. /* un-reserve some of the out-queue now that we have a
  965. * better idea of reply size
  966. */
  967. if (procp->pc_xdrressize)
  968. svc_reserve_auth(rqstp, procp->pc_xdrressize<<2);
  969. /* Call the function that processes the request. */
  970. if (!versp->vs_dispatch) {
  971. /* Decode arguments */
  972. xdr = procp->pc_decode;
  973. if (xdr && !xdr(rqstp, argv->iov_base, rqstp->rq_argp))
  974. goto err_garbage;
  975. *statp = procp->pc_func(rqstp, rqstp->rq_argp, rqstp->rq_resp);
  976. /* Encode reply */
  977. if (rqstp->rq_dropme) {
  978. if (procp->pc_release)
  979. procp->pc_release(rqstp, NULL, rqstp->rq_resp);
  980. goto dropit;
  981. }
  982. if (*statp == rpc_success &&
  983. (xdr = procp->pc_encode) &&
  984. !xdr(rqstp, resv->iov_base+resv->iov_len, rqstp->rq_resp)) {
  985. dprintk("svc: failed to encode reply\n");
  986. /* serv->sv_stats->rpcsystemerr++; */
  987. *statp = rpc_system_err;
  988. }
  989. } else {
  990. dprintk("svc: calling dispatcher\n");
  991. if (!versp->vs_dispatch(rqstp, statp)) {
  992. /* Release reply info */
  993. if (procp->pc_release)
  994. procp->pc_release(rqstp, NULL, rqstp->rq_resp);
  995. goto dropit;
  996. }
  997. }
  998. /* Check RPC status result */
  999. if (*statp != rpc_success)
  1000. resv->iov_len = ((void*)statp) - resv->iov_base + 4;
  1001. /* Release reply info */
  1002. if (procp->pc_release)
  1003. procp->pc_release(rqstp, NULL, rqstp->rq_resp);
  1004. if (procp->pc_encode == NULL)
  1005. goto dropit;
  1006. sendit:
  1007. if (svc_authorise(rqstp))
  1008. goto dropit;
  1009. return 1; /* Caller can now send it */
  1010. dropit:
  1011. svc_authorise(rqstp); /* doesn't hurt to call this twice */
  1012. dprintk("svc: svc_process dropit\n");
  1013. return 0;
  1014. err_short_len:
  1015. svc_printk(rqstp, "short len %Zd, dropping request\n",
  1016. argv->iov_len);
  1017. goto dropit; /* drop request */
  1018. err_bad_rpc:
  1019. serv->sv_stats->rpcbadfmt++;
  1020. svc_putnl(resv, 1); /* REJECT */
  1021. svc_putnl(resv, 0); /* RPC_MISMATCH */
  1022. svc_putnl(resv, 2); /* Only RPCv2 supported */
  1023. svc_putnl(resv, 2);
  1024. goto sendit;
  1025. err_bad_auth:
  1026. dprintk("svc: authentication failed (%d)\n", ntohl(auth_stat));
  1027. serv->sv_stats->rpcbadauth++;
  1028. /* Restore write pointer to location of accept status: */
  1029. xdr_ressize_check(rqstp, reply_statp);
  1030. svc_putnl(resv, 1); /* REJECT */
  1031. svc_putnl(resv, 1); /* AUTH_ERROR */
  1032. svc_putnl(resv, ntohl(auth_stat)); /* status */
  1033. goto sendit;
  1034. err_bad_prog:
  1035. dprintk("svc: unknown program %d\n", prog);
  1036. serv->sv_stats->rpcbadfmt++;
  1037. svc_putnl(resv, RPC_PROG_UNAVAIL);
  1038. goto sendit;
  1039. err_bad_vers:
  1040. svc_printk(rqstp, "unknown version (%d for prog %d, %s)\n",
  1041. vers, prog, progp->pg_name);
  1042. serv->sv_stats->rpcbadfmt++;
  1043. svc_putnl(resv, RPC_PROG_MISMATCH);
  1044. svc_putnl(resv, progp->pg_lovers);
  1045. svc_putnl(resv, progp->pg_hivers);
  1046. goto sendit;
  1047. err_bad_proc:
  1048. svc_printk(rqstp, "unknown procedure (%d)\n", proc);
  1049. serv->sv_stats->rpcbadfmt++;
  1050. svc_putnl(resv, RPC_PROC_UNAVAIL);
  1051. goto sendit;
  1052. err_garbage:
  1053. svc_printk(rqstp, "failed to decode args\n");
  1054. rpc_stat = rpc_garbage_args;
  1055. err_bad:
  1056. serv->sv_stats->rpcbadfmt++;
  1057. svc_putnl(resv, ntohl(rpc_stat));
  1058. goto sendit;
  1059. }
  1060. EXPORT_SYMBOL_GPL(svc_process);
  1061. /*
  1062. * Process the RPC request.
  1063. */
  1064. int
  1065. svc_process(struct svc_rqst *rqstp)
  1066. {
  1067. struct kvec *argv = &rqstp->rq_arg.head[0];
  1068. struct kvec *resv = &rqstp->rq_res.head[0];
  1069. struct svc_serv *serv = rqstp->rq_server;
  1070. u32 dir;
  1071. /*
  1072. * Setup response xdr_buf.
  1073. * Initially it has just one page
  1074. */
  1075. rqstp->rq_resused = 1;
  1076. resv->iov_base = page_address(rqstp->rq_respages[0]);
  1077. resv->iov_len = 0;
  1078. rqstp->rq_res.pages = rqstp->rq_respages + 1;
  1079. rqstp->rq_res.len = 0;
  1080. rqstp->rq_res.page_base = 0;
  1081. rqstp->rq_res.page_len = 0;
  1082. rqstp->rq_res.buflen = PAGE_SIZE;
  1083. rqstp->rq_res.tail[0].iov_base = NULL;
  1084. rqstp->rq_res.tail[0].iov_len = 0;
  1085. rqstp->rq_xid = svc_getu32(argv);
  1086. dir = svc_getnl(argv);
  1087. if (dir != 0) {
  1088. /* direction != CALL */
  1089. svc_printk(rqstp, "bad direction %d, dropping request\n", dir);
  1090. serv->sv_stats->rpcbadfmt++;
  1091. svc_drop(rqstp);
  1092. return 0;
  1093. }
  1094. /* Returns 1 for send, 0 for drop */
  1095. if (svc_process_common(rqstp, argv, resv))
  1096. return svc_send(rqstp);
  1097. else {
  1098. svc_drop(rqstp);
  1099. return 0;
  1100. }
  1101. }
  1102. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  1103. /*
  1104. * Process a backchannel RPC request that arrived over an existing
  1105. * outbound connection
  1106. */
  1107. int
  1108. bc_svc_process(struct svc_serv *serv, struct rpc_rqst *req,
  1109. struct svc_rqst *rqstp)
  1110. {
  1111. struct kvec *argv = &rqstp->rq_arg.head[0];
  1112. struct kvec *resv = &rqstp->rq_res.head[0];
  1113. /* Build the svc_rqst used by the common processing routine */
  1114. rqstp->rq_xprt = serv->sv_bc_xprt;
  1115. rqstp->rq_xid = req->rq_xid;
  1116. rqstp->rq_prot = req->rq_xprt->prot;
  1117. rqstp->rq_server = serv;
  1118. rqstp->rq_addrlen = sizeof(req->rq_xprt->addr);
  1119. memcpy(&rqstp->rq_addr, &req->rq_xprt->addr, rqstp->rq_addrlen);
  1120. memcpy(&rqstp->rq_arg, &req->rq_rcv_buf, sizeof(rqstp->rq_arg));
  1121. memcpy(&rqstp->rq_res, &req->rq_snd_buf, sizeof(rqstp->rq_res));
  1122. /* reset result send buffer "put" position */
  1123. resv->iov_len = 0;
  1124. if (rqstp->rq_prot != IPPROTO_TCP) {
  1125. printk(KERN_ERR "No support for Non-TCP transports!\n");
  1126. BUG();
  1127. }
  1128. /*
  1129. * Skip the next two words because they've already been
  1130. * processed in the trasport
  1131. */
  1132. svc_getu32(argv); /* XID */
  1133. svc_getnl(argv); /* CALLDIR */
  1134. /* Returns 1 for send, 0 for drop */
  1135. if (svc_process_common(rqstp, argv, resv)) {
  1136. memcpy(&req->rq_snd_buf, &rqstp->rq_res,
  1137. sizeof(req->rq_snd_buf));
  1138. return bc_send(req);
  1139. } else {
  1140. /* Nothing to do to drop request */
  1141. return 0;
  1142. }
  1143. }
  1144. EXPORT_SYMBOL_GPL(bc_svc_process);
  1145. #endif /* CONFIG_SUNRPC_BACKCHANNEL */
  1146. /*
  1147. * Return (transport-specific) limit on the rpc payload.
  1148. */
  1149. u32 svc_max_payload(const struct svc_rqst *rqstp)
  1150. {
  1151. u32 max = rqstp->rq_xprt->xpt_class->xcl_max_payload;
  1152. if (rqstp->rq_server->sv_max_payload < max)
  1153. max = rqstp->rq_server->sv_max_payload;
  1154. return max;
  1155. }
  1156. EXPORT_SYMBOL_GPL(svc_max_payload);