svc_xprt.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  1. /*
  2. * linux/net/sunrpc/svc_xprt.c
  3. *
  4. * Author: Tom Tucker <tom@opengridcomputing.com>
  5. */
  6. #include <linux/sched.h>
  7. #include <linux/errno.h>
  8. #include <linux/freezer.h>
  9. #include <linux/kthread.h>
  10. #include <net/sock.h>
  11. #include <linux/sunrpc/stats.h>
  12. #include <linux/sunrpc/svc_xprt.h>
  13. #define RPCDBG_FACILITY RPCDBG_SVCXPRT
  14. #define SVC_MAX_WAKING 5
  15. static struct svc_deferred_req *svc_deferred_dequeue(struct svc_xprt *xprt);
  16. static int svc_deferred_recv(struct svc_rqst *rqstp);
  17. static struct cache_deferred_req *svc_defer(struct cache_req *req);
  18. static void svc_age_temp_xprts(unsigned long closure);
  19. /* apparently the "standard" is that clients close
  20. * idle connections after 5 minutes, servers after
  21. * 6 minutes
  22. * http://www.connectathon.org/talks96/nfstcp.pdf
  23. */
  24. static int svc_conn_age_period = 6*60;
  25. /* List of registered transport classes */
  26. static DEFINE_SPINLOCK(svc_xprt_class_lock);
  27. static LIST_HEAD(svc_xprt_class_list);
  28. /* SMP locking strategy:
  29. *
  30. * svc_pool->sp_lock protects most of the fields of that pool.
  31. * svc_serv->sv_lock protects sv_tempsocks, sv_permsocks, sv_tmpcnt.
  32. * when both need to be taken (rare), svc_serv->sv_lock is first.
  33. * BKL protects svc_serv->sv_nrthread.
  34. * svc_sock->sk_lock protects the svc_sock->sk_deferred list
  35. * and the ->sk_info_authunix cache.
  36. *
  37. * The XPT_BUSY bit in xprt->xpt_flags prevents a transport being
  38. * enqueued multiply. During normal transport processing this bit
  39. * is set by svc_xprt_enqueue and cleared by svc_xprt_received.
  40. * Providers should not manipulate this bit directly.
  41. *
  42. * Some flags can be set to certain values at any time
  43. * providing that certain rules are followed:
  44. *
  45. * XPT_CONN, XPT_DATA:
  46. * - Can be set or cleared at any time.
  47. * - After a set, svc_xprt_enqueue must be called to enqueue
  48. * the transport for processing.
  49. * - After a clear, the transport must be read/accepted.
  50. * If this succeeds, it must be set again.
  51. * XPT_CLOSE:
  52. * - Can set at any time. It is never cleared.
  53. * XPT_DEAD:
  54. * - Can only be set while XPT_BUSY is held which ensures
  55. * that no other thread will be using the transport or will
  56. * try to set XPT_DEAD.
  57. */
  58. int svc_reg_xprt_class(struct svc_xprt_class *xcl)
  59. {
  60. struct svc_xprt_class *cl;
  61. int res = -EEXIST;
  62. dprintk("svc: Adding svc transport class '%s'\n", xcl->xcl_name);
  63. INIT_LIST_HEAD(&xcl->xcl_list);
  64. spin_lock(&svc_xprt_class_lock);
  65. /* Make sure there isn't already a class with the same name */
  66. list_for_each_entry(cl, &svc_xprt_class_list, xcl_list) {
  67. if (strcmp(xcl->xcl_name, cl->xcl_name) == 0)
  68. goto out;
  69. }
  70. list_add_tail(&xcl->xcl_list, &svc_xprt_class_list);
  71. res = 0;
  72. out:
  73. spin_unlock(&svc_xprt_class_lock);
  74. return res;
  75. }
  76. EXPORT_SYMBOL_GPL(svc_reg_xprt_class);
  77. void svc_unreg_xprt_class(struct svc_xprt_class *xcl)
  78. {
  79. dprintk("svc: Removing svc transport class '%s'\n", xcl->xcl_name);
  80. spin_lock(&svc_xprt_class_lock);
  81. list_del_init(&xcl->xcl_list);
  82. spin_unlock(&svc_xprt_class_lock);
  83. }
  84. EXPORT_SYMBOL_GPL(svc_unreg_xprt_class);
  85. /*
  86. * Format the transport list for printing
  87. */
  88. int svc_print_xprts(char *buf, int maxlen)
  89. {
  90. struct list_head *le;
  91. char tmpstr[80];
  92. int len = 0;
  93. buf[0] = '\0';
  94. spin_lock(&svc_xprt_class_lock);
  95. list_for_each(le, &svc_xprt_class_list) {
  96. int slen;
  97. struct svc_xprt_class *xcl =
  98. list_entry(le, struct svc_xprt_class, xcl_list);
  99. sprintf(tmpstr, "%s %d\n", xcl->xcl_name, xcl->xcl_max_payload);
  100. slen = strlen(tmpstr);
  101. if (len + slen > maxlen)
  102. break;
  103. len += slen;
  104. strcat(buf, tmpstr);
  105. }
  106. spin_unlock(&svc_xprt_class_lock);
  107. return len;
  108. }
  109. static void svc_xprt_free(struct kref *kref)
  110. {
  111. struct svc_xprt *xprt =
  112. container_of(kref, struct svc_xprt, xpt_ref);
  113. struct module *owner = xprt->xpt_class->xcl_owner;
  114. if (test_bit(XPT_CACHE_AUTH, &xprt->xpt_flags)
  115. && xprt->xpt_auth_cache != NULL)
  116. svcauth_unix_info_release(xprt->xpt_auth_cache);
  117. xprt->xpt_ops->xpo_free(xprt);
  118. module_put(owner);
  119. }
  120. void svc_xprt_put(struct svc_xprt *xprt)
  121. {
  122. kref_put(&xprt->xpt_ref, svc_xprt_free);
  123. }
  124. EXPORT_SYMBOL_GPL(svc_xprt_put);
  125. /*
  126. * Called by transport drivers to initialize the transport independent
  127. * portion of the transport instance.
  128. */
  129. void svc_xprt_init(struct svc_xprt_class *xcl, struct svc_xprt *xprt,
  130. struct svc_serv *serv)
  131. {
  132. memset(xprt, 0, sizeof(*xprt));
  133. xprt->xpt_class = xcl;
  134. xprt->xpt_ops = xcl->xcl_ops;
  135. kref_init(&xprt->xpt_ref);
  136. xprt->xpt_server = serv;
  137. INIT_LIST_HEAD(&xprt->xpt_list);
  138. INIT_LIST_HEAD(&xprt->xpt_ready);
  139. INIT_LIST_HEAD(&xprt->xpt_deferred);
  140. mutex_init(&xprt->xpt_mutex);
  141. spin_lock_init(&xprt->xpt_lock);
  142. set_bit(XPT_BUSY, &xprt->xpt_flags);
  143. }
  144. EXPORT_SYMBOL_GPL(svc_xprt_init);
  145. static struct svc_xprt *__svc_xpo_create(struct svc_xprt_class *xcl,
  146. struct svc_serv *serv,
  147. const int family,
  148. const unsigned short port,
  149. int flags)
  150. {
  151. struct sockaddr_in sin = {
  152. .sin_family = AF_INET,
  153. .sin_addr.s_addr = htonl(INADDR_ANY),
  154. .sin_port = htons(port),
  155. };
  156. struct sockaddr_in6 sin6 = {
  157. .sin6_family = AF_INET6,
  158. .sin6_addr = IN6ADDR_ANY_INIT,
  159. .sin6_port = htons(port),
  160. };
  161. struct sockaddr *sap;
  162. size_t len;
  163. switch (family) {
  164. case PF_INET:
  165. sap = (struct sockaddr *)&sin;
  166. len = sizeof(sin);
  167. break;
  168. case PF_INET6:
  169. sap = (struct sockaddr *)&sin6;
  170. len = sizeof(sin6);
  171. break;
  172. default:
  173. return ERR_PTR(-EAFNOSUPPORT);
  174. }
  175. return xcl->xcl_ops->xpo_create(serv, sap, len, flags);
  176. }
  177. int svc_create_xprt(struct svc_serv *serv, const char *xprt_name,
  178. const int family, const unsigned short port,
  179. int flags)
  180. {
  181. struct svc_xprt_class *xcl;
  182. dprintk("svc: creating transport %s[%d]\n", xprt_name, port);
  183. spin_lock(&svc_xprt_class_lock);
  184. list_for_each_entry(xcl, &svc_xprt_class_list, xcl_list) {
  185. struct svc_xprt *newxprt;
  186. if (strcmp(xprt_name, xcl->xcl_name))
  187. continue;
  188. if (!try_module_get(xcl->xcl_owner))
  189. goto err;
  190. spin_unlock(&svc_xprt_class_lock);
  191. newxprt = __svc_xpo_create(xcl, serv, family, port, flags);
  192. if (IS_ERR(newxprt)) {
  193. module_put(xcl->xcl_owner);
  194. return PTR_ERR(newxprt);
  195. }
  196. clear_bit(XPT_TEMP, &newxprt->xpt_flags);
  197. spin_lock_bh(&serv->sv_lock);
  198. list_add(&newxprt->xpt_list, &serv->sv_permsocks);
  199. spin_unlock_bh(&serv->sv_lock);
  200. clear_bit(XPT_BUSY, &newxprt->xpt_flags);
  201. return svc_xprt_local_port(newxprt);
  202. }
  203. err:
  204. spin_unlock(&svc_xprt_class_lock);
  205. dprintk("svc: transport %s not found\n", xprt_name);
  206. return -ENOENT;
  207. }
  208. EXPORT_SYMBOL_GPL(svc_create_xprt);
  209. /*
  210. * Copy the local and remote xprt addresses to the rqstp structure
  211. */
  212. void svc_xprt_copy_addrs(struct svc_rqst *rqstp, struct svc_xprt *xprt)
  213. {
  214. struct sockaddr *sin;
  215. memcpy(&rqstp->rq_addr, &xprt->xpt_remote, xprt->xpt_remotelen);
  216. rqstp->rq_addrlen = xprt->xpt_remotelen;
  217. /*
  218. * Destination address in request is needed for binding the
  219. * source address in RPC replies/callbacks later.
  220. */
  221. sin = (struct sockaddr *)&xprt->xpt_local;
  222. switch (sin->sa_family) {
  223. case AF_INET:
  224. rqstp->rq_daddr.addr = ((struct sockaddr_in *)sin)->sin_addr;
  225. break;
  226. case AF_INET6:
  227. rqstp->rq_daddr.addr6 = ((struct sockaddr_in6 *)sin)->sin6_addr;
  228. break;
  229. }
  230. }
  231. EXPORT_SYMBOL_GPL(svc_xprt_copy_addrs);
  232. /**
  233. * svc_print_addr - Format rq_addr field for printing
  234. * @rqstp: svc_rqst struct containing address to print
  235. * @buf: target buffer for formatted address
  236. * @len: length of target buffer
  237. *
  238. */
  239. char *svc_print_addr(struct svc_rqst *rqstp, char *buf, size_t len)
  240. {
  241. return __svc_print_addr(svc_addr(rqstp), buf, len);
  242. }
  243. EXPORT_SYMBOL_GPL(svc_print_addr);
  244. /*
  245. * Queue up an idle server thread. Must have pool->sp_lock held.
  246. * Note: this is really a stack rather than a queue, so that we only
  247. * use as many different threads as we need, and the rest don't pollute
  248. * the cache.
  249. */
  250. static void svc_thread_enqueue(struct svc_pool *pool, struct svc_rqst *rqstp)
  251. {
  252. list_add(&rqstp->rq_list, &pool->sp_threads);
  253. }
  254. /*
  255. * Dequeue an nfsd thread. Must have pool->sp_lock held.
  256. */
  257. static void svc_thread_dequeue(struct svc_pool *pool, struct svc_rqst *rqstp)
  258. {
  259. list_del(&rqstp->rq_list);
  260. }
  261. /*
  262. * Queue up a transport with data pending. If there are idle nfsd
  263. * processes, wake 'em up.
  264. *
  265. */
  266. void svc_xprt_enqueue(struct svc_xprt *xprt)
  267. {
  268. struct svc_serv *serv = xprt->xpt_server;
  269. struct svc_pool *pool;
  270. struct svc_rqst *rqstp;
  271. int cpu;
  272. int thread_avail;
  273. if (!(xprt->xpt_flags &
  274. ((1<<XPT_CONN)|(1<<XPT_DATA)|(1<<XPT_CLOSE)|(1<<XPT_DEFERRED))))
  275. return;
  276. cpu = get_cpu();
  277. pool = svc_pool_for_cpu(xprt->xpt_server, cpu);
  278. put_cpu();
  279. spin_lock_bh(&pool->sp_lock);
  280. if (test_bit(XPT_DEAD, &xprt->xpt_flags)) {
  281. /* Don't enqueue dead transports */
  282. dprintk("svc: transport %p is dead, not enqueued\n", xprt);
  283. goto out_unlock;
  284. }
  285. pool->sp_stats.packets++;
  286. /* Mark transport as busy. It will remain in this state until
  287. * the provider calls svc_xprt_received. We update XPT_BUSY
  288. * atomically because it also guards against trying to enqueue
  289. * the transport twice.
  290. */
  291. if (test_and_set_bit(XPT_BUSY, &xprt->xpt_flags)) {
  292. /* Don't enqueue transport while already enqueued */
  293. dprintk("svc: transport %p busy, not enqueued\n", xprt);
  294. goto out_unlock;
  295. }
  296. BUG_ON(xprt->xpt_pool != NULL);
  297. xprt->xpt_pool = pool;
  298. /* Handle pending connection */
  299. if (test_bit(XPT_CONN, &xprt->xpt_flags))
  300. goto process;
  301. /* Handle close in-progress */
  302. if (test_bit(XPT_CLOSE, &xprt->xpt_flags))
  303. goto process;
  304. /* Check if we have space to reply to a request */
  305. if (!xprt->xpt_ops->xpo_has_wspace(xprt)) {
  306. /* Don't enqueue while not enough space for reply */
  307. dprintk("svc: no write space, transport %p not enqueued\n",
  308. xprt);
  309. xprt->xpt_pool = NULL;
  310. clear_bit(XPT_BUSY, &xprt->xpt_flags);
  311. goto out_unlock;
  312. }
  313. process:
  314. /* Work out whether threads are available */
  315. thread_avail = !list_empty(&pool->sp_threads); /* threads are asleep */
  316. if (pool->sp_nwaking >= SVC_MAX_WAKING) {
  317. /* too many threads are runnable and trying to wake up */
  318. thread_avail = 0;
  319. pool->sp_stats.overloads_avoided++;
  320. }
  321. if (thread_avail) {
  322. rqstp = list_entry(pool->sp_threads.next,
  323. struct svc_rqst,
  324. rq_list);
  325. dprintk("svc: transport %p served by daemon %p\n",
  326. xprt, rqstp);
  327. svc_thread_dequeue(pool, rqstp);
  328. if (rqstp->rq_xprt)
  329. printk(KERN_ERR
  330. "svc_xprt_enqueue: server %p, rq_xprt=%p!\n",
  331. rqstp, rqstp->rq_xprt);
  332. rqstp->rq_xprt = xprt;
  333. svc_xprt_get(xprt);
  334. rqstp->rq_reserved = serv->sv_max_mesg;
  335. atomic_add(rqstp->rq_reserved, &xprt->xpt_reserved);
  336. rqstp->rq_waking = 1;
  337. pool->sp_nwaking++;
  338. pool->sp_stats.threads_woken++;
  339. BUG_ON(xprt->xpt_pool != pool);
  340. wake_up(&rqstp->rq_wait);
  341. } else {
  342. dprintk("svc: transport %p put into queue\n", xprt);
  343. list_add_tail(&xprt->xpt_ready, &pool->sp_sockets);
  344. pool->sp_stats.sockets_queued++;
  345. BUG_ON(xprt->xpt_pool != pool);
  346. }
  347. out_unlock:
  348. spin_unlock_bh(&pool->sp_lock);
  349. }
  350. EXPORT_SYMBOL_GPL(svc_xprt_enqueue);
  351. /*
  352. * Dequeue the first transport. Must be called with the pool->sp_lock held.
  353. */
  354. static struct svc_xprt *svc_xprt_dequeue(struct svc_pool *pool)
  355. {
  356. struct svc_xprt *xprt;
  357. if (list_empty(&pool->sp_sockets))
  358. return NULL;
  359. xprt = list_entry(pool->sp_sockets.next,
  360. struct svc_xprt, xpt_ready);
  361. list_del_init(&xprt->xpt_ready);
  362. dprintk("svc: transport %p dequeued, inuse=%d\n",
  363. xprt, atomic_read(&xprt->xpt_ref.refcount));
  364. return xprt;
  365. }
  366. /*
  367. * svc_xprt_received conditionally queues the transport for processing
  368. * by another thread. The caller must hold the XPT_BUSY bit and must
  369. * not thereafter touch transport data.
  370. *
  371. * Note: XPT_DATA only gets cleared when a read-attempt finds no (or
  372. * insufficient) data.
  373. */
  374. void svc_xprt_received(struct svc_xprt *xprt)
  375. {
  376. BUG_ON(!test_bit(XPT_BUSY, &xprt->xpt_flags));
  377. xprt->xpt_pool = NULL;
  378. clear_bit(XPT_BUSY, &xprt->xpt_flags);
  379. svc_xprt_enqueue(xprt);
  380. }
  381. EXPORT_SYMBOL_GPL(svc_xprt_received);
  382. /**
  383. * svc_reserve - change the space reserved for the reply to a request.
  384. * @rqstp: The request in question
  385. * @space: new max space to reserve
  386. *
  387. * Each request reserves some space on the output queue of the transport
  388. * to make sure the reply fits. This function reduces that reserved
  389. * space to be the amount of space used already, plus @space.
  390. *
  391. */
  392. void svc_reserve(struct svc_rqst *rqstp, int space)
  393. {
  394. space += rqstp->rq_res.head[0].iov_len;
  395. if (space < rqstp->rq_reserved) {
  396. struct svc_xprt *xprt = rqstp->rq_xprt;
  397. atomic_sub((rqstp->rq_reserved - space), &xprt->xpt_reserved);
  398. rqstp->rq_reserved = space;
  399. svc_xprt_enqueue(xprt);
  400. }
  401. }
  402. EXPORT_SYMBOL_GPL(svc_reserve);
  403. static void svc_xprt_release(struct svc_rqst *rqstp)
  404. {
  405. struct svc_xprt *xprt = rqstp->rq_xprt;
  406. rqstp->rq_xprt->xpt_ops->xpo_release_rqst(rqstp);
  407. kfree(rqstp->rq_deferred);
  408. rqstp->rq_deferred = NULL;
  409. svc_free_res_pages(rqstp);
  410. rqstp->rq_res.page_len = 0;
  411. rqstp->rq_res.page_base = 0;
  412. /* Reset response buffer and release
  413. * the reservation.
  414. * But first, check that enough space was reserved
  415. * for the reply, otherwise we have a bug!
  416. */
  417. if ((rqstp->rq_res.len) > rqstp->rq_reserved)
  418. printk(KERN_ERR "RPC request reserved %d but used %d\n",
  419. rqstp->rq_reserved,
  420. rqstp->rq_res.len);
  421. rqstp->rq_res.head[0].iov_len = 0;
  422. svc_reserve(rqstp, 0);
  423. rqstp->rq_xprt = NULL;
  424. svc_xprt_put(xprt);
  425. }
  426. /*
  427. * External function to wake up a server waiting for data
  428. * This really only makes sense for services like lockd
  429. * which have exactly one thread anyway.
  430. */
  431. void svc_wake_up(struct svc_serv *serv)
  432. {
  433. struct svc_rqst *rqstp;
  434. unsigned int i;
  435. struct svc_pool *pool;
  436. for (i = 0; i < serv->sv_nrpools; i++) {
  437. pool = &serv->sv_pools[i];
  438. spin_lock_bh(&pool->sp_lock);
  439. if (!list_empty(&pool->sp_threads)) {
  440. rqstp = list_entry(pool->sp_threads.next,
  441. struct svc_rqst,
  442. rq_list);
  443. dprintk("svc: daemon %p woken up.\n", rqstp);
  444. /*
  445. svc_thread_dequeue(pool, rqstp);
  446. rqstp->rq_xprt = NULL;
  447. */
  448. wake_up(&rqstp->rq_wait);
  449. }
  450. spin_unlock_bh(&pool->sp_lock);
  451. }
  452. }
  453. EXPORT_SYMBOL_GPL(svc_wake_up);
  454. int svc_port_is_privileged(struct sockaddr *sin)
  455. {
  456. switch (sin->sa_family) {
  457. case AF_INET:
  458. return ntohs(((struct sockaddr_in *)sin)->sin_port)
  459. < PROT_SOCK;
  460. case AF_INET6:
  461. return ntohs(((struct sockaddr_in6 *)sin)->sin6_port)
  462. < PROT_SOCK;
  463. default:
  464. return 0;
  465. }
  466. }
  467. /*
  468. * Make sure that we don't have too many active connections. If we have,
  469. * something must be dropped. It's not clear what will happen if we allow
  470. * "too many" connections, but when dealing with network-facing software,
  471. * we have to code defensively. Here we do that by imposing hard limits.
  472. *
  473. * There's no point in trying to do random drop here for DoS
  474. * prevention. The NFS clients does 1 reconnect in 15 seconds. An
  475. * attacker can easily beat that.
  476. *
  477. * The only somewhat efficient mechanism would be if drop old
  478. * connections from the same IP first. But right now we don't even
  479. * record the client IP in svc_sock.
  480. *
  481. * single-threaded services that expect a lot of clients will probably
  482. * need to set sv_maxconn to override the default value which is based
  483. * on the number of threads
  484. */
  485. static void svc_check_conn_limits(struct svc_serv *serv)
  486. {
  487. unsigned int limit = serv->sv_maxconn ? serv->sv_maxconn :
  488. (serv->sv_nrthreads+3) * 20;
  489. if (serv->sv_tmpcnt > limit) {
  490. struct svc_xprt *xprt = NULL;
  491. spin_lock_bh(&serv->sv_lock);
  492. if (!list_empty(&serv->sv_tempsocks)) {
  493. if (net_ratelimit()) {
  494. /* Try to help the admin */
  495. printk(KERN_NOTICE "%s: too many open "
  496. "connections, consider increasing %s\n",
  497. serv->sv_name, serv->sv_maxconn ?
  498. "the max number of connections." :
  499. "the number of threads.");
  500. }
  501. /*
  502. * Always select the oldest connection. It's not fair,
  503. * but so is life
  504. */
  505. xprt = list_entry(serv->sv_tempsocks.prev,
  506. struct svc_xprt,
  507. xpt_list);
  508. set_bit(XPT_CLOSE, &xprt->xpt_flags);
  509. svc_xprt_get(xprt);
  510. }
  511. spin_unlock_bh(&serv->sv_lock);
  512. if (xprt) {
  513. svc_xprt_enqueue(xprt);
  514. svc_xprt_put(xprt);
  515. }
  516. }
  517. }
  518. /*
  519. * Receive the next request on any transport. This code is carefully
  520. * organised not to touch any cachelines in the shared svc_serv
  521. * structure, only cachelines in the local svc_pool.
  522. */
  523. int svc_recv(struct svc_rqst *rqstp, long timeout)
  524. {
  525. struct svc_xprt *xprt = NULL;
  526. struct svc_serv *serv = rqstp->rq_server;
  527. struct svc_pool *pool = rqstp->rq_pool;
  528. int len, i;
  529. int pages;
  530. struct xdr_buf *arg;
  531. DECLARE_WAITQUEUE(wait, current);
  532. long time_left;
  533. dprintk("svc: server %p waiting for data (to = %ld)\n",
  534. rqstp, timeout);
  535. if (rqstp->rq_xprt)
  536. printk(KERN_ERR
  537. "svc_recv: service %p, transport not NULL!\n",
  538. rqstp);
  539. if (waitqueue_active(&rqstp->rq_wait))
  540. printk(KERN_ERR
  541. "svc_recv: service %p, wait queue active!\n",
  542. rqstp);
  543. /* now allocate needed pages. If we get a failure, sleep briefly */
  544. pages = (serv->sv_max_mesg + PAGE_SIZE) / PAGE_SIZE;
  545. for (i = 0; i < pages ; i++)
  546. while (rqstp->rq_pages[i] == NULL) {
  547. struct page *p = alloc_page(GFP_KERNEL);
  548. if (!p) {
  549. set_current_state(TASK_INTERRUPTIBLE);
  550. if (signalled() || kthread_should_stop()) {
  551. set_current_state(TASK_RUNNING);
  552. return -EINTR;
  553. }
  554. schedule_timeout(msecs_to_jiffies(500));
  555. }
  556. rqstp->rq_pages[i] = p;
  557. }
  558. rqstp->rq_pages[i++] = NULL; /* this might be seen in nfs_read_actor */
  559. BUG_ON(pages >= RPCSVC_MAXPAGES);
  560. /* Make arg->head point to first page and arg->pages point to rest */
  561. arg = &rqstp->rq_arg;
  562. arg->head[0].iov_base = page_address(rqstp->rq_pages[0]);
  563. arg->head[0].iov_len = PAGE_SIZE;
  564. arg->pages = rqstp->rq_pages + 1;
  565. arg->page_base = 0;
  566. /* save at least one page for response */
  567. arg->page_len = (pages-2)*PAGE_SIZE;
  568. arg->len = (pages-1)*PAGE_SIZE;
  569. arg->tail[0].iov_len = 0;
  570. try_to_freeze();
  571. cond_resched();
  572. if (signalled() || kthread_should_stop())
  573. return -EINTR;
  574. spin_lock_bh(&pool->sp_lock);
  575. if (rqstp->rq_waking) {
  576. rqstp->rq_waking = 0;
  577. pool->sp_nwaking--;
  578. BUG_ON(pool->sp_nwaking < 0);
  579. }
  580. xprt = svc_xprt_dequeue(pool);
  581. if (xprt) {
  582. rqstp->rq_xprt = xprt;
  583. svc_xprt_get(xprt);
  584. rqstp->rq_reserved = serv->sv_max_mesg;
  585. atomic_add(rqstp->rq_reserved, &xprt->xpt_reserved);
  586. } else {
  587. /* No data pending. Go to sleep */
  588. svc_thread_enqueue(pool, rqstp);
  589. /*
  590. * We have to be able to interrupt this wait
  591. * to bring down the daemons ...
  592. */
  593. set_current_state(TASK_INTERRUPTIBLE);
  594. /*
  595. * checking kthread_should_stop() here allows us to avoid
  596. * locking and signalling when stopping kthreads that call
  597. * svc_recv. If the thread has already been woken up, then
  598. * we can exit here without sleeping. If not, then it
  599. * it'll be woken up quickly during the schedule_timeout
  600. */
  601. if (kthread_should_stop()) {
  602. set_current_state(TASK_RUNNING);
  603. spin_unlock_bh(&pool->sp_lock);
  604. return -EINTR;
  605. }
  606. add_wait_queue(&rqstp->rq_wait, &wait);
  607. spin_unlock_bh(&pool->sp_lock);
  608. time_left = schedule_timeout(timeout);
  609. try_to_freeze();
  610. spin_lock_bh(&pool->sp_lock);
  611. remove_wait_queue(&rqstp->rq_wait, &wait);
  612. if (!time_left)
  613. pool->sp_stats.threads_timedout++;
  614. xprt = rqstp->rq_xprt;
  615. if (!xprt) {
  616. svc_thread_dequeue(pool, rqstp);
  617. spin_unlock_bh(&pool->sp_lock);
  618. dprintk("svc: server %p, no data yet\n", rqstp);
  619. if (signalled() || kthread_should_stop())
  620. return -EINTR;
  621. else
  622. return -EAGAIN;
  623. }
  624. }
  625. spin_unlock_bh(&pool->sp_lock);
  626. len = 0;
  627. if (test_bit(XPT_CLOSE, &xprt->xpt_flags)) {
  628. dprintk("svc_recv: found XPT_CLOSE\n");
  629. svc_delete_xprt(xprt);
  630. } else if (test_bit(XPT_LISTENER, &xprt->xpt_flags)) {
  631. struct svc_xprt *newxpt;
  632. newxpt = xprt->xpt_ops->xpo_accept(xprt);
  633. if (newxpt) {
  634. /*
  635. * We know this module_get will succeed because the
  636. * listener holds a reference too
  637. */
  638. __module_get(newxpt->xpt_class->xcl_owner);
  639. svc_check_conn_limits(xprt->xpt_server);
  640. spin_lock_bh(&serv->sv_lock);
  641. set_bit(XPT_TEMP, &newxpt->xpt_flags);
  642. list_add(&newxpt->xpt_list, &serv->sv_tempsocks);
  643. serv->sv_tmpcnt++;
  644. if (serv->sv_temptimer.function == NULL) {
  645. /* setup timer to age temp transports */
  646. setup_timer(&serv->sv_temptimer,
  647. svc_age_temp_xprts,
  648. (unsigned long)serv);
  649. mod_timer(&serv->sv_temptimer,
  650. jiffies + svc_conn_age_period * HZ);
  651. }
  652. spin_unlock_bh(&serv->sv_lock);
  653. svc_xprt_received(newxpt);
  654. }
  655. svc_xprt_received(xprt);
  656. } else {
  657. dprintk("svc: server %p, pool %u, transport %p, inuse=%d\n",
  658. rqstp, pool->sp_id, xprt,
  659. atomic_read(&xprt->xpt_ref.refcount));
  660. rqstp->rq_deferred = svc_deferred_dequeue(xprt);
  661. if (rqstp->rq_deferred) {
  662. svc_xprt_received(xprt);
  663. len = svc_deferred_recv(rqstp);
  664. } else
  665. len = xprt->xpt_ops->xpo_recvfrom(rqstp);
  666. dprintk("svc: got len=%d\n", len);
  667. }
  668. /* No data, incomplete (TCP) read, or accept() */
  669. if (len == 0 || len == -EAGAIN) {
  670. rqstp->rq_res.len = 0;
  671. svc_xprt_release(rqstp);
  672. return -EAGAIN;
  673. }
  674. clear_bit(XPT_OLD, &xprt->xpt_flags);
  675. rqstp->rq_secure = svc_port_is_privileged(svc_addr(rqstp));
  676. rqstp->rq_chandle.defer = svc_defer;
  677. if (serv->sv_stats)
  678. serv->sv_stats->netcnt++;
  679. return len;
  680. }
  681. EXPORT_SYMBOL_GPL(svc_recv);
  682. /*
  683. * Drop request
  684. */
  685. void svc_drop(struct svc_rqst *rqstp)
  686. {
  687. dprintk("svc: xprt %p dropped request\n", rqstp->rq_xprt);
  688. svc_xprt_release(rqstp);
  689. }
  690. EXPORT_SYMBOL_GPL(svc_drop);
  691. /*
  692. * Return reply to client.
  693. */
  694. int svc_send(struct svc_rqst *rqstp)
  695. {
  696. struct svc_xprt *xprt;
  697. int len;
  698. struct xdr_buf *xb;
  699. xprt = rqstp->rq_xprt;
  700. if (!xprt)
  701. return -EFAULT;
  702. /* release the receive skb before sending the reply */
  703. rqstp->rq_xprt->xpt_ops->xpo_release_rqst(rqstp);
  704. /* calculate over-all length */
  705. xb = &rqstp->rq_res;
  706. xb->len = xb->head[0].iov_len +
  707. xb->page_len +
  708. xb->tail[0].iov_len;
  709. /* Grab mutex to serialize outgoing data. */
  710. mutex_lock(&xprt->xpt_mutex);
  711. if (test_bit(XPT_DEAD, &xprt->xpt_flags))
  712. len = -ENOTCONN;
  713. else
  714. len = xprt->xpt_ops->xpo_sendto(rqstp);
  715. mutex_unlock(&xprt->xpt_mutex);
  716. svc_xprt_release(rqstp);
  717. if (len == -ECONNREFUSED || len == -ENOTCONN || len == -EAGAIN)
  718. return 0;
  719. return len;
  720. }
  721. /*
  722. * Timer function to close old temporary transports, using
  723. * a mark-and-sweep algorithm.
  724. */
  725. static void svc_age_temp_xprts(unsigned long closure)
  726. {
  727. struct svc_serv *serv = (struct svc_serv *)closure;
  728. struct svc_xprt *xprt;
  729. struct list_head *le, *next;
  730. LIST_HEAD(to_be_aged);
  731. dprintk("svc_age_temp_xprts\n");
  732. if (!spin_trylock_bh(&serv->sv_lock)) {
  733. /* busy, try again 1 sec later */
  734. dprintk("svc_age_temp_xprts: busy\n");
  735. mod_timer(&serv->sv_temptimer, jiffies + HZ);
  736. return;
  737. }
  738. list_for_each_safe(le, next, &serv->sv_tempsocks) {
  739. xprt = list_entry(le, struct svc_xprt, xpt_list);
  740. /* First time through, just mark it OLD. Second time
  741. * through, close it. */
  742. if (!test_and_set_bit(XPT_OLD, &xprt->xpt_flags))
  743. continue;
  744. if (atomic_read(&xprt->xpt_ref.refcount) > 1
  745. || test_bit(XPT_BUSY, &xprt->xpt_flags))
  746. continue;
  747. svc_xprt_get(xprt);
  748. list_move(le, &to_be_aged);
  749. set_bit(XPT_CLOSE, &xprt->xpt_flags);
  750. set_bit(XPT_DETACHED, &xprt->xpt_flags);
  751. }
  752. spin_unlock_bh(&serv->sv_lock);
  753. while (!list_empty(&to_be_aged)) {
  754. le = to_be_aged.next;
  755. /* fiddling the xpt_list node is safe 'cos we're XPT_DETACHED */
  756. list_del_init(le);
  757. xprt = list_entry(le, struct svc_xprt, xpt_list);
  758. dprintk("queuing xprt %p for closing\n", xprt);
  759. /* a thread will dequeue and close it soon */
  760. svc_xprt_enqueue(xprt);
  761. svc_xprt_put(xprt);
  762. }
  763. mod_timer(&serv->sv_temptimer, jiffies + svc_conn_age_period * HZ);
  764. }
  765. /*
  766. * Remove a dead transport
  767. */
  768. void svc_delete_xprt(struct svc_xprt *xprt)
  769. {
  770. struct svc_serv *serv = xprt->xpt_server;
  771. struct svc_deferred_req *dr;
  772. /* Only do this once */
  773. if (test_and_set_bit(XPT_DEAD, &xprt->xpt_flags))
  774. return;
  775. dprintk("svc: svc_delete_xprt(%p)\n", xprt);
  776. xprt->xpt_ops->xpo_detach(xprt);
  777. spin_lock_bh(&serv->sv_lock);
  778. if (!test_and_set_bit(XPT_DETACHED, &xprt->xpt_flags))
  779. list_del_init(&xprt->xpt_list);
  780. /*
  781. * We used to delete the transport from whichever list
  782. * it's sk_xprt.xpt_ready node was on, but we don't actually
  783. * need to. This is because the only time we're called
  784. * while still attached to a queue, the queue itself
  785. * is about to be destroyed (in svc_destroy).
  786. */
  787. if (test_bit(XPT_TEMP, &xprt->xpt_flags))
  788. serv->sv_tmpcnt--;
  789. for (dr = svc_deferred_dequeue(xprt); dr;
  790. dr = svc_deferred_dequeue(xprt)) {
  791. svc_xprt_put(xprt);
  792. kfree(dr);
  793. }
  794. svc_xprt_put(xprt);
  795. spin_unlock_bh(&serv->sv_lock);
  796. }
  797. void svc_close_xprt(struct svc_xprt *xprt)
  798. {
  799. set_bit(XPT_CLOSE, &xprt->xpt_flags);
  800. if (test_and_set_bit(XPT_BUSY, &xprt->xpt_flags))
  801. /* someone else will have to effect the close */
  802. return;
  803. svc_xprt_get(xprt);
  804. svc_delete_xprt(xprt);
  805. clear_bit(XPT_BUSY, &xprt->xpt_flags);
  806. svc_xprt_put(xprt);
  807. }
  808. EXPORT_SYMBOL_GPL(svc_close_xprt);
  809. void svc_close_all(struct list_head *xprt_list)
  810. {
  811. struct svc_xprt *xprt;
  812. struct svc_xprt *tmp;
  813. list_for_each_entry_safe(xprt, tmp, xprt_list, xpt_list) {
  814. set_bit(XPT_CLOSE, &xprt->xpt_flags);
  815. if (test_bit(XPT_BUSY, &xprt->xpt_flags)) {
  816. /* Waiting to be processed, but no threads left,
  817. * So just remove it from the waiting list
  818. */
  819. list_del_init(&xprt->xpt_ready);
  820. clear_bit(XPT_BUSY, &xprt->xpt_flags);
  821. }
  822. svc_close_xprt(xprt);
  823. }
  824. }
  825. /*
  826. * Handle defer and revisit of requests
  827. */
  828. static void svc_revisit(struct cache_deferred_req *dreq, int too_many)
  829. {
  830. struct svc_deferred_req *dr =
  831. container_of(dreq, struct svc_deferred_req, handle);
  832. struct svc_xprt *xprt = dr->xprt;
  833. spin_lock(&xprt->xpt_lock);
  834. set_bit(XPT_DEFERRED, &xprt->xpt_flags);
  835. if (too_many || test_bit(XPT_DEAD, &xprt->xpt_flags)) {
  836. spin_unlock(&xprt->xpt_lock);
  837. dprintk("revisit canceled\n");
  838. svc_xprt_put(xprt);
  839. kfree(dr);
  840. return;
  841. }
  842. dprintk("revisit queued\n");
  843. dr->xprt = NULL;
  844. list_add(&dr->handle.recent, &xprt->xpt_deferred);
  845. spin_unlock(&xprt->xpt_lock);
  846. svc_xprt_enqueue(xprt);
  847. svc_xprt_put(xprt);
  848. }
  849. /*
  850. * Save the request off for later processing. The request buffer looks
  851. * like this:
  852. *
  853. * <xprt-header><rpc-header><rpc-pagelist><rpc-tail>
  854. *
  855. * This code can only handle requests that consist of an xprt-header
  856. * and rpc-header.
  857. */
  858. static struct cache_deferred_req *svc_defer(struct cache_req *req)
  859. {
  860. struct svc_rqst *rqstp = container_of(req, struct svc_rqst, rq_chandle);
  861. struct svc_deferred_req *dr;
  862. if (rqstp->rq_arg.page_len || !rqstp->rq_usedeferral)
  863. return NULL; /* if more than a page, give up FIXME */
  864. if (rqstp->rq_deferred) {
  865. dr = rqstp->rq_deferred;
  866. rqstp->rq_deferred = NULL;
  867. } else {
  868. size_t skip;
  869. size_t size;
  870. /* FIXME maybe discard if size too large */
  871. size = sizeof(struct svc_deferred_req) + rqstp->rq_arg.len;
  872. dr = kmalloc(size, GFP_KERNEL);
  873. if (dr == NULL)
  874. return NULL;
  875. dr->handle.owner = rqstp->rq_server;
  876. dr->prot = rqstp->rq_prot;
  877. memcpy(&dr->addr, &rqstp->rq_addr, rqstp->rq_addrlen);
  878. dr->addrlen = rqstp->rq_addrlen;
  879. dr->daddr = rqstp->rq_daddr;
  880. dr->argslen = rqstp->rq_arg.len >> 2;
  881. dr->xprt_hlen = rqstp->rq_xprt_hlen;
  882. /* back up head to the start of the buffer and copy */
  883. skip = rqstp->rq_arg.len - rqstp->rq_arg.head[0].iov_len;
  884. memcpy(dr->args, rqstp->rq_arg.head[0].iov_base - skip,
  885. dr->argslen << 2);
  886. }
  887. svc_xprt_get(rqstp->rq_xprt);
  888. dr->xprt = rqstp->rq_xprt;
  889. dr->handle.revisit = svc_revisit;
  890. return &dr->handle;
  891. }
  892. /*
  893. * recv data from a deferred request into an active one
  894. */
  895. static int svc_deferred_recv(struct svc_rqst *rqstp)
  896. {
  897. struct svc_deferred_req *dr = rqstp->rq_deferred;
  898. /* setup iov_base past transport header */
  899. rqstp->rq_arg.head[0].iov_base = dr->args + (dr->xprt_hlen>>2);
  900. /* The iov_len does not include the transport header bytes */
  901. rqstp->rq_arg.head[0].iov_len = (dr->argslen<<2) - dr->xprt_hlen;
  902. rqstp->rq_arg.page_len = 0;
  903. /* The rq_arg.len includes the transport header bytes */
  904. rqstp->rq_arg.len = dr->argslen<<2;
  905. rqstp->rq_prot = dr->prot;
  906. memcpy(&rqstp->rq_addr, &dr->addr, dr->addrlen);
  907. rqstp->rq_addrlen = dr->addrlen;
  908. /* Save off transport header len in case we get deferred again */
  909. rqstp->rq_xprt_hlen = dr->xprt_hlen;
  910. rqstp->rq_daddr = dr->daddr;
  911. rqstp->rq_respages = rqstp->rq_pages;
  912. return (dr->argslen<<2) - dr->xprt_hlen;
  913. }
  914. static struct svc_deferred_req *svc_deferred_dequeue(struct svc_xprt *xprt)
  915. {
  916. struct svc_deferred_req *dr = NULL;
  917. if (!test_bit(XPT_DEFERRED, &xprt->xpt_flags))
  918. return NULL;
  919. spin_lock(&xprt->xpt_lock);
  920. clear_bit(XPT_DEFERRED, &xprt->xpt_flags);
  921. if (!list_empty(&xprt->xpt_deferred)) {
  922. dr = list_entry(xprt->xpt_deferred.next,
  923. struct svc_deferred_req,
  924. handle.recent);
  925. list_del_init(&dr->handle.recent);
  926. set_bit(XPT_DEFERRED, &xprt->xpt_flags);
  927. }
  928. spin_unlock(&xprt->xpt_lock);
  929. return dr;
  930. }
  931. /**
  932. * svc_find_xprt - find an RPC transport instance
  933. * @serv: pointer to svc_serv to search
  934. * @xcl_name: C string containing transport's class name
  935. * @af: Address family of transport's local address
  936. * @port: transport's IP port number
  937. *
  938. * Return the transport instance pointer for the endpoint accepting
  939. * connections/peer traffic from the specified transport class,
  940. * address family and port.
  941. *
  942. * Specifying 0 for the address family or port is effectively a
  943. * wild-card, and will result in matching the first transport in the
  944. * service's list that has a matching class name.
  945. */
  946. struct svc_xprt *svc_find_xprt(struct svc_serv *serv, const char *xcl_name,
  947. const sa_family_t af, const unsigned short port)
  948. {
  949. struct svc_xprt *xprt;
  950. struct svc_xprt *found = NULL;
  951. /* Sanity check the args */
  952. if (serv == NULL || xcl_name == NULL)
  953. return found;
  954. spin_lock_bh(&serv->sv_lock);
  955. list_for_each_entry(xprt, &serv->sv_permsocks, xpt_list) {
  956. if (strcmp(xprt->xpt_class->xcl_name, xcl_name))
  957. continue;
  958. if (af != AF_UNSPEC && af != xprt->xpt_local.ss_family)
  959. continue;
  960. if (port != 0 && port != svc_xprt_local_port(xprt))
  961. continue;
  962. found = xprt;
  963. svc_xprt_get(xprt);
  964. break;
  965. }
  966. spin_unlock_bh(&serv->sv_lock);
  967. return found;
  968. }
  969. EXPORT_SYMBOL_GPL(svc_find_xprt);
  970. /*
  971. * Format a buffer with a list of the active transports. A zero for
  972. * the buflen parameter disables target buffer overflow checking.
  973. */
  974. int svc_xprt_names(struct svc_serv *serv, char *buf, int buflen)
  975. {
  976. struct svc_xprt *xprt;
  977. char xprt_str[64];
  978. int totlen = 0;
  979. int len;
  980. /* Sanity check args */
  981. if (!serv)
  982. return 0;
  983. spin_lock_bh(&serv->sv_lock);
  984. list_for_each_entry(xprt, &serv->sv_permsocks, xpt_list) {
  985. len = snprintf(xprt_str, sizeof(xprt_str),
  986. "%s %d\n", xprt->xpt_class->xcl_name,
  987. svc_xprt_local_port(xprt));
  988. /* If the string was truncated, replace with error string */
  989. if (len >= sizeof(xprt_str))
  990. strcpy(xprt_str, "name-too-long\n");
  991. /* Don't overflow buffer */
  992. len = strlen(xprt_str);
  993. if (buflen && (len + totlen >= buflen))
  994. break;
  995. strcpy(buf+totlen, xprt_str);
  996. totlen += len;
  997. }
  998. spin_unlock_bh(&serv->sv_lock);
  999. return totlen;
  1000. }
  1001. EXPORT_SYMBOL_GPL(svc_xprt_names);
  1002. /*----------------------------------------------------------------------------*/
  1003. static void *svc_pool_stats_start(struct seq_file *m, loff_t *pos)
  1004. {
  1005. unsigned int pidx = (unsigned int)*pos;
  1006. struct svc_serv *serv = m->private;
  1007. dprintk("svc_pool_stats_start, *pidx=%u\n", pidx);
  1008. lock_kernel();
  1009. /* bump up the pseudo refcount while traversing */
  1010. svc_get(serv);
  1011. unlock_kernel();
  1012. if (!pidx)
  1013. return SEQ_START_TOKEN;
  1014. return (pidx > serv->sv_nrpools ? NULL : &serv->sv_pools[pidx-1]);
  1015. }
  1016. static void *svc_pool_stats_next(struct seq_file *m, void *p, loff_t *pos)
  1017. {
  1018. struct svc_pool *pool = p;
  1019. struct svc_serv *serv = m->private;
  1020. dprintk("svc_pool_stats_next, *pos=%llu\n", *pos);
  1021. if (p == SEQ_START_TOKEN) {
  1022. pool = &serv->sv_pools[0];
  1023. } else {
  1024. unsigned int pidx = (pool - &serv->sv_pools[0]);
  1025. if (pidx < serv->sv_nrpools-1)
  1026. pool = &serv->sv_pools[pidx+1];
  1027. else
  1028. pool = NULL;
  1029. }
  1030. ++*pos;
  1031. return pool;
  1032. }
  1033. static void svc_pool_stats_stop(struct seq_file *m, void *p)
  1034. {
  1035. struct svc_serv *serv = m->private;
  1036. lock_kernel();
  1037. /* this function really, really should have been called svc_put() */
  1038. svc_destroy(serv);
  1039. unlock_kernel();
  1040. }
  1041. static int svc_pool_stats_show(struct seq_file *m, void *p)
  1042. {
  1043. struct svc_pool *pool = p;
  1044. if (p == SEQ_START_TOKEN) {
  1045. seq_puts(m, "# pool packets-arrived sockets-enqueued threads-woken overloads-avoided threads-timedout\n");
  1046. return 0;
  1047. }
  1048. seq_printf(m, "%u %lu %lu %lu %lu %lu\n",
  1049. pool->sp_id,
  1050. pool->sp_stats.packets,
  1051. pool->sp_stats.sockets_queued,
  1052. pool->sp_stats.threads_woken,
  1053. pool->sp_stats.overloads_avoided,
  1054. pool->sp_stats.threads_timedout);
  1055. return 0;
  1056. }
  1057. static const struct seq_operations svc_pool_stats_seq_ops = {
  1058. .start = svc_pool_stats_start,
  1059. .next = svc_pool_stats_next,
  1060. .stop = svc_pool_stats_stop,
  1061. .show = svc_pool_stats_show,
  1062. };
  1063. int svc_pool_stats_open(struct svc_serv *serv, struct file *file)
  1064. {
  1065. int err;
  1066. err = seq_open(file, &svc_pool_stats_seq_ops);
  1067. if (!err)
  1068. ((struct seq_file *) file->private_data)->private = serv;
  1069. return err;
  1070. }
  1071. EXPORT_SYMBOL(svc_pool_stats_open);
  1072. /*----------------------------------------------------------------------------*/