]> asedeno.scripts.mit.edu Git - linux.git/blob - net/sunrpc/xprt.c
36af1a1929afe70467c2e1a62cb35570ccdd1413
[linux.git] / net / sunrpc / xprt.c
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
13  *      the request struct, and calls xprt_transmit().
14  *  -   xprt_transmit sends the message and installs the caller on the
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.
18  *  -   When a packet arrives, the data_ready handler walks the list of
19  *      pending requests for that transport. If a matching XID is found, the
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>
36  *
37  *  Transport switch API copyright (C) 2005, Chuck Lever <cel@netapp.com>
38  */
39
40 #include <linux/module.h>
41
42 #include <linux/types.h>
43 #include <linux/interrupt.h>
44 #include <linux/workqueue.h>
45 #include <linux/net.h>
46 #include <linux/ktime.h>
47
48 #include <linux/sunrpc/clnt.h>
49 #include <linux/sunrpc/metrics.h>
50 #include <linux/sunrpc/bc_xprt.h>
51 #include <linux/rcupdate.h>
52 #include <linux/sched/mm.h>
53
54 #include <trace/events/sunrpc.h>
55
56 #include "sunrpc.h"
57
58 /*
59  * Local variables
60  */
61
62 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
63 # define RPCDBG_FACILITY        RPCDBG_XPRT
64 #endif
65
66 /*
67  * Local functions
68  */
69 static void      xprt_init(struct rpc_xprt *xprt, struct net *net);
70 static __be32   xprt_alloc_xid(struct rpc_xprt *xprt);
71 static void      xprt_destroy(struct rpc_xprt *xprt);
72
73 static DEFINE_SPINLOCK(xprt_list_lock);
74 static LIST_HEAD(xprt_list);
75
76 /**
77  * xprt_register_transport - register a transport implementation
78  * @transport: transport to register
79  *
80  * If a transport implementation is loaded as a kernel module, it can
81  * call this interface to make itself known to the RPC client.
82  *
83  * Returns:
84  * 0:           transport successfully registered
85  * -EEXIST:     transport already registered
86  * -EINVAL:     transport module being unloaded
87  */
88 int xprt_register_transport(struct xprt_class *transport)
89 {
90         struct xprt_class *t;
91         int result;
92
93         result = -EEXIST;
94         spin_lock(&xprt_list_lock);
95         list_for_each_entry(t, &xprt_list, list) {
96                 /* don't register the same transport class twice */
97                 if (t->ident == transport->ident)
98                         goto out;
99         }
100
101         list_add_tail(&transport->list, &xprt_list);
102         printk(KERN_INFO "RPC: Registered %s transport module.\n",
103                transport->name);
104         result = 0;
105
106 out:
107         spin_unlock(&xprt_list_lock);
108         return result;
109 }
110 EXPORT_SYMBOL_GPL(xprt_register_transport);
111
112 /**
113  * xprt_unregister_transport - unregister a transport implementation
114  * @transport: transport to unregister
115  *
116  * Returns:
117  * 0:           transport successfully unregistered
118  * -ENOENT:     transport never registered
119  */
120 int xprt_unregister_transport(struct xprt_class *transport)
121 {
122         struct xprt_class *t;
123         int result;
124
125         result = 0;
126         spin_lock(&xprt_list_lock);
127         list_for_each_entry(t, &xprt_list, list) {
128                 if (t == transport) {
129                         printk(KERN_INFO
130                                 "RPC: Unregistered %s transport module.\n",
131                                 transport->name);
132                         list_del_init(&transport->list);
133                         goto out;
134                 }
135         }
136         result = -ENOENT;
137
138 out:
139         spin_unlock(&xprt_list_lock);
140         return result;
141 }
142 EXPORT_SYMBOL_GPL(xprt_unregister_transport);
143
144 /**
145  * xprt_load_transport - load a transport implementation
146  * @transport_name: transport to load
147  *
148  * Returns:
149  * 0:           transport successfully loaded
150  * -ENOENT:     transport module not available
151  */
152 int xprt_load_transport(const char *transport_name)
153 {
154         struct xprt_class *t;
155         int result;
156
157         result = 0;
158         spin_lock(&xprt_list_lock);
159         list_for_each_entry(t, &xprt_list, list) {
160                 if (strcmp(t->name, transport_name) == 0) {
161                         spin_unlock(&xprt_list_lock);
162                         goto out;
163                 }
164         }
165         spin_unlock(&xprt_list_lock);
166         result = request_module("xprt%s", transport_name);
167 out:
168         return result;
169 }
170 EXPORT_SYMBOL_GPL(xprt_load_transport);
171
172 static void xprt_clear_locked(struct rpc_xprt *xprt)
173 {
174         xprt->snd_task = NULL;
175         if (!test_bit(XPRT_CLOSE_WAIT, &xprt->state)) {
176                 smp_mb__before_atomic();
177                 clear_bit(XPRT_LOCKED, &xprt->state);
178                 smp_mb__after_atomic();
179         } else
180                 queue_work(xprtiod_workqueue, &xprt->task_cleanup);
181 }
182
183 /**
184  * xprt_reserve_xprt - serialize write access to transports
185  * @task: task that is requesting access to the transport
186  * @xprt: pointer to the target transport
187  *
188  * This prevents mixing the payload of separate requests, and prevents
189  * transport connects from colliding with writes.  No congestion control
190  * is provided.
191  */
192 int xprt_reserve_xprt(struct rpc_xprt *xprt, struct rpc_task *task)
193 {
194         struct rpc_rqst *req = task->tk_rqstp;
195
196         if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) {
197                 if (task == xprt->snd_task)
198                         return 1;
199                 goto out_sleep;
200         }
201         if (test_bit(XPRT_WRITE_SPACE, &xprt->state))
202                 goto out_unlock;
203         xprt->snd_task = task;
204
205         return 1;
206
207 out_unlock:
208         xprt_clear_locked(xprt);
209 out_sleep:
210         dprintk("RPC: %5u failed to lock transport %p\n",
211                         task->tk_pid, xprt);
212         task->tk_status = -EAGAIN;
213         if  (RPC_IS_SOFT(task))
214                 rpc_sleep_on_timeout(&xprt->sending, task, NULL,
215                                 jiffies + req->rq_timeout);
216         else
217                 rpc_sleep_on(&xprt->sending, task, NULL);
218         return 0;
219 }
220 EXPORT_SYMBOL_GPL(xprt_reserve_xprt);
221
222 static bool
223 xprt_need_congestion_window_wait(struct rpc_xprt *xprt)
224 {
225         return test_bit(XPRT_CWND_WAIT, &xprt->state);
226 }
227
228 static void
229 xprt_set_congestion_window_wait(struct rpc_xprt *xprt)
230 {
231         if (!list_empty(&xprt->xmit_queue)) {
232                 /* Peek at head of queue to see if it can make progress */
233                 if (list_first_entry(&xprt->xmit_queue, struct rpc_rqst,
234                                         rq_xmit)->rq_cong)
235                         return;
236         }
237         set_bit(XPRT_CWND_WAIT, &xprt->state);
238 }
239
240 static void
241 xprt_test_and_clear_congestion_window_wait(struct rpc_xprt *xprt)
242 {
243         if (!RPCXPRT_CONGESTED(xprt))
244                 clear_bit(XPRT_CWND_WAIT, &xprt->state);
245 }
246
247 /*
248  * xprt_reserve_xprt_cong - serialize write access to transports
249  * @task: task that is requesting access to the transport
250  *
251  * Same as xprt_reserve_xprt, but Van Jacobson congestion control is
252  * integrated into the decision of whether a request is allowed to be
253  * woken up and given access to the transport.
254  * Note that the lock is only granted if we know there are free slots.
255  */
256 int xprt_reserve_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task)
257 {
258         struct rpc_rqst *req = task->tk_rqstp;
259
260         if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) {
261                 if (task == xprt->snd_task)
262                         return 1;
263                 goto out_sleep;
264         }
265         if (req == NULL) {
266                 xprt->snd_task = task;
267                 return 1;
268         }
269         if (test_bit(XPRT_WRITE_SPACE, &xprt->state))
270                 goto out_unlock;
271         if (!xprt_need_congestion_window_wait(xprt)) {
272                 xprt->snd_task = task;
273                 return 1;
274         }
275 out_unlock:
276         xprt_clear_locked(xprt);
277 out_sleep:
278         dprintk("RPC: %5u failed to lock transport %p\n", task->tk_pid, xprt);
279         task->tk_status = -EAGAIN;
280         if (RPC_IS_SOFT(task))
281                 rpc_sleep_on_timeout(&xprt->sending, task, NULL,
282                                 jiffies + req->rq_timeout);
283         else
284                 rpc_sleep_on(&xprt->sending, task, NULL);
285         return 0;
286 }
287 EXPORT_SYMBOL_GPL(xprt_reserve_xprt_cong);
288
289 static inline int xprt_lock_write(struct rpc_xprt *xprt, struct rpc_task *task)
290 {
291         int retval;
292
293         if (test_bit(XPRT_LOCKED, &xprt->state) && xprt->snd_task == task)
294                 return 1;
295         spin_lock_bh(&xprt->transport_lock);
296         retval = xprt->ops->reserve_xprt(xprt, task);
297         spin_unlock_bh(&xprt->transport_lock);
298         return retval;
299 }
300
301 static bool __xprt_lock_write_func(struct rpc_task *task, void *data)
302 {
303         struct rpc_xprt *xprt = data;
304
305         xprt->snd_task = task;
306         return true;
307 }
308
309 static void __xprt_lock_write_next(struct rpc_xprt *xprt)
310 {
311         if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
312                 return;
313         if (test_bit(XPRT_WRITE_SPACE, &xprt->state))
314                 goto out_unlock;
315         if (rpc_wake_up_first_on_wq(xprtiod_workqueue, &xprt->sending,
316                                 __xprt_lock_write_func, xprt))
317                 return;
318 out_unlock:
319         xprt_clear_locked(xprt);
320 }
321
322 static void __xprt_lock_write_next_cong(struct rpc_xprt *xprt)
323 {
324         if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
325                 return;
326         if (test_bit(XPRT_WRITE_SPACE, &xprt->state))
327                 goto out_unlock;
328         if (xprt_need_congestion_window_wait(xprt))
329                 goto out_unlock;
330         if (rpc_wake_up_first_on_wq(xprtiod_workqueue, &xprt->sending,
331                                 __xprt_lock_write_func, xprt))
332                 return;
333 out_unlock:
334         xprt_clear_locked(xprt);
335 }
336
337 /**
338  * xprt_release_xprt - allow other requests to use a transport
339  * @xprt: transport with other tasks potentially waiting
340  * @task: task that is releasing access to the transport
341  *
342  * Note that "task" can be NULL.  No congestion control is provided.
343  */
344 void xprt_release_xprt(struct rpc_xprt *xprt, struct rpc_task *task)
345 {
346         if (xprt->snd_task == task) {
347                 xprt_clear_locked(xprt);
348                 __xprt_lock_write_next(xprt);
349         }
350 }
351 EXPORT_SYMBOL_GPL(xprt_release_xprt);
352
353 /**
354  * xprt_release_xprt_cong - allow other requests to use a transport
355  * @xprt: transport with other tasks potentially waiting
356  * @task: task that is releasing access to the transport
357  *
358  * Note that "task" can be NULL.  Another task is awoken to use the
359  * transport if the transport's congestion window allows it.
360  */
361 void xprt_release_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task)
362 {
363         if (xprt->snd_task == task) {
364                 xprt_clear_locked(xprt);
365                 __xprt_lock_write_next_cong(xprt);
366         }
367 }
368 EXPORT_SYMBOL_GPL(xprt_release_xprt_cong);
369
370 static inline void xprt_release_write(struct rpc_xprt *xprt, struct rpc_task *task)
371 {
372         if (xprt->snd_task != task)
373                 return;
374         spin_lock_bh(&xprt->transport_lock);
375         xprt->ops->release_xprt(xprt, task);
376         spin_unlock_bh(&xprt->transport_lock);
377 }
378
379 /*
380  * Van Jacobson congestion avoidance. Check if the congestion window
381  * overflowed. Put the task to sleep if this is the case.
382  */
383 static int
384 __xprt_get_cong(struct rpc_xprt *xprt, struct rpc_rqst *req)
385 {
386         if (req->rq_cong)
387                 return 1;
388         dprintk("RPC: %5u xprt_cwnd_limited cong = %lu cwnd = %lu\n",
389                         req->rq_task->tk_pid, xprt->cong, xprt->cwnd);
390         if (RPCXPRT_CONGESTED(xprt)) {
391                 xprt_set_congestion_window_wait(xprt);
392                 return 0;
393         }
394         req->rq_cong = 1;
395         xprt->cong += RPC_CWNDSCALE;
396         return 1;
397 }
398
399 /*
400  * Adjust the congestion window, and wake up the next task
401  * that has been sleeping due to congestion
402  */
403 static void
404 __xprt_put_cong(struct rpc_xprt *xprt, struct rpc_rqst *req)
405 {
406         if (!req->rq_cong)
407                 return;
408         req->rq_cong = 0;
409         xprt->cong -= RPC_CWNDSCALE;
410         xprt_test_and_clear_congestion_window_wait(xprt);
411         __xprt_lock_write_next_cong(xprt);
412 }
413
414 /**
415  * xprt_request_get_cong - Request congestion control credits
416  * @xprt: pointer to transport
417  * @req: pointer to RPC request
418  *
419  * Useful for transports that require congestion control.
420  */
421 bool
422 xprt_request_get_cong(struct rpc_xprt *xprt, struct rpc_rqst *req)
423 {
424         bool ret = false;
425
426         if (req->rq_cong)
427                 return true;
428         spin_lock_bh(&xprt->transport_lock);
429         ret = __xprt_get_cong(xprt, req) != 0;
430         spin_unlock_bh(&xprt->transport_lock);
431         return ret;
432 }
433 EXPORT_SYMBOL_GPL(xprt_request_get_cong);
434
435 /**
436  * xprt_release_rqst_cong - housekeeping when request is complete
437  * @task: RPC request that recently completed
438  *
439  * Useful for transports that require congestion control.
440  */
441 void xprt_release_rqst_cong(struct rpc_task *task)
442 {
443         struct rpc_rqst *req = task->tk_rqstp;
444
445         __xprt_put_cong(req->rq_xprt, req);
446 }
447 EXPORT_SYMBOL_GPL(xprt_release_rqst_cong);
448
449 /*
450  * Clear the congestion window wait flag and wake up the next
451  * entry on xprt->sending
452  */
453 static void
454 xprt_clear_congestion_window_wait(struct rpc_xprt *xprt)
455 {
456         if (test_and_clear_bit(XPRT_CWND_WAIT, &xprt->state)) {
457                 spin_lock_bh(&xprt->transport_lock);
458                 __xprt_lock_write_next_cong(xprt);
459                 spin_unlock_bh(&xprt->transport_lock);
460         }
461 }
462
463 /**
464  * xprt_adjust_cwnd - adjust transport congestion window
465  * @xprt: pointer to xprt
466  * @task: recently completed RPC request used to adjust window
467  * @result: result code of completed RPC request
468  *
469  * The transport code maintains an estimate on the maximum number of out-
470  * standing RPC requests, using a smoothed version of the congestion
471  * avoidance implemented in 44BSD. This is basically the Van Jacobson
472  * congestion algorithm: If a retransmit occurs, the congestion window is
473  * halved; otherwise, it is incremented by 1/cwnd when
474  *
475  *      -       a reply is received and
476  *      -       a full number of requests are outstanding and
477  *      -       the congestion window hasn't been updated recently.
478  */
479 void xprt_adjust_cwnd(struct rpc_xprt *xprt, struct rpc_task *task, int result)
480 {
481         struct rpc_rqst *req = task->tk_rqstp;
482         unsigned long cwnd = xprt->cwnd;
483
484         if (result >= 0 && cwnd <= xprt->cong) {
485                 /* The (cwnd >> 1) term makes sure
486                  * the result gets rounded properly. */
487                 cwnd += (RPC_CWNDSCALE * RPC_CWNDSCALE + (cwnd >> 1)) / cwnd;
488                 if (cwnd > RPC_MAXCWND(xprt))
489                         cwnd = RPC_MAXCWND(xprt);
490                 __xprt_lock_write_next_cong(xprt);
491         } else if (result == -ETIMEDOUT) {
492                 cwnd >>= 1;
493                 if (cwnd < RPC_CWNDSCALE)
494                         cwnd = RPC_CWNDSCALE;
495         }
496         dprintk("RPC:       cong %ld, cwnd was %ld, now %ld\n",
497                         xprt->cong, xprt->cwnd, cwnd);
498         xprt->cwnd = cwnd;
499         __xprt_put_cong(xprt, req);
500 }
501 EXPORT_SYMBOL_GPL(xprt_adjust_cwnd);
502
503 /**
504  * xprt_wake_pending_tasks - wake all tasks on a transport's pending queue
505  * @xprt: transport with waiting tasks
506  * @status: result code to plant in each task before waking it
507  *
508  */
509 void xprt_wake_pending_tasks(struct rpc_xprt *xprt, int status)
510 {
511         if (status < 0)
512                 rpc_wake_up_status(&xprt->pending, status);
513         else
514                 rpc_wake_up(&xprt->pending);
515 }
516 EXPORT_SYMBOL_GPL(xprt_wake_pending_tasks);
517
518 /**
519  * xprt_wait_for_buffer_space - wait for transport output buffer to clear
520  * @xprt: transport
521  *
522  * Note that we only set the timer for the case of RPC_IS_SOFT(), since
523  * we don't in general want to force a socket disconnection due to
524  * an incomplete RPC call transmission.
525  */
526 void xprt_wait_for_buffer_space(struct rpc_xprt *xprt)
527 {
528         set_bit(XPRT_WRITE_SPACE, &xprt->state);
529 }
530 EXPORT_SYMBOL_GPL(xprt_wait_for_buffer_space);
531
532 static bool
533 xprt_clear_write_space_locked(struct rpc_xprt *xprt)
534 {
535         if (test_and_clear_bit(XPRT_WRITE_SPACE, &xprt->state)) {
536                 __xprt_lock_write_next(xprt);
537                 dprintk("RPC:       write space: waking waiting task on "
538                                 "xprt %p\n", xprt);
539                 return true;
540         }
541         return false;
542 }
543
544 /**
545  * xprt_write_space - wake the task waiting for transport output buffer space
546  * @xprt: transport with waiting tasks
547  *
548  * Can be called in a soft IRQ context, so xprt_write_space never sleeps.
549  */
550 bool xprt_write_space(struct rpc_xprt *xprt)
551 {
552         bool ret;
553
554         if (!test_bit(XPRT_WRITE_SPACE, &xprt->state))
555                 return false;
556         spin_lock_bh(&xprt->transport_lock);
557         ret = xprt_clear_write_space_locked(xprt);
558         spin_unlock_bh(&xprt->transport_lock);
559         return ret;
560 }
561 EXPORT_SYMBOL_GPL(xprt_write_space);
562
563 static void xprt_reset_majortimeo(struct rpc_rqst *req)
564 {
565         const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout;
566
567         req->rq_majortimeo = req->rq_timeout;
568         if (to->to_exponential)
569                 req->rq_majortimeo <<= to->to_retries;
570         else
571                 req->rq_majortimeo += to->to_increment * to->to_retries;
572         if (req->rq_majortimeo > to->to_maxval || req->rq_majortimeo == 0)
573                 req->rq_majortimeo = to->to_maxval;
574         req->rq_majortimeo += jiffies;
575 }
576
577 /**
578  * xprt_adjust_timeout - adjust timeout values for next retransmit
579  * @req: RPC request containing parameters to use for the adjustment
580  *
581  */
582 int xprt_adjust_timeout(struct rpc_rqst *req)
583 {
584         struct rpc_xprt *xprt = req->rq_xprt;
585         const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout;
586         int status = 0;
587
588         if (time_before(jiffies, req->rq_majortimeo)) {
589                 if (to->to_exponential)
590                         req->rq_timeout <<= 1;
591                 else
592                         req->rq_timeout += to->to_increment;
593                 if (to->to_maxval && req->rq_timeout >= to->to_maxval)
594                         req->rq_timeout = to->to_maxval;
595                 req->rq_retries++;
596         } else {
597                 req->rq_timeout = to->to_initval;
598                 req->rq_retries = 0;
599                 xprt_reset_majortimeo(req);
600                 /* Reset the RTT counters == "slow start" */
601                 spin_lock_bh(&xprt->transport_lock);
602                 rpc_init_rtt(req->rq_task->tk_client->cl_rtt, to->to_initval);
603                 spin_unlock_bh(&xprt->transport_lock);
604                 status = -ETIMEDOUT;
605         }
606
607         if (req->rq_timeout == 0) {
608                 printk(KERN_WARNING "xprt_adjust_timeout: rq_timeout = 0!\n");
609                 req->rq_timeout = 5 * HZ;
610         }
611         return status;
612 }
613
614 static void xprt_autoclose(struct work_struct *work)
615 {
616         struct rpc_xprt *xprt =
617                 container_of(work, struct rpc_xprt, task_cleanup);
618         unsigned int pflags = memalloc_nofs_save();
619
620         clear_bit(XPRT_CLOSE_WAIT, &xprt->state);
621         xprt->ops->close(xprt);
622         xprt_release_write(xprt, NULL);
623         wake_up_bit(&xprt->state, XPRT_LOCKED);
624         memalloc_nofs_restore(pflags);
625 }
626
627 /**
628  * xprt_disconnect_done - mark a transport as disconnected
629  * @xprt: transport to flag for disconnect
630  *
631  */
632 void xprt_disconnect_done(struct rpc_xprt *xprt)
633 {
634         dprintk("RPC:       disconnected transport %p\n", xprt);
635         spin_lock_bh(&xprt->transport_lock);
636         xprt_clear_connected(xprt);
637         xprt_clear_write_space_locked(xprt);
638         xprt_wake_pending_tasks(xprt, -ENOTCONN);
639         spin_unlock_bh(&xprt->transport_lock);
640 }
641 EXPORT_SYMBOL_GPL(xprt_disconnect_done);
642
643 /**
644  * xprt_force_disconnect - force a transport to disconnect
645  * @xprt: transport to disconnect
646  *
647  */
648 void xprt_force_disconnect(struct rpc_xprt *xprt)
649 {
650         /* Don't race with the test_bit() in xprt_clear_locked() */
651         spin_lock_bh(&xprt->transport_lock);
652         set_bit(XPRT_CLOSE_WAIT, &xprt->state);
653         /* Try to schedule an autoclose RPC call */
654         if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
655                 queue_work(xprtiod_workqueue, &xprt->task_cleanup);
656         else if (xprt->snd_task)
657                 rpc_wake_up_queued_task_set_status(&xprt->pending,
658                                 xprt->snd_task, -ENOTCONN);
659         spin_unlock_bh(&xprt->transport_lock);
660 }
661 EXPORT_SYMBOL_GPL(xprt_force_disconnect);
662
663 static unsigned int
664 xprt_connect_cookie(struct rpc_xprt *xprt)
665 {
666         return READ_ONCE(xprt->connect_cookie);
667 }
668
669 static bool
670 xprt_request_retransmit_after_disconnect(struct rpc_task *task)
671 {
672         struct rpc_rqst *req = task->tk_rqstp;
673         struct rpc_xprt *xprt = req->rq_xprt;
674
675         return req->rq_connect_cookie != xprt_connect_cookie(xprt) ||
676                 !xprt_connected(xprt);
677 }
678
679 /**
680  * xprt_conditional_disconnect - force a transport to disconnect
681  * @xprt: transport to disconnect
682  * @cookie: 'connection cookie'
683  *
684  * This attempts to break the connection if and only if 'cookie' matches
685  * the current transport 'connection cookie'. It ensures that we don't
686  * try to break the connection more than once when we need to retransmit
687  * a batch of RPC requests.
688  *
689  */
690 void xprt_conditional_disconnect(struct rpc_xprt *xprt, unsigned int cookie)
691 {
692         /* Don't race with the test_bit() in xprt_clear_locked() */
693         spin_lock_bh(&xprt->transport_lock);
694         if (cookie != xprt->connect_cookie)
695                 goto out;
696         if (test_bit(XPRT_CLOSING, &xprt->state))
697                 goto out;
698         set_bit(XPRT_CLOSE_WAIT, &xprt->state);
699         /* Try to schedule an autoclose RPC call */
700         if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
701                 queue_work(xprtiod_workqueue, &xprt->task_cleanup);
702         xprt_wake_pending_tasks(xprt, -EAGAIN);
703 out:
704         spin_unlock_bh(&xprt->transport_lock);
705 }
706
707 static bool
708 xprt_has_timer(const struct rpc_xprt *xprt)
709 {
710         return xprt->idle_timeout != 0;
711 }
712
713 static void
714 xprt_schedule_autodisconnect(struct rpc_xprt *xprt)
715         __must_hold(&xprt->transport_lock)
716 {
717         if (RB_EMPTY_ROOT(&xprt->recv_queue) && xprt_has_timer(xprt))
718                 mod_timer(&xprt->timer, xprt->last_used + xprt->idle_timeout);
719 }
720
721 static void
722 xprt_init_autodisconnect(struct timer_list *t)
723 {
724         struct rpc_xprt *xprt = from_timer(xprt, t, timer);
725
726         spin_lock(&xprt->transport_lock);
727         if (!RB_EMPTY_ROOT(&xprt->recv_queue))
728                 goto out_abort;
729         /* Reset xprt->last_used to avoid connect/autodisconnect cycling */
730         xprt->last_used = jiffies;
731         if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
732                 goto out_abort;
733         spin_unlock(&xprt->transport_lock);
734         queue_work(xprtiod_workqueue, &xprt->task_cleanup);
735         return;
736 out_abort:
737         spin_unlock(&xprt->transport_lock);
738 }
739
740 bool xprt_lock_connect(struct rpc_xprt *xprt,
741                 struct rpc_task *task,
742                 void *cookie)
743 {
744         bool ret = false;
745
746         spin_lock_bh(&xprt->transport_lock);
747         if (!test_bit(XPRT_LOCKED, &xprt->state))
748                 goto out;
749         if (xprt->snd_task != task)
750                 goto out;
751         xprt->snd_task = cookie;
752         ret = true;
753 out:
754         spin_unlock_bh(&xprt->transport_lock);
755         return ret;
756 }
757
758 void xprt_unlock_connect(struct rpc_xprt *xprt, void *cookie)
759 {
760         spin_lock_bh(&xprt->transport_lock);
761         if (xprt->snd_task != cookie)
762                 goto out;
763         if (!test_bit(XPRT_LOCKED, &xprt->state))
764                 goto out;
765         xprt->snd_task =NULL;
766         xprt->ops->release_xprt(xprt, NULL);
767         xprt_schedule_autodisconnect(xprt);
768 out:
769         spin_unlock_bh(&xprt->transport_lock);
770         wake_up_bit(&xprt->state, XPRT_LOCKED);
771 }
772
773 /**
774  * xprt_connect - schedule a transport connect operation
775  * @task: RPC task that is requesting the connect
776  *
777  */
778 void xprt_connect(struct rpc_task *task)
779 {
780         struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt;
781
782         dprintk("RPC: %5u xprt_connect xprt %p %s connected\n", task->tk_pid,
783                         xprt, (xprt_connected(xprt) ? "is" : "is not"));
784
785         if (!xprt_bound(xprt)) {
786                 task->tk_status = -EAGAIN;
787                 return;
788         }
789         if (!xprt_lock_write(xprt, task))
790                 return;
791
792         if (test_and_clear_bit(XPRT_CLOSE_WAIT, &xprt->state))
793                 xprt->ops->close(xprt);
794
795         if (!xprt_connected(xprt)) {
796                 task->tk_rqstp->rq_connect_cookie = xprt->connect_cookie;
797                 rpc_sleep_on_timeout(&xprt->pending, task, NULL,
798                                 jiffies + task->tk_rqstp->rq_timeout);
799
800                 if (test_bit(XPRT_CLOSING, &xprt->state))
801                         return;
802                 if (xprt_test_and_set_connecting(xprt))
803                         return;
804                 /* Race breaker */
805                 if (!xprt_connected(xprt)) {
806                         xprt->stat.connect_start = jiffies;
807                         xprt->ops->connect(xprt, task);
808                 } else {
809                         xprt_clear_connecting(xprt);
810                         task->tk_status = 0;
811                         rpc_wake_up_queued_task(&xprt->pending, task);
812                 }
813         }
814         xprt_release_write(xprt, task);
815 }
816
817 enum xprt_xid_rb_cmp {
818         XID_RB_EQUAL,
819         XID_RB_LEFT,
820         XID_RB_RIGHT,
821 };
822 static enum xprt_xid_rb_cmp
823 xprt_xid_cmp(__be32 xid1, __be32 xid2)
824 {
825         if (xid1 == xid2)
826                 return XID_RB_EQUAL;
827         if ((__force u32)xid1 < (__force u32)xid2)
828                 return XID_RB_LEFT;
829         return XID_RB_RIGHT;
830 }
831
832 static struct rpc_rqst *
833 xprt_request_rb_find(struct rpc_xprt *xprt, __be32 xid)
834 {
835         struct rb_node *n = xprt->recv_queue.rb_node;
836         struct rpc_rqst *req;
837
838         while (n != NULL) {
839                 req = rb_entry(n, struct rpc_rqst, rq_recv);
840                 switch (xprt_xid_cmp(xid, req->rq_xid)) {
841                 case XID_RB_LEFT:
842                         n = n->rb_left;
843                         break;
844                 case XID_RB_RIGHT:
845                         n = n->rb_right;
846                         break;
847                 case XID_RB_EQUAL:
848                         return req;
849                 }
850         }
851         return NULL;
852 }
853
854 static void
855 xprt_request_rb_insert(struct rpc_xprt *xprt, struct rpc_rqst *new)
856 {
857         struct rb_node **p = &xprt->recv_queue.rb_node;
858         struct rb_node *n = NULL;
859         struct rpc_rqst *req;
860
861         while (*p != NULL) {
862                 n = *p;
863                 req = rb_entry(n, struct rpc_rqst, rq_recv);
864                 switch(xprt_xid_cmp(new->rq_xid, req->rq_xid)) {
865                 case XID_RB_LEFT:
866                         p = &n->rb_left;
867                         break;
868                 case XID_RB_RIGHT:
869                         p = &n->rb_right;
870                         break;
871                 case XID_RB_EQUAL:
872                         WARN_ON_ONCE(new != req);
873                         return;
874                 }
875         }
876         rb_link_node(&new->rq_recv, n, p);
877         rb_insert_color(&new->rq_recv, &xprt->recv_queue);
878 }
879
880 static void
881 xprt_request_rb_remove(struct rpc_xprt *xprt, struct rpc_rqst *req)
882 {
883         rb_erase(&req->rq_recv, &xprt->recv_queue);
884 }
885
886 /**
887  * xprt_lookup_rqst - find an RPC request corresponding to an XID
888  * @xprt: transport on which the original request was transmitted
889  * @xid: RPC XID of incoming reply
890  *
891  * Caller holds xprt->queue_lock.
892  */
893 struct rpc_rqst *xprt_lookup_rqst(struct rpc_xprt *xprt, __be32 xid)
894 {
895         struct rpc_rqst *entry;
896
897         entry = xprt_request_rb_find(xprt, xid);
898         if (entry != NULL) {
899                 trace_xprt_lookup_rqst(xprt, xid, 0);
900                 entry->rq_rtt = ktime_sub(ktime_get(), entry->rq_xtime);
901                 return entry;
902         }
903
904         dprintk("RPC:       xprt_lookup_rqst did not find xid %08x\n",
905                         ntohl(xid));
906         trace_xprt_lookup_rqst(xprt, xid, -ENOENT);
907         xprt->stat.bad_xids++;
908         return NULL;
909 }
910 EXPORT_SYMBOL_GPL(xprt_lookup_rqst);
911
912 static bool
913 xprt_is_pinned_rqst(struct rpc_rqst *req)
914 {
915         return atomic_read(&req->rq_pin) != 0;
916 }
917
918 /**
919  * xprt_pin_rqst - Pin a request on the transport receive list
920  * @req: Request to pin
921  *
922  * Caller must ensure this is atomic with the call to xprt_lookup_rqst()
923  * so should be holding the xprt receive lock.
924  */
925 void xprt_pin_rqst(struct rpc_rqst *req)
926 {
927         atomic_inc(&req->rq_pin);
928 }
929 EXPORT_SYMBOL_GPL(xprt_pin_rqst);
930
931 /**
932  * xprt_unpin_rqst - Unpin a request on the transport receive list
933  * @req: Request to pin
934  *
935  * Caller should be holding the xprt receive lock.
936  */
937 void xprt_unpin_rqst(struct rpc_rqst *req)
938 {
939         if (!test_bit(RPC_TASK_MSG_PIN_WAIT, &req->rq_task->tk_runstate)) {
940                 atomic_dec(&req->rq_pin);
941                 return;
942         }
943         if (atomic_dec_and_test(&req->rq_pin))
944                 wake_up_var(&req->rq_pin);
945 }
946 EXPORT_SYMBOL_GPL(xprt_unpin_rqst);
947
948 static void xprt_wait_on_pinned_rqst(struct rpc_rqst *req)
949 {
950         wait_var_event(&req->rq_pin, !xprt_is_pinned_rqst(req));
951 }
952
953 static bool
954 xprt_request_data_received(struct rpc_task *task)
955 {
956         return !test_bit(RPC_TASK_NEED_RECV, &task->tk_runstate) &&
957                 READ_ONCE(task->tk_rqstp->rq_reply_bytes_recvd) != 0;
958 }
959
960 static bool
961 xprt_request_need_enqueue_receive(struct rpc_task *task, struct rpc_rqst *req)
962 {
963         return !test_bit(RPC_TASK_NEED_RECV, &task->tk_runstate) &&
964                 READ_ONCE(task->tk_rqstp->rq_reply_bytes_recvd) == 0;
965 }
966
967 /**
968  * xprt_request_enqueue_receive - Add an request to the receive queue
969  * @task: RPC task
970  *
971  */
972 void
973 xprt_request_enqueue_receive(struct rpc_task *task)
974 {
975         struct rpc_rqst *req = task->tk_rqstp;
976         struct rpc_xprt *xprt = req->rq_xprt;
977
978         if (!xprt_request_need_enqueue_receive(task, req))
979                 return;
980         spin_lock(&xprt->queue_lock);
981
982         /* Update the softirq receive buffer */
983         memcpy(&req->rq_private_buf, &req->rq_rcv_buf,
984                         sizeof(req->rq_private_buf));
985
986         /* Add request to the receive list */
987         xprt_request_rb_insert(xprt, req);
988         set_bit(RPC_TASK_NEED_RECV, &task->tk_runstate);
989         spin_unlock(&xprt->queue_lock);
990
991         xprt_reset_majortimeo(req);
992         /* Turn off autodisconnect */
993         del_singleshot_timer_sync(&xprt->timer);
994 }
995
996 /**
997  * xprt_request_dequeue_receive_locked - Remove a request from the receive queue
998  * @task: RPC task
999  *
1000  * Caller must hold xprt->queue_lock.
1001  */
1002 static void
1003 xprt_request_dequeue_receive_locked(struct rpc_task *task)
1004 {
1005         struct rpc_rqst *req = task->tk_rqstp;
1006
1007         if (test_and_clear_bit(RPC_TASK_NEED_RECV, &task->tk_runstate))
1008                 xprt_request_rb_remove(req->rq_xprt, req);
1009 }
1010
1011 /**
1012  * xprt_update_rtt - Update RPC RTT statistics
1013  * @task: RPC request that recently completed
1014  *
1015  * Caller holds xprt->queue_lock.
1016  */
1017 void xprt_update_rtt(struct rpc_task *task)
1018 {
1019         struct rpc_rqst *req = task->tk_rqstp;
1020         struct rpc_rtt *rtt = task->tk_client->cl_rtt;
1021         unsigned int timer = task->tk_msg.rpc_proc->p_timer;
1022         long m = usecs_to_jiffies(ktime_to_us(req->rq_rtt));
1023
1024         if (timer) {
1025                 if (req->rq_ntrans == 1)
1026                         rpc_update_rtt(rtt, timer, m);
1027                 rpc_set_timeo(rtt, timer, req->rq_ntrans - 1);
1028         }
1029 }
1030 EXPORT_SYMBOL_GPL(xprt_update_rtt);
1031
1032 /**
1033  * xprt_complete_rqst - called when reply processing is complete
1034  * @task: RPC request that recently completed
1035  * @copied: actual number of bytes received from the transport
1036  *
1037  * Caller holds xprt->queue_lock.
1038  */
1039 void xprt_complete_rqst(struct rpc_task *task, int copied)
1040 {
1041         struct rpc_rqst *req = task->tk_rqstp;
1042         struct rpc_xprt *xprt = req->rq_xprt;
1043
1044         dprintk("RPC: %5u xid %08x complete (%d bytes received)\n",
1045                         task->tk_pid, ntohl(req->rq_xid), copied);
1046         trace_xprt_complete_rqst(xprt, req->rq_xid, copied);
1047
1048         xprt->stat.recvs++;
1049
1050         req->rq_private_buf.len = copied;
1051         /* Ensure all writes are done before we update */
1052         /* req->rq_reply_bytes_recvd */
1053         smp_wmb();
1054         req->rq_reply_bytes_recvd = copied;
1055         xprt_request_dequeue_receive_locked(task);
1056         rpc_wake_up_queued_task(&xprt->pending, task);
1057 }
1058 EXPORT_SYMBOL_GPL(xprt_complete_rqst);
1059
1060 static void xprt_timer(struct rpc_task *task)
1061 {
1062         struct rpc_rqst *req = task->tk_rqstp;
1063         struct rpc_xprt *xprt = req->rq_xprt;
1064
1065         if (task->tk_status != -ETIMEDOUT)
1066                 return;
1067
1068         trace_xprt_timer(xprt, req->rq_xid, task->tk_status);
1069         if (!req->rq_reply_bytes_recvd) {
1070                 if (xprt->ops->timer)
1071                         xprt->ops->timer(xprt, task);
1072         } else
1073                 task->tk_status = 0;
1074 }
1075
1076 /**
1077  * xprt_wait_for_reply_request_def - wait for reply
1078  * @task: pointer to rpc_task
1079  *
1080  * Set a request's retransmit timeout based on the transport's
1081  * default timeout parameters.  Used by transports that don't adjust
1082  * the retransmit timeout based on round-trip time estimation,
1083  * and put the task to sleep on the pending queue.
1084  */
1085 void xprt_wait_for_reply_request_def(struct rpc_task *task)
1086 {
1087         struct rpc_rqst *req = task->tk_rqstp;
1088
1089         rpc_sleep_on_timeout(&req->rq_xprt->pending, task, xprt_timer,
1090                         jiffies + req->rq_timeout);
1091 }
1092 EXPORT_SYMBOL_GPL(xprt_wait_for_reply_request_def);
1093
1094 /**
1095  * xprt_wait_for_reply_request_rtt - wait for reply using RTT estimator
1096  * @task: pointer to rpc_task
1097  *
1098  * Set a request's retransmit timeout using the RTT estimator,
1099  * and put the task to sleep on the pending queue.
1100  */
1101 void xprt_wait_for_reply_request_rtt(struct rpc_task *task)
1102 {
1103         int timer = task->tk_msg.rpc_proc->p_timer;
1104         struct rpc_clnt *clnt = task->tk_client;
1105         struct rpc_rtt *rtt = clnt->cl_rtt;
1106         struct rpc_rqst *req = task->tk_rqstp;
1107         unsigned long max_timeout = clnt->cl_timeout->to_maxval;
1108         unsigned long timeout;
1109
1110         timeout = rpc_calc_rto(rtt, timer);
1111         timeout <<= rpc_ntimeo(rtt, timer) + req->rq_retries;
1112         if (timeout > max_timeout || timeout == 0)
1113                 timeout = max_timeout;
1114         rpc_sleep_on_timeout(&req->rq_xprt->pending, task, xprt_timer,
1115                         jiffies + timeout);
1116 }
1117 EXPORT_SYMBOL_GPL(xprt_wait_for_reply_request_rtt);
1118
1119 /**
1120  * xprt_request_wait_receive - wait for the reply to an RPC request
1121  * @task: RPC task about to send a request
1122  *
1123  */
1124 void xprt_request_wait_receive(struct rpc_task *task)
1125 {
1126         struct rpc_rqst *req = task->tk_rqstp;
1127         struct rpc_xprt *xprt = req->rq_xprt;
1128
1129         if (!test_bit(RPC_TASK_NEED_RECV, &task->tk_runstate))
1130                 return;
1131         /*
1132          * Sleep on the pending queue if we're expecting a reply.
1133          * The spinlock ensures atomicity between the test of
1134          * req->rq_reply_bytes_recvd, and the call to rpc_sleep_on().
1135          */
1136         spin_lock(&xprt->queue_lock);
1137         if (test_bit(RPC_TASK_NEED_RECV, &task->tk_runstate)) {
1138                 xprt->ops->wait_for_reply_request(task);
1139                 /*
1140                  * Send an extra queue wakeup call if the
1141                  * connection was dropped in case the call to
1142                  * rpc_sleep_on() raced.
1143                  */
1144                 if (xprt_request_retransmit_after_disconnect(task))
1145                         rpc_wake_up_queued_task_set_status(&xprt->pending,
1146                                         task, -ENOTCONN);
1147         }
1148         spin_unlock(&xprt->queue_lock);
1149 }
1150
1151 static bool
1152 xprt_request_need_enqueue_transmit(struct rpc_task *task, struct rpc_rqst *req)
1153 {
1154         return !test_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate);
1155 }
1156
1157 /**
1158  * xprt_request_enqueue_transmit - queue a task for transmission
1159  * @task: pointer to rpc_task
1160  *
1161  * Add a task to the transmission queue.
1162  */
1163 void
1164 xprt_request_enqueue_transmit(struct rpc_task *task)
1165 {
1166         struct rpc_rqst *pos, *req = task->tk_rqstp;
1167         struct rpc_xprt *xprt = req->rq_xprt;
1168
1169         if (xprt_request_need_enqueue_transmit(task, req)) {
1170                 req->rq_bytes_sent = 0;
1171                 spin_lock(&xprt->queue_lock);
1172                 /*
1173                  * Requests that carry congestion control credits are added
1174                  * to the head of the list to avoid starvation issues.
1175                  */
1176                 if (req->rq_cong) {
1177                         xprt_clear_congestion_window_wait(xprt);
1178                         list_for_each_entry(pos, &xprt->xmit_queue, rq_xmit) {
1179                                 if (pos->rq_cong)
1180                                         continue;
1181                                 /* Note: req is added _before_ pos */
1182                                 list_add_tail(&req->rq_xmit, &pos->rq_xmit);
1183                                 INIT_LIST_HEAD(&req->rq_xmit2);
1184                                 trace_xprt_enq_xmit(task, 1);
1185                                 goto out;
1186                         }
1187                 } else if (RPC_IS_SWAPPER(task)) {
1188                         list_for_each_entry(pos, &xprt->xmit_queue, rq_xmit) {
1189                                 if (pos->rq_cong || pos->rq_bytes_sent)
1190                                         continue;
1191                                 if (RPC_IS_SWAPPER(pos->rq_task))
1192                                         continue;
1193                                 /* Note: req is added _before_ pos */
1194                                 list_add_tail(&req->rq_xmit, &pos->rq_xmit);
1195                                 INIT_LIST_HEAD(&req->rq_xmit2);
1196                                 trace_xprt_enq_xmit(task, 2);
1197                                 goto out;
1198                         }
1199                 } else if (!req->rq_seqno) {
1200                         list_for_each_entry(pos, &xprt->xmit_queue, rq_xmit) {
1201                                 if (pos->rq_task->tk_owner != task->tk_owner)
1202                                         continue;
1203                                 list_add_tail(&req->rq_xmit2, &pos->rq_xmit2);
1204                                 INIT_LIST_HEAD(&req->rq_xmit);
1205                                 trace_xprt_enq_xmit(task, 3);
1206                                 goto out;
1207                         }
1208                 }
1209                 list_add_tail(&req->rq_xmit, &xprt->xmit_queue);
1210                 INIT_LIST_HEAD(&req->rq_xmit2);
1211                 trace_xprt_enq_xmit(task, 4);
1212 out:
1213                 set_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate);
1214                 spin_unlock(&xprt->queue_lock);
1215         }
1216 }
1217
1218 /**
1219  * xprt_request_dequeue_transmit_locked - remove a task from the transmission queue
1220  * @task: pointer to rpc_task
1221  *
1222  * Remove a task from the transmission queue
1223  * Caller must hold xprt->queue_lock
1224  */
1225 static void
1226 xprt_request_dequeue_transmit_locked(struct rpc_task *task)
1227 {
1228         struct rpc_rqst *req = task->tk_rqstp;
1229
1230         if (!test_and_clear_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate))
1231                 return;
1232         if (!list_empty(&req->rq_xmit)) {
1233                 list_del(&req->rq_xmit);
1234                 if (!list_empty(&req->rq_xmit2)) {
1235                         struct rpc_rqst *next = list_first_entry(&req->rq_xmit2,
1236                                         struct rpc_rqst, rq_xmit2);
1237                         list_del(&req->rq_xmit2);
1238                         list_add_tail(&next->rq_xmit, &next->rq_xprt->xmit_queue);
1239                 }
1240         } else
1241                 list_del(&req->rq_xmit2);
1242 }
1243
1244 /**
1245  * xprt_request_dequeue_transmit - remove a task from the transmission queue
1246  * @task: pointer to rpc_task
1247  *
1248  * Remove a task from the transmission queue
1249  */
1250 static void
1251 xprt_request_dequeue_transmit(struct rpc_task *task)
1252 {
1253         struct rpc_rqst *req = task->tk_rqstp;
1254         struct rpc_xprt *xprt = req->rq_xprt;
1255
1256         spin_lock(&xprt->queue_lock);
1257         xprt_request_dequeue_transmit_locked(task);
1258         spin_unlock(&xprt->queue_lock);
1259 }
1260
1261 /**
1262  * xprt_request_prepare - prepare an encoded request for transport
1263  * @req: pointer to rpc_rqst
1264  *
1265  * Calls into the transport layer to do whatever is needed to prepare
1266  * the request for transmission or receive.
1267  */
1268 void
1269 xprt_request_prepare(struct rpc_rqst *req)
1270 {
1271         struct rpc_xprt *xprt = req->rq_xprt;
1272
1273         if (xprt->ops->prepare_request)
1274                 xprt->ops->prepare_request(req);
1275 }
1276
1277 /**
1278  * xprt_request_need_retransmit - Test if a task needs retransmission
1279  * @task: pointer to rpc_task
1280  *
1281  * Test for whether a connection breakage requires the task to retransmit
1282  */
1283 bool
1284 xprt_request_need_retransmit(struct rpc_task *task)
1285 {
1286         return xprt_request_retransmit_after_disconnect(task);
1287 }
1288
1289 /**
1290  * xprt_prepare_transmit - reserve the transport before sending a request
1291  * @task: RPC task about to send a request
1292  *
1293  */
1294 bool xprt_prepare_transmit(struct rpc_task *task)
1295 {
1296         struct rpc_rqst *req = task->tk_rqstp;
1297         struct rpc_xprt *xprt = req->rq_xprt;
1298
1299         dprintk("RPC: %5u xprt_prepare_transmit\n", task->tk_pid);
1300
1301         if (!xprt_lock_write(xprt, task)) {
1302                 /* Race breaker: someone may have transmitted us */
1303                 if (!test_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate))
1304                         rpc_wake_up_queued_task_set_status(&xprt->sending,
1305                                         task, 0);
1306                 return false;
1307
1308         }
1309         return true;
1310 }
1311
1312 void xprt_end_transmit(struct rpc_task *task)
1313 {
1314         xprt_release_write(task->tk_rqstp->rq_xprt, task);
1315 }
1316
1317 /**
1318  * xprt_request_transmit - send an RPC request on a transport
1319  * @req: pointer to request to transmit
1320  * @snd_task: RPC task that owns the transport lock
1321  *
1322  * This performs the transmission of a single request.
1323  * Note that if the request is not the same as snd_task, then it
1324  * does need to be pinned.
1325  * Returns '0' on success.
1326  */
1327 static int
1328 xprt_request_transmit(struct rpc_rqst *req, struct rpc_task *snd_task)
1329 {
1330         struct rpc_xprt *xprt = req->rq_xprt;
1331         struct rpc_task *task = req->rq_task;
1332         unsigned int connect_cookie;
1333         int is_retrans = RPC_WAS_SENT(task);
1334         int status;
1335
1336         if (!req->rq_bytes_sent) {
1337                 if (xprt_request_data_received(task)) {
1338                         status = 0;
1339                         goto out_dequeue;
1340                 }
1341                 /* Verify that our message lies in the RPCSEC_GSS window */
1342                 if (rpcauth_xmit_need_reencode(task)) {
1343                         status = -EBADMSG;
1344                         goto out_dequeue;
1345                 }
1346                 if (task->tk_ops->rpc_call_prepare_transmit) {
1347                         task->tk_ops->rpc_call_prepare_transmit(task,
1348                                         task->tk_calldata);
1349                         status = task->tk_status;
1350                         if (status < 0)
1351                                 goto out_dequeue;
1352                 }
1353                 if (RPC_SIGNALLED(task)) {
1354                         status = -ERESTARTSYS;
1355                         goto out_dequeue;
1356                 }
1357         }
1358
1359         /*
1360          * Update req->rq_ntrans before transmitting to avoid races with
1361          * xprt_update_rtt(), which needs to know that it is recording a
1362          * reply to the first transmission.
1363          */
1364         req->rq_ntrans++;
1365
1366         connect_cookie = xprt->connect_cookie;
1367         status = xprt->ops->send_request(req);
1368         if (status != 0) {
1369                 req->rq_ntrans--;
1370                 trace_xprt_transmit(req, status);
1371                 return status;
1372         }
1373
1374         if (is_retrans)
1375                 task->tk_client->cl_stats->rpcretrans++;
1376
1377         xprt_inject_disconnect(xprt);
1378
1379         task->tk_flags |= RPC_TASK_SENT;
1380         spin_lock_bh(&xprt->transport_lock);
1381
1382         xprt->stat.sends++;
1383         xprt->stat.req_u += xprt->stat.sends - xprt->stat.recvs;
1384         xprt->stat.bklog_u += xprt->backlog.qlen;
1385         xprt->stat.sending_u += xprt->sending.qlen;
1386         xprt->stat.pending_u += xprt->pending.qlen;
1387         spin_unlock_bh(&xprt->transport_lock);
1388
1389         req->rq_connect_cookie = connect_cookie;
1390 out_dequeue:
1391         trace_xprt_transmit(req, status);
1392         xprt_request_dequeue_transmit(task);
1393         rpc_wake_up_queued_task_set_status(&xprt->sending, task, status);
1394         return status;
1395 }
1396
1397 /**
1398  * xprt_transmit - send an RPC request on a transport
1399  * @task: controlling RPC task
1400  *
1401  * Attempts to drain the transmit queue. On exit, either the transport
1402  * signalled an error that needs to be handled before transmission can
1403  * resume, or @task finished transmitting, and detected that it already
1404  * received a reply.
1405  */
1406 void
1407 xprt_transmit(struct rpc_task *task)
1408 {
1409         struct rpc_rqst *next, *req = task->tk_rqstp;
1410         struct rpc_xprt *xprt = req->rq_xprt;
1411         int status;
1412
1413         spin_lock(&xprt->queue_lock);
1414         while (!list_empty(&xprt->xmit_queue)) {
1415                 next = list_first_entry(&xprt->xmit_queue,
1416                                 struct rpc_rqst, rq_xmit);
1417                 xprt_pin_rqst(next);
1418                 spin_unlock(&xprt->queue_lock);
1419                 status = xprt_request_transmit(next, task);
1420                 if (status == -EBADMSG && next != req)
1421                         status = 0;
1422                 cond_resched();
1423                 spin_lock(&xprt->queue_lock);
1424                 xprt_unpin_rqst(next);
1425                 if (status == 0) {
1426                         if (!xprt_request_data_received(task) ||
1427                             test_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate))
1428                                 continue;
1429                 } else if (test_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate))
1430                         task->tk_status = status;
1431                 break;
1432         }
1433         spin_unlock(&xprt->queue_lock);
1434 }
1435
1436 static void xprt_add_backlog(struct rpc_xprt *xprt, struct rpc_task *task)
1437 {
1438         set_bit(XPRT_CONGESTED, &xprt->state);
1439         rpc_sleep_on(&xprt->backlog, task, NULL);
1440 }
1441
1442 static void xprt_wake_up_backlog(struct rpc_xprt *xprt)
1443 {
1444         if (rpc_wake_up_next(&xprt->backlog) == NULL)
1445                 clear_bit(XPRT_CONGESTED, &xprt->state);
1446 }
1447
1448 static bool xprt_throttle_congested(struct rpc_xprt *xprt, struct rpc_task *task)
1449 {
1450         bool ret = false;
1451
1452         if (!test_bit(XPRT_CONGESTED, &xprt->state))
1453                 goto out;
1454         spin_lock(&xprt->reserve_lock);
1455         if (test_bit(XPRT_CONGESTED, &xprt->state)) {
1456                 rpc_sleep_on(&xprt->backlog, task, NULL);
1457                 ret = true;
1458         }
1459         spin_unlock(&xprt->reserve_lock);
1460 out:
1461         return ret;
1462 }
1463
1464 static struct rpc_rqst *xprt_dynamic_alloc_slot(struct rpc_xprt *xprt)
1465 {
1466         struct rpc_rqst *req = ERR_PTR(-EAGAIN);
1467
1468         if (xprt->num_reqs >= xprt->max_reqs)
1469                 goto out;
1470         ++xprt->num_reqs;
1471         spin_unlock(&xprt->reserve_lock);
1472         req = kzalloc(sizeof(struct rpc_rqst), GFP_NOFS);
1473         spin_lock(&xprt->reserve_lock);
1474         if (req != NULL)
1475                 goto out;
1476         --xprt->num_reqs;
1477         req = ERR_PTR(-ENOMEM);
1478 out:
1479         return req;
1480 }
1481
1482 static bool xprt_dynamic_free_slot(struct rpc_xprt *xprt, struct rpc_rqst *req)
1483 {
1484         if (xprt->num_reqs > xprt->min_reqs) {
1485                 --xprt->num_reqs;
1486                 kfree(req);
1487                 return true;
1488         }
1489         return false;
1490 }
1491
1492 void xprt_alloc_slot(struct rpc_xprt *xprt, struct rpc_task *task)
1493 {
1494         struct rpc_rqst *req;
1495
1496         spin_lock(&xprt->reserve_lock);
1497         if (!list_empty(&xprt->free)) {
1498                 req = list_entry(xprt->free.next, struct rpc_rqst, rq_list);
1499                 list_del(&req->rq_list);
1500                 goto out_init_req;
1501         }
1502         req = xprt_dynamic_alloc_slot(xprt);
1503         if (!IS_ERR(req))
1504                 goto out_init_req;
1505         switch (PTR_ERR(req)) {
1506         case -ENOMEM:
1507                 dprintk("RPC:       dynamic allocation of request slot "
1508                                 "failed! Retrying\n");
1509                 task->tk_status = -ENOMEM;
1510                 break;
1511         case -EAGAIN:
1512                 xprt_add_backlog(xprt, task);
1513                 dprintk("RPC:       waiting for request slot\n");
1514                 /* fall through */
1515         default:
1516                 task->tk_status = -EAGAIN;
1517         }
1518         spin_unlock(&xprt->reserve_lock);
1519         return;
1520 out_init_req:
1521         xprt->stat.max_slots = max_t(unsigned int, xprt->stat.max_slots,
1522                                      xprt->num_reqs);
1523         spin_unlock(&xprt->reserve_lock);
1524
1525         task->tk_status = 0;
1526         task->tk_rqstp = req;
1527 }
1528 EXPORT_SYMBOL_GPL(xprt_alloc_slot);
1529
1530 void xprt_free_slot(struct rpc_xprt *xprt, struct rpc_rqst *req)
1531 {
1532         spin_lock(&xprt->reserve_lock);
1533         if (!xprt_dynamic_free_slot(xprt, req)) {
1534                 memset(req, 0, sizeof(*req));   /* mark unused */
1535                 list_add(&req->rq_list, &xprt->free);
1536         }
1537         xprt_wake_up_backlog(xprt);
1538         spin_unlock(&xprt->reserve_lock);
1539 }
1540 EXPORT_SYMBOL_GPL(xprt_free_slot);
1541
1542 static void xprt_free_all_slots(struct rpc_xprt *xprt)
1543 {
1544         struct rpc_rqst *req;
1545         while (!list_empty(&xprt->free)) {
1546                 req = list_first_entry(&xprt->free, struct rpc_rqst, rq_list);
1547                 list_del(&req->rq_list);
1548                 kfree(req);
1549         }
1550 }
1551
1552 struct rpc_xprt *xprt_alloc(struct net *net, size_t size,
1553                 unsigned int num_prealloc,
1554                 unsigned int max_alloc)
1555 {
1556         struct rpc_xprt *xprt;
1557         struct rpc_rqst *req;
1558         int i;
1559
1560         xprt = kzalloc(size, GFP_KERNEL);
1561         if (xprt == NULL)
1562                 goto out;
1563
1564         xprt_init(xprt, net);
1565
1566         for (i = 0; i < num_prealloc; i++) {
1567                 req = kzalloc(sizeof(struct rpc_rqst), GFP_KERNEL);
1568                 if (!req)
1569                         goto out_free;
1570                 list_add(&req->rq_list, &xprt->free);
1571         }
1572         if (max_alloc > num_prealloc)
1573                 xprt->max_reqs = max_alloc;
1574         else
1575                 xprt->max_reqs = num_prealloc;
1576         xprt->min_reqs = num_prealloc;
1577         xprt->num_reqs = num_prealloc;
1578
1579         return xprt;
1580
1581 out_free:
1582         xprt_free(xprt);
1583 out:
1584         return NULL;
1585 }
1586 EXPORT_SYMBOL_GPL(xprt_alloc);
1587
1588 void xprt_free(struct rpc_xprt *xprt)
1589 {
1590         put_net(xprt->xprt_net);
1591         xprt_free_all_slots(xprt);
1592         kfree_rcu(xprt, rcu);
1593 }
1594 EXPORT_SYMBOL_GPL(xprt_free);
1595
1596 static void
1597 xprt_init_connect_cookie(struct rpc_rqst *req, struct rpc_xprt *xprt)
1598 {
1599         req->rq_connect_cookie = xprt_connect_cookie(xprt) - 1;
1600 }
1601
1602 static __be32
1603 xprt_alloc_xid(struct rpc_xprt *xprt)
1604 {
1605         __be32 xid;
1606
1607         spin_lock(&xprt->reserve_lock);
1608         xid = (__force __be32)xprt->xid++;
1609         spin_unlock(&xprt->reserve_lock);
1610         return xid;
1611 }
1612
1613 static void
1614 xprt_init_xid(struct rpc_xprt *xprt)
1615 {
1616         xprt->xid = prandom_u32();
1617 }
1618
1619 static void
1620 xprt_request_init(struct rpc_task *task)
1621 {
1622         struct rpc_xprt *xprt = task->tk_xprt;
1623         struct rpc_rqst *req = task->tk_rqstp;
1624
1625         req->rq_timeout = task->tk_client->cl_timeout->to_initval;
1626         req->rq_task    = task;
1627         req->rq_xprt    = xprt;
1628         req->rq_buffer  = NULL;
1629         req->rq_xid     = xprt_alloc_xid(xprt);
1630         xprt_init_connect_cookie(req, xprt);
1631         req->rq_snd_buf.len = 0;
1632         req->rq_snd_buf.buflen = 0;
1633         req->rq_rcv_buf.len = 0;
1634         req->rq_rcv_buf.buflen = 0;
1635         req->rq_snd_buf.bvec = NULL;
1636         req->rq_rcv_buf.bvec = NULL;
1637         req->rq_release_snd_buf = NULL;
1638         xprt_reset_majortimeo(req);
1639         dprintk("RPC: %5u reserved req %p xid %08x\n", task->tk_pid,
1640                         req, ntohl(req->rq_xid));
1641 }
1642
1643 static void
1644 xprt_do_reserve(struct rpc_xprt *xprt, struct rpc_task *task)
1645 {
1646         xprt->ops->alloc_slot(xprt, task);
1647         if (task->tk_rqstp != NULL)
1648                 xprt_request_init(task);
1649 }
1650
1651 /**
1652  * xprt_reserve - allocate an RPC request slot
1653  * @task: RPC task requesting a slot allocation
1654  *
1655  * If the transport is marked as being congested, or if no more
1656  * slots are available, place the task on the transport's
1657  * backlog queue.
1658  */
1659 void xprt_reserve(struct rpc_task *task)
1660 {
1661         struct rpc_xprt *xprt = task->tk_xprt;
1662
1663         task->tk_status = 0;
1664         if (task->tk_rqstp != NULL)
1665                 return;
1666
1667         task->tk_status = -EAGAIN;
1668         if (!xprt_throttle_congested(xprt, task))
1669                 xprt_do_reserve(xprt, task);
1670 }
1671
1672 /**
1673  * xprt_retry_reserve - allocate an RPC request slot
1674  * @task: RPC task requesting a slot allocation
1675  *
1676  * If no more slots are available, place the task on the transport's
1677  * backlog queue.
1678  * Note that the only difference with xprt_reserve is that we now
1679  * ignore the value of the XPRT_CONGESTED flag.
1680  */
1681 void xprt_retry_reserve(struct rpc_task *task)
1682 {
1683         struct rpc_xprt *xprt = task->tk_xprt;
1684
1685         task->tk_status = 0;
1686         if (task->tk_rqstp != NULL)
1687                 return;
1688
1689         task->tk_status = -EAGAIN;
1690         xprt_do_reserve(xprt, task);
1691 }
1692
1693 static void
1694 xprt_request_dequeue_all(struct rpc_task *task, struct rpc_rqst *req)
1695 {
1696         struct rpc_xprt *xprt = req->rq_xprt;
1697
1698         if (test_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate) ||
1699             test_bit(RPC_TASK_NEED_RECV, &task->tk_runstate) ||
1700             xprt_is_pinned_rqst(req)) {
1701                 spin_lock(&xprt->queue_lock);
1702                 xprt_request_dequeue_transmit_locked(task);
1703                 xprt_request_dequeue_receive_locked(task);
1704                 while (xprt_is_pinned_rqst(req)) {
1705                         set_bit(RPC_TASK_MSG_PIN_WAIT, &task->tk_runstate);
1706                         spin_unlock(&xprt->queue_lock);
1707                         xprt_wait_on_pinned_rqst(req);
1708                         spin_lock(&xprt->queue_lock);
1709                         clear_bit(RPC_TASK_MSG_PIN_WAIT, &task->tk_runstate);
1710                 }
1711                 spin_unlock(&xprt->queue_lock);
1712         }
1713 }
1714
1715 /**
1716  * xprt_release - release an RPC request slot
1717  * @task: task which is finished with the slot
1718  *
1719  */
1720 void xprt_release(struct rpc_task *task)
1721 {
1722         struct rpc_xprt *xprt;
1723         struct rpc_rqst *req = task->tk_rqstp;
1724
1725         if (req == NULL) {
1726                 if (task->tk_client) {
1727                         xprt = task->tk_xprt;
1728                         xprt_release_write(xprt, task);
1729                 }
1730                 return;
1731         }
1732
1733         xprt = req->rq_xprt;
1734         if (task->tk_ops->rpc_count_stats != NULL)
1735                 task->tk_ops->rpc_count_stats(task, task->tk_calldata);
1736         else if (task->tk_client)
1737                 rpc_count_iostats(task, task->tk_client->cl_metrics);
1738         xprt_request_dequeue_all(task, req);
1739         spin_lock_bh(&xprt->transport_lock);
1740         xprt->ops->release_xprt(xprt, task);
1741         if (xprt->ops->release_request)
1742                 xprt->ops->release_request(task);
1743         xprt->last_used = jiffies;
1744         xprt_schedule_autodisconnect(xprt);
1745         spin_unlock_bh(&xprt->transport_lock);
1746         if (req->rq_buffer)
1747                 xprt->ops->buf_free(task);
1748         xprt_inject_disconnect(xprt);
1749         xdr_free_bvec(&req->rq_rcv_buf);
1750         xdr_free_bvec(&req->rq_snd_buf);
1751         if (req->rq_cred != NULL)
1752                 put_rpccred(req->rq_cred);
1753         task->tk_rqstp = NULL;
1754         if (req->rq_release_snd_buf)
1755                 req->rq_release_snd_buf(req);
1756
1757         dprintk("RPC: %5u release request %p\n", task->tk_pid, req);
1758         if (likely(!bc_prealloc(req)))
1759                 xprt->ops->free_slot(xprt, req);
1760         else
1761                 xprt_free_bc_request(req);
1762 }
1763
1764 #ifdef CONFIG_SUNRPC_BACKCHANNEL
1765 void
1766 xprt_init_bc_request(struct rpc_rqst *req, struct rpc_task *task)
1767 {
1768         struct xdr_buf *xbufp = &req->rq_snd_buf;
1769
1770         task->tk_rqstp = req;
1771         req->rq_task = task;
1772         xprt_init_connect_cookie(req, req->rq_xprt);
1773         /*
1774          * Set up the xdr_buf length.
1775          * This also indicates that the buffer is XDR encoded already.
1776          */
1777         xbufp->len = xbufp->head[0].iov_len + xbufp->page_len +
1778                 xbufp->tail[0].iov_len;
1779 }
1780 #endif
1781
1782 static void xprt_init(struct rpc_xprt *xprt, struct net *net)
1783 {
1784         kref_init(&xprt->kref);
1785
1786         spin_lock_init(&xprt->transport_lock);
1787         spin_lock_init(&xprt->reserve_lock);
1788         spin_lock_init(&xprt->queue_lock);
1789
1790         INIT_LIST_HEAD(&xprt->free);
1791         xprt->recv_queue = RB_ROOT;
1792         INIT_LIST_HEAD(&xprt->xmit_queue);
1793 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
1794         spin_lock_init(&xprt->bc_pa_lock);
1795         INIT_LIST_HEAD(&xprt->bc_pa_list);
1796 #endif /* CONFIG_SUNRPC_BACKCHANNEL */
1797         INIT_LIST_HEAD(&xprt->xprt_switch);
1798
1799         xprt->last_used = jiffies;
1800         xprt->cwnd = RPC_INITCWND;
1801         xprt->bind_index = 0;
1802
1803         rpc_init_wait_queue(&xprt->binding, "xprt_binding");
1804         rpc_init_wait_queue(&xprt->pending, "xprt_pending");
1805         rpc_init_wait_queue(&xprt->sending, "xprt_sending");
1806         rpc_init_priority_wait_queue(&xprt->backlog, "xprt_backlog");
1807
1808         xprt_init_xid(xprt);
1809
1810         xprt->xprt_net = get_net(net);
1811 }
1812
1813 /**
1814  * xprt_create_transport - create an RPC transport
1815  * @args: rpc transport creation arguments
1816  *
1817  */
1818 struct rpc_xprt *xprt_create_transport(struct xprt_create *args)
1819 {
1820         struct rpc_xprt *xprt;
1821         struct xprt_class *t;
1822
1823         spin_lock(&xprt_list_lock);
1824         list_for_each_entry(t, &xprt_list, list) {
1825                 if (t->ident == args->ident) {
1826                         spin_unlock(&xprt_list_lock);
1827                         goto found;
1828                 }
1829         }
1830         spin_unlock(&xprt_list_lock);
1831         dprintk("RPC: transport (%d) not supported\n", args->ident);
1832         return ERR_PTR(-EIO);
1833
1834 found:
1835         xprt = t->setup(args);
1836         if (IS_ERR(xprt)) {
1837                 dprintk("RPC:       xprt_create_transport: failed, %ld\n",
1838                                 -PTR_ERR(xprt));
1839                 goto out;
1840         }
1841         if (args->flags & XPRT_CREATE_NO_IDLE_TIMEOUT)
1842                 xprt->idle_timeout = 0;
1843         INIT_WORK(&xprt->task_cleanup, xprt_autoclose);
1844         if (xprt_has_timer(xprt))
1845                 timer_setup(&xprt->timer,
1846                                 xprt_init_autodisconnect,
1847                                 TIMER_DEFERRABLE);
1848         else
1849                 timer_setup(&xprt->timer, NULL, 0);
1850
1851         if (strlen(args->servername) > RPC_MAXNETNAMELEN) {
1852                 xprt_destroy(xprt);
1853                 return ERR_PTR(-EINVAL);
1854         }
1855         xprt->servername = kstrdup(args->servername, GFP_KERNEL);
1856         if (xprt->servername == NULL) {
1857                 xprt_destroy(xprt);
1858                 return ERR_PTR(-ENOMEM);
1859         }
1860
1861         rpc_xprt_debugfs_register(xprt);
1862
1863         dprintk("RPC:       created transport %p with %u slots\n", xprt,
1864                         xprt->max_reqs);
1865 out:
1866         return xprt;
1867 }
1868
1869 static void xprt_destroy_cb(struct work_struct *work)
1870 {
1871         struct rpc_xprt *xprt =
1872                 container_of(work, struct rpc_xprt, task_cleanup);
1873
1874         rpc_xprt_debugfs_unregister(xprt);
1875         rpc_destroy_wait_queue(&xprt->binding);
1876         rpc_destroy_wait_queue(&xprt->pending);
1877         rpc_destroy_wait_queue(&xprt->sending);
1878         rpc_destroy_wait_queue(&xprt->backlog);
1879         kfree(xprt->servername);
1880         /*
1881          * Tear down transport state and free the rpc_xprt
1882          */
1883         xprt->ops->destroy(xprt);
1884 }
1885
1886 /**
1887  * xprt_destroy - destroy an RPC transport, killing off all requests.
1888  * @xprt: transport to destroy
1889  *
1890  */
1891 static void xprt_destroy(struct rpc_xprt *xprt)
1892 {
1893         dprintk("RPC:       destroying transport %p\n", xprt);
1894
1895         /*
1896          * Exclude transport connect/disconnect handlers and autoclose
1897          */
1898         wait_on_bit_lock(&xprt->state, XPRT_LOCKED, TASK_UNINTERRUPTIBLE);
1899
1900         del_timer_sync(&xprt->timer);
1901
1902         /*
1903          * Destroy sockets etc from the system workqueue so they can
1904          * safely flush receive work running on rpciod.
1905          */
1906         INIT_WORK(&xprt->task_cleanup, xprt_destroy_cb);
1907         schedule_work(&xprt->task_cleanup);
1908 }
1909
1910 static void xprt_destroy_kref(struct kref *kref)
1911 {
1912         xprt_destroy(container_of(kref, struct rpc_xprt, kref));
1913 }
1914
1915 /**
1916  * xprt_get - return a reference to an RPC transport.
1917  * @xprt: pointer to the transport
1918  *
1919  */
1920 struct rpc_xprt *xprt_get(struct rpc_xprt *xprt)
1921 {
1922         if (xprt != NULL && kref_get_unless_zero(&xprt->kref))
1923                 return xprt;
1924         return NULL;
1925 }
1926 EXPORT_SYMBOL_GPL(xprt_get);
1927
1928 /**
1929  * xprt_put - release a reference to an RPC transport.
1930  * @xprt: pointer to the transport
1931  *
1932  */
1933 void xprt_put(struct rpc_xprt *xprt)
1934 {
1935         if (xprt != NULL)
1936                 kref_put(&xprt->kref, xprt_destroy_kref);
1937 }
1938 EXPORT_SYMBOL_GPL(xprt_put);