]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/sunrpc/xprt.c
SUNRPC: Fail over more quickly on connect errors
[net-next-2.6.git] / net / sunrpc / xprt.c
CommitLineData
1da177e4
LT
1/*
2 * linux/net/sunrpc/xprt.c
3 *
4 * This is a generic RPC call interface supporting congestion avoidance,
5 * and asynchronous calls.
6 *
7 * The interface works like this:
8 *
9 * - When a process places a call, it allocates a request slot if
10 * one is available. Otherwise, it sleeps on the backlog queue
11 * (xprt_reserve).
12 * - Next, the caller puts together the RPC message, stuffs it into
55aa4f58
CL
13 * the request struct, and calls xprt_transmit().
14 * - xprt_transmit sends the message and installs the caller on the
55ae1aab
RL
15 * transport's wait list. At the same time, if a reply is expected,
16 * it installs a timer that is run after the packet's timeout has
17 * expired.
1da177e4 18 * - When a packet arrives, the data_ready handler walks the list of
55aa4f58 19 * pending requests for that transport. If a matching XID is found, the
1da177e4
LT
20 * caller is woken up, and the timer removed.
21 * - When no reply arrives within the timeout interval, the timer is
22 * fired by the kernel and runs xprt_timer(). It either adjusts the
23 * timeout values (minor timeout) or wakes up the caller with a status
24 * of -ETIMEDOUT.
25 * - When the caller receives a notification from RPC that a reply arrived,
26 * it should release the RPC slot, and process the reply.
27 * If the call timed out, it may choose to retry the operation by
28 * adjusting the initial timeout value, and simply calling rpc_call
29 * again.
30 *
31 * Support for async RPC is done through a set of RPC-specific scheduling
32 * primitives that `transparently' work for processes as well as async
33 * tasks that rely on callbacks.
34 *
35 * Copyright (C) 1995-1997, Olaf Kirch <okir@monad.swb.de>
55aa4f58
CL
36 *
37 * Transport switch API copyright (C) 2005, Chuck Lever <cel@netapp.com>
1da177e4
LT
38 */
39
a246b010
CL
40#include <linux/module.h>
41
1da177e4 42#include <linux/types.h>
a246b010 43#include <linux/interrupt.h>
1da177e4 44#include <linux/workqueue.h>
bf3fcf89 45#include <linux/net.h>
1da177e4 46
a246b010 47#include <linux/sunrpc/clnt.h>
11c556b3 48#include <linux/sunrpc/metrics.h>
c9acb42e 49#include <linux/sunrpc/bc_xprt.h>
1da177e4 50
55ae1aab
RL
51#include "sunrpc.h"
52
1da177e4
LT
53/*
54 * Local variables
55 */
56
57#ifdef RPC_DEBUG
1da177e4
LT
58# define RPCDBG_FACILITY RPCDBG_XPRT
59#endif
60
1da177e4
LT
61/*
62 * Local functions
63 */
64static void xprt_request_init(struct rpc_task *, struct rpc_xprt *);
1da177e4 65static void xprt_connect_status(struct rpc_task *task);
1da177e4
LT
66static int __xprt_get_cong(struct rpc_xprt *, struct rpc_task *);
67
5ba03e82 68static DEFINE_SPINLOCK(xprt_list_lock);
81c098af
TT
69static LIST_HEAD(xprt_list);
70
555ee3af
CL
71/*
72 * The transport code maintains an estimate on the maximum number of out-
73 * standing RPC requests, using a smoothed version of the congestion
74 * avoidance implemented in 44BSD. This is basically the Van Jacobson
75 * congestion algorithm: If a retransmit occurs, the congestion window is
76 * halved; otherwise, it is incremented by 1/cwnd when
77 *
78 * - a reply is received and
79 * - a full number of requests are outstanding and
80 * - the congestion window hasn't been updated recently.
81 */
82#define RPC_CWNDSHIFT (8U)
83#define RPC_CWNDSCALE (1U << RPC_CWNDSHIFT)
84#define RPC_INITCWND RPC_CWNDSCALE
85#define RPC_MAXCWND(xprt) ((xprt)->max_reqs << RPC_CWNDSHIFT)
86
87#define RPCXPRT_CONGESTED(xprt) ((xprt)->cong >= (xprt)->cwnd)
1da177e4 88
81c098af
TT
89/**
90 * xprt_register_transport - register a transport implementation
91 * @transport: transport to register
92 *
93 * If a transport implementation is loaded as a kernel module, it can
94 * call this interface to make itself known to the RPC client.
95 *
96 * Returns:
97 * 0: transport successfully registered
98 * -EEXIST: transport already registered
99 * -EINVAL: transport module being unloaded
100 */
101int xprt_register_transport(struct xprt_class *transport)
102{
103 struct xprt_class *t;
104 int result;
105
106 result = -EEXIST;
107 spin_lock(&xprt_list_lock);
108 list_for_each_entry(t, &xprt_list, list) {
109 /* don't register the same transport class twice */
4fa016eb 110 if (t->ident == transport->ident)
81c098af
TT
111 goto out;
112 }
113
c9f6cde6
DL
114 list_add_tail(&transport->list, &xprt_list);
115 printk(KERN_INFO "RPC: Registered %s transport module.\n",
116 transport->name);
117 result = 0;
81c098af
TT
118
119out:
120 spin_unlock(&xprt_list_lock);
121 return result;
122}
123EXPORT_SYMBOL_GPL(xprt_register_transport);
124
125/**
126 * xprt_unregister_transport - unregister a transport implementation
65b6e42c 127 * @transport: transport to unregister
81c098af
TT
128 *
129 * Returns:
130 * 0: transport successfully unregistered
131 * -ENOENT: transport never registered
132 */
133int xprt_unregister_transport(struct xprt_class *transport)
134{
135 struct xprt_class *t;
136 int result;
137
138 result = 0;
139 spin_lock(&xprt_list_lock);
140 list_for_each_entry(t, &xprt_list, list) {
141 if (t == transport) {
142 printk(KERN_INFO
143 "RPC: Unregistered %s transport module.\n",
144 transport->name);
145 list_del_init(&transport->list);
81c098af
TT
146 goto out;
147 }
148 }
149 result = -ENOENT;
150
151out:
152 spin_unlock(&xprt_list_lock);
153 return result;
154}
155EXPORT_SYMBOL_GPL(xprt_unregister_transport);
156
441e3e24
TT
157/**
158 * xprt_load_transport - load a transport implementation
159 * @transport_name: transport to load
160 *
161 * Returns:
162 * 0: transport successfully loaded
163 * -ENOENT: transport module not available
164 */
165int xprt_load_transport(const char *transport_name)
166{
167 struct xprt_class *t;
168 char module_name[sizeof t->name + 5];
169 int result;
170
171 result = 0;
172 spin_lock(&xprt_list_lock);
173 list_for_each_entry(t, &xprt_list, list) {
174 if (strcmp(t->name, transport_name) == 0) {
175 spin_unlock(&xprt_list_lock);
176 goto out;
177 }
178 }
179 spin_unlock(&xprt_list_lock);
180 strcpy(module_name, "xprt");
181 strncat(module_name, transport_name, sizeof t->name);
182 result = request_module(module_name);
183out:
184 return result;
185}
186EXPORT_SYMBOL_GPL(xprt_load_transport);
187
12a80469
CL
188/**
189 * xprt_reserve_xprt - serialize write access to transports
190 * @task: task that is requesting access to the transport
191 *
192 * This prevents mixing the payload of separate requests, and prevents
193 * transport connects from colliding with writes. No congestion control
194 * is provided.
195 */
196int xprt_reserve_xprt(struct rpc_task *task)
197{
12a80469 198 struct rpc_rqst *req = task->tk_rqstp;
343952fa 199 struct rpc_xprt *xprt = req->rq_xprt;
12a80469
CL
200
201 if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) {
202 if (task == xprt->snd_task)
203 return 1;
204 if (task == NULL)
205 return 0;
206 goto out_sleep;
207 }
208 xprt->snd_task = task;
209 if (req) {
210 req->rq_bytes_sent = 0;
211 req->rq_ntrans++;
212 }
213 return 1;
214
215out_sleep:
46121cf7 216 dprintk("RPC: %5u failed to lock transport %p\n",
12a80469
CL
217 task->tk_pid, xprt);
218 task->tk_timeout = 0;
219 task->tk_status = -EAGAIN;
220 if (req && req->rq_ntrans)
5d00837b 221 rpc_sleep_on(&xprt->resend, task, NULL);
12a80469 222 else
5d00837b 223 rpc_sleep_on(&xprt->sending, task, NULL);
12a80469
CL
224 return 0;
225}
12444809 226EXPORT_SYMBOL_GPL(xprt_reserve_xprt);
12a80469 227
632e3bdc
TM
228static void xprt_clear_locked(struct rpc_xprt *xprt)
229{
230 xprt->snd_task = NULL;
231 if (!test_bit(XPRT_CLOSE_WAIT, &xprt->state) || xprt->shutdown) {
232 smp_mb__before_clear_bit();
233 clear_bit(XPRT_LOCKED, &xprt->state);
234 smp_mb__after_clear_bit();
235 } else
c1384c9c 236 queue_work(rpciod_workqueue, &xprt->task_cleanup);
632e3bdc
TM
237}
238
1da177e4 239/*
12a80469
CL
240 * xprt_reserve_xprt_cong - serialize write access to transports
241 * @task: task that is requesting access to the transport
242 *
243 * Same as xprt_reserve_xprt, but Van Jacobson congestion control is
244 * integrated into the decision of whether a request is allowed to be
245 * woken up and given access to the transport.
1da177e4 246 */
12a80469 247int xprt_reserve_xprt_cong(struct rpc_task *task)
1da177e4 248{
12a80469 249 struct rpc_xprt *xprt = task->tk_xprt;
1da177e4
LT
250 struct rpc_rqst *req = task->tk_rqstp;
251
2226feb6 252 if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) {
1da177e4
LT
253 if (task == xprt->snd_task)
254 return 1;
1da177e4
LT
255 goto out_sleep;
256 }
12a80469 257 if (__xprt_get_cong(xprt, task)) {
1da177e4
LT
258 xprt->snd_task = task;
259 if (req) {
260 req->rq_bytes_sent = 0;
261 req->rq_ntrans++;
262 }
263 return 1;
264 }
632e3bdc 265 xprt_clear_locked(xprt);
1da177e4 266out_sleep:
46121cf7 267 dprintk("RPC: %5u failed to lock transport %p\n", task->tk_pid, xprt);
1da177e4
LT
268 task->tk_timeout = 0;
269 task->tk_status = -EAGAIN;
270 if (req && req->rq_ntrans)
5d00837b 271 rpc_sleep_on(&xprt->resend, task, NULL);
1da177e4 272 else
5d00837b 273 rpc_sleep_on(&xprt->sending, task, NULL);
1da177e4
LT
274 return 0;
275}
12444809 276EXPORT_SYMBOL_GPL(xprt_reserve_xprt_cong);
1da177e4 277
12a80469 278static inline int xprt_lock_write(struct rpc_xprt *xprt, struct rpc_task *task)
1da177e4
LT
279{
280 int retval;
281
4a0f8c04 282 spin_lock_bh(&xprt->transport_lock);
12a80469 283 retval = xprt->ops->reserve_xprt(task);
4a0f8c04 284 spin_unlock_bh(&xprt->transport_lock);
1da177e4
LT
285 return retval;
286}
287
12a80469 288static void __xprt_lock_write_next(struct rpc_xprt *xprt)
49e9a890
CL
289{
290 struct rpc_task *task;
291 struct rpc_rqst *req;
292
293 if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
294 return;
295
296 task = rpc_wake_up_next(&xprt->resend);
297 if (!task) {
298 task = rpc_wake_up_next(&xprt->sending);
299 if (!task)
300 goto out_unlock;
301 }
302
303 req = task->tk_rqstp;
304 xprt->snd_task = task;
305 if (req) {
306 req->rq_bytes_sent = 0;
307 req->rq_ntrans++;
308 }
309 return;
310
311out_unlock:
632e3bdc 312 xprt_clear_locked(xprt);
49e9a890
CL
313}
314
315static void __xprt_lock_write_next_cong(struct rpc_xprt *xprt)
1da177e4
LT
316{
317 struct rpc_task *task;
318
2226feb6 319 if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
1da177e4 320 return;
49e9a890 321 if (RPCXPRT_CONGESTED(xprt))
1da177e4
LT
322 goto out_unlock;
323 task = rpc_wake_up_next(&xprt->resend);
324 if (!task) {
325 task = rpc_wake_up_next(&xprt->sending);
326 if (!task)
327 goto out_unlock;
328 }
49e9a890 329 if (__xprt_get_cong(xprt, task)) {
1da177e4
LT
330 struct rpc_rqst *req = task->tk_rqstp;
331 xprt->snd_task = task;
332 if (req) {
333 req->rq_bytes_sent = 0;
334 req->rq_ntrans++;
335 }
336 return;
337 }
338out_unlock:
632e3bdc 339 xprt_clear_locked(xprt);
1da177e4
LT
340}
341
49e9a890
CL
342/**
343 * xprt_release_xprt - allow other requests to use a transport
344 * @xprt: transport with other tasks potentially waiting
345 * @task: task that is releasing access to the transport
346 *
347 * Note that "task" can be NULL. No congestion control is provided.
1da177e4 348 */
49e9a890 349void xprt_release_xprt(struct rpc_xprt *xprt, struct rpc_task *task)
1da177e4
LT
350{
351 if (xprt->snd_task == task) {
632e3bdc 352 xprt_clear_locked(xprt);
1da177e4
LT
353 __xprt_lock_write_next(xprt);
354 }
355}
12444809 356EXPORT_SYMBOL_GPL(xprt_release_xprt);
1da177e4 357
49e9a890
CL
358/**
359 * xprt_release_xprt_cong - allow other requests to use a transport
360 * @xprt: transport with other tasks potentially waiting
361 * @task: task that is releasing access to the transport
362 *
363 * Note that "task" can be NULL. Another task is awoken to use the
364 * transport if the transport's congestion window allows it.
365 */
366void xprt_release_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task)
367{
368 if (xprt->snd_task == task) {
632e3bdc 369 xprt_clear_locked(xprt);
49e9a890
CL
370 __xprt_lock_write_next_cong(xprt);
371 }
372}
12444809 373EXPORT_SYMBOL_GPL(xprt_release_xprt_cong);
49e9a890
CL
374
375static inline void xprt_release_write(struct rpc_xprt *xprt, struct rpc_task *task)
1da177e4 376{
4a0f8c04 377 spin_lock_bh(&xprt->transport_lock);
49e9a890 378 xprt->ops->release_xprt(xprt, task);
4a0f8c04 379 spin_unlock_bh(&xprt->transport_lock);
1da177e4
LT
380}
381
1da177e4
LT
382/*
383 * Van Jacobson congestion avoidance. Check if the congestion window
384 * overflowed. Put the task to sleep if this is the case.
385 */
386static int
387__xprt_get_cong(struct rpc_xprt *xprt, struct rpc_task *task)
388{
389 struct rpc_rqst *req = task->tk_rqstp;
390
391 if (req->rq_cong)
392 return 1;
46121cf7 393 dprintk("RPC: %5u xprt_cwnd_limited cong = %lu cwnd = %lu\n",
1da177e4
LT
394 task->tk_pid, xprt->cong, xprt->cwnd);
395 if (RPCXPRT_CONGESTED(xprt))
396 return 0;
397 req->rq_cong = 1;
398 xprt->cong += RPC_CWNDSCALE;
399 return 1;
400}
401
402/*
403 * Adjust the congestion window, and wake up the next task
404 * that has been sleeping due to congestion
405 */
406static void
407__xprt_put_cong(struct rpc_xprt *xprt, struct rpc_rqst *req)
408{
409 if (!req->rq_cong)
410 return;
411 req->rq_cong = 0;
412 xprt->cong -= RPC_CWNDSCALE;
49e9a890 413 __xprt_lock_write_next_cong(xprt);
1da177e4
LT
414}
415
a58dd398
CL
416/**
417 * xprt_release_rqst_cong - housekeeping when request is complete
418 * @task: RPC request that recently completed
419 *
420 * Useful for transports that require congestion control.
421 */
422void xprt_release_rqst_cong(struct rpc_task *task)
423{
424 __xprt_put_cong(task->tk_xprt, task->tk_rqstp);
425}
12444809 426EXPORT_SYMBOL_GPL(xprt_release_rqst_cong);
a58dd398 427
46c0ee8b
CL
428/**
429 * xprt_adjust_cwnd - adjust transport congestion window
430 * @task: recently completed RPC request used to adjust window
431 * @result: result code of completed RPC request
432 *
1da177e4
LT
433 * We use a time-smoothed congestion estimator to avoid heavy oscillation.
434 */
46c0ee8b 435void xprt_adjust_cwnd(struct rpc_task *task, int result)
1da177e4 436{
46c0ee8b
CL
437 struct rpc_rqst *req = task->tk_rqstp;
438 struct rpc_xprt *xprt = task->tk_xprt;
439 unsigned long cwnd = xprt->cwnd;
1da177e4 440
1da177e4
LT
441 if (result >= 0 && cwnd <= xprt->cong) {
442 /* The (cwnd >> 1) term makes sure
443 * the result gets rounded properly. */
444 cwnd += (RPC_CWNDSCALE * RPC_CWNDSCALE + (cwnd >> 1)) / cwnd;
445 if (cwnd > RPC_MAXCWND(xprt))
446 cwnd = RPC_MAXCWND(xprt);
49e9a890 447 __xprt_lock_write_next_cong(xprt);
1da177e4
LT
448 } else if (result == -ETIMEDOUT) {
449 cwnd >>= 1;
450 if (cwnd < RPC_CWNDSCALE)
451 cwnd = RPC_CWNDSCALE;
452 }
46121cf7 453 dprintk("RPC: cong %ld, cwnd was %ld, now %ld\n",
1da177e4
LT
454 xprt->cong, xprt->cwnd, cwnd);
455 xprt->cwnd = cwnd;
46c0ee8b 456 __xprt_put_cong(xprt, req);
1da177e4 457}
12444809 458EXPORT_SYMBOL_GPL(xprt_adjust_cwnd);
1da177e4 459
44fbac22
CL
460/**
461 * xprt_wake_pending_tasks - wake all tasks on a transport's pending queue
462 * @xprt: transport with waiting tasks
463 * @status: result code to plant in each task before waking it
464 *
465 */
466void xprt_wake_pending_tasks(struct rpc_xprt *xprt, int status)
467{
468 if (status < 0)
469 rpc_wake_up_status(&xprt->pending, status);
470 else
471 rpc_wake_up(&xprt->pending);
472}
12444809 473EXPORT_SYMBOL_GPL(xprt_wake_pending_tasks);
44fbac22 474
c7b2cae8
CL
475/**
476 * xprt_wait_for_buffer_space - wait for transport output buffer to clear
477 * @task: task to be put to sleep
0b80ae42 478 * @action: function pointer to be executed after wait
c7b2cae8 479 */
b6ddf64f 480void xprt_wait_for_buffer_space(struct rpc_task *task, rpc_action action)
c7b2cae8
CL
481{
482 struct rpc_rqst *req = task->tk_rqstp;
483 struct rpc_xprt *xprt = req->rq_xprt;
484
485 task->tk_timeout = req->rq_timeout;
b6ddf64f 486 rpc_sleep_on(&xprt->pending, task, action);
c7b2cae8 487}
12444809 488EXPORT_SYMBOL_GPL(xprt_wait_for_buffer_space);
c7b2cae8
CL
489
490/**
491 * xprt_write_space - wake the task waiting for transport output buffer space
492 * @xprt: transport with waiting tasks
493 *
494 * Can be called in a soft IRQ context, so xprt_write_space never sleeps.
495 */
496void xprt_write_space(struct rpc_xprt *xprt)
497{
498 if (unlikely(xprt->shutdown))
499 return;
500
501 spin_lock_bh(&xprt->transport_lock);
502 if (xprt->snd_task) {
46121cf7
CL
503 dprintk("RPC: write space: waking waiting task on "
504 "xprt %p\n", xprt);
fda13939 505 rpc_wake_up_queued_task(&xprt->pending, xprt->snd_task);
c7b2cae8
CL
506 }
507 spin_unlock_bh(&xprt->transport_lock);
508}
12444809 509EXPORT_SYMBOL_GPL(xprt_write_space);
c7b2cae8 510
fe3aca29
CL
511/**
512 * xprt_set_retrans_timeout_def - set a request's retransmit timeout
513 * @task: task whose timeout is to be set
514 *
515 * Set a request's retransmit timeout based on the transport's
516 * default timeout parameters. Used by transports that don't adjust
517 * the retransmit timeout based on round-trip time estimation.
518 */
519void xprt_set_retrans_timeout_def(struct rpc_task *task)
520{
521 task->tk_timeout = task->tk_rqstp->rq_timeout;
522}
12444809 523EXPORT_SYMBOL_GPL(xprt_set_retrans_timeout_def);
fe3aca29
CL
524
525/*
526 * xprt_set_retrans_timeout_rtt - set a request's retransmit timeout
527 * @task: task whose timeout is to be set
cca5172a 528 *
fe3aca29
CL
529 * Set a request's retransmit timeout using the RTT estimator.
530 */
531void xprt_set_retrans_timeout_rtt(struct rpc_task *task)
532{
533 int timer = task->tk_msg.rpc_proc->p_timer;
ba7392bb
TM
534 struct rpc_clnt *clnt = task->tk_client;
535 struct rpc_rtt *rtt = clnt->cl_rtt;
fe3aca29 536 struct rpc_rqst *req = task->tk_rqstp;
ba7392bb 537 unsigned long max_timeout = clnt->cl_timeout->to_maxval;
fe3aca29
CL
538
539 task->tk_timeout = rpc_calc_rto(rtt, timer);
540 task->tk_timeout <<= rpc_ntimeo(rtt, timer) + req->rq_retries;
541 if (task->tk_timeout > max_timeout || task->tk_timeout == 0)
542 task->tk_timeout = max_timeout;
543}
12444809 544EXPORT_SYMBOL_GPL(xprt_set_retrans_timeout_rtt);
fe3aca29 545
1da177e4
LT
546static void xprt_reset_majortimeo(struct rpc_rqst *req)
547{
ba7392bb 548 const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout;
1da177e4
LT
549
550 req->rq_majortimeo = req->rq_timeout;
551 if (to->to_exponential)
552 req->rq_majortimeo <<= to->to_retries;
553 else
554 req->rq_majortimeo += to->to_increment * to->to_retries;
555 if (req->rq_majortimeo > to->to_maxval || req->rq_majortimeo == 0)
556 req->rq_majortimeo = to->to_maxval;
557 req->rq_majortimeo += jiffies;
558}
559
9903cd1c
CL
560/**
561 * xprt_adjust_timeout - adjust timeout values for next retransmit
562 * @req: RPC request containing parameters to use for the adjustment
563 *
1da177e4
LT
564 */
565int xprt_adjust_timeout(struct rpc_rqst *req)
566{
567 struct rpc_xprt *xprt = req->rq_xprt;
ba7392bb 568 const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout;
1da177e4
LT
569 int status = 0;
570
571 if (time_before(jiffies, req->rq_majortimeo)) {
572 if (to->to_exponential)
573 req->rq_timeout <<= 1;
574 else
575 req->rq_timeout += to->to_increment;
576 if (to->to_maxval && req->rq_timeout >= to->to_maxval)
577 req->rq_timeout = to->to_maxval;
578 req->rq_retries++;
1da177e4
LT
579 } else {
580 req->rq_timeout = to->to_initval;
581 req->rq_retries = 0;
582 xprt_reset_majortimeo(req);
583 /* Reset the RTT counters == "slow start" */
4a0f8c04 584 spin_lock_bh(&xprt->transport_lock);
1da177e4 585 rpc_init_rtt(req->rq_task->tk_client->cl_rtt, to->to_initval);
4a0f8c04 586 spin_unlock_bh(&xprt->transport_lock);
1da177e4
LT
587 status = -ETIMEDOUT;
588 }
589
590 if (req->rq_timeout == 0) {
591 printk(KERN_WARNING "xprt_adjust_timeout: rq_timeout = 0!\n");
592 req->rq_timeout = 5 * HZ;
593 }
594 return status;
595}
596
65f27f38 597static void xprt_autoclose(struct work_struct *work)
1da177e4 598{
65f27f38
DH
599 struct rpc_xprt *xprt =
600 container_of(work, struct rpc_xprt, task_cleanup);
1da177e4 601
a246b010 602 xprt->ops->close(xprt);
66af1e55 603 clear_bit(XPRT_CLOSE_WAIT, &xprt->state);
1da177e4
LT
604 xprt_release_write(xprt, NULL);
605}
606
9903cd1c 607/**
62da3b24 608 * xprt_disconnect_done - mark a transport as disconnected
9903cd1c
CL
609 * @xprt: transport to flag for disconnect
610 *
1da177e4 611 */
62da3b24 612void xprt_disconnect_done(struct rpc_xprt *xprt)
1da177e4 613{
46121cf7 614 dprintk("RPC: disconnected transport %p\n", xprt);
4a0f8c04 615 spin_lock_bh(&xprt->transport_lock);
1da177e4 616 xprt_clear_connected(xprt);
2a491991 617 xprt_wake_pending_tasks(xprt, -EAGAIN);
4a0f8c04 618 spin_unlock_bh(&xprt->transport_lock);
1da177e4 619}
62da3b24 620EXPORT_SYMBOL_GPL(xprt_disconnect_done);
1da177e4 621
66af1e55
TM
622/**
623 * xprt_force_disconnect - force a transport to disconnect
624 * @xprt: transport to disconnect
625 *
626 */
627void xprt_force_disconnect(struct rpc_xprt *xprt)
628{
629 /* Don't race with the test_bit() in xprt_clear_locked() */
630 spin_lock_bh(&xprt->transport_lock);
631 set_bit(XPRT_CLOSE_WAIT, &xprt->state);
632 /* Try to schedule an autoclose RPC call */
633 if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
634 queue_work(rpciod_workqueue, &xprt->task_cleanup);
2a491991 635 xprt_wake_pending_tasks(xprt, -EAGAIN);
66af1e55
TM
636 spin_unlock_bh(&xprt->transport_lock);
637}
66af1e55 638
7c1d71cf
TM
639/**
640 * xprt_conditional_disconnect - force a transport to disconnect
641 * @xprt: transport to disconnect
642 * @cookie: 'connection cookie'
643 *
644 * This attempts to break the connection if and only if 'cookie' matches
645 * the current transport 'connection cookie'. It ensures that we don't
646 * try to break the connection more than once when we need to retransmit
647 * a batch of RPC requests.
648 *
649 */
650void xprt_conditional_disconnect(struct rpc_xprt *xprt, unsigned int cookie)
651{
652 /* Don't race with the test_bit() in xprt_clear_locked() */
653 spin_lock_bh(&xprt->transport_lock);
654 if (cookie != xprt->connect_cookie)
655 goto out;
656 if (test_bit(XPRT_CLOSING, &xprt->state) || !xprt_connected(xprt))
657 goto out;
658 set_bit(XPRT_CLOSE_WAIT, &xprt->state);
659 /* Try to schedule an autoclose RPC call */
660 if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
661 queue_work(rpciod_workqueue, &xprt->task_cleanup);
2a491991 662 xprt_wake_pending_tasks(xprt, -EAGAIN);
7c1d71cf
TM
663out:
664 spin_unlock_bh(&xprt->transport_lock);
665}
666
1da177e4
LT
667static void
668xprt_init_autodisconnect(unsigned long data)
669{
670 struct rpc_xprt *xprt = (struct rpc_xprt *)data;
671
4a0f8c04 672 spin_lock(&xprt->transport_lock);
1da177e4
LT
673 if (!list_empty(&xprt->recv) || xprt->shutdown)
674 goto out_abort;
2226feb6 675 if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
1da177e4 676 goto out_abort;
4a0f8c04 677 spin_unlock(&xprt->transport_lock);
f75e6745
TM
678 set_bit(XPRT_CONNECTION_CLOSE, &xprt->state);
679 queue_work(rpciod_workqueue, &xprt->task_cleanup);
1da177e4
LT
680 return;
681out_abort:
4a0f8c04 682 spin_unlock(&xprt->transport_lock);
1da177e4
LT
683}
684
9903cd1c
CL
685/**
686 * xprt_connect - schedule a transport connect operation
687 * @task: RPC task that is requesting the connect
1da177e4
LT
688 *
689 */
690void xprt_connect(struct rpc_task *task)
691{
692 struct rpc_xprt *xprt = task->tk_xprt;
693
46121cf7 694 dprintk("RPC: %5u xprt_connect xprt %p %s connected\n", task->tk_pid,
1da177e4
LT
695 xprt, (xprt_connected(xprt) ? "is" : "is not"));
696
ec739ef0 697 if (!xprt_bound(xprt)) {
01d37c42 698 task->tk_status = -EAGAIN;
1da177e4
LT
699 return;
700 }
701 if (!xprt_lock_write(xprt, task))
702 return;
feb8ca37
TM
703
704 if (test_and_clear_bit(XPRT_CLOSE_WAIT, &xprt->state))
705 xprt->ops->close(xprt);
706
1da177e4 707 if (xprt_connected(xprt))
a246b010
CL
708 xprt_release_write(xprt, task);
709 else {
710 if (task->tk_rqstp)
711 task->tk_rqstp->rq_bytes_sent = 0;
1da177e4 712
a8ce4a8f 713 task->tk_timeout = task->tk_rqstp->rq_timeout;
5d00837b 714 rpc_sleep_on(&xprt->pending, task, xprt_connect_status);
0b9e7943
TM
715
716 if (test_bit(XPRT_CLOSING, &xprt->state))
717 return;
718 if (xprt_test_and_set_connecting(xprt))
719 return;
262ca07d 720 xprt->stat.connect_start = jiffies;
a246b010 721 xprt->ops->connect(task);
1da177e4 722 }
1da177e4
LT
723}
724
9903cd1c 725static void xprt_connect_status(struct rpc_task *task)
1da177e4
LT
726{
727 struct rpc_xprt *xprt = task->tk_xprt;
728
cd983ef8 729 if (task->tk_status == 0) {
262ca07d
CL
730 xprt->stat.connect_count++;
731 xprt->stat.connect_time += (long)jiffies - xprt->stat.connect_start;
46121cf7 732 dprintk("RPC: %5u xprt_connect_status: connection established\n",
1da177e4
LT
733 task->tk_pid);
734 return;
735 }
736
1da177e4 737 switch (task->tk_status) {
2a491991
TM
738 case -EAGAIN:
739 dprintk("RPC: %5u xprt_connect_status: retrying\n", task->tk_pid);
23475d66 740 break;
1da177e4 741 case -ETIMEDOUT:
46121cf7
CL
742 dprintk("RPC: %5u xprt_connect_status: connect attempt timed "
743 "out\n", task->tk_pid);
1da177e4
LT
744 break;
745 default:
46121cf7
CL
746 dprintk("RPC: %5u xprt_connect_status: error %d connecting to "
747 "server %s\n", task->tk_pid, -task->tk_status,
748 task->tk_client->cl_server);
23475d66
CL
749 xprt_release_write(xprt, task);
750 task->tk_status = -EIO;
1da177e4 751 }
1da177e4
LT
752}
753
9903cd1c
CL
754/**
755 * xprt_lookup_rqst - find an RPC request corresponding to an XID
756 * @xprt: transport on which the original request was transmitted
757 * @xid: RPC XID of incoming reply
758 *
1da177e4 759 */
d8ed029d 760struct rpc_rqst *xprt_lookup_rqst(struct rpc_xprt *xprt, __be32 xid)
1da177e4
LT
761{
762 struct list_head *pos;
1da177e4
LT
763
764 list_for_each(pos, &xprt->recv) {
765 struct rpc_rqst *entry = list_entry(pos, struct rpc_rqst, rq_list);
262ca07d
CL
766 if (entry->rq_xid == xid)
767 return entry;
1da177e4 768 }
46121cf7
CL
769
770 dprintk("RPC: xprt_lookup_rqst did not find xid %08x\n",
771 ntohl(xid));
262ca07d
CL
772 xprt->stat.bad_xids++;
773 return NULL;
1da177e4 774}
12444809 775EXPORT_SYMBOL_GPL(xprt_lookup_rqst);
1da177e4 776
1570c1e4
CL
777/**
778 * xprt_update_rtt - update an RPC client's RTT state after receiving a reply
779 * @task: RPC request that recently completed
780 *
781 */
782void xprt_update_rtt(struct rpc_task *task)
783{
784 struct rpc_rqst *req = task->tk_rqstp;
785 struct rpc_rtt *rtt = task->tk_client->cl_rtt;
786 unsigned timer = task->tk_msg.rpc_proc->p_timer;
787
788 if (timer) {
789 if (req->rq_ntrans == 1)
790 rpc_update_rtt(rtt, timer,
791 (long)jiffies - req->rq_xtime);
792 rpc_set_timeo(rtt, timer, req->rq_ntrans - 1);
793 }
794}
12444809 795EXPORT_SYMBOL_GPL(xprt_update_rtt);
1570c1e4 796
9903cd1c
CL
797/**
798 * xprt_complete_rqst - called when reply processing is complete
1570c1e4 799 * @task: RPC request that recently completed
9903cd1c
CL
800 * @copied: actual number of bytes received from the transport
801 *
1570c1e4 802 * Caller holds transport lock.
1da177e4 803 */
1570c1e4 804void xprt_complete_rqst(struct rpc_task *task, int copied)
1da177e4 805{
1570c1e4 806 struct rpc_rqst *req = task->tk_rqstp;
fda13939 807 struct rpc_xprt *xprt = req->rq_xprt;
1da177e4 808
1570c1e4
CL
809 dprintk("RPC: %5u xid %08x complete (%d bytes received)\n",
810 task->tk_pid, ntohl(req->rq_xid), copied);
1da177e4 811
fda13939 812 xprt->stat.recvs++;
ef759a2e
CL
813 task->tk_rtt = (long)jiffies - req->rq_xtime;
814
1da177e4 815 list_del_init(&req->rq_list);
1e799b67 816 req->rq_private_buf.len = copied;
dd2b63d0
RL
817 /* Ensure all writes are done before we update */
818 /* req->rq_reply_bytes_recvd */
43ac3f29 819 smp_wmb();
dd2b63d0 820 req->rq_reply_bytes_recvd = copied;
fda13939 821 rpc_wake_up_queued_task(&xprt->pending, task);
1da177e4 822}
12444809 823EXPORT_SYMBOL_GPL(xprt_complete_rqst);
1da177e4 824
46c0ee8b 825static void xprt_timer(struct rpc_task *task)
1da177e4 826{
46c0ee8b 827 struct rpc_rqst *req = task->tk_rqstp;
1da177e4
LT
828 struct rpc_xprt *xprt = req->rq_xprt;
829
5d00837b
TM
830 if (task->tk_status != -ETIMEDOUT)
831 return;
46121cf7 832 dprintk("RPC: %5u xprt_timer\n", task->tk_pid);
1da177e4 833
5d00837b 834 spin_lock_bh(&xprt->transport_lock);
dd2b63d0 835 if (!req->rq_reply_bytes_recvd) {
46c0ee8b
CL
836 if (xprt->ops->timer)
837 xprt->ops->timer(task);
5d00837b
TM
838 } else
839 task->tk_status = 0;
840 spin_unlock_bh(&xprt->transport_lock);
1da177e4
LT
841}
842
4cfc7e60
RI
843static inline int xprt_has_timer(struct rpc_xprt *xprt)
844{
845 return xprt->idle_timeout != 0;
846}
847
9903cd1c
CL
848/**
849 * xprt_prepare_transmit - reserve the transport before sending a request
850 * @task: RPC task about to send a request
851 *
1da177e4 852 */
9903cd1c 853int xprt_prepare_transmit(struct rpc_task *task)
1da177e4
LT
854{
855 struct rpc_rqst *req = task->tk_rqstp;
856 struct rpc_xprt *xprt = req->rq_xprt;
857 int err = 0;
858
46121cf7 859 dprintk("RPC: %5u xprt_prepare_transmit\n", task->tk_pid);
1da177e4 860
4a0f8c04 861 spin_lock_bh(&xprt->transport_lock);
dd2b63d0
RL
862 if (req->rq_reply_bytes_recvd && !req->rq_bytes_sent) {
863 err = req->rq_reply_bytes_recvd;
1da177e4
LT
864 goto out_unlock;
865 }
2a491991 866 if (!xprt->ops->reserve_xprt(task))
1da177e4 867 err = -EAGAIN;
1da177e4 868out_unlock:
4a0f8c04 869 spin_unlock_bh(&xprt->transport_lock);
1da177e4
LT
870 return err;
871}
872
e0ab53de 873void xprt_end_transmit(struct rpc_task *task)
5e5ce5be 874{
343952fa 875 xprt_release_write(task->tk_rqstp->rq_xprt, task);
5e5ce5be
TM
876}
877
9903cd1c
CL
878/**
879 * xprt_transmit - send an RPC request on a transport
880 * @task: controlling RPC task
881 *
882 * We have to copy the iovec because sendmsg fiddles with its contents.
883 */
884void xprt_transmit(struct rpc_task *task)
1da177e4 885{
1da177e4
LT
886 struct rpc_rqst *req = task->tk_rqstp;
887 struct rpc_xprt *xprt = req->rq_xprt;
a246b010 888 int status;
1da177e4 889
46121cf7 890 dprintk("RPC: %5u xprt_transmit(%u)\n", task->tk_pid, req->rq_slen);
1da177e4 891
dd2b63d0 892 if (!req->rq_reply_bytes_recvd) {
55ae1aab
RL
893 if (list_empty(&req->rq_list) && rpc_reply_expected(task)) {
894 /*
895 * Add to the list only if we're expecting a reply
896 */
4a0f8c04 897 spin_lock_bh(&xprt->transport_lock);
1da177e4
LT
898 /* Update the softirq receive buffer */
899 memcpy(&req->rq_private_buf, &req->rq_rcv_buf,
900 sizeof(req->rq_private_buf));
901 /* Add request to the receive list */
902 list_add_tail(&req->rq_list, &xprt->recv);
4a0f8c04 903 spin_unlock_bh(&xprt->transport_lock);
1da177e4 904 xprt_reset_majortimeo(req);
0f9dc2b1
TM
905 /* Turn off autodisconnect */
906 del_singleshot_timer_sync(&xprt->timer);
1da177e4
LT
907 }
908 } else if (!req->rq_bytes_sent)
909 return;
910
7c1d71cf 911 req->rq_connect_cookie = xprt->connect_cookie;
b22602a6 912 req->rq_xtime = jiffies;
a246b010 913 status = xprt->ops->send_request(task);
c8485e4d
TM
914 if (status != 0) {
915 task->tk_status = status;
916 return;
917 }
262ca07d 918
c8485e4d
TM
919 dprintk("RPC: %5u xmit complete\n", task->tk_pid);
920 spin_lock_bh(&xprt->transport_lock);
262ca07d 921
c8485e4d 922 xprt->ops->set_retrans_timeout(task);
262ca07d 923
c8485e4d
TM
924 xprt->stat.sends++;
925 xprt->stat.req_u += xprt->stat.sends - xprt->stat.recvs;
926 xprt->stat.bklog_u += xprt->backlog.qlen;
1da177e4 927
c8485e4d
TM
928 /* Don't race with disconnect */
929 if (!xprt_connected(xprt))
930 task->tk_status = -ENOTCONN;
dd2b63d0 931 else if (!req->rq_reply_bytes_recvd && rpc_reply_expected(task)) {
55ae1aab
RL
932 /*
933 * Sleep on the pending queue since
934 * we're expecting a reply.
935 */
c8485e4d 936 rpc_sleep_on(&xprt->pending, task, xprt_timer);
55ae1aab 937 }
c8485e4d 938 spin_unlock_bh(&xprt->transport_lock);
1da177e4
LT
939}
940
ee5ebe85 941static void xprt_alloc_slot(struct rpc_task *task)
1da177e4
LT
942{
943 struct rpc_xprt *xprt = task->tk_xprt;
944
945 task->tk_status = 0;
946 if (task->tk_rqstp)
947 return;
948 if (!list_empty(&xprt->free)) {
949 struct rpc_rqst *req = list_entry(xprt->free.next, struct rpc_rqst, rq_list);
950 list_del_init(&req->rq_list);
951 task->tk_rqstp = req;
952 xprt_request_init(task, xprt);
953 return;
954 }
46121cf7 955 dprintk("RPC: waiting for request slot\n");
1da177e4
LT
956 task->tk_status = -EAGAIN;
957 task->tk_timeout = 0;
5d00837b 958 rpc_sleep_on(&xprt->backlog, task, NULL);
1da177e4
LT
959}
960
ee5ebe85
TM
961static void xprt_free_slot(struct rpc_xprt *xprt, struct rpc_rqst *req)
962{
963 memset(req, 0, sizeof(*req)); /* mark unused */
964
965 spin_lock(&xprt->reserve_lock);
966 list_add(&req->rq_list, &xprt->free);
967 rpc_wake_up_next(&xprt->backlog);
968 spin_unlock(&xprt->reserve_lock);
969}
970
9903cd1c
CL
971/**
972 * xprt_reserve - allocate an RPC request slot
973 * @task: RPC task requesting a slot allocation
974 *
975 * If no more slots are available, place the task on the transport's
976 * backlog queue.
977 */
978void xprt_reserve(struct rpc_task *task)
1da177e4
LT
979{
980 struct rpc_xprt *xprt = task->tk_xprt;
981
982 task->tk_status = -EIO;
0065db32 983 spin_lock(&xprt->reserve_lock);
ee5ebe85 984 xprt_alloc_slot(task);
0065db32 985 spin_unlock(&xprt->reserve_lock);
1da177e4
LT
986}
987
d8ed029d 988static inline __be32 xprt_alloc_xid(struct rpc_xprt *xprt)
1da177e4
LT
989{
990 return xprt->xid++;
991}
992
993static inline void xprt_init_xid(struct rpc_xprt *xprt)
994{
bf3fcf89 995 xprt->xid = net_random();
1da177e4
LT
996}
997
9903cd1c 998static void xprt_request_init(struct rpc_task *task, struct rpc_xprt *xprt)
1da177e4
LT
999{
1000 struct rpc_rqst *req = task->tk_rqstp;
1001
ba7392bb 1002 req->rq_timeout = task->tk_client->cl_timeout->to_initval;
1da177e4
LT
1003 req->rq_task = task;
1004 req->rq_xprt = xprt;
02107148 1005 req->rq_buffer = NULL;
1da177e4 1006 req->rq_xid = xprt_alloc_xid(xprt);
ead5e1c2 1007 req->rq_release_snd_buf = NULL;
da45828e 1008 xprt_reset_majortimeo(req);
46121cf7 1009 dprintk("RPC: %5u reserved req %p xid %08x\n", task->tk_pid,
1da177e4
LT
1010 req, ntohl(req->rq_xid));
1011}
1012
9903cd1c
CL
1013/**
1014 * xprt_release - release an RPC request slot
1015 * @task: task which is finished with the slot
1016 *
1da177e4 1017 */
9903cd1c 1018void xprt_release(struct rpc_task *task)
1da177e4 1019{
55ae1aab 1020 struct rpc_xprt *xprt;
1da177e4
LT
1021 struct rpc_rqst *req;
1022
1023 if (!(req = task->tk_rqstp))
1024 return;
55ae1aab 1025
55ae1aab 1026 xprt = req->rq_xprt;
11c556b3 1027 rpc_count_iostats(task);
4a0f8c04 1028 spin_lock_bh(&xprt->transport_lock);
49e9a890 1029 xprt->ops->release_xprt(xprt, task);
a58dd398
CL
1030 if (xprt->ops->release_request)
1031 xprt->ops->release_request(task);
1da177e4
LT
1032 if (!list_empty(&req->rq_list))
1033 list_del(&req->rq_list);
1034 xprt->last_used = jiffies;
4cfc7e60 1035 if (list_empty(&xprt->recv) && xprt_has_timer(xprt))
a246b010 1036 mod_timer(&xprt->timer,
03bf4b70 1037 xprt->last_used + xprt->idle_timeout);
4a0f8c04 1038 spin_unlock_bh(&xprt->transport_lock);
ee5ebe85 1039 if (req->rq_buffer)
55ae1aab 1040 xprt->ops->buf_free(req->rq_buffer);
1da177e4 1041 task->tk_rqstp = NULL;
ead5e1c2
BF
1042 if (req->rq_release_snd_buf)
1043 req->rq_release_snd_buf(req);
55ae1aab 1044
46121cf7 1045 dprintk("RPC: %5u release request %p\n", task->tk_pid, req);
ee5ebe85
TM
1046 if (likely(!bc_prealloc(req)))
1047 xprt_free_slot(xprt, req);
1048 else
c9acb42e 1049 xprt_free_bc_request(req);
1da177e4
LT
1050}
1051
c2866763
CL
1052/**
1053 * xprt_create_transport - create an RPC transport
96802a09 1054 * @args: rpc transport creation arguments
c2866763
CL
1055 *
1056 */
3c341b0b 1057struct rpc_xprt *xprt_create_transport(struct xprt_create *args)
c2866763 1058{
c2866763
CL
1059 struct rpc_xprt *xprt;
1060 struct rpc_rqst *req;
bc25571e 1061 struct xprt_class *t;
c2866763 1062
bc25571e
TT
1063 spin_lock(&xprt_list_lock);
1064 list_for_each_entry(t, &xprt_list, list) {
4fa016eb 1065 if (t->ident == args->ident) {
bc25571e
TT
1066 spin_unlock(&xprt_list_lock);
1067 goto found;
1068 }
c2866763 1069 }
bc25571e 1070 spin_unlock(&xprt_list_lock);
4fa016eb 1071 printk(KERN_ERR "RPC: transport (%d) not supported\n", args->ident);
bc25571e
TT
1072 return ERR_PTR(-EIO);
1073
1074found:
1075 xprt = t->setup(args);
c8541ecd 1076 if (IS_ERR(xprt)) {
46121cf7 1077 dprintk("RPC: xprt_create_transport: failed, %ld\n",
c8541ecd
CL
1078 -PTR_ERR(xprt));
1079 return xprt;
c2866763
CL
1080 }
1081
6b6ca86b 1082 kref_init(&xprt->kref);
c2866763
CL
1083 spin_lock_init(&xprt->transport_lock);
1084 spin_lock_init(&xprt->reserve_lock);
1085
1086 INIT_LIST_HEAD(&xprt->free);
1087 INIT_LIST_HEAD(&xprt->recv);
f9acac1a
RL
1088#if defined(CONFIG_NFS_V4_1)
1089 spin_lock_init(&xprt->bc_pa_lock);
1090 INIT_LIST_HEAD(&xprt->bc_pa_list);
1091#endif /* CONFIG_NFS_V4_1 */
1092
65f27f38 1093 INIT_WORK(&xprt->task_cleanup, xprt_autoclose);
4cfc7e60
RI
1094 if (xprt_has_timer(xprt))
1095 setup_timer(&xprt->timer, xprt_init_autodisconnect,
1096 (unsigned long)xprt);
1097 else
1098 init_timer(&xprt->timer);
c2866763
CL
1099 xprt->last_used = jiffies;
1100 xprt->cwnd = RPC_INITCWND;
a509050b 1101 xprt->bind_index = 0;
c2866763
CL
1102
1103 rpc_init_wait_queue(&xprt->binding, "xprt_binding");
1104 rpc_init_wait_queue(&xprt->pending, "xprt_pending");
1105 rpc_init_wait_queue(&xprt->sending, "xprt_sending");
1106 rpc_init_wait_queue(&xprt->resend, "xprt_resend");
1107 rpc_init_priority_wait_queue(&xprt->backlog, "xprt_backlog");
1108
1109 /* initialize free list */
1110 for (req = &xprt->slot[xprt->max_reqs-1]; req >= &xprt->slot[0]; req--)
1111 list_add(&req->rq_list, &xprt->free);
1112
1113 xprt_init_xid(xprt);
1114
46121cf7 1115 dprintk("RPC: created transport %p with %u slots\n", xprt,
c2866763 1116 xprt->max_reqs);
c2866763
CL
1117 return xprt;
1118}
1119
9903cd1c
CL
1120/**
1121 * xprt_destroy - destroy an RPC transport, killing off all requests.
6b6ca86b 1122 * @kref: kref for the transport to destroy
9903cd1c 1123 *
1da177e4 1124 */
6b6ca86b 1125static void xprt_destroy(struct kref *kref)
1da177e4 1126{
6b6ca86b
TM
1127 struct rpc_xprt *xprt = container_of(kref, struct rpc_xprt, kref);
1128
46121cf7 1129 dprintk("RPC: destroying transport %p\n", xprt);
0065db32
TM
1130 xprt->shutdown = 1;
1131 del_timer_sync(&xprt->timer);
c8541ecd 1132
f6a1cc89
TM
1133 rpc_destroy_wait_queue(&xprt->binding);
1134 rpc_destroy_wait_queue(&xprt->pending);
1135 rpc_destroy_wait_queue(&xprt->sending);
1136 rpc_destroy_wait_queue(&xprt->resend);
1137 rpc_destroy_wait_queue(&xprt->backlog);
c8541ecd
CL
1138 /*
1139 * Tear down transport state and free the rpc_xprt
1140 */
a246b010 1141 xprt->ops->destroy(xprt);
6b6ca86b 1142}
1da177e4 1143
6b6ca86b
TM
1144/**
1145 * xprt_put - release a reference to an RPC transport.
1146 * @xprt: pointer to the transport
1147 *
1148 */
1149void xprt_put(struct rpc_xprt *xprt)
1150{
1151 kref_put(&xprt->kref, xprt_destroy);
1152}
1153
1154/**
1155 * xprt_get - return a reference to an RPC transport.
1156 * @xprt: pointer to the transport
1157 *
1158 */
1159struct rpc_xprt *xprt_get(struct rpc_xprt *xprt)
1160{
1161 kref_get(&xprt->kref);
1162 return xprt;
1da177e4 1163}