svc_rdma_recvfrom.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /*
  2. * Copyright (c) 2005-2006 Network Appliance, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the BSD-type
  8. * license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. *
  17. * Redistributions in binary form must reproduce the above
  18. * copyright notice, this list of conditions and the following
  19. * disclaimer in the documentation and/or other materials provided
  20. * with the distribution.
  21. *
  22. * Neither the name of the Network Appliance, Inc. nor the names of
  23. * its contributors may be used to endorse or promote products
  24. * derived from this software without specific prior written
  25. * permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  30. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  31. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  33. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  34. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  35. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  36. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  37. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * Author: Tom Tucker <tom@opengridcomputing.com>
  40. */
  41. #include <linux/sunrpc/debug.h>
  42. #include <linux/sunrpc/rpc_rdma.h>
  43. #include <linux/spinlock.h>
  44. #include <asm/unaligned.h>
  45. #include <rdma/ib_verbs.h>
  46. #include <rdma/rdma_cm.h>
  47. #include <linux/sunrpc/svc_rdma.h>
  48. #define RPCDBG_FACILITY RPCDBG_SVCXPRT
  49. /*
  50. * Replace the pages in the rq_argpages array with the pages from the SGE in
  51. * the RDMA_RECV completion. The SGL should contain full pages up until the
  52. * last one.
  53. */
  54. static void rdma_build_arg_xdr(struct svc_rqst *rqstp,
  55. struct svc_rdma_op_ctxt *ctxt,
  56. u32 byte_count)
  57. {
  58. struct page *page;
  59. u32 bc;
  60. int sge_no;
  61. /* Swap the page in the SGE with the page in argpages */
  62. page = ctxt->pages[0];
  63. put_page(rqstp->rq_pages[0]);
  64. rqstp->rq_pages[0] = page;
  65. /* Set up the XDR head */
  66. rqstp->rq_arg.head[0].iov_base = page_address(page);
  67. rqstp->rq_arg.head[0].iov_len = min(byte_count, ctxt->sge[0].length);
  68. rqstp->rq_arg.len = byte_count;
  69. rqstp->rq_arg.buflen = byte_count;
  70. /* Compute bytes past head in the SGL */
  71. bc = byte_count - rqstp->rq_arg.head[0].iov_len;
  72. /* If data remains, store it in the pagelist */
  73. rqstp->rq_arg.page_len = bc;
  74. rqstp->rq_arg.page_base = 0;
  75. rqstp->rq_arg.pages = &rqstp->rq_pages[1];
  76. sge_no = 1;
  77. while (bc && sge_no < ctxt->count) {
  78. page = ctxt->pages[sge_no];
  79. put_page(rqstp->rq_pages[sge_no]);
  80. rqstp->rq_pages[sge_no] = page;
  81. bc -= min(bc, ctxt->sge[sge_no].length);
  82. rqstp->rq_arg.buflen += ctxt->sge[sge_no].length;
  83. sge_no++;
  84. }
  85. rqstp->rq_respages = &rqstp->rq_pages[sge_no];
  86. /* We should never run out of SGE because the limit is defined to
  87. * support the max allowed RPC data length
  88. */
  89. BUG_ON(bc && (sge_no == ctxt->count));
  90. BUG_ON((rqstp->rq_arg.head[0].iov_len + rqstp->rq_arg.page_len)
  91. != byte_count);
  92. BUG_ON(rqstp->rq_arg.len != byte_count);
  93. /* If not all pages were used from the SGL, free the remaining ones */
  94. bc = sge_no;
  95. while (sge_no < ctxt->count) {
  96. page = ctxt->pages[sge_no++];
  97. put_page(page);
  98. }
  99. ctxt->count = bc;
  100. /* Set up tail */
  101. rqstp->rq_arg.tail[0].iov_base = NULL;
  102. rqstp->rq_arg.tail[0].iov_len = 0;
  103. }
  104. struct chunk_sge {
  105. int start; /* sge no for this chunk */
  106. int count; /* sge count for this chunk */
  107. };
  108. /* Encode a read-chunk-list as an array of IB SGE
  109. *
  110. * Assumptions:
  111. * - chunk[0]->position points to pages[0] at an offset of 0
  112. * - pages[] is not physically or virtually contigous and consists of
  113. * PAGE_SIZE elements.
  114. *
  115. * Output:
  116. * - sge array pointing into pages[] array.
  117. * - chunk_sge array specifying sge index and count for each
  118. * chunk in the read list
  119. *
  120. */
  121. static int rdma_rcl_to_sge(struct svcxprt_rdma *xprt,
  122. struct svc_rqst *rqstp,
  123. struct svc_rdma_op_ctxt *head,
  124. struct rpcrdma_msg *rmsgp,
  125. struct ib_sge *sge,
  126. struct chunk_sge *ch_sge_ary,
  127. int ch_count,
  128. int byte_count)
  129. {
  130. int sge_no;
  131. int sge_bytes;
  132. int page_off;
  133. int page_no;
  134. int ch_bytes;
  135. int ch_no;
  136. struct rpcrdma_read_chunk *ch;
  137. sge_no = 0;
  138. page_no = 0;
  139. page_off = 0;
  140. ch = (struct rpcrdma_read_chunk *)&rmsgp->rm_body.rm_chunks[0];
  141. ch_no = 0;
  142. ch_bytes = ch->rc_target.rs_length;
  143. head->arg.head[0] = rqstp->rq_arg.head[0];
  144. head->arg.tail[0] = rqstp->rq_arg.tail[0];
  145. head->arg.pages = &head->pages[head->count];
  146. head->sge[0].length = head->count; /* save count of hdr pages */
  147. head->arg.page_base = 0;
  148. head->arg.page_len = ch_bytes;
  149. head->arg.len = rqstp->rq_arg.len + ch_bytes;
  150. head->arg.buflen = rqstp->rq_arg.buflen + ch_bytes;
  151. head->count++;
  152. ch_sge_ary[0].start = 0;
  153. while (byte_count) {
  154. sge_bytes = min_t(int, PAGE_SIZE-page_off, ch_bytes);
  155. sge[sge_no].addr =
  156. ib_dma_map_page(xprt->sc_cm_id->device,
  157. rqstp->rq_arg.pages[page_no],
  158. page_off, sge_bytes,
  159. DMA_FROM_DEVICE);
  160. sge[sge_no].length = sge_bytes;
  161. sge[sge_no].lkey = xprt->sc_phys_mr->lkey;
  162. /*
  163. * Don't bump head->count here because the same page
  164. * may be used by multiple SGE.
  165. */
  166. head->arg.pages[page_no] = rqstp->rq_arg.pages[page_no];
  167. rqstp->rq_respages = &rqstp->rq_arg.pages[page_no+1];
  168. byte_count -= sge_bytes;
  169. ch_bytes -= sge_bytes;
  170. sge_no++;
  171. /*
  172. * If all bytes for this chunk have been mapped to an
  173. * SGE, move to the next SGE
  174. */
  175. if (ch_bytes == 0) {
  176. ch_sge_ary[ch_no].count =
  177. sge_no - ch_sge_ary[ch_no].start;
  178. ch_no++;
  179. ch++;
  180. ch_sge_ary[ch_no].start = sge_no;
  181. ch_bytes = ch->rc_target.rs_length;
  182. /* If bytes remaining account for next chunk */
  183. if (byte_count) {
  184. head->arg.page_len += ch_bytes;
  185. head->arg.len += ch_bytes;
  186. head->arg.buflen += ch_bytes;
  187. }
  188. }
  189. /*
  190. * If this SGE consumed all of the page, move to the
  191. * next page
  192. */
  193. if ((sge_bytes + page_off) == PAGE_SIZE) {
  194. page_no++;
  195. page_off = 0;
  196. /*
  197. * If there are still bytes left to map, bump
  198. * the page count
  199. */
  200. if (byte_count)
  201. head->count++;
  202. } else
  203. page_off += sge_bytes;
  204. }
  205. BUG_ON(byte_count != 0);
  206. return sge_no;
  207. }
  208. static void rdma_set_ctxt_sge(struct svc_rdma_op_ctxt *ctxt,
  209. struct ib_sge *sge,
  210. u64 *sgl_offset,
  211. int count)
  212. {
  213. int i;
  214. ctxt->count = count;
  215. for (i = 0; i < count; i++) {
  216. ctxt->sge[i].addr = sge[i].addr;
  217. ctxt->sge[i].length = sge[i].length;
  218. *sgl_offset = *sgl_offset + sge[i].length;
  219. }
  220. }
  221. static int rdma_read_max_sge(struct svcxprt_rdma *xprt, int sge_count)
  222. {
  223. if ((RDMA_TRANSPORT_IWARP ==
  224. rdma_node_get_transport(xprt->sc_cm_id->
  225. device->node_type))
  226. && sge_count > 1)
  227. return 1;
  228. else
  229. return min_t(int, sge_count, xprt->sc_max_sge);
  230. }
  231. /*
  232. * Use RDMA_READ to read data from the advertised client buffer into the
  233. * XDR stream starting at rq_arg.head[0].iov_base.
  234. * Each chunk in the array
  235. * contains the following fields:
  236. * discrim - '1', This isn't used for data placement
  237. * position - The xdr stream offset (the same for every chunk)
  238. * handle - RMR for client memory region
  239. * length - data transfer length
  240. * offset - 64 bit tagged offset in remote memory region
  241. *
  242. * On our side, we need to read into a pagelist. The first page immediately
  243. * follows the RPC header.
  244. *
  245. * This function returns 1 to indicate success. The data is not yet in
  246. * the pagelist and therefore the RPC request must be deferred. The
  247. * I/O completion will enqueue the transport again and
  248. * svc_rdma_recvfrom will complete the request.
  249. *
  250. * NOTE: The ctxt must not be touched after the last WR has been posted
  251. * because the I/O completion processing may occur on another
  252. * processor and free / modify the context. Ne touche pas!
  253. */
  254. static int rdma_read_xdr(struct svcxprt_rdma *xprt,
  255. struct rpcrdma_msg *rmsgp,
  256. struct svc_rqst *rqstp,
  257. struct svc_rdma_op_ctxt *hdr_ctxt)
  258. {
  259. struct ib_send_wr read_wr;
  260. int err = 0;
  261. int ch_no;
  262. struct ib_sge *sge;
  263. int ch_count;
  264. int byte_count;
  265. int sge_count;
  266. u64 sgl_offset;
  267. struct rpcrdma_read_chunk *ch;
  268. struct svc_rdma_op_ctxt *ctxt = NULL;
  269. struct svc_rdma_op_ctxt *head;
  270. struct svc_rdma_op_ctxt *tmp_sge_ctxt;
  271. struct svc_rdma_op_ctxt *tmp_ch_ctxt;
  272. struct chunk_sge *ch_sge_ary;
  273. /* If no read list is present, return 0 */
  274. ch = svc_rdma_get_read_chunk(rmsgp);
  275. if (!ch)
  276. return 0;
  277. /* Allocate temporary contexts to keep SGE */
  278. BUG_ON(sizeof(struct ib_sge) < sizeof(struct chunk_sge));
  279. tmp_sge_ctxt = svc_rdma_get_context(xprt);
  280. sge = tmp_sge_ctxt->sge;
  281. tmp_ch_ctxt = svc_rdma_get_context(xprt);
  282. ch_sge_ary = (struct chunk_sge *)tmp_ch_ctxt->sge;
  283. svc_rdma_rcl_chunk_counts(ch, &ch_count, &byte_count);
  284. sge_count = rdma_rcl_to_sge(xprt, rqstp, hdr_ctxt, rmsgp,
  285. sge, ch_sge_ary,
  286. ch_count, byte_count);
  287. head = svc_rdma_get_context(xprt);
  288. sgl_offset = 0;
  289. ch_no = 0;
  290. for (ch = (struct rpcrdma_read_chunk *)&rmsgp->rm_body.rm_chunks[0];
  291. ch->rc_discrim != 0; ch++, ch_no++) {
  292. next_sge:
  293. if (!ctxt)
  294. ctxt = head;
  295. else {
  296. ctxt->next = svc_rdma_get_context(xprt);
  297. ctxt = ctxt->next;
  298. }
  299. ctxt->next = NULL;
  300. ctxt->direction = DMA_FROM_DEVICE;
  301. clear_bit(RDMACTXT_F_READ_DONE, &ctxt->flags);
  302. clear_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags);
  303. /* Prepare READ WR */
  304. memset(&read_wr, 0, sizeof read_wr);
  305. ctxt->wr_op = IB_WR_RDMA_READ;
  306. read_wr.wr_id = (unsigned long)ctxt;
  307. read_wr.opcode = IB_WR_RDMA_READ;
  308. read_wr.send_flags = IB_SEND_SIGNALED;
  309. read_wr.wr.rdma.rkey = ch->rc_target.rs_handle;
  310. read_wr.wr.rdma.remote_addr =
  311. get_unaligned(&(ch->rc_target.rs_offset)) +
  312. sgl_offset;
  313. read_wr.sg_list = &sge[ch_sge_ary[ch_no].start];
  314. read_wr.num_sge =
  315. rdma_read_max_sge(xprt, ch_sge_ary[ch_no].count);
  316. rdma_set_ctxt_sge(ctxt, &sge[ch_sge_ary[ch_no].start],
  317. &sgl_offset,
  318. read_wr.num_sge);
  319. if (((ch+1)->rc_discrim == 0) &&
  320. (read_wr.num_sge == ch_sge_ary[ch_no].count)) {
  321. /*
  322. * Mark the last RDMA_READ with a bit to
  323. * indicate all RPC data has been fetched from
  324. * the client and the RPC needs to be enqueued.
  325. */
  326. set_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags);
  327. ctxt->next = hdr_ctxt;
  328. hdr_ctxt->next = head;
  329. }
  330. /* Post the read */
  331. err = svc_rdma_send(xprt, &read_wr);
  332. if (err) {
  333. printk(KERN_ERR "svcrdma: Error posting send = %d\n",
  334. err);
  335. /*
  336. * Break the circular list so free knows when
  337. * to stop if the error happened to occur on
  338. * the last read
  339. */
  340. ctxt->next = NULL;
  341. goto out;
  342. }
  343. atomic_inc(&rdma_stat_read);
  344. if (read_wr.num_sge < ch_sge_ary[ch_no].count) {
  345. ch_sge_ary[ch_no].count -= read_wr.num_sge;
  346. ch_sge_ary[ch_no].start += read_wr.num_sge;
  347. goto next_sge;
  348. }
  349. sgl_offset = 0;
  350. err = 0;
  351. }
  352. out:
  353. svc_rdma_put_context(tmp_sge_ctxt, 0);
  354. svc_rdma_put_context(tmp_ch_ctxt, 0);
  355. /* Detach arg pages. svc_recv will replenish them */
  356. for (ch_no = 0; &rqstp->rq_pages[ch_no] < rqstp->rq_respages; ch_no++)
  357. rqstp->rq_pages[ch_no] = NULL;
  358. /*
  359. * Detach res pages. svc_release must see a resused count of
  360. * zero or it will attempt to put them.
  361. */
  362. while (rqstp->rq_resused)
  363. rqstp->rq_respages[--rqstp->rq_resused] = NULL;
  364. if (err) {
  365. printk(KERN_ERR "svcrdma : RDMA_READ error = %d\n", err);
  366. set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
  367. /* Free the linked list of read contexts */
  368. while (head != NULL) {
  369. ctxt = head->next;
  370. svc_rdma_put_context(head, 1);
  371. head = ctxt;
  372. }
  373. return 0;
  374. }
  375. return 1;
  376. }
  377. static int rdma_read_complete(struct svc_rqst *rqstp,
  378. struct svc_rdma_op_ctxt *data)
  379. {
  380. struct svc_rdma_op_ctxt *head = data->next;
  381. int page_no;
  382. int ret;
  383. BUG_ON(!head);
  384. /* Copy RPC pages */
  385. for (page_no = 0; page_no < head->count; page_no++) {
  386. put_page(rqstp->rq_pages[page_no]);
  387. rqstp->rq_pages[page_no] = head->pages[page_no];
  388. }
  389. /* Point rq_arg.pages past header */
  390. rqstp->rq_arg.pages = &rqstp->rq_pages[head->sge[0].length];
  391. rqstp->rq_arg.page_len = head->arg.page_len;
  392. rqstp->rq_arg.page_base = head->arg.page_base;
  393. /* rq_respages starts after the last arg page */
  394. rqstp->rq_respages = &rqstp->rq_arg.pages[page_no];
  395. rqstp->rq_resused = 0;
  396. /* Rebuild rq_arg head and tail. */
  397. rqstp->rq_arg.head[0] = head->arg.head[0];
  398. rqstp->rq_arg.tail[0] = head->arg.tail[0];
  399. rqstp->rq_arg.len = head->arg.len;
  400. rqstp->rq_arg.buflen = head->arg.buflen;
  401. /* XXX: What should this be? */
  402. rqstp->rq_prot = IPPROTO_MAX;
  403. /*
  404. * Free the contexts we used to build the RDMA_READ. We have
  405. * to be careful here because the context list uses the same
  406. * next pointer used to chain the contexts associated with the
  407. * RDMA_READ
  408. */
  409. data->next = NULL; /* terminate circular list */
  410. do {
  411. data = head->next;
  412. svc_rdma_put_context(head, 0);
  413. head = data;
  414. } while (head != NULL);
  415. ret = rqstp->rq_arg.head[0].iov_len
  416. + rqstp->rq_arg.page_len
  417. + rqstp->rq_arg.tail[0].iov_len;
  418. dprintk("svcrdma: deferred read ret=%d, rq_arg.len =%d, "
  419. "rq_arg.head[0].iov_base=%p, rq_arg.head[0].iov_len = %zd\n",
  420. ret, rqstp->rq_arg.len, rqstp->rq_arg.head[0].iov_base,
  421. rqstp->rq_arg.head[0].iov_len);
  422. /* Indicate that we've consumed an RQ credit */
  423. rqstp->rq_xprt_ctxt = rqstp->rq_xprt;
  424. svc_xprt_received(rqstp->rq_xprt);
  425. return ret;
  426. }
  427. /*
  428. * Set up the rqstp thread context to point to the RQ buffer. If
  429. * necessary, pull additional data from the client with an RDMA_READ
  430. * request.
  431. */
  432. int svc_rdma_recvfrom(struct svc_rqst *rqstp)
  433. {
  434. struct svc_xprt *xprt = rqstp->rq_xprt;
  435. struct svcxprt_rdma *rdma_xprt =
  436. container_of(xprt, struct svcxprt_rdma, sc_xprt);
  437. struct svc_rdma_op_ctxt *ctxt = NULL;
  438. struct rpcrdma_msg *rmsgp;
  439. int ret = 0;
  440. int len;
  441. dprintk("svcrdma: rqstp=%p\n", rqstp);
  442. /*
  443. * The rq_xprt_ctxt indicates if we've consumed an RQ credit
  444. * or not. It is used in the rdma xpo_release_rqst function to
  445. * determine whether or not to return an RQ WQE to the RQ.
  446. */
  447. rqstp->rq_xprt_ctxt = NULL;
  448. spin_lock_bh(&rdma_xprt->sc_read_complete_lock);
  449. if (!list_empty(&rdma_xprt->sc_read_complete_q)) {
  450. ctxt = list_entry(rdma_xprt->sc_read_complete_q.next,
  451. struct svc_rdma_op_ctxt,
  452. dto_q);
  453. list_del_init(&ctxt->dto_q);
  454. }
  455. spin_unlock_bh(&rdma_xprt->sc_read_complete_lock);
  456. if (ctxt)
  457. return rdma_read_complete(rqstp, ctxt);
  458. spin_lock_bh(&rdma_xprt->sc_rq_dto_lock);
  459. if (!list_empty(&rdma_xprt->sc_rq_dto_q)) {
  460. ctxt = list_entry(rdma_xprt->sc_rq_dto_q.next,
  461. struct svc_rdma_op_ctxt,
  462. dto_q);
  463. list_del_init(&ctxt->dto_q);
  464. } else {
  465. atomic_inc(&rdma_stat_rq_starve);
  466. clear_bit(XPT_DATA, &xprt->xpt_flags);
  467. ctxt = NULL;
  468. }
  469. spin_unlock_bh(&rdma_xprt->sc_rq_dto_lock);
  470. if (!ctxt) {
  471. /* This is the EAGAIN path. The svc_recv routine will
  472. * return -EAGAIN, the nfsd thread will go to call into
  473. * svc_recv again and we shouldn't be on the active
  474. * transport list
  475. */
  476. if (test_bit(XPT_CLOSE, &xprt->xpt_flags))
  477. goto close_out;
  478. BUG_ON(ret);
  479. goto out;
  480. }
  481. dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
  482. ctxt, rdma_xprt, rqstp, ctxt->wc_status);
  483. BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
  484. atomic_inc(&rdma_stat_recv);
  485. /* Build up the XDR from the receive buffers. */
  486. rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
  487. /* Decode the RDMA header. */
  488. len = svc_rdma_xdr_decode_req(&rmsgp, rqstp);
  489. rqstp->rq_xprt_hlen = len;
  490. /* If the request is invalid, reply with an error */
  491. if (len < 0) {
  492. if (len == -ENOSYS)
  493. (void)svc_rdma_send_error(rdma_xprt, rmsgp, ERR_VERS);
  494. goto close_out;
  495. }
  496. /* Read read-list data. If we would need to wait, defer
  497. * it. Not that in this case, we don't return the RQ credit
  498. * until after the read completes.
  499. */
  500. if (rdma_read_xdr(rdma_xprt, rmsgp, rqstp, ctxt)) {
  501. svc_xprt_received(xprt);
  502. return 0;
  503. }
  504. /* Indicate we've consumed an RQ credit */
  505. rqstp->rq_xprt_ctxt = rqstp->rq_xprt;
  506. ret = rqstp->rq_arg.head[0].iov_len
  507. + rqstp->rq_arg.page_len
  508. + rqstp->rq_arg.tail[0].iov_len;
  509. svc_rdma_put_context(ctxt, 0);
  510. out:
  511. dprintk("svcrdma: ret = %d, rq_arg.len =%d, "
  512. "rq_arg.head[0].iov_base=%p, rq_arg.head[0].iov_len = %zd\n",
  513. ret, rqstp->rq_arg.len,
  514. rqstp->rq_arg.head[0].iov_base,
  515. rqstp->rq_arg.head[0].iov_len);
  516. rqstp->rq_prot = IPPROTO_MAX;
  517. svc_xprt_copy_addrs(rqstp, xprt);
  518. svc_xprt_received(xprt);
  519. return ret;
  520. close_out:
  521. if (ctxt) {
  522. svc_rdma_put_context(ctxt, 1);
  523. /* Indicate we've consumed an RQ credit */
  524. rqstp->rq_xprt_ctxt = rqstp->rq_xprt;
  525. }
  526. dprintk("svcrdma: transport %p is closing\n", xprt);
  527. /*
  528. * Set the close bit and enqueue it. svc_recv will see the
  529. * close bit and call svc_xprt_delete
  530. */
  531. set_bit(XPT_CLOSE, &xprt->xpt_flags);
  532. svc_xprt_received(xprt);
  533. return 0;
  534. }