2 * linux/net/sunrpc/xprt.c
4 * This is a generic RPC call interface supporting congestion avoidance,
5 * and asynchronous calls.
7 * The interface works like this:
9 * - When a process places a call, it allocates a request slot if
10 * one is available. Otherwise, it sleeps on the backlog queue
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
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
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
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.
35 * Copyright (C) 1995-1997, Olaf Kirch <okir@monad.swb.de>
37 * Transport switch API copyright (C) 2005, Chuck Lever <cel@netapp.com>
40 #include <linux/module.h>
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>
48 #include <linux/sunrpc/clnt.h>
49 #include <linux/sunrpc/metrics.h>
50 #include <linux/sunrpc/bc_xprt.h>
51 #include <linux/rcupdate.h>
53 #include <trace/events/sunrpc.h>
61 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
62 # define RPCDBG_FACILITY RPCDBG_XPRT
68 static void xprt_init(struct rpc_xprt *xprt, struct net *net);
69 static __be32 xprt_alloc_xid(struct rpc_xprt *xprt);
70 static void xprt_connect_status(struct rpc_task *task);
71 static int __xprt_get_cong(struct rpc_xprt *, struct rpc_task *);
72 static void __xprt_put_cong(struct rpc_xprt *, struct rpc_rqst *);
73 static void xprt_destroy(struct rpc_xprt *xprt);
75 static DEFINE_SPINLOCK(xprt_list_lock);
76 static LIST_HEAD(xprt_list);
79 * xprt_register_transport - register a transport implementation
80 * @transport: transport to register
82 * If a transport implementation is loaded as a kernel module, it can
83 * call this interface to make itself known to the RPC client.
86 * 0: transport successfully registered
87 * -EEXIST: transport already registered
88 * -EINVAL: transport module being unloaded
90 int xprt_register_transport(struct xprt_class *transport)
96 spin_lock(&xprt_list_lock);
97 list_for_each_entry(t, &xprt_list, list) {
98 /* don't register the same transport class twice */
99 if (t->ident == transport->ident)
103 list_add_tail(&transport->list, &xprt_list);
104 printk(KERN_INFO "RPC: Registered %s transport module.\n",
109 spin_unlock(&xprt_list_lock);
112 EXPORT_SYMBOL_GPL(xprt_register_transport);
115 * xprt_unregister_transport - unregister a transport implementation
116 * @transport: transport to unregister
119 * 0: transport successfully unregistered
120 * -ENOENT: transport never registered
122 int xprt_unregister_transport(struct xprt_class *transport)
124 struct xprt_class *t;
128 spin_lock(&xprt_list_lock);
129 list_for_each_entry(t, &xprt_list, list) {
130 if (t == transport) {
132 "RPC: Unregistered %s transport module.\n",
134 list_del_init(&transport->list);
141 spin_unlock(&xprt_list_lock);
144 EXPORT_SYMBOL_GPL(xprt_unregister_transport);
147 xprt_class_release(const struct xprt_class *t)
149 module_put(t->owner);
152 static const struct xprt_class *
153 xprt_class_find_by_netid_locked(const char *netid)
155 const struct xprt_class *t;
158 list_for_each_entry(t, &xprt_list, list) {
159 for (i = 0; t->netid[i][0] != '\0'; i++) {
160 if (strcmp(t->netid[i], netid) != 0)
162 if (!try_module_get(t->owner))
170 static const struct xprt_class *
171 xprt_class_find_by_netid(const char *netid)
173 const struct xprt_class *t;
175 spin_lock(&xprt_list_lock);
176 t = xprt_class_find_by_netid_locked(netid);
178 spin_unlock(&xprt_list_lock);
179 request_module("rpc%s", netid);
180 spin_lock(&xprt_list_lock);
181 t = xprt_class_find_by_netid_locked(netid);
183 spin_unlock(&xprt_list_lock);
188 * xprt_load_transport - load a transport implementation
189 * @netid: transport to load
192 * 0: transport successfully loaded
193 * -ENOENT: transport module not available
195 int xprt_load_transport(const char *netid)
197 const struct xprt_class *t;
199 t = xprt_class_find_by_netid(netid);
202 xprt_class_release(t);
205 EXPORT_SYMBOL_GPL(xprt_load_transport);
208 * xprt_reserve_xprt - serialize write access to transports
209 * @task: task that is requesting access to the transport
210 * @xprt: pointer to the target transport
212 * This prevents mixing the payload of separate requests, and prevents
213 * transport connects from colliding with writes. No congestion control
216 int xprt_reserve_xprt(struct rpc_xprt *xprt, struct rpc_task *task)
218 struct rpc_rqst *req = task->tk_rqstp;
221 if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) {
222 if (task == xprt->snd_task)
226 xprt->snd_task = task;
233 dprintk("RPC: %5u failed to lock transport %p\n",
235 task->tk_timeout = 0;
236 task->tk_status = -EAGAIN;
238 priority = RPC_PRIORITY_LOW;
239 else if (!req->rq_ntrans)
240 priority = RPC_PRIORITY_NORMAL;
242 priority = RPC_PRIORITY_HIGH;
243 rpc_sleep_on_priority(&xprt->sending, task, NULL, priority);
246 EXPORT_SYMBOL_GPL(xprt_reserve_xprt);
248 static void xprt_clear_locked(struct rpc_xprt *xprt)
250 xprt->snd_task = NULL;
251 if (!test_bit(XPRT_CLOSE_WAIT, &xprt->state)) {
252 smp_mb__before_atomic();
253 clear_bit(XPRT_LOCKED, &xprt->state);
254 smp_mb__after_atomic();
256 queue_work(xprtiod_workqueue, &xprt->task_cleanup);
260 * xprt_reserve_xprt_cong - serialize write access to transports
261 * @task: task that is requesting access to the transport
263 * Same as xprt_reserve_xprt, but Van Jacobson congestion control is
264 * integrated into the decision of whether a request is allowed to be
265 * woken up and given access to the transport.
267 int xprt_reserve_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task)
269 struct rpc_rqst *req = task->tk_rqstp;
272 if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) {
273 if (task == xprt->snd_task)
278 xprt->snd_task = task;
281 if (__xprt_get_cong(xprt, task)) {
282 xprt->snd_task = task;
286 xprt_clear_locked(xprt);
289 __xprt_put_cong(xprt, req);
290 dprintk("RPC: %5u failed to lock transport %p\n", task->tk_pid, xprt);
291 task->tk_timeout = 0;
292 task->tk_status = -EAGAIN;
294 priority = RPC_PRIORITY_LOW;
295 else if (!req->rq_ntrans)
296 priority = RPC_PRIORITY_NORMAL;
298 priority = RPC_PRIORITY_HIGH;
299 rpc_sleep_on_priority(&xprt->sending, task, NULL, priority);
302 EXPORT_SYMBOL_GPL(xprt_reserve_xprt_cong);
304 static inline int xprt_lock_write(struct rpc_xprt *xprt, struct rpc_task *task)
308 spin_lock_bh(&xprt->transport_lock);
309 retval = xprt->ops->reserve_xprt(xprt, task);
310 spin_unlock_bh(&xprt->transport_lock);
314 static bool __xprt_lock_write_func(struct rpc_task *task, void *data)
316 struct rpc_xprt *xprt = data;
317 struct rpc_rqst *req;
319 req = task->tk_rqstp;
320 xprt->snd_task = task;
326 static void __xprt_lock_write_next(struct rpc_xprt *xprt)
328 if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
331 if (rpc_wake_up_first_on_wq(xprtiod_workqueue, &xprt->sending,
332 __xprt_lock_write_func, xprt))
334 xprt_clear_locked(xprt);
337 static bool __xprt_lock_write_cong_func(struct rpc_task *task, void *data)
339 struct rpc_xprt *xprt = data;
340 struct rpc_rqst *req;
342 req = task->tk_rqstp;
344 xprt->snd_task = task;
347 if (__xprt_get_cong(xprt, task)) {
348 xprt->snd_task = task;
355 static void __xprt_lock_write_next_cong(struct rpc_xprt *xprt)
357 if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
359 if (RPCXPRT_CONGESTED(xprt))
361 if (rpc_wake_up_first_on_wq(xprtiod_workqueue, &xprt->sending,
362 __xprt_lock_write_cong_func, xprt))
365 xprt_clear_locked(xprt);
368 static void xprt_task_clear_bytes_sent(struct rpc_task *task)
371 struct rpc_rqst *req = task->tk_rqstp;
373 req->rq_bytes_sent = 0;
378 * xprt_release_xprt - allow other requests to use a transport
379 * @xprt: transport with other tasks potentially waiting
380 * @task: task that is releasing access to the transport
382 * Note that "task" can be NULL. No congestion control is provided.
384 void xprt_release_xprt(struct rpc_xprt *xprt, struct rpc_task *task)
386 if (xprt->snd_task == task) {
387 xprt_task_clear_bytes_sent(task);
388 xprt_clear_locked(xprt);
389 __xprt_lock_write_next(xprt);
392 EXPORT_SYMBOL_GPL(xprt_release_xprt);
395 * xprt_release_xprt_cong - allow other requests to use a transport
396 * @xprt: transport with other tasks potentially waiting
397 * @task: task that is releasing access to the transport
399 * Note that "task" can be NULL. Another task is awoken to use the
400 * transport if the transport's congestion window allows it.
402 void xprt_release_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task)
404 if (xprt->snd_task == task) {
405 xprt_task_clear_bytes_sent(task);
406 xprt_clear_locked(xprt);
407 __xprt_lock_write_next_cong(xprt);
410 EXPORT_SYMBOL_GPL(xprt_release_xprt_cong);
412 static inline void xprt_release_write(struct rpc_xprt *xprt, struct rpc_task *task)
414 spin_lock_bh(&xprt->transport_lock);
415 xprt->ops->release_xprt(xprt, task);
416 spin_unlock_bh(&xprt->transport_lock);
420 * Van Jacobson congestion avoidance. Check if the congestion window
421 * overflowed. Put the task to sleep if this is the case.
424 __xprt_get_cong(struct rpc_xprt *xprt, struct rpc_task *task)
426 struct rpc_rqst *req = task->tk_rqstp;
430 dprintk("RPC: %5u xprt_cwnd_limited cong = %lu cwnd = %lu\n",
431 task->tk_pid, xprt->cong, xprt->cwnd);
432 if (RPCXPRT_CONGESTED(xprt))
435 xprt->cong += RPC_CWNDSCALE;
440 * Adjust the congestion window, and wake up the next task
441 * that has been sleeping due to congestion
444 __xprt_put_cong(struct rpc_xprt *xprt, struct rpc_rqst *req)
449 xprt->cong -= RPC_CWNDSCALE;
450 __xprt_lock_write_next_cong(xprt);
454 * xprt_release_rqst_cong - housekeeping when request is complete
455 * @task: RPC request that recently completed
457 * Useful for transports that require congestion control.
459 void xprt_release_rqst_cong(struct rpc_task *task)
461 struct rpc_rqst *req = task->tk_rqstp;
463 __xprt_put_cong(req->rq_xprt, req);
465 EXPORT_SYMBOL_GPL(xprt_release_rqst_cong);
468 * xprt_adjust_cwnd - adjust transport congestion window
469 * @xprt: pointer to xprt
470 * @task: recently completed RPC request used to adjust window
471 * @result: result code of completed RPC request
473 * The transport code maintains an estimate on the maximum number of out-
474 * standing RPC requests, using a smoothed version of the congestion
475 * avoidance implemented in 44BSD. This is basically the Van Jacobson
476 * congestion algorithm: If a retransmit occurs, the congestion window is
477 * halved; otherwise, it is incremented by 1/cwnd when
479 * - a reply is received and
480 * - a full number of requests are outstanding and
481 * - the congestion window hasn't been updated recently.
483 void xprt_adjust_cwnd(struct rpc_xprt *xprt, struct rpc_task *task, int result)
485 struct rpc_rqst *req = task->tk_rqstp;
486 unsigned long cwnd = xprt->cwnd;
488 if (result >= 0 && cwnd <= xprt->cong) {
489 /* The (cwnd >> 1) term makes sure
490 * the result gets rounded properly. */
491 cwnd += (RPC_CWNDSCALE * RPC_CWNDSCALE + (cwnd >> 1)) / cwnd;
492 if (cwnd > RPC_MAXCWND(xprt))
493 cwnd = RPC_MAXCWND(xprt);
494 __xprt_lock_write_next_cong(xprt);
495 } else if (result == -ETIMEDOUT) {
497 if (cwnd < RPC_CWNDSCALE)
498 cwnd = RPC_CWNDSCALE;
500 dprintk("RPC: cong %ld, cwnd was %ld, now %ld\n",
501 xprt->cong, xprt->cwnd, cwnd);
503 __xprt_put_cong(xprt, req);
505 EXPORT_SYMBOL_GPL(xprt_adjust_cwnd);
508 * xprt_wake_pending_tasks - wake all tasks on a transport's pending queue
509 * @xprt: transport with waiting tasks
510 * @status: result code to plant in each task before waking it
513 void xprt_wake_pending_tasks(struct rpc_xprt *xprt, int status)
516 rpc_wake_up_status(&xprt->pending, status);
518 rpc_wake_up(&xprt->pending);
520 EXPORT_SYMBOL_GPL(xprt_wake_pending_tasks);
523 * xprt_wait_for_buffer_space - wait for transport output buffer to clear
524 * @task: task to be put to sleep
525 * @action: function pointer to be executed after wait
527 * Note that we only set the timer for the case of RPC_IS_SOFT(), since
528 * we don't in general want to force a socket disconnection due to
529 * an incomplete RPC call transmission.
531 void xprt_wait_for_buffer_space(struct rpc_task *task, rpc_action action)
533 struct rpc_rqst *req = task->tk_rqstp;
534 struct rpc_xprt *xprt = req->rq_xprt;
536 task->tk_timeout = RPC_IS_SOFT(task) ? req->rq_timeout : 0;
537 rpc_sleep_on(&xprt->pending, task, action);
539 EXPORT_SYMBOL_GPL(xprt_wait_for_buffer_space);
542 * xprt_write_space - wake the task waiting for transport output buffer space
543 * @xprt: transport with waiting tasks
545 * Can be called in a soft IRQ context, so xprt_write_space never sleeps.
547 void xprt_write_space(struct rpc_xprt *xprt)
549 spin_lock_bh(&xprt->transport_lock);
550 if (xprt->snd_task) {
551 dprintk("RPC: write space: waking waiting task on "
553 rpc_wake_up_queued_task_on_wq(xprtiod_workqueue,
554 &xprt->pending, xprt->snd_task);
556 spin_unlock_bh(&xprt->transport_lock);
558 EXPORT_SYMBOL_GPL(xprt_write_space);
561 * xprt_set_retrans_timeout_def - set a request's retransmit timeout
562 * @task: task whose timeout is to be set
564 * Set a request's retransmit timeout based on the transport's
565 * default timeout parameters. Used by transports that don't adjust
566 * the retransmit timeout based on round-trip time estimation.
568 void xprt_set_retrans_timeout_def(struct rpc_task *task)
570 task->tk_timeout = task->tk_rqstp->rq_timeout;
572 EXPORT_SYMBOL_GPL(xprt_set_retrans_timeout_def);
575 * xprt_set_retrans_timeout_rtt - set a request's retransmit timeout
576 * @task: task whose timeout is to be set
578 * Set a request's retransmit timeout using the RTT estimator.
580 void xprt_set_retrans_timeout_rtt(struct rpc_task *task)
582 int timer = task->tk_msg.rpc_proc->p_timer;
583 struct rpc_clnt *clnt = task->tk_client;
584 struct rpc_rtt *rtt = clnt->cl_rtt;
585 struct rpc_rqst *req = task->tk_rqstp;
586 unsigned long max_timeout = clnt->cl_timeout->to_maxval;
588 task->tk_timeout = rpc_calc_rto(rtt, timer);
589 task->tk_timeout <<= rpc_ntimeo(rtt, timer) + req->rq_retries;
590 if (task->tk_timeout > max_timeout || task->tk_timeout == 0)
591 task->tk_timeout = max_timeout;
593 EXPORT_SYMBOL_GPL(xprt_set_retrans_timeout_rtt);
595 static void xprt_reset_majortimeo(struct rpc_rqst *req)
597 const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout;
599 req->rq_majortimeo = req->rq_timeout;
600 if (to->to_exponential)
601 req->rq_majortimeo <<= to->to_retries;
603 req->rq_majortimeo += to->to_increment * to->to_retries;
604 if (req->rq_majortimeo > to->to_maxval || req->rq_majortimeo == 0)
605 req->rq_majortimeo = to->to_maxval;
606 req->rq_majortimeo += jiffies;
610 * xprt_adjust_timeout - adjust timeout values for next retransmit
611 * @req: RPC request containing parameters to use for the adjustment
614 int xprt_adjust_timeout(struct rpc_rqst *req)
616 struct rpc_xprt *xprt = req->rq_xprt;
617 const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout;
620 if (time_before(jiffies, req->rq_majortimeo)) {
621 if (to->to_exponential)
622 req->rq_timeout <<= 1;
624 req->rq_timeout += to->to_increment;
625 if (to->to_maxval && req->rq_timeout >= to->to_maxval)
626 req->rq_timeout = to->to_maxval;
629 req->rq_timeout = to->to_initval;
631 xprt_reset_majortimeo(req);
632 /* Reset the RTT counters == "slow start" */
633 spin_lock_bh(&xprt->transport_lock);
634 rpc_init_rtt(req->rq_task->tk_client->cl_rtt, to->to_initval);
635 spin_unlock_bh(&xprt->transport_lock);
639 if (req->rq_timeout == 0) {
640 printk(KERN_WARNING "xprt_adjust_timeout: rq_timeout = 0!\n");
641 req->rq_timeout = 5 * HZ;
646 static void xprt_autoclose(struct work_struct *work)
648 struct rpc_xprt *xprt =
649 container_of(work, struct rpc_xprt, task_cleanup);
651 clear_bit(XPRT_CLOSE_WAIT, &xprt->state);
652 xprt->ops->close(xprt);
653 xprt_release_write(xprt, NULL);
654 wake_up_bit(&xprt->state, XPRT_LOCKED);
658 * xprt_disconnect_done - mark a transport as disconnected
659 * @xprt: transport to flag for disconnect
662 void xprt_disconnect_done(struct rpc_xprt *xprt)
664 dprintk("RPC: disconnected transport %p\n", xprt);
665 spin_lock_bh(&xprt->transport_lock);
666 xprt_clear_connected(xprt);
667 xprt_wake_pending_tasks(xprt, -EAGAIN);
668 spin_unlock_bh(&xprt->transport_lock);
670 EXPORT_SYMBOL_GPL(xprt_disconnect_done);
673 * xprt_force_disconnect - force a transport to disconnect
674 * @xprt: transport to disconnect
677 void xprt_force_disconnect(struct rpc_xprt *xprt)
679 /* Don't race with the test_bit() in xprt_clear_locked() */
680 spin_lock_bh(&xprt->transport_lock);
681 set_bit(XPRT_CLOSE_WAIT, &xprt->state);
682 /* Try to schedule an autoclose RPC call */
683 if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
684 queue_work(xprtiod_workqueue, &xprt->task_cleanup);
685 xprt_wake_pending_tasks(xprt, -EAGAIN);
686 spin_unlock_bh(&xprt->transport_lock);
688 EXPORT_SYMBOL_GPL(xprt_force_disconnect);
691 * xprt_conditional_disconnect - force a transport to disconnect
692 * @xprt: transport to disconnect
693 * @cookie: 'connection cookie'
695 * This attempts to break the connection if and only if 'cookie' matches
696 * the current transport 'connection cookie'. It ensures that we don't
697 * try to break the connection more than once when we need to retransmit
698 * a batch of RPC requests.
701 void xprt_conditional_disconnect(struct rpc_xprt *xprt, unsigned int cookie)
703 /* Don't race with the test_bit() in xprt_clear_locked() */
704 spin_lock_bh(&xprt->transport_lock);
705 if (cookie != xprt->connect_cookie)
707 if (test_bit(XPRT_CLOSING, &xprt->state))
709 set_bit(XPRT_CLOSE_WAIT, &xprt->state);
710 /* Try to schedule an autoclose RPC call */
711 if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
712 queue_work(xprtiod_workqueue, &xprt->task_cleanup);
713 xprt_wake_pending_tasks(xprt, -EAGAIN);
715 spin_unlock_bh(&xprt->transport_lock);
719 xprt_has_timer(const struct rpc_xprt *xprt)
721 return xprt->idle_timeout != 0;
725 xprt_schedule_autodisconnect(struct rpc_xprt *xprt)
726 __must_hold(&xprt->transport_lock)
728 if (list_empty(&xprt->recv) && xprt_has_timer(xprt))
729 mod_timer(&xprt->timer, xprt->last_used + xprt->idle_timeout);
733 xprt_init_autodisconnect(struct timer_list *t)
735 struct rpc_xprt *xprt = from_timer(xprt, t, timer);
737 spin_lock(&xprt->transport_lock);
738 if (!list_empty(&xprt->recv))
740 /* Reset xprt->last_used to avoid connect/autodisconnect cycling */
741 xprt->last_used = jiffies;
742 if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
744 spin_unlock(&xprt->transport_lock);
745 queue_work(xprtiod_workqueue, &xprt->task_cleanup);
748 spin_unlock(&xprt->transport_lock);
751 bool xprt_lock_connect(struct rpc_xprt *xprt,
752 struct rpc_task *task,
757 spin_lock_bh(&xprt->transport_lock);
758 if (!test_bit(XPRT_LOCKED, &xprt->state))
760 if (xprt->snd_task != task)
762 xprt_task_clear_bytes_sent(task);
763 xprt->snd_task = cookie;
766 spin_unlock_bh(&xprt->transport_lock);
770 void xprt_unlock_connect(struct rpc_xprt *xprt, void *cookie)
772 spin_lock_bh(&xprt->transport_lock);
773 if (xprt->snd_task != cookie)
775 if (!test_bit(XPRT_LOCKED, &xprt->state))
777 xprt->snd_task =NULL;
778 xprt->ops->release_xprt(xprt, NULL);
779 xprt_schedule_autodisconnect(xprt);
781 spin_unlock_bh(&xprt->transport_lock);
782 wake_up_bit(&xprt->state, XPRT_LOCKED);
786 * xprt_connect - schedule a transport connect operation
787 * @task: RPC task that is requesting the connect
790 void xprt_connect(struct rpc_task *task)
792 struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt;
794 dprintk("RPC: %5u xprt_connect xprt %p %s connected\n", task->tk_pid,
795 xprt, (xprt_connected(xprt) ? "is" : "is not"));
797 if (!xprt_bound(xprt)) {
798 task->tk_status = -EAGAIN;
801 if (!xprt_lock_write(xprt, task))
804 if (test_and_clear_bit(XPRT_CLOSE_WAIT, &xprt->state))
805 xprt->ops->close(xprt);
807 if (!xprt_connected(xprt)) {
808 task->tk_rqstp->rq_bytes_sent = 0;
809 task->tk_timeout = task->tk_rqstp->rq_timeout;
810 task->tk_rqstp->rq_connect_cookie = xprt->connect_cookie;
811 rpc_sleep_on(&xprt->pending, task, xprt_connect_status);
813 if (test_bit(XPRT_CLOSING, &xprt->state))
815 if (xprt_test_and_set_connecting(xprt))
818 if (!xprt_connected(xprt)) {
819 xprt->stat.connect_start = jiffies;
820 xprt->ops->connect(xprt, task);
822 xprt_clear_connecting(xprt);
824 rpc_wake_up_queued_task(&xprt->pending, task);
827 xprt_release_write(xprt, task);
830 static void xprt_connect_status(struct rpc_task *task)
832 switch (task->tk_status) {
834 dprintk("RPC: %5u xprt_connect_status: connection established\n",
844 dprintk("RPC: %5u xprt_connect_status: retrying\n", task->tk_pid);
847 dprintk("RPC: %5u xprt_connect_status: connect attempt timed "
848 "out\n", task->tk_pid);
851 dprintk("RPC: %5u xprt_connect_status: error %d connecting to "
852 "server %s\n", task->tk_pid, -task->tk_status,
853 task->tk_rqstp->rq_xprt->servername);
854 task->tk_status = -EIO;
859 * xprt_lookup_rqst - find an RPC request corresponding to an XID
860 * @xprt: transport on which the original request was transmitted
861 * @xid: RPC XID of incoming reply
863 * Caller holds xprt->recv_lock.
865 struct rpc_rqst *xprt_lookup_rqst(struct rpc_xprt *xprt, __be32 xid)
867 struct rpc_rqst *entry;
869 list_for_each_entry(entry, &xprt->recv, rq_list)
870 if (entry->rq_xid == xid) {
871 trace_xprt_lookup_rqst(xprt, xid, 0);
872 entry->rq_rtt = ktime_sub(ktime_get(), entry->rq_xtime);
876 dprintk("RPC: xprt_lookup_rqst did not find xid %08x\n",
878 trace_xprt_lookup_rqst(xprt, xid, -ENOENT);
879 xprt->stat.bad_xids++;
882 EXPORT_SYMBOL_GPL(xprt_lookup_rqst);
885 * xprt_pin_rqst - Pin a request on the transport receive list
886 * @req: Request to pin
888 * Caller must ensure this is atomic with the call to xprt_lookup_rqst()
889 * so should be holding the xprt transport lock.
891 void xprt_pin_rqst(struct rpc_rqst *req)
893 set_bit(RPC_TASK_MSG_RECV, &req->rq_task->tk_runstate);
895 EXPORT_SYMBOL_GPL(xprt_pin_rqst);
898 * xprt_unpin_rqst - Unpin a request on the transport receive list
899 * @req: Request to pin
901 * Caller should be holding the xprt transport lock.
903 void xprt_unpin_rqst(struct rpc_rqst *req)
905 struct rpc_task *task = req->rq_task;
907 clear_bit(RPC_TASK_MSG_RECV, &task->tk_runstate);
908 if (test_bit(RPC_TASK_MSG_RECV_WAIT, &task->tk_runstate))
909 wake_up_bit(&task->tk_runstate, RPC_TASK_MSG_RECV);
911 EXPORT_SYMBOL_GPL(xprt_unpin_rqst);
913 static void xprt_wait_on_pinned_rqst(struct rpc_rqst *req)
914 __must_hold(&req->rq_xprt->recv_lock)
916 struct rpc_task *task = req->rq_task;
918 if (task && test_bit(RPC_TASK_MSG_RECV, &task->tk_runstate)) {
919 spin_unlock(&req->rq_xprt->recv_lock);
920 set_bit(RPC_TASK_MSG_RECV_WAIT, &task->tk_runstate);
921 wait_on_bit(&task->tk_runstate, RPC_TASK_MSG_RECV,
922 TASK_UNINTERRUPTIBLE);
923 clear_bit(RPC_TASK_MSG_RECV_WAIT, &task->tk_runstate);
924 spin_lock(&req->rq_xprt->recv_lock);
929 * xprt_update_rtt - Update RPC RTT statistics
930 * @task: RPC request that recently completed
932 * Caller holds xprt->recv_lock.
934 void xprt_update_rtt(struct rpc_task *task)
936 struct rpc_rqst *req = task->tk_rqstp;
937 struct rpc_rtt *rtt = task->tk_client->cl_rtt;
938 unsigned int timer = task->tk_msg.rpc_proc->p_timer;
939 long m = usecs_to_jiffies(ktime_to_us(req->rq_rtt));
942 if (req->rq_ntrans == 1)
943 rpc_update_rtt(rtt, timer, m);
944 rpc_set_timeo(rtt, timer, req->rq_ntrans - 1);
947 EXPORT_SYMBOL_GPL(xprt_update_rtt);
950 * xprt_complete_rqst - called when reply processing is complete
951 * @task: RPC request that recently completed
952 * @copied: actual number of bytes received from the transport
954 * Caller holds xprt->recv_lock.
956 void xprt_complete_rqst(struct rpc_task *task, int copied)
958 struct rpc_rqst *req = task->tk_rqstp;
959 struct rpc_xprt *xprt = req->rq_xprt;
961 dprintk("RPC: %5u xid %08x complete (%d bytes received)\n",
962 task->tk_pid, ntohl(req->rq_xid), copied);
963 trace_xprt_complete_rqst(xprt, req->rq_xid, copied);
967 list_del_init(&req->rq_list);
968 req->rq_private_buf.len = copied;
969 /* Ensure all writes are done before we update */
970 /* req->rq_reply_bytes_recvd */
972 req->rq_reply_bytes_recvd = copied;
973 rpc_wake_up_queued_task(&xprt->pending, task);
975 EXPORT_SYMBOL_GPL(xprt_complete_rqst);
977 static void xprt_timer(struct rpc_task *task)
979 struct rpc_rqst *req = task->tk_rqstp;
980 struct rpc_xprt *xprt = req->rq_xprt;
982 if (task->tk_status != -ETIMEDOUT)
985 trace_xprt_timer(xprt, req->rq_xid, task->tk_status);
986 if (!req->rq_reply_bytes_recvd) {
987 if (xprt->ops->timer)
988 xprt->ops->timer(xprt, task);
994 * xprt_prepare_transmit - reserve the transport before sending a request
995 * @task: RPC task about to send a request
998 bool xprt_prepare_transmit(struct rpc_task *task)
1000 struct rpc_rqst *req = task->tk_rqstp;
1001 struct rpc_xprt *xprt = req->rq_xprt;
1004 dprintk("RPC: %5u xprt_prepare_transmit\n", task->tk_pid);
1006 spin_lock_bh(&xprt->transport_lock);
1007 if (!req->rq_bytes_sent) {
1008 if (req->rq_reply_bytes_recvd) {
1009 task->tk_status = req->rq_reply_bytes_recvd;
1012 if ((task->tk_flags & RPC_TASK_NO_RETRANS_TIMEOUT)
1013 && xprt_connected(xprt)
1014 && req->rq_connect_cookie == xprt->connect_cookie) {
1015 xprt->ops->set_retrans_timeout(task);
1016 rpc_sleep_on(&xprt->pending, task, xprt_timer);
1020 if (!xprt->ops->reserve_xprt(xprt, task)) {
1021 task->tk_status = -EAGAIN;
1026 spin_unlock_bh(&xprt->transport_lock);
1030 void xprt_end_transmit(struct rpc_task *task)
1032 xprt_release_write(task->tk_rqstp->rq_xprt, task);
1036 * xprt_transmit - send an RPC request on a transport
1037 * @task: controlling RPC task
1039 * We have to copy the iovec because sendmsg fiddles with its contents.
1041 void xprt_transmit(struct rpc_task *task)
1043 struct rpc_rqst *req = task->tk_rqstp;
1044 struct rpc_xprt *xprt = req->rq_xprt;
1045 unsigned int connect_cookie;
1048 dprintk("RPC: %5u xprt_transmit(%u)\n", task->tk_pid, req->rq_slen);
1050 if (!req->rq_reply_bytes_recvd) {
1051 if (list_empty(&req->rq_list) && rpc_reply_expected(task)) {
1053 * Add to the list only if we're expecting a reply
1055 /* Update the softirq receive buffer */
1056 memcpy(&req->rq_private_buf, &req->rq_rcv_buf,
1057 sizeof(req->rq_private_buf));
1058 /* Add request to the receive list */
1059 spin_lock(&xprt->recv_lock);
1060 list_add_tail(&req->rq_list, &xprt->recv);
1061 spin_unlock(&xprt->recv_lock);
1062 xprt_reset_majortimeo(req);
1063 /* Turn off autodisconnect */
1064 del_singleshot_timer_sync(&xprt->timer);
1066 } else if (!req->rq_bytes_sent)
1069 connect_cookie = xprt->connect_cookie;
1070 status = xprt->ops->send_request(task);
1071 trace_xprt_transmit(xprt, req->rq_xid, status);
1073 task->tk_status = status;
1076 xprt_inject_disconnect(xprt);
1078 dprintk("RPC: %5u xmit complete\n", task->tk_pid);
1079 task->tk_flags |= RPC_TASK_SENT;
1080 spin_lock_bh(&xprt->transport_lock);
1082 xprt->ops->set_retrans_timeout(task);
1085 xprt->stat.req_u += xprt->stat.sends - xprt->stat.recvs;
1086 xprt->stat.bklog_u += xprt->backlog.qlen;
1087 xprt->stat.sending_u += xprt->sending.qlen;
1088 xprt->stat.pending_u += xprt->pending.qlen;
1089 spin_unlock_bh(&xprt->transport_lock);
1091 req->rq_connect_cookie = connect_cookie;
1092 if (rpc_reply_expected(task) && !READ_ONCE(req->rq_reply_bytes_recvd)) {
1094 * Sleep on the pending queue if we're expecting a reply.
1095 * The spinlock ensures atomicity between the test of
1096 * req->rq_reply_bytes_recvd, and the call to rpc_sleep_on().
1098 spin_lock(&xprt->recv_lock);
1099 if (!req->rq_reply_bytes_recvd) {
1100 rpc_sleep_on(&xprt->pending, task, xprt_timer);
1102 * Send an extra queue wakeup call if the
1103 * connection was dropped in case the call to
1104 * rpc_sleep_on() raced.
1106 if (!xprt_connected(xprt))
1107 xprt_wake_pending_tasks(xprt, -ENOTCONN);
1109 spin_unlock(&xprt->recv_lock);
1113 static void xprt_add_backlog(struct rpc_xprt *xprt, struct rpc_task *task)
1115 set_bit(XPRT_CONGESTED, &xprt->state);
1116 rpc_sleep_on(&xprt->backlog, task, NULL);
1119 static void xprt_wake_up_backlog(struct rpc_xprt *xprt)
1121 if (rpc_wake_up_next(&xprt->backlog) == NULL)
1122 clear_bit(XPRT_CONGESTED, &xprt->state);
1125 static bool xprt_throttle_congested(struct rpc_xprt *xprt, struct rpc_task *task)
1129 if (!test_bit(XPRT_CONGESTED, &xprt->state))
1131 spin_lock(&xprt->reserve_lock);
1132 if (test_bit(XPRT_CONGESTED, &xprt->state)) {
1133 rpc_sleep_on(&xprt->backlog, task, NULL);
1136 spin_unlock(&xprt->reserve_lock);
1141 static struct rpc_rqst *xprt_dynamic_alloc_slot(struct rpc_xprt *xprt)
1143 struct rpc_rqst *req = ERR_PTR(-EAGAIN);
1145 if (xprt->num_reqs >= xprt->max_reqs)
1148 spin_unlock(&xprt->reserve_lock);
1149 req = kzalloc(sizeof(struct rpc_rqst), GFP_NOFS);
1150 spin_lock(&xprt->reserve_lock);
1154 req = ERR_PTR(-ENOMEM);
1159 static bool xprt_dynamic_free_slot(struct rpc_xprt *xprt, struct rpc_rqst *req)
1161 if (xprt->num_reqs > xprt->min_reqs) {
1169 void xprt_alloc_slot(struct rpc_xprt *xprt, struct rpc_task *task)
1171 struct rpc_rqst *req;
1173 spin_lock(&xprt->reserve_lock);
1174 if (!list_empty(&xprt->free)) {
1175 req = list_entry(xprt->free.next, struct rpc_rqst, rq_list);
1176 list_del(&req->rq_list);
1179 req = xprt_dynamic_alloc_slot(xprt);
1182 switch (PTR_ERR(req)) {
1184 dprintk("RPC: dynamic allocation of request slot "
1185 "failed! Retrying\n");
1186 task->tk_status = -ENOMEM;
1189 xprt_add_backlog(xprt, task);
1190 dprintk("RPC: waiting for request slot\n");
1193 task->tk_status = -EAGAIN;
1195 spin_unlock(&xprt->reserve_lock);
1198 xprt->stat.max_slots = max_t(unsigned int, xprt->stat.max_slots,
1200 spin_unlock(&xprt->reserve_lock);
1202 task->tk_status = 0;
1203 task->tk_rqstp = req;
1205 EXPORT_SYMBOL_GPL(xprt_alloc_slot);
1207 void xprt_lock_and_alloc_slot(struct rpc_xprt *xprt, struct rpc_task *task)
1209 /* Note: grabbing the xprt_lock_write() ensures that we throttle
1210 * new slot allocation if the transport is congested (i.e. when
1211 * reconnecting a stream transport or when out of socket write
1214 if (xprt_lock_write(xprt, task)) {
1215 xprt_alloc_slot(xprt, task);
1216 xprt_release_write(xprt, task);
1219 EXPORT_SYMBOL_GPL(xprt_lock_and_alloc_slot);
1221 void xprt_free_slot(struct rpc_xprt *xprt, struct rpc_rqst *req)
1223 spin_lock(&xprt->reserve_lock);
1224 if (!xprt_dynamic_free_slot(xprt, req)) {
1225 memset(req, 0, sizeof(*req)); /* mark unused */
1226 list_add(&req->rq_list, &xprt->free);
1228 xprt_wake_up_backlog(xprt);
1229 spin_unlock(&xprt->reserve_lock);
1231 EXPORT_SYMBOL_GPL(xprt_free_slot);
1233 static void xprt_free_all_slots(struct rpc_xprt *xprt)
1235 struct rpc_rqst *req;
1236 while (!list_empty(&xprt->free)) {
1237 req = list_first_entry(&xprt->free, struct rpc_rqst, rq_list);
1238 list_del(&req->rq_list);
1243 struct rpc_xprt *xprt_alloc(struct net *net, size_t size,
1244 unsigned int num_prealloc,
1245 unsigned int max_alloc)
1247 struct rpc_xprt *xprt;
1248 struct rpc_rqst *req;
1251 xprt = kzalloc(size, GFP_KERNEL);
1255 xprt_init(xprt, net);
1257 for (i = 0; i < num_prealloc; i++) {
1258 req = kzalloc(sizeof(struct rpc_rqst), GFP_KERNEL);
1261 list_add(&req->rq_list, &xprt->free);
1263 if (max_alloc > num_prealloc)
1264 xprt->max_reqs = max_alloc;
1266 xprt->max_reqs = num_prealloc;
1267 xprt->min_reqs = num_prealloc;
1268 xprt->num_reqs = num_prealloc;
1277 EXPORT_SYMBOL_GPL(xprt_alloc);
1279 void xprt_free(struct rpc_xprt *xprt)
1281 put_net(xprt->xprt_net);
1282 xprt_free_all_slots(xprt);
1283 kfree_rcu(xprt, rcu);
1285 EXPORT_SYMBOL_GPL(xprt_free);
1288 xprt_alloc_xid(struct rpc_xprt *xprt)
1292 spin_lock(&xprt->reserve_lock);
1293 xid = (__force __be32)xprt->xid++;
1294 spin_unlock(&xprt->reserve_lock);
1299 xprt_init_xid(struct rpc_xprt *xprt)
1301 xprt->xid = prandom_u32();
1305 xprt_request_init(struct rpc_task *task)
1307 struct rpc_xprt *xprt = task->tk_xprt;
1308 struct rpc_rqst *req = task->tk_rqstp;
1310 INIT_LIST_HEAD(&req->rq_list);
1311 req->rq_timeout = task->tk_client->cl_timeout->to_initval;
1312 req->rq_task = task;
1313 req->rq_xprt = xprt;
1314 req->rq_buffer = NULL;
1315 req->rq_xid = xprt_alloc_xid(xprt);
1316 req->rq_connect_cookie = xprt->connect_cookie - 1;
1317 req->rq_bytes_sent = 0;
1318 req->rq_snd_buf.len = 0;
1319 req->rq_snd_buf.buflen = 0;
1320 req->rq_rcv_buf.len = 0;
1321 req->rq_rcv_buf.buflen = 0;
1322 req->rq_release_snd_buf = NULL;
1323 xprt_reset_majortimeo(req);
1324 dprintk("RPC: %5u reserved req %p xid %08x\n", task->tk_pid,
1325 req, ntohl(req->rq_xid));
1329 xprt_do_reserve(struct rpc_xprt *xprt, struct rpc_task *task)
1331 xprt->ops->alloc_slot(xprt, task);
1332 if (task->tk_rqstp != NULL)
1333 xprt_request_init(task);
1337 * xprt_reserve - allocate an RPC request slot
1338 * @task: RPC task requesting a slot allocation
1340 * If the transport is marked as being congested, or if no more
1341 * slots are available, place the task on the transport's
1344 void xprt_reserve(struct rpc_task *task)
1346 struct rpc_xprt *xprt = task->tk_xprt;
1348 task->tk_status = 0;
1349 if (task->tk_rqstp != NULL)
1352 task->tk_timeout = 0;
1353 task->tk_status = -EAGAIN;
1354 if (!xprt_throttle_congested(xprt, task))
1355 xprt_do_reserve(xprt, task);
1359 * xprt_retry_reserve - allocate an RPC request slot
1360 * @task: RPC task requesting a slot allocation
1362 * If no more slots are available, place the task on the transport's
1364 * Note that the only difference with xprt_reserve is that we now
1365 * ignore the value of the XPRT_CONGESTED flag.
1367 void xprt_retry_reserve(struct rpc_task *task)
1369 struct rpc_xprt *xprt = task->tk_xprt;
1371 task->tk_status = 0;
1372 if (task->tk_rqstp != NULL)
1375 task->tk_timeout = 0;
1376 task->tk_status = -EAGAIN;
1377 xprt_do_reserve(xprt, task);
1381 * xprt_release - release an RPC request slot
1382 * @task: task which is finished with the slot
1385 void xprt_release(struct rpc_task *task)
1387 struct rpc_xprt *xprt;
1388 struct rpc_rqst *req = task->tk_rqstp;
1391 if (task->tk_client) {
1392 xprt = task->tk_xprt;
1393 if (xprt->snd_task == task)
1394 xprt_release_write(xprt, task);
1399 xprt = req->rq_xprt;
1400 if (task->tk_ops->rpc_count_stats != NULL)
1401 task->tk_ops->rpc_count_stats(task, task->tk_calldata);
1402 else if (task->tk_client)
1403 rpc_count_iostats(task, task->tk_client->cl_metrics);
1404 spin_lock(&xprt->recv_lock);
1405 if (!list_empty(&req->rq_list)) {
1406 list_del_init(&req->rq_list);
1407 xprt_wait_on_pinned_rqst(req);
1409 spin_unlock(&xprt->recv_lock);
1410 spin_lock_bh(&xprt->transport_lock);
1411 xprt->ops->release_xprt(xprt, task);
1412 if (xprt->ops->release_request)
1413 xprt->ops->release_request(task);
1414 xprt->last_used = jiffies;
1415 xprt_schedule_autodisconnect(xprt);
1416 spin_unlock_bh(&xprt->transport_lock);
1418 xprt->ops->buf_free(task);
1419 xprt_inject_disconnect(xprt);
1420 if (req->rq_cred != NULL)
1421 put_rpccred(req->rq_cred);
1422 task->tk_rqstp = NULL;
1423 if (req->rq_release_snd_buf)
1424 req->rq_release_snd_buf(req);
1426 dprintk("RPC: %5u release request %p\n", task->tk_pid, req);
1427 if (likely(!bc_prealloc(req)))
1428 xprt->ops->free_slot(xprt, req);
1430 xprt_free_bc_request(req);
1433 static void xprt_init(struct rpc_xprt *xprt, struct net *net)
1435 kref_init(&xprt->kref);
1437 spin_lock_init(&xprt->transport_lock);
1438 spin_lock_init(&xprt->reserve_lock);
1439 spin_lock_init(&xprt->recv_lock);
1441 INIT_LIST_HEAD(&xprt->free);
1442 INIT_LIST_HEAD(&xprt->recv);
1443 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
1444 spin_lock_init(&xprt->bc_pa_lock);
1445 INIT_LIST_HEAD(&xprt->bc_pa_list);
1446 #endif /* CONFIG_SUNRPC_BACKCHANNEL */
1447 INIT_LIST_HEAD(&xprt->xprt_switch);
1449 xprt->last_used = jiffies;
1450 xprt->cwnd = RPC_INITCWND;
1451 xprt->bind_index = 0;
1453 rpc_init_wait_queue(&xprt->binding, "xprt_binding");
1454 rpc_init_wait_queue(&xprt->pending, "xprt_pending");
1455 rpc_init_priority_wait_queue(&xprt->sending, "xprt_sending");
1456 rpc_init_priority_wait_queue(&xprt->backlog, "xprt_backlog");
1458 xprt_init_xid(xprt);
1460 xprt->xprt_net = get_net(net);
1464 * xprt_create_transport - create an RPC transport
1465 * @args: rpc transport creation arguments
1468 struct rpc_xprt *xprt_create_transport(struct xprt_create *args)
1470 struct rpc_xprt *xprt;
1471 struct xprt_class *t;
1473 spin_lock(&xprt_list_lock);
1474 list_for_each_entry(t, &xprt_list, list) {
1475 if (t->ident == args->ident) {
1476 spin_unlock(&xprt_list_lock);
1480 spin_unlock(&xprt_list_lock);
1481 dprintk("RPC: transport (%d) not supported\n", args->ident);
1482 return ERR_PTR(-EIO);
1485 xprt = t->setup(args);
1487 dprintk("RPC: xprt_create_transport: failed, %ld\n",
1491 if (args->flags & XPRT_CREATE_NO_IDLE_TIMEOUT)
1492 xprt->idle_timeout = 0;
1493 INIT_WORK(&xprt->task_cleanup, xprt_autoclose);
1494 if (xprt_has_timer(xprt))
1495 timer_setup(&xprt->timer, xprt_init_autodisconnect, 0);
1497 timer_setup(&xprt->timer, NULL, 0);
1499 if (strlen(args->servername) > RPC_MAXNETNAMELEN) {
1501 return ERR_PTR(-EINVAL);
1503 xprt->servername = kstrdup(args->servername, GFP_KERNEL);
1504 if (xprt->servername == NULL) {
1506 return ERR_PTR(-ENOMEM);
1509 rpc_xprt_debugfs_register(xprt);
1511 dprintk("RPC: created transport %p with %u slots\n", xprt,
1517 static void xprt_destroy_cb(struct work_struct *work)
1519 struct rpc_xprt *xprt =
1520 container_of(work, struct rpc_xprt, task_cleanup);
1522 rpc_xprt_debugfs_unregister(xprt);
1523 rpc_destroy_wait_queue(&xprt->binding);
1524 rpc_destroy_wait_queue(&xprt->pending);
1525 rpc_destroy_wait_queue(&xprt->sending);
1526 rpc_destroy_wait_queue(&xprt->backlog);
1527 kfree(xprt->servername);
1529 * Tear down transport state and free the rpc_xprt
1531 xprt->ops->destroy(xprt);
1535 * xprt_destroy - destroy an RPC transport, killing off all requests.
1536 * @xprt: transport to destroy
1539 static void xprt_destroy(struct rpc_xprt *xprt)
1541 dprintk("RPC: destroying transport %p\n", xprt);
1544 * Exclude transport connect/disconnect handlers and autoclose
1546 wait_on_bit_lock(&xprt->state, XPRT_LOCKED, TASK_UNINTERRUPTIBLE);
1549 * xprt_schedule_autodisconnect() can run after XPRT_LOCKED
1550 * is cleared. We use ->transport_lock to ensure the mod_timer()
1551 * can only run *before* del_time_sync(), never after.
1553 spin_lock_bh(&xprt->transport_lock);
1554 del_timer_sync(&xprt->timer);
1555 spin_unlock_bh(&xprt->transport_lock);
1558 * Destroy sockets etc from the system workqueue so they can
1559 * safely flush receive work running on rpciod.
1561 INIT_WORK(&xprt->task_cleanup, xprt_destroy_cb);
1562 schedule_work(&xprt->task_cleanup);
1565 static void xprt_destroy_kref(struct kref *kref)
1567 xprt_destroy(container_of(kref, struct rpc_xprt, kref));
1571 * xprt_get - return a reference to an RPC transport.
1572 * @xprt: pointer to the transport
1575 struct rpc_xprt *xprt_get(struct rpc_xprt *xprt)
1577 if (xprt != NULL && kref_get_unless_zero(&xprt->kref))
1581 EXPORT_SYMBOL_GPL(xprt_get);
1584 * xprt_put - release a reference to an RPC transport.
1585 * @xprt: pointer to the transport
1588 void xprt_put(struct rpc_xprt *xprt)
1591 kref_put(&xprt->kref, xprt_destroy_kref);
1593 EXPORT_SYMBOL_GPL(xprt_put);