2 * Copyright (c) 2003-2007 Network Appliance, Inc. All rights reserved.
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
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
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.
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
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.
43 * This file contains the top-level implementation of an RPC RDMA
46 * Naming convention: functions beginning with xprt_ are part of the
47 * transport switch. All others are RPC RDMA internal.
50 #include <linux/module.h>
51 #include <linux/init.h>
52 #include <linux/slab.h>
53 #include <linux/seq_file.h>
55 #include "xprt_rdma.h"
58 # define RPCDBG_FACILITY RPCDBG_TRANS
61 MODULE_LICENSE("Dual BSD/GPL");
63 MODULE_DESCRIPTION("RPC/RDMA Transport for Linux kernel NFS");
64 MODULE_AUTHOR("Network Appliance, Inc.");
70 static unsigned int xprt_rdma_slot_table_entries
= RPCRDMA_DEF_SLOT_TABLE
;
71 static unsigned int xprt_rdma_max_inline_read
= RPCRDMA_DEF_INLINE
;
72 static unsigned int xprt_rdma_max_inline_write
= RPCRDMA_DEF_INLINE
;
73 static unsigned int xprt_rdma_inline_write_padding
;
74 static unsigned int xprt_rdma_memreg_strategy
= RPCRDMA_FRMR
;
75 int xprt_rdma_pad_optimize
= 0;
79 static unsigned int min_slot_table_size
= RPCRDMA_MIN_SLOT_TABLE
;
80 static unsigned int max_slot_table_size
= RPCRDMA_MAX_SLOT_TABLE
;
81 static unsigned int zero
;
82 static unsigned int max_padding
= PAGE_SIZE
;
83 static unsigned int min_memreg
= RPCRDMA_BOUNCEBUFFERS
;
84 static unsigned int max_memreg
= RPCRDMA_LAST
- 1;
86 static struct ctl_table_header
*sunrpc_table_header
;
88 static ctl_table xr_tunables_table
[] = {
90 .procname
= "rdma_slot_table_entries",
91 .data
= &xprt_rdma_slot_table_entries
,
92 .maxlen
= sizeof(unsigned int),
94 .proc_handler
= proc_dointvec_minmax
,
95 .extra1
= &min_slot_table_size
,
96 .extra2
= &max_slot_table_size
99 .procname
= "rdma_max_inline_read",
100 .data
= &xprt_rdma_max_inline_read
,
101 .maxlen
= sizeof(unsigned int),
103 .proc_handler
= proc_dointvec
,
106 .procname
= "rdma_max_inline_write",
107 .data
= &xprt_rdma_max_inline_write
,
108 .maxlen
= sizeof(unsigned int),
110 .proc_handler
= proc_dointvec
,
113 .procname
= "rdma_inline_write_padding",
114 .data
= &xprt_rdma_inline_write_padding
,
115 .maxlen
= sizeof(unsigned int),
117 .proc_handler
= proc_dointvec_minmax
,
119 .extra2
= &max_padding
,
122 .procname
= "rdma_memreg_strategy",
123 .data
= &xprt_rdma_memreg_strategy
,
124 .maxlen
= sizeof(unsigned int),
126 .proc_handler
= proc_dointvec_minmax
,
127 .extra1
= &min_memreg
,
128 .extra2
= &max_memreg
,
131 .procname
= "rdma_pad_optimize",
132 .data
= &xprt_rdma_pad_optimize
,
133 .maxlen
= sizeof(unsigned int),
135 .proc_handler
= proc_dointvec
,
140 static ctl_table sunrpc_table
[] = {
142 .procname
= "sunrpc",
144 .child
= xr_tunables_table
151 static struct rpc_xprt_ops xprt_rdma_procs
; /* forward reference */
154 xprt_rdma_format_addresses(struct rpc_xprt
*xprt
)
156 struct sockaddr
*sap
= (struct sockaddr
*)
157 &rpcx_to_rdmad(xprt
).addr
;
158 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sap
;
161 (void)rpc_ntop(sap
, buf
, sizeof(buf
));
162 xprt
->address_strings
[RPC_DISPLAY_ADDR
] = kstrdup(buf
, GFP_KERNEL
);
164 snprintf(buf
, sizeof(buf
), "%u", rpc_get_port(sap
));
165 xprt
->address_strings
[RPC_DISPLAY_PORT
] = kstrdup(buf
, GFP_KERNEL
);
167 xprt
->address_strings
[RPC_DISPLAY_PROTO
] = "rdma";
169 snprintf(buf
, sizeof(buf
), "%08x", ntohl(sin
->sin_addr
.s_addr
));
170 xprt
->address_strings
[RPC_DISPLAY_HEX_ADDR
] = kstrdup(buf
, GFP_KERNEL
);
172 snprintf(buf
, sizeof(buf
), "%4hx", rpc_get_port(sap
));
173 xprt
->address_strings
[RPC_DISPLAY_HEX_PORT
] = kstrdup(buf
, GFP_KERNEL
);
176 xprt
->address_strings
[RPC_DISPLAY_NETID
] = "rdma";
180 xprt_rdma_free_addresses(struct rpc_xprt
*xprt
)
184 for (i
= 0; i
< RPC_DISPLAY_MAX
; i
++)
186 case RPC_DISPLAY_PROTO
:
187 case RPC_DISPLAY_NETID
:
190 kfree(xprt
->address_strings
[i
]);
195 xprt_rdma_connect_worker(struct work_struct
*work
)
197 struct rpcrdma_xprt
*r_xprt
=
198 container_of(work
, struct rpcrdma_xprt
, rdma_connect
.work
);
199 struct rpc_xprt
*xprt
= &r_xprt
->xprt
;
202 if (!xprt
->shutdown
) {
203 xprt_clear_connected(xprt
);
205 dprintk("RPC: %s: %sconnect\n", __func__
,
206 r_xprt
->rx_ep
.rep_connected
!= 0 ? "re" : "");
207 rc
= rpcrdma_ep_connect(&r_xprt
->rx_ep
, &r_xprt
->rx_ia
);
214 xprt_wake_pending_tasks(xprt
, rc
);
217 dprintk("RPC: %s: exit\n", __func__
);
218 xprt_clear_connecting(xprt
);
225 * Free all memory associated with the object, including its own.
226 * NOTE: none of the *destroy methods free memory for their top-level
227 * objects, even though they may have allocated it (they do free
228 * private memory). It's up to the caller to handle it. In this
229 * case (RDMA transport), all structure memory is inlined with the
230 * struct rpcrdma_xprt.
233 xprt_rdma_destroy(struct rpc_xprt
*xprt
)
235 struct rpcrdma_xprt
*r_xprt
= rpcx_to_rdmax(xprt
);
238 dprintk("RPC: %s: called\n", __func__
);
240 cancel_delayed_work(&r_xprt
->rdma_connect
);
241 flush_scheduled_work();
243 xprt_clear_connected(xprt
);
245 rpcrdma_buffer_destroy(&r_xprt
->rx_buf
);
246 rc
= rpcrdma_ep_destroy(&r_xprt
->rx_ep
, &r_xprt
->rx_ia
);
248 dprintk("RPC: %s: rpcrdma_ep_destroy returned %i\n",
250 rpcrdma_ia_close(&r_xprt
->rx_ia
);
252 xprt_rdma_free_addresses(xprt
);
258 dprintk("RPC: %s: returning\n", __func__
);
260 module_put(THIS_MODULE
);
263 static const struct rpc_timeout xprt_rdma_default_timeout
= {
264 .to_initval
= 60 * HZ
,
265 .to_maxval
= 60 * HZ
,
269 * xprt_setup_rdma - Set up transport to use RDMA
271 * @args: rpc transport arguments
273 static struct rpc_xprt
*
274 xprt_setup_rdma(struct xprt_create
*args
)
276 struct rpcrdma_create_data_internal cdata
;
277 struct rpc_xprt
*xprt
;
278 struct rpcrdma_xprt
*new_xprt
;
279 struct rpcrdma_ep
*new_ep
;
280 struct sockaddr_in
*sin
;
283 if (args
->addrlen
> sizeof(xprt
->addr
)) {
284 dprintk("RPC: %s: address too large\n", __func__
);
285 return ERR_PTR(-EBADF
);
288 xprt
= kzalloc(sizeof(struct rpcrdma_xprt
), GFP_KERNEL
);
290 dprintk("RPC: %s: couldn't allocate rpcrdma_xprt\n",
292 return ERR_PTR(-ENOMEM
);
295 xprt
->max_reqs
= xprt_rdma_slot_table_entries
;
296 xprt
->slot
= kcalloc(xprt
->max_reqs
,
297 sizeof(struct rpc_rqst
), GFP_KERNEL
);
298 if (xprt
->slot
== NULL
) {
299 dprintk("RPC: %s: couldn't allocate %d slots\n",
300 __func__
, xprt
->max_reqs
);
302 return ERR_PTR(-ENOMEM
);
305 /* 60 second timeout, no retries */
306 xprt
->timeout
= &xprt_rdma_default_timeout
;
307 xprt
->bind_timeout
= (60U * HZ
);
308 xprt
->connect_timeout
= (60U * HZ
);
309 xprt
->reestablish_timeout
= (5U * HZ
);
310 xprt
->idle_timeout
= (5U * 60 * HZ
);
312 xprt
->resvport
= 0; /* privileged port not needed */
313 xprt
->tsh_size
= 0; /* RPC-RDMA handles framing */
314 xprt
->max_payload
= RPCRDMA_MAX_DATA_SEGS
* PAGE_SIZE
;
315 xprt
->ops
= &xprt_rdma_procs
;
318 * Set up RDMA-specific connect data.
321 /* Put server RDMA address in local cdata */
322 memcpy(&cdata
.addr
, args
->dstaddr
, args
->addrlen
);
324 /* Ensure xprt->addr holds valid server TCP (not RDMA)
325 * address, for any side protocols which peek at it */
326 xprt
->prot
= IPPROTO_TCP
;
327 xprt
->addrlen
= args
->addrlen
;
328 memcpy(&xprt
->addr
, &cdata
.addr
, xprt
->addrlen
);
330 sin
= (struct sockaddr_in
*)&cdata
.addr
;
331 if (ntohs(sin
->sin_port
) != 0)
332 xprt_set_bound(xprt
);
334 dprintk("RPC: %s: %pI4:%u\n",
335 __func__
, &sin
->sin_addr
.s_addr
, ntohs(sin
->sin_port
));
337 /* Set max requests */
338 cdata
.max_requests
= xprt
->max_reqs
;
340 /* Set some length limits */
341 cdata
.rsize
= RPCRDMA_MAX_SEGS
* PAGE_SIZE
; /* RDMA write max */
342 cdata
.wsize
= RPCRDMA_MAX_SEGS
* PAGE_SIZE
; /* RDMA read max */
344 cdata
.inline_wsize
= xprt_rdma_max_inline_write
;
345 if (cdata
.inline_wsize
> cdata
.wsize
)
346 cdata
.inline_wsize
= cdata
.wsize
;
348 cdata
.inline_rsize
= xprt_rdma_max_inline_read
;
349 if (cdata
.inline_rsize
> cdata
.rsize
)
350 cdata
.inline_rsize
= cdata
.rsize
;
352 cdata
.padding
= xprt_rdma_inline_write_padding
;
355 * Create new transport instance, which includes initialized
361 new_xprt
= rpcx_to_rdmax(xprt
);
363 rc
= rpcrdma_ia_open(new_xprt
, (struct sockaddr
*) &cdata
.addr
,
364 xprt_rdma_memreg_strategy
);
369 * initialize and create ep
371 new_xprt
->rx_data
= cdata
;
372 new_ep
= &new_xprt
->rx_ep
;
373 new_ep
->rep_remote_addr
= cdata
.addr
;
375 rc
= rpcrdma_ep_create(&new_xprt
->rx_ep
,
376 &new_xprt
->rx_ia
, &new_xprt
->rx_data
);
381 * Allocate pre-registered send and receive buffers for headers and
382 * any inline data. Also specify any padding which will be provided
383 * from a preregistered zero buffer.
385 rc
= rpcrdma_buffer_create(&new_xprt
->rx_buf
, new_ep
, &new_xprt
->rx_ia
,
391 * Register a callback for connection events. This is necessary because
392 * connection loss notification is async. We also catch connection loss
393 * when reaping receives.
395 INIT_DELAYED_WORK(&new_xprt
->rdma_connect
, xprt_rdma_connect_worker
);
396 new_ep
->rep_func
= rpcrdma_conn_func
;
397 new_ep
->rep_xprt
= xprt
;
399 xprt_rdma_format_addresses(xprt
);
401 if (!try_module_get(THIS_MODULE
))
407 xprt_rdma_free_addresses(xprt
);
410 (void) rpcrdma_ep_destroy(new_ep
, &new_xprt
->rx_ia
);
412 rpcrdma_ia_close(&new_xprt
->rx_ia
);
420 * Close a connection, during shutdown or timeout/reconnect
423 xprt_rdma_close(struct rpc_xprt
*xprt
)
425 struct rpcrdma_xprt
*r_xprt
= rpcx_to_rdmax(xprt
);
427 dprintk("RPC: %s: closing\n", __func__
);
428 if (r_xprt
->rx_ep
.rep_connected
> 0)
429 xprt
->reestablish_timeout
= 0;
430 xprt_disconnect_done(xprt
);
431 (void) rpcrdma_ep_disconnect(&r_xprt
->rx_ep
, &r_xprt
->rx_ia
);
435 xprt_rdma_set_port(struct rpc_xprt
*xprt
, u16 port
)
437 struct sockaddr_in
*sap
;
439 sap
= (struct sockaddr_in
*)&xprt
->addr
;
440 sap
->sin_port
= htons(port
);
441 sap
= (struct sockaddr_in
*)&rpcx_to_rdmad(xprt
).addr
;
442 sap
->sin_port
= htons(port
);
443 dprintk("RPC: %s: %u\n", __func__
, port
);
447 xprt_rdma_connect(struct rpc_task
*task
)
449 struct rpc_xprt
*xprt
= (struct rpc_xprt
*)task
->tk_xprt
;
450 struct rpcrdma_xprt
*r_xprt
= rpcx_to_rdmax(xprt
);
452 if (!xprt_test_and_set_connecting(xprt
)) {
453 if (r_xprt
->rx_ep
.rep_connected
!= 0) {
455 schedule_delayed_work(&r_xprt
->rdma_connect
,
456 xprt
->reestablish_timeout
);
457 xprt
->reestablish_timeout
<<= 1;
458 if (xprt
->reestablish_timeout
> (30 * HZ
))
459 xprt
->reestablish_timeout
= (30 * HZ
);
460 else if (xprt
->reestablish_timeout
< (5 * HZ
))
461 xprt
->reestablish_timeout
= (5 * HZ
);
463 schedule_delayed_work(&r_xprt
->rdma_connect
, 0);
464 if (!RPC_IS_ASYNC(task
))
465 flush_scheduled_work();
471 xprt_rdma_reserve_xprt(struct rpc_task
*task
)
473 struct rpc_xprt
*xprt
= task
->tk_xprt
;
474 struct rpcrdma_xprt
*r_xprt
= rpcx_to_rdmax(xprt
);
475 int credits
= atomic_read(&r_xprt
->rx_buf
.rb_credits
);
477 /* == RPC_CWNDSCALE @ init, but *after* setup */
478 if (r_xprt
->rx_buf
.rb_cwndscale
== 0UL) {
479 r_xprt
->rx_buf
.rb_cwndscale
= xprt
->cwnd
;
480 dprintk("RPC: %s: cwndscale %lu\n", __func__
,
481 r_xprt
->rx_buf
.rb_cwndscale
);
482 BUG_ON(r_xprt
->rx_buf
.rb_cwndscale
<= 0);
484 xprt
->cwnd
= credits
* r_xprt
->rx_buf
.rb_cwndscale
;
485 return xprt_reserve_xprt_cong(task
);
489 * The RDMA allocate/free functions need the task structure as a place
490 * to hide the struct rpcrdma_req, which is necessary for the actual send/recv
491 * sequence. For this reason, the recv buffers are attached to send
492 * buffers for portions of the RPC. Note that the RPC layer allocates
493 * both send and receive buffers in the same call. We may register
494 * the receive buffer portion when using reply chunks.
497 xprt_rdma_allocate(struct rpc_task
*task
, size_t size
)
499 struct rpc_xprt
*xprt
= task
->tk_xprt
;
500 struct rpcrdma_req
*req
, *nreq
;
502 req
= rpcrdma_buffer_get(&rpcx_to_rdmax(xprt
)->rx_buf
);
505 if (size
> req
->rl_size
) {
506 dprintk("RPC: %s: size %zd too large for buffer[%zd]: "
507 "prog %d vers %d proc %d\n",
508 __func__
, size
, req
->rl_size
,
509 task
->tk_client
->cl_prog
, task
->tk_client
->cl_vers
,
510 task
->tk_msg
.rpc_proc
->p_proc
);
512 * Outgoing length shortage. Our inline write max must have
513 * been configured to perform direct i/o.
515 * This is therefore a large metadata operation, and the
516 * allocate call was made on the maximum possible message,
517 * e.g. containing long filename(s) or symlink data. In
518 * fact, while these metadata operations *might* carry
519 * large outgoing payloads, they rarely *do*. However, we
520 * have to commit to the request here, so reallocate and
521 * register it now. The data path will never require this
524 * If the allocation or registration fails, the RPC framework
525 * will (doggedly) retry.
527 if (rpcx_to_rdmax(xprt
)->rx_ia
.ri_memreg_strategy
==
528 RPCRDMA_BOUNCEBUFFERS
) {
529 /* forced to "pure inline" */
530 dprintk("RPC: %s: too much data (%zd) for inline "
531 "(r/w max %d/%d)\n", __func__
, size
,
532 rpcx_to_rdmad(xprt
).inline_rsize
,
533 rpcx_to_rdmad(xprt
).inline_wsize
);
535 rpc_exit(task
, -EIO
); /* fail the operation */
536 rpcx_to_rdmax(xprt
)->rx_stats
.failed_marshal_count
++;
539 if (task
->tk_flags
& RPC_TASK_SWAPPER
)
540 nreq
= kmalloc(sizeof *req
+ size
, GFP_ATOMIC
);
542 nreq
= kmalloc(sizeof *req
+ size
, GFP_NOFS
);
546 if (rpcrdma_register_internal(&rpcx_to_rdmax(xprt
)->rx_ia
,
547 nreq
->rl_base
, size
+ sizeof(struct rpcrdma_req
)
548 - offsetof(struct rpcrdma_req
, rl_base
),
549 &nreq
->rl_handle
, &nreq
->rl_iov
)) {
553 rpcx_to_rdmax(xprt
)->rx_stats
.hardway_register_count
+= size
;
554 nreq
->rl_size
= size
;
556 nreq
->rl_nchunks
= 0;
557 nreq
->rl_buffer
= (struct rpcrdma_buffer
*)req
;
558 nreq
->rl_reply
= req
->rl_reply
;
559 memcpy(nreq
->rl_segments
,
560 req
->rl_segments
, sizeof nreq
->rl_segments
);
561 /* flag the swap with an unused field */
562 nreq
->rl_iov
.length
= 0;
563 req
->rl_reply
= NULL
;
566 dprintk("RPC: %s: size %zd, request 0x%p\n", __func__
, size
, req
);
568 req
->rl_connect_cookie
= 0; /* our reserved value */
569 return req
->rl_xdr_buf
;
572 rpcrdma_buffer_put(req
);
573 rpcx_to_rdmax(xprt
)->rx_stats
.failed_marshal_count
++;
578 * This function returns all RDMA resources to the pool.
581 xprt_rdma_free(void *buffer
)
583 struct rpcrdma_req
*req
;
584 struct rpcrdma_xprt
*r_xprt
;
585 struct rpcrdma_rep
*rep
;
591 req
= container_of(buffer
, struct rpcrdma_req
, rl_xdr_buf
[0]);
592 if (req
->rl_iov
.length
== 0) { /* see allocate above */
593 r_xprt
= container_of(((struct rpcrdma_req
*) req
->rl_buffer
)->rl_buffer
,
594 struct rpcrdma_xprt
, rx_buf
);
596 r_xprt
= container_of(req
->rl_buffer
, struct rpcrdma_xprt
, rx_buf
);
599 dprintk("RPC: %s: called on 0x%p%s\n",
600 __func__
, rep
, (rep
&& rep
->rr_func
) ? " (with waiter)" : "");
603 * Finish the deregistration. When using mw bind, this was
604 * begun in rpcrdma_reply_handler(). In all other modes, we
605 * do it here, in thread context. The process is considered
606 * complete when the rr_func vector becomes NULL - this
607 * was put in place during rpcrdma_reply_handler() - the wait
608 * call below will not block if the dereg is "done". If
609 * interrupted, our framework will clean up.
611 for (i
= 0; req
->rl_nchunks
;) {
613 i
+= rpcrdma_deregister_external(
614 &req
->rl_segments
[i
], r_xprt
, NULL
);
617 if (rep
&& wait_event_interruptible(rep
->rr_unbind
, !rep
->rr_func
)) {
618 rep
->rr_func
= NULL
; /* abandon the callback */
619 req
->rl_reply
= NULL
;
622 if (req
->rl_iov
.length
== 0) { /* see allocate above */
623 struct rpcrdma_req
*oreq
= (struct rpcrdma_req
*)req
->rl_buffer
;
624 oreq
->rl_reply
= req
->rl_reply
;
625 (void) rpcrdma_deregister_internal(&r_xprt
->rx_ia
,
632 /* Put back request+reply buffers */
633 rpcrdma_buffer_put(req
);
637 * send_request invokes the meat of RPC RDMA. It must do the following:
638 * 1. Marshal the RPC request into an RPC RDMA request, which means
639 * putting a header in front of data, and creating IOVs for RDMA
640 * from those in the request.
641 * 2. In marshaling, detect opportunities for RDMA, and use them.
642 * 3. Post a recv message to set up asynch completion, then send
643 * the request (rpcrdma_ep_post).
644 * 4. No partial sends are possible in the RPC-RDMA protocol (as in UDP).
648 xprt_rdma_send_request(struct rpc_task
*task
)
650 struct rpc_rqst
*rqst
= task
->tk_rqstp
;
651 struct rpc_xprt
*xprt
= task
->tk_xprt
;
652 struct rpcrdma_req
*req
= rpcr_to_rdmar(rqst
);
653 struct rpcrdma_xprt
*r_xprt
= rpcx_to_rdmax(xprt
);
655 /* marshal the send itself */
656 if (req
->rl_niovs
== 0 && rpcrdma_marshal_req(rqst
) != 0) {
657 r_xprt
->rx_stats
.failed_marshal_count
++;
658 dprintk("RPC: %s: rpcrdma_marshal_req failed\n",
663 if (req
->rl_reply
== NULL
) /* e.g. reconnection */
664 rpcrdma_recv_buffer_get(req
);
667 req
->rl_reply
->rr_func
= rpcrdma_reply_handler
;
668 /* this need only be done once, but... */
669 req
->rl_reply
->rr_xprt
= xprt
;
672 /* Must suppress retransmit to maintain credits */
673 if (req
->rl_connect_cookie
== xprt
->connect_cookie
)
674 goto drop_connection
;
675 req
->rl_connect_cookie
= xprt
->connect_cookie
;
677 if (rpcrdma_ep_post(&r_xprt
->rx_ia
, &r_xprt
->rx_ep
, req
))
678 goto drop_connection
;
680 task
->tk_bytes_sent
+= rqst
->rq_snd_buf
.len
;
681 rqst
->rq_bytes_sent
= 0;
685 xprt_disconnect_done(xprt
);
686 return -ENOTCONN
; /* implies disconnect */
689 static void xprt_rdma_print_stats(struct rpc_xprt
*xprt
, struct seq_file
*seq
)
691 struct rpcrdma_xprt
*r_xprt
= rpcx_to_rdmax(xprt
);
694 if (xprt_connected(xprt
))
695 idle_time
= (long)(jiffies
- xprt
->last_used
) / HZ
;
698 "\txprt:\trdma %u %lu %lu %lu %ld %lu %lu %lu %Lu %Lu "
699 "%lu %lu %lu %Lu %Lu %Lu %Lu %lu %lu %lu\n",
701 0, /* need a local port? */
702 xprt
->stat
.bind_count
,
703 xprt
->stat
.connect_count
,
704 xprt
->stat
.connect_time
,
712 r_xprt
->rx_stats
.read_chunk_count
,
713 r_xprt
->rx_stats
.write_chunk_count
,
714 r_xprt
->rx_stats
.reply_chunk_count
,
715 r_xprt
->rx_stats
.total_rdma_request
,
716 r_xprt
->rx_stats
.total_rdma_reply
,
717 r_xprt
->rx_stats
.pullup_copy_count
,
718 r_xprt
->rx_stats
.fixup_copy_count
,
719 r_xprt
->rx_stats
.hardway_register_count
,
720 r_xprt
->rx_stats
.failed_marshal_count
,
721 r_xprt
->rx_stats
.bad_reply_count
);
725 * Plumbing for rpc transport switch and kernel module
728 static struct rpc_xprt_ops xprt_rdma_procs
= {
729 .reserve_xprt
= xprt_rdma_reserve_xprt
,
730 .release_xprt
= xprt_release_xprt_cong
, /* sunrpc/xprt.c */
731 .release_request
= xprt_release_rqst_cong
, /* ditto */
732 .set_retrans_timeout
= xprt_set_retrans_timeout_def
, /* ditto */
733 .rpcbind
= rpcb_getport_async
, /* sunrpc/rpcb_clnt.c */
734 .set_port
= xprt_rdma_set_port
,
735 .connect
= xprt_rdma_connect
,
736 .buf_alloc
= xprt_rdma_allocate
,
737 .buf_free
= xprt_rdma_free
,
738 .send_request
= xprt_rdma_send_request
,
739 .close
= xprt_rdma_close
,
740 .destroy
= xprt_rdma_destroy
,
741 .print_stats
= xprt_rdma_print_stats
744 static struct xprt_class xprt_rdma
= {
745 .list
= LIST_HEAD_INIT(xprt_rdma
.list
),
747 .owner
= THIS_MODULE
,
748 .ident
= XPRT_TRANSPORT_RDMA
,
749 .setup
= xprt_setup_rdma
,
752 static void __exit
xprt_rdma_cleanup(void)
756 dprintk(KERN_INFO
"RPCRDMA Module Removed, deregister RPC RDMA transport\n");
758 if (sunrpc_table_header
) {
759 unregister_sysctl_table(sunrpc_table_header
);
760 sunrpc_table_header
= NULL
;
763 rc
= xprt_unregister_transport(&xprt_rdma
);
765 dprintk("RPC: %s: xprt_unregister returned %i\n",
769 static int __init
xprt_rdma_init(void)
773 rc
= xprt_register_transport(&xprt_rdma
);
778 dprintk(KERN_INFO
"RPCRDMA Module Init, register RPC RDMA transport\n");
780 dprintk(KERN_INFO
"Defaults:\n");
781 dprintk(KERN_INFO
"\tSlots %d\n"
782 "\tMaxInlineRead %d\n\tMaxInlineWrite %d\n",
783 xprt_rdma_slot_table_entries
,
784 xprt_rdma_max_inline_read
, xprt_rdma_max_inline_write
);
785 dprintk(KERN_INFO
"\tPadding %d\n\tMemreg %d\n",
786 xprt_rdma_inline_write_padding
, xprt_rdma_memreg_strategy
);
789 if (!sunrpc_table_header
)
790 sunrpc_table_header
= register_sysctl_table(sunrpc_table
);
795 module_init(xprt_rdma_init
);
796 module_exit(xprt_rdma_cleanup
);