blob: 4c8f18aff7c341885764c6f1525a292688328c5d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Chuck Lever55aa4f52005-08-11 16:25:47 -040013 * the request struct, and calls xprt_transmit().
14 * - xprt_transmit sends the message and installs the caller on the
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -040015 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * - When a packet arrives, the data_ready handler walks the list of
Chuck Lever55aa4f52005-08-11 16:25:47 -040019 * pending requests for that transport. If a matching XID is found, the
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 * 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>
Chuck Lever55aa4f52005-08-11 16:25:47 -040036 *
37 * Transport switch API copyright (C) 2005, Chuck Lever <cel@netapp.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 */
39
Chuck Levera246b012005-08-11 16:25:23 -040040#include <linux/module.h>
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/types.h>
Chuck Levera246b012005-08-11 16:25:23 -040043#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/workqueue.h>
Chuck Leverbf3fcf82006-05-25 01:40:51 -040045#include <linux/net.h>
Chuck Leverff839972010-05-07 13:34:47 -040046#include <linux/ktime.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Chuck Levera246b012005-08-11 16:25:23 -040048#include <linux/sunrpc/clnt.h>
Chuck Lever11c556b2006-03-20 13:44:22 -050049#include <linux/sunrpc/metrics.h>
Trond Myklebustc9acb422010-03-19 15:36:22 -040050#include <linux/sunrpc/bc_xprt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -040052#include "sunrpc.h"
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054/*
55 * Local variables
56 */
57
58#ifdef RPC_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070059# define RPCDBG_FACILITY RPCDBG_XPRT
60#endif
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/*
63 * Local functions
64 */
65static void xprt_request_init(struct rpc_task *, struct rpc_xprt *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066static void xprt_connect_status(struct rpc_task *task);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067static int __xprt_get_cong(struct rpc_xprt *, struct rpc_task *);
68
Jiri Slaby5ba03e82007-11-22 19:40:22 +080069static DEFINE_SPINLOCK(xprt_list_lock);
\"Talpey, Thomas\81c098a2007-09-10 13:46:00 -040070static LIST_HEAD(xprt_list);
71
Chuck Lever555ee3a2005-08-25 16:25:54 -070072/*
73 * The transport code maintains an estimate on the maximum number of out-
74 * standing RPC requests, using a smoothed version of the congestion
75 * avoidance implemented in 44BSD. This is basically the Van Jacobson
76 * congestion algorithm: If a retransmit occurs, the congestion window is
77 * halved; otherwise, it is incremented by 1/cwnd when
78 *
79 * - a reply is received and
80 * - a full number of requests are outstanding and
81 * - the congestion window hasn't been updated recently.
82 */
83#define RPC_CWNDSHIFT (8U)
84#define RPC_CWNDSCALE (1U << RPC_CWNDSHIFT)
85#define RPC_INITCWND RPC_CWNDSCALE
86#define RPC_MAXCWND(xprt) ((xprt)->max_reqs << RPC_CWNDSHIFT)
87
88#define RPCXPRT_CONGESTED(xprt) ((xprt)->cong >= (xprt)->cwnd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Chuck Lever12a80462005-08-25 16:25:51 -070090/**
\"Talpey, Thomas\81c098a2007-09-10 13:46:00 -040091 * xprt_register_transport - register a transport implementation
92 * @transport: transport to register
93 *
94 * If a transport implementation is loaded as a kernel module, it can
95 * call this interface to make itself known to the RPC client.
96 *
97 * Returns:
98 * 0: transport successfully registered
99 * -EEXIST: transport already registered
100 * -EINVAL: transport module being unloaded
101 */
102int xprt_register_transport(struct xprt_class *transport)
103{
104 struct xprt_class *t;
105 int result;
106
107 result = -EEXIST;
108 spin_lock(&xprt_list_lock);
109 list_for_each_entry(t, &xprt_list, list) {
110 /* don't register the same transport class twice */
\"Talpey, Thomas\4fa016e2007-09-10 13:47:57 -0400111 if (t->ident == transport->ident)
\"Talpey, Thomas\81c098a2007-09-10 13:46:00 -0400112 goto out;
113 }
114
Denis V. Lunevc9f6cde2008-07-31 09:53:56 +0400115 list_add_tail(&transport->list, &xprt_list);
116 printk(KERN_INFO "RPC: Registered %s transport module.\n",
117 transport->name);
118 result = 0;
\"Talpey, Thomas\81c098a2007-09-10 13:46:00 -0400119
120out:
121 spin_unlock(&xprt_list_lock);
122 return result;
123}
124EXPORT_SYMBOL_GPL(xprt_register_transport);
125
126/**
127 * xprt_unregister_transport - unregister a transport implementation
Randy Dunlap65b6e422008-02-13 15:03:23 -0800128 * @transport: transport to unregister
\"Talpey, Thomas\81c098a2007-09-10 13:46:00 -0400129 *
130 * Returns:
131 * 0: transport successfully unregistered
132 * -ENOENT: transport never registered
133 */
134int xprt_unregister_transport(struct xprt_class *transport)
135{
136 struct xprt_class *t;
137 int result;
138
139 result = 0;
140 spin_lock(&xprt_list_lock);
141 list_for_each_entry(t, &xprt_list, list) {
142 if (t == transport) {
143 printk(KERN_INFO
144 "RPC: Unregistered %s transport module.\n",
145 transport->name);
146 list_del_init(&transport->list);
\"Talpey, Thomas\81c098a2007-09-10 13:46:00 -0400147 goto out;
148 }
149 }
150 result = -ENOENT;
151
152out:
153 spin_unlock(&xprt_list_lock);
154 return result;
155}
156EXPORT_SYMBOL_GPL(xprt_unregister_transport);
157
158/**
Tom Talpey441e3e22009-03-11 14:37:56 -0400159 * xprt_load_transport - load a transport implementation
160 * @transport_name: transport to load
161 *
162 * Returns:
163 * 0: transport successfully loaded
164 * -ENOENT: transport module not available
165 */
166int xprt_load_transport(const char *transport_name)
167{
168 struct xprt_class *t;
Tom Talpey441e3e22009-03-11 14:37:56 -0400169 int result;
170
171 result = 0;
172 spin_lock(&xprt_list_lock);
173 list_for_each_entry(t, &xprt_list, list) {
174 if (strcmp(t->name, transport_name) == 0) {
175 spin_unlock(&xprt_list_lock);
176 goto out;
177 }
178 }
179 spin_unlock(&xprt_list_lock);
Alex Riesenef7ffe82010-05-24 14:33:05 -0700180 result = request_module("xprt%s", transport_name);
Tom Talpey441e3e22009-03-11 14:37:56 -0400181out:
182 return result;
183}
184EXPORT_SYMBOL_GPL(xprt_load_transport);
185
186/**
Chuck Lever12a80462005-08-25 16:25:51 -0700187 * xprt_reserve_xprt - serialize write access to transports
188 * @task: task that is requesting access to the transport
189 *
190 * This prevents mixing the payload of separate requests, and prevents
191 * transport connects from colliding with writes. No congestion control
192 * is provided.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 */
Chuck Lever12a80462005-08-25 16:25:51 -0700194int xprt_reserve_xprt(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Chuck Lever12a80462005-08-25 16:25:51 -0700196 struct rpc_rqst *req = task->tk_rqstp;
Rahul Iyer343952f2009-04-01 09:23:17 -0400197 struct rpc_xprt *xprt = req->rq_xprt;
Chuck Lever12a80462005-08-25 16:25:51 -0700198
199 if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) {
200 if (task == xprt->snd_task)
201 return 1;
Chuck Lever12a80462005-08-25 16:25:51 -0700202 goto out_sleep;
203 }
204 xprt->snd_task = task;
205 if (req) {
206 req->rq_bytes_sent = 0;
207 req->rq_ntrans++;
208 }
209 return 1;
210
211out_sleep:
Chuck Lever46121cf2007-01-31 12:14:08 -0500212 dprintk("RPC: %5u failed to lock transport %p\n",
Chuck Lever12a80462005-08-25 16:25:51 -0700213 task->tk_pid, xprt);
214 task->tk_timeout = 0;
215 task->tk_status = -EAGAIN;
216 if (req && req->rq_ntrans)
Trond Myklebust5d008372008-02-22 16:34:17 -0500217 rpc_sleep_on(&xprt->resend, task, NULL);
Chuck Lever12a80462005-08-25 16:25:51 -0700218 else
Trond Myklebust5d008372008-02-22 16:34:17 -0500219 rpc_sleep_on(&xprt->sending, task, NULL);
Chuck Lever12a80462005-08-25 16:25:51 -0700220 return 0;
221}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400222EXPORT_SYMBOL_GPL(xprt_reserve_xprt);
Chuck Lever12a80462005-08-25 16:25:51 -0700223
Trond Myklebust632e3bd2006-01-03 09:55:55 +0100224static void xprt_clear_locked(struct rpc_xprt *xprt)
225{
226 xprt->snd_task = NULL;
227 if (!test_bit(XPRT_CLOSE_WAIT, &xprt->state) || xprt->shutdown) {
228 smp_mb__before_clear_bit();
229 clear_bit(XPRT_LOCKED, &xprt->state);
230 smp_mb__after_clear_bit();
231 } else
Trond Myklebustc1384c92007-06-14 18:00:42 -0400232 queue_work(rpciod_workqueue, &xprt->task_cleanup);
Trond Myklebust632e3bd2006-01-03 09:55:55 +0100233}
234
Chuck Lever12a80462005-08-25 16:25:51 -0700235/*
236 * xprt_reserve_xprt_cong - serialize write access to transports
237 * @task: task that is requesting access to the transport
238 *
239 * Same as xprt_reserve_xprt, but Van Jacobson congestion control is
240 * integrated into the decision of whether a request is allowed to be
241 * woken up and given access to the transport.
242 */
243int xprt_reserve_xprt_cong(struct rpc_task *task)
244{
245 struct rpc_xprt *xprt = task->tk_xprt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 struct rpc_rqst *req = task->tk_rqstp;
247
Chuck Lever2226feb2005-08-11 16:25:38 -0400248 if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 if (task == xprt->snd_task)
250 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 goto out_sleep;
252 }
Chuck Lever12a80462005-08-25 16:25:51 -0700253 if (__xprt_get_cong(xprt, task)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 xprt->snd_task = task;
255 if (req) {
256 req->rq_bytes_sent = 0;
257 req->rq_ntrans++;
258 }
259 return 1;
260 }
Trond Myklebust632e3bd2006-01-03 09:55:55 +0100261 xprt_clear_locked(xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262out_sleep:
Chuck Lever46121cf2007-01-31 12:14:08 -0500263 dprintk("RPC: %5u failed to lock transport %p\n", task->tk_pid, xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 task->tk_timeout = 0;
265 task->tk_status = -EAGAIN;
266 if (req && req->rq_ntrans)
Trond Myklebust5d008372008-02-22 16:34:17 -0500267 rpc_sleep_on(&xprt->resend, task, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 else
Trond Myklebust5d008372008-02-22 16:34:17 -0500269 rpc_sleep_on(&xprt->sending, task, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 return 0;
271}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400272EXPORT_SYMBOL_GPL(xprt_reserve_xprt_cong);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Chuck Lever12a80462005-08-25 16:25:51 -0700274static inline int xprt_lock_write(struct rpc_xprt *xprt, struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
276 int retval;
277
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400278 spin_lock_bh(&xprt->transport_lock);
Chuck Lever12a80462005-08-25 16:25:51 -0700279 retval = xprt->ops->reserve_xprt(task);
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400280 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 return retval;
282}
283
Chuck Lever12a80462005-08-25 16:25:51 -0700284static void __xprt_lock_write_next(struct rpc_xprt *xprt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
286 struct rpc_task *task;
Chuck Lever49e9a892005-08-25 16:25:51 -0700287 struct rpc_rqst *req;
288
289 if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
290 return;
291
292 task = rpc_wake_up_next(&xprt->resend);
293 if (!task) {
294 task = rpc_wake_up_next(&xprt->sending);
295 if (!task)
296 goto out_unlock;
297 }
298
299 req = task->tk_rqstp;
300 xprt->snd_task = task;
301 if (req) {
302 req->rq_bytes_sent = 0;
303 req->rq_ntrans++;
304 }
305 return;
306
307out_unlock:
Trond Myklebust632e3bd2006-01-03 09:55:55 +0100308 xprt_clear_locked(xprt);
Chuck Lever49e9a892005-08-25 16:25:51 -0700309}
310
311static void __xprt_lock_write_next_cong(struct rpc_xprt *xprt)
312{
313 struct rpc_task *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Chuck Lever2226feb2005-08-11 16:25:38 -0400315 if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 return;
Chuck Lever49e9a892005-08-25 16:25:51 -0700317 if (RPCXPRT_CONGESTED(xprt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 goto out_unlock;
319 task = rpc_wake_up_next(&xprt->resend);
320 if (!task) {
321 task = rpc_wake_up_next(&xprt->sending);
322 if (!task)
323 goto out_unlock;
324 }
Chuck Lever49e9a892005-08-25 16:25:51 -0700325 if (__xprt_get_cong(xprt, task)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 struct rpc_rqst *req = task->tk_rqstp;
327 xprt->snd_task = task;
328 if (req) {
329 req->rq_bytes_sent = 0;
330 req->rq_ntrans++;
331 }
332 return;
333 }
334out_unlock:
Trond Myklebust632e3bd2006-01-03 09:55:55 +0100335 xprt_clear_locked(xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
Chuck Lever49e9a892005-08-25 16:25:51 -0700338/**
339 * xprt_release_xprt - allow other requests to use a transport
340 * @xprt: transport with other tasks potentially waiting
341 * @task: task that is releasing access to the transport
342 *
343 * Note that "task" can be NULL. No congestion control is provided.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 */
Chuck Lever49e9a892005-08-25 16:25:51 -0700345void xprt_release_xprt(struct rpc_xprt *xprt, struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
347 if (xprt->snd_task == task) {
Trond Myklebust632e3bd2006-01-03 09:55:55 +0100348 xprt_clear_locked(xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 __xprt_lock_write_next(xprt);
350 }
351}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400352EXPORT_SYMBOL_GPL(xprt_release_xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Chuck Lever49e9a892005-08-25 16:25:51 -0700354/**
355 * xprt_release_xprt_cong - allow other requests to use a transport
356 * @xprt: transport with other tasks potentially waiting
357 * @task: task that is releasing access to the transport
358 *
359 * Note that "task" can be NULL. Another task is awoken to use the
360 * transport if the transport's congestion window allows it.
361 */
362void xprt_release_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task)
363{
364 if (xprt->snd_task == task) {
Trond Myklebust632e3bd2006-01-03 09:55:55 +0100365 xprt_clear_locked(xprt);
Chuck Lever49e9a892005-08-25 16:25:51 -0700366 __xprt_lock_write_next_cong(xprt);
367 }
368}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400369EXPORT_SYMBOL_GPL(xprt_release_xprt_cong);
Chuck Lever49e9a892005-08-25 16:25:51 -0700370
371static inline void xprt_release_write(struct rpc_xprt *xprt, struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372{
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400373 spin_lock_bh(&xprt->transport_lock);
Chuck Lever49e9a892005-08-25 16:25:51 -0700374 xprt->ops->release_xprt(xprt, task);
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400375 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
378/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 * Van Jacobson congestion avoidance. Check if the congestion window
380 * overflowed. Put the task to sleep if this is the case.
381 */
382static int
383__xprt_get_cong(struct rpc_xprt *xprt, struct rpc_task *task)
384{
385 struct rpc_rqst *req = task->tk_rqstp;
386
387 if (req->rq_cong)
388 return 1;
Chuck Lever46121cf2007-01-31 12:14:08 -0500389 dprintk("RPC: %5u xprt_cwnd_limited cong = %lu cwnd = %lu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 task->tk_pid, xprt->cong, xprt->cwnd);
391 if (RPCXPRT_CONGESTED(xprt))
392 return 0;
393 req->rq_cong = 1;
394 xprt->cong += RPC_CWNDSCALE;
395 return 1;
396}
397
398/*
399 * Adjust the congestion window, and wake up the next task
400 * that has been sleeping due to congestion
401 */
402static void
403__xprt_put_cong(struct rpc_xprt *xprt, struct rpc_rqst *req)
404{
405 if (!req->rq_cong)
406 return;
407 req->rq_cong = 0;
408 xprt->cong -= RPC_CWNDSCALE;
Chuck Lever49e9a892005-08-25 16:25:51 -0700409 __xprt_lock_write_next_cong(xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410}
411
Chuck Lever46c0ee82005-08-25 16:25:52 -0700412/**
Chuck Levera58dd392005-08-25 16:25:53 -0700413 * xprt_release_rqst_cong - housekeeping when request is complete
414 * @task: RPC request that recently completed
415 *
416 * Useful for transports that require congestion control.
417 */
418void xprt_release_rqst_cong(struct rpc_task *task)
419{
420 __xprt_put_cong(task->tk_xprt, task->tk_rqstp);
421}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400422EXPORT_SYMBOL_GPL(xprt_release_rqst_cong);
Chuck Levera58dd392005-08-25 16:25:53 -0700423
424/**
Chuck Lever46c0ee82005-08-25 16:25:52 -0700425 * xprt_adjust_cwnd - adjust transport congestion window
426 * @task: recently completed RPC request used to adjust window
427 * @result: result code of completed RPC request
428 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 * We use a time-smoothed congestion estimator to avoid heavy oscillation.
430 */
Chuck Lever46c0ee82005-08-25 16:25:52 -0700431void xprt_adjust_cwnd(struct rpc_task *task, int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
Chuck Lever46c0ee82005-08-25 16:25:52 -0700433 struct rpc_rqst *req = task->tk_rqstp;
434 struct rpc_xprt *xprt = task->tk_xprt;
435 unsigned long cwnd = xprt->cwnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 if (result >= 0 && cwnd <= xprt->cong) {
438 /* The (cwnd >> 1) term makes sure
439 * the result gets rounded properly. */
440 cwnd += (RPC_CWNDSCALE * RPC_CWNDSCALE + (cwnd >> 1)) / cwnd;
441 if (cwnd > RPC_MAXCWND(xprt))
442 cwnd = RPC_MAXCWND(xprt);
Chuck Lever49e9a892005-08-25 16:25:51 -0700443 __xprt_lock_write_next_cong(xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 } else if (result == -ETIMEDOUT) {
445 cwnd >>= 1;
446 if (cwnd < RPC_CWNDSCALE)
447 cwnd = RPC_CWNDSCALE;
448 }
Chuck Lever46121cf2007-01-31 12:14:08 -0500449 dprintk("RPC: cong %ld, cwnd was %ld, now %ld\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 xprt->cong, xprt->cwnd, cwnd);
451 xprt->cwnd = cwnd;
Chuck Lever46c0ee82005-08-25 16:25:52 -0700452 __xprt_put_cong(xprt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400454EXPORT_SYMBOL_GPL(xprt_adjust_cwnd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Chuck Lever44fbac22005-08-11 16:25:44 -0400456/**
457 * xprt_wake_pending_tasks - wake all tasks on a transport's pending queue
458 * @xprt: transport with waiting tasks
459 * @status: result code to plant in each task before waking it
460 *
461 */
462void xprt_wake_pending_tasks(struct rpc_xprt *xprt, int status)
463{
464 if (status < 0)
465 rpc_wake_up_status(&xprt->pending, status);
466 else
467 rpc_wake_up(&xprt->pending);
468}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400469EXPORT_SYMBOL_GPL(xprt_wake_pending_tasks);
Chuck Lever44fbac22005-08-11 16:25:44 -0400470
Chuck Leverc7b2cae2005-08-11 16:25:50 -0400471/**
472 * xprt_wait_for_buffer_space - wait for transport output buffer to clear
473 * @task: task to be put to sleep
Randy Dunlap0b80ae42008-04-26 22:59:02 -0700474 * @action: function pointer to be executed after wait
Chuck Leverc7b2cae2005-08-11 16:25:50 -0400475 */
Trond Myklebustb6ddf642008-04-17 18:52:19 -0400476void xprt_wait_for_buffer_space(struct rpc_task *task, rpc_action action)
Chuck Leverc7b2cae2005-08-11 16:25:50 -0400477{
478 struct rpc_rqst *req = task->tk_rqstp;
479 struct rpc_xprt *xprt = req->rq_xprt;
480
481 task->tk_timeout = req->rq_timeout;
Trond Myklebustb6ddf642008-04-17 18:52:19 -0400482 rpc_sleep_on(&xprt->pending, task, action);
Chuck Leverc7b2cae2005-08-11 16:25:50 -0400483}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400484EXPORT_SYMBOL_GPL(xprt_wait_for_buffer_space);
Chuck Leverc7b2cae2005-08-11 16:25:50 -0400485
486/**
487 * xprt_write_space - wake the task waiting for transport output buffer space
488 * @xprt: transport with waiting tasks
489 *
490 * Can be called in a soft IRQ context, so xprt_write_space never sleeps.
491 */
492void xprt_write_space(struct rpc_xprt *xprt)
493{
494 if (unlikely(xprt->shutdown))
495 return;
496
497 spin_lock_bh(&xprt->transport_lock);
498 if (xprt->snd_task) {
Chuck Lever46121cf2007-01-31 12:14:08 -0500499 dprintk("RPC: write space: waking waiting task on "
500 "xprt %p\n", xprt);
Trond Myklebustfda13932008-02-22 16:34:12 -0500501 rpc_wake_up_queued_task(&xprt->pending, xprt->snd_task);
Chuck Leverc7b2cae2005-08-11 16:25:50 -0400502 }
503 spin_unlock_bh(&xprt->transport_lock);
504}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400505EXPORT_SYMBOL_GPL(xprt_write_space);
Chuck Leverc7b2cae2005-08-11 16:25:50 -0400506
Chuck Leverfe3aca22005-08-25 16:25:50 -0700507/**
508 * xprt_set_retrans_timeout_def - set a request's retransmit timeout
509 * @task: task whose timeout is to be set
510 *
511 * Set a request's retransmit timeout based on the transport's
512 * default timeout parameters. Used by transports that don't adjust
513 * the retransmit timeout based on round-trip time estimation.
514 */
515void xprt_set_retrans_timeout_def(struct rpc_task *task)
516{
517 task->tk_timeout = task->tk_rqstp->rq_timeout;
518}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400519EXPORT_SYMBOL_GPL(xprt_set_retrans_timeout_def);
Chuck Leverfe3aca22005-08-25 16:25:50 -0700520
521/*
522 * xprt_set_retrans_timeout_rtt - set a request's retransmit timeout
523 * @task: task whose timeout is to be set
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800524 *
Chuck Leverfe3aca22005-08-25 16:25:50 -0700525 * Set a request's retransmit timeout using the RTT estimator.
526 */
527void xprt_set_retrans_timeout_rtt(struct rpc_task *task)
528{
529 int timer = task->tk_msg.rpc_proc->p_timer;
Trond Myklebustba7392b2007-12-20 16:03:55 -0500530 struct rpc_clnt *clnt = task->tk_client;
531 struct rpc_rtt *rtt = clnt->cl_rtt;
Chuck Leverfe3aca22005-08-25 16:25:50 -0700532 struct rpc_rqst *req = task->tk_rqstp;
Trond Myklebustba7392b2007-12-20 16:03:55 -0500533 unsigned long max_timeout = clnt->cl_timeout->to_maxval;
Chuck Leverfe3aca22005-08-25 16:25:50 -0700534
535 task->tk_timeout = rpc_calc_rto(rtt, timer);
536 task->tk_timeout <<= rpc_ntimeo(rtt, timer) + req->rq_retries;
537 if (task->tk_timeout > max_timeout || task->tk_timeout == 0)
538 task->tk_timeout = max_timeout;
539}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400540EXPORT_SYMBOL_GPL(xprt_set_retrans_timeout_rtt);
Chuck Leverfe3aca22005-08-25 16:25:50 -0700541
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542static void xprt_reset_majortimeo(struct rpc_rqst *req)
543{
Trond Myklebustba7392b2007-12-20 16:03:55 -0500544 const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 req->rq_majortimeo = req->rq_timeout;
547 if (to->to_exponential)
548 req->rq_majortimeo <<= to->to_retries;
549 else
550 req->rq_majortimeo += to->to_increment * to->to_retries;
551 if (req->rq_majortimeo > to->to_maxval || req->rq_majortimeo == 0)
552 req->rq_majortimeo = to->to_maxval;
553 req->rq_majortimeo += jiffies;
554}
555
Chuck Lever9903cd12005-08-11 16:25:26 -0400556/**
557 * xprt_adjust_timeout - adjust timeout values for next retransmit
558 * @req: RPC request containing parameters to use for the adjustment
559 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 */
561int xprt_adjust_timeout(struct rpc_rqst *req)
562{
563 struct rpc_xprt *xprt = req->rq_xprt;
Trond Myklebustba7392b2007-12-20 16:03:55 -0500564 const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 int status = 0;
566
567 if (time_before(jiffies, req->rq_majortimeo)) {
568 if (to->to_exponential)
569 req->rq_timeout <<= 1;
570 else
571 req->rq_timeout += to->to_increment;
572 if (to->to_maxval && req->rq_timeout >= to->to_maxval)
573 req->rq_timeout = to->to_maxval;
574 req->rq_retries++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 } else {
576 req->rq_timeout = to->to_initval;
577 req->rq_retries = 0;
578 xprt_reset_majortimeo(req);
579 /* Reset the RTT counters == "slow start" */
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400580 spin_lock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 rpc_init_rtt(req->rq_task->tk_client->cl_rtt, to->to_initval);
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400582 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 status = -ETIMEDOUT;
584 }
585
586 if (req->rq_timeout == 0) {
587 printk(KERN_WARNING "xprt_adjust_timeout: rq_timeout = 0!\n");
588 req->rq_timeout = 5 * HZ;
589 }
590 return status;
591}
592
David Howells65f27f32006-11-22 14:55:48 +0000593static void xprt_autoclose(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
David Howells65f27f32006-11-22 14:55:48 +0000595 struct rpc_xprt *xprt =
596 container_of(work, struct rpc_xprt, task_cleanup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Chuck Levera246b012005-08-11 16:25:23 -0400598 xprt->ops->close(xprt);
Trond Myklebust66af1e52007-11-06 10:18:36 -0500599 clear_bit(XPRT_CLOSE_WAIT, &xprt->state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 xprt_release_write(xprt, NULL);
601}
602
Chuck Lever9903cd12005-08-11 16:25:26 -0400603/**
Trond Myklebust62da3b22007-11-06 18:44:20 -0500604 * xprt_disconnect_done - mark a transport as disconnected
Chuck Lever9903cd12005-08-11 16:25:26 -0400605 * @xprt: transport to flag for disconnect
606 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 */
Trond Myklebust62da3b22007-11-06 18:44:20 -0500608void xprt_disconnect_done(struct rpc_xprt *xprt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609{
Chuck Lever46121cf2007-01-31 12:14:08 -0500610 dprintk("RPC: disconnected transport %p\n", xprt);
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400611 spin_lock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 xprt_clear_connected(xprt);
Trond Myklebust2a491992009-03-11 14:38:00 -0400613 xprt_wake_pending_tasks(xprt, -EAGAIN);
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400614 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615}
Trond Myklebust62da3b22007-11-06 18:44:20 -0500616EXPORT_SYMBOL_GPL(xprt_disconnect_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Trond Myklebust66af1e52007-11-06 10:18:36 -0500618/**
619 * xprt_force_disconnect - force a transport to disconnect
620 * @xprt: transport to disconnect
621 *
622 */
623void xprt_force_disconnect(struct rpc_xprt *xprt)
624{
625 /* Don't race with the test_bit() in xprt_clear_locked() */
626 spin_lock_bh(&xprt->transport_lock);
627 set_bit(XPRT_CLOSE_WAIT, &xprt->state);
628 /* Try to schedule an autoclose RPC call */
629 if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
630 queue_work(rpciod_workqueue, &xprt->task_cleanup);
Trond Myklebust2a491992009-03-11 14:38:00 -0400631 xprt_wake_pending_tasks(xprt, -EAGAIN);
Trond Myklebust66af1e52007-11-06 10:18:36 -0500632 spin_unlock_bh(&xprt->transport_lock);
633}
Trond Myklebust66af1e52007-11-06 10:18:36 -0500634
Trond Myklebust7c1d71c2008-04-17 16:52:57 -0400635/**
636 * xprt_conditional_disconnect - force a transport to disconnect
637 * @xprt: transport to disconnect
638 * @cookie: 'connection cookie'
639 *
640 * This attempts to break the connection if and only if 'cookie' matches
641 * the current transport 'connection cookie'. It ensures that we don't
642 * try to break the connection more than once when we need to retransmit
643 * a batch of RPC requests.
644 *
645 */
646void xprt_conditional_disconnect(struct rpc_xprt *xprt, unsigned int cookie)
647{
648 /* Don't race with the test_bit() in xprt_clear_locked() */
649 spin_lock_bh(&xprt->transport_lock);
650 if (cookie != xprt->connect_cookie)
651 goto out;
652 if (test_bit(XPRT_CLOSING, &xprt->state) || !xprt_connected(xprt))
653 goto out;
654 set_bit(XPRT_CLOSE_WAIT, &xprt->state);
655 /* Try to schedule an autoclose RPC call */
656 if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
657 queue_work(rpciod_workqueue, &xprt->task_cleanup);
Trond Myklebust2a491992009-03-11 14:38:00 -0400658 xprt_wake_pending_tasks(xprt, -EAGAIN);
Trond Myklebust7c1d71c2008-04-17 16:52:57 -0400659out:
660 spin_unlock_bh(&xprt->transport_lock);
661}
662
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663static void
664xprt_init_autodisconnect(unsigned long data)
665{
666 struct rpc_xprt *xprt = (struct rpc_xprt *)data;
667
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400668 spin_lock(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 if (!list_empty(&xprt->recv) || xprt->shutdown)
670 goto out_abort;
Chuck Lever2226feb2005-08-11 16:25:38 -0400671 if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 goto out_abort;
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400673 spin_unlock(&xprt->transport_lock);
Trond Myklebustf75e6742009-04-21 17:18:20 -0400674 set_bit(XPRT_CONNECTION_CLOSE, &xprt->state);
675 queue_work(rpciod_workqueue, &xprt->task_cleanup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 return;
677out_abort:
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400678 spin_unlock(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679}
680
Chuck Lever9903cd12005-08-11 16:25:26 -0400681/**
682 * xprt_connect - schedule a transport connect operation
683 * @task: RPC task that is requesting the connect
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 *
685 */
686void xprt_connect(struct rpc_task *task)
687{
688 struct rpc_xprt *xprt = task->tk_xprt;
689
Chuck Lever46121cf2007-01-31 12:14:08 -0500690 dprintk("RPC: %5u xprt_connect xprt %p %s connected\n", task->tk_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 xprt, (xprt_connected(xprt) ? "is" : "is not"));
692
Chuck Leverec739ef2006-08-22 20:06:15 -0400693 if (!xprt_bound(xprt)) {
Trond Myklebust01d37c42009-03-11 14:09:39 -0400694 task->tk_status = -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 return;
696 }
697 if (!xprt_lock_write(xprt, task))
698 return;
Trond Myklebustfeb8ca32009-12-03 08:10:17 -0500699
700 if (test_and_clear_bit(XPRT_CLOSE_WAIT, &xprt->state))
701 xprt->ops->close(xprt);
702
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 if (xprt_connected(xprt))
Chuck Levera246b012005-08-11 16:25:23 -0400704 xprt_release_write(xprt, task);
705 else {
706 if (task->tk_rqstp)
707 task->tk_rqstp->rq_bytes_sent = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Trond Myklebusta8ce4a82010-04-16 16:42:12 -0400709 task->tk_timeout = task->tk_rqstp->rq_timeout;
Trond Myklebust5d008372008-02-22 16:34:17 -0500710 rpc_sleep_on(&xprt->pending, task, xprt_connect_status);
Trond Myklebust0b9e7942010-04-16 16:41:57 -0400711
712 if (test_bit(XPRT_CLOSING, &xprt->state))
713 return;
714 if (xprt_test_and_set_connecting(xprt))
715 return;
Chuck Lever262ca072006-03-20 13:44:16 -0500716 xprt->stat.connect_start = jiffies;
Chuck Levera246b012005-08-11 16:25:23 -0400717 xprt->ops->connect(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719}
720
Chuck Lever9903cd12005-08-11 16:25:26 -0400721static void xprt_connect_status(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722{
723 struct rpc_xprt *xprt = task->tk_xprt;
724
Chuck Levercd983ef2008-06-11 17:56:13 -0400725 if (task->tk_status == 0) {
Chuck Lever262ca072006-03-20 13:44:16 -0500726 xprt->stat.connect_count++;
727 xprt->stat.connect_time += (long)jiffies - xprt->stat.connect_start;
Chuck Lever46121cf2007-01-31 12:14:08 -0500728 dprintk("RPC: %5u xprt_connect_status: connection established\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 task->tk_pid);
730 return;
731 }
732
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 switch (task->tk_status) {
Trond Myklebust2a491992009-03-11 14:38:00 -0400734 case -EAGAIN:
735 dprintk("RPC: %5u xprt_connect_status: retrying\n", task->tk_pid);
Chuck Lever23475d62005-08-11 16:25:08 -0400736 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 case -ETIMEDOUT:
Chuck Lever46121cf2007-01-31 12:14:08 -0500738 dprintk("RPC: %5u xprt_connect_status: connect attempt timed "
739 "out\n", task->tk_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 break;
741 default:
Chuck Lever46121cf2007-01-31 12:14:08 -0500742 dprintk("RPC: %5u xprt_connect_status: error %d connecting to "
743 "server %s\n", task->tk_pid, -task->tk_status,
744 task->tk_client->cl_server);
Chuck Lever23475d62005-08-11 16:25:08 -0400745 xprt_release_write(xprt, task);
746 task->tk_status = -EIO;
Chuck Lever23475d62005-08-11 16:25:08 -0400747 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748}
749
Chuck Lever9903cd12005-08-11 16:25:26 -0400750/**
751 * xprt_lookup_rqst - find an RPC request corresponding to an XID
752 * @xprt: transport on which the original request was transmitted
753 * @xid: RPC XID of incoming reply
754 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 */
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700756struct rpc_rqst *xprt_lookup_rqst(struct rpc_xprt *xprt, __be32 xid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
Pavel Emelyanov8f3a6de2010-10-05 23:30:19 +0400758 struct rpc_rqst *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
Pavel Emelyanov8f3a6de2010-10-05 23:30:19 +0400760 list_for_each_entry(entry, &xprt->recv, rq_list)
Chuck Lever262ca072006-03-20 13:44:16 -0500761 if (entry->rq_xid == xid)
762 return entry;
Chuck Lever46121cf2007-01-31 12:14:08 -0500763
764 dprintk("RPC: xprt_lookup_rqst did not find xid %08x\n",
765 ntohl(xid));
Chuck Lever262ca072006-03-20 13:44:16 -0500766 xprt->stat.bad_xids++;
767 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400769EXPORT_SYMBOL_GPL(xprt_lookup_rqst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Chuck Leverbbc72ce2010-05-07 13:34:27 -0400771static void xprt_update_rtt(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772{
Chuck Lever1570c1e2005-08-25 16:25:52 -0700773 struct rpc_rqst *req = task->tk_rqstp;
774 struct rpc_rtt *rtt = task->tk_client->cl_rtt;
775 unsigned timer = task->tk_msg.rpc_proc->p_timer;
Trond Myklebustd60dbb22010-05-13 12:51:49 -0400776 long m = usecs_to_jiffies(ktime_to_us(req->rq_rtt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
Chuck Lever1570c1e2005-08-25 16:25:52 -0700778 if (timer) {
779 if (req->rq_ntrans == 1)
Chuck Leverff839972010-05-07 13:34:47 -0400780 rpc_update_rtt(rtt, timer, m);
Chuck Lever1570c1e2005-08-25 16:25:52 -0700781 rpc_set_timeo(rtt, timer, req->rq_ntrans - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 }
Chuck Lever1570c1e2005-08-25 16:25:52 -0700783}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Chuck Lever1570c1e2005-08-25 16:25:52 -0700785/**
786 * xprt_complete_rqst - called when reply processing is complete
787 * @task: RPC request that recently completed
788 * @copied: actual number of bytes received from the transport
789 *
790 * Caller holds transport lock.
791 */
792void xprt_complete_rqst(struct rpc_task *task, int copied)
793{
794 struct rpc_rqst *req = task->tk_rqstp;
Trond Myklebustfda13932008-02-22 16:34:12 -0500795 struct rpc_xprt *xprt = req->rq_xprt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Chuck Lever1570c1e2005-08-25 16:25:52 -0700797 dprintk("RPC: %5u xid %08x complete (%d bytes received)\n",
798 task->tk_pid, ntohl(req->rq_xid), copied);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Trond Myklebustfda13932008-02-22 16:34:12 -0500800 xprt->stat.recvs++;
Trond Myklebustd60dbb22010-05-13 12:51:49 -0400801 req->rq_rtt = ktime_sub(ktime_get(), req->rq_xtime);
Chuck Leverbbc72ce2010-05-07 13:34:27 -0400802 if (xprt->ops->timer != NULL)
803 xprt_update_rtt(task);
Chuck Leveref759a22006-03-20 13:44:17 -0500804
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 list_del_init(&req->rq_list);
Trond Myklebust1e799b62008-03-21 16:19:41 -0400806 req->rq_private_buf.len = copied;
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -0400807 /* Ensure all writes are done before we update */
808 /* req->rq_reply_bytes_recvd */
Trond Myklebust43ac3f22006-03-20 13:44:51 -0500809 smp_wmb();
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -0400810 req->rq_reply_bytes_recvd = copied;
Trond Myklebustfda13932008-02-22 16:34:12 -0500811 rpc_wake_up_queued_task(&xprt->pending, task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400813EXPORT_SYMBOL_GPL(xprt_complete_rqst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Chuck Lever46c0ee82005-08-25 16:25:52 -0700815static void xprt_timer(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816{
Chuck Lever46c0ee82005-08-25 16:25:52 -0700817 struct rpc_rqst *req = task->tk_rqstp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 struct rpc_xprt *xprt = req->rq_xprt;
819
Trond Myklebust5d008372008-02-22 16:34:17 -0500820 if (task->tk_status != -ETIMEDOUT)
821 return;
Chuck Lever46121cf2007-01-31 12:14:08 -0500822 dprintk("RPC: %5u xprt_timer\n", task->tk_pid);
Chuck Lever46c0ee82005-08-25 16:25:52 -0700823
Trond Myklebust5d008372008-02-22 16:34:17 -0500824 spin_lock_bh(&xprt->transport_lock);
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -0400825 if (!req->rq_reply_bytes_recvd) {
Chuck Lever46c0ee82005-08-25 16:25:52 -0700826 if (xprt->ops->timer)
827 xprt->ops->timer(task);
Trond Myklebust5d008372008-02-22 16:34:17 -0500828 } else
829 task->tk_status = 0;
830 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831}
832
Rahul Iyer4cfc7e62009-09-10 17:32:28 +0300833static inline int xprt_has_timer(struct rpc_xprt *xprt)
834{
835 return xprt->idle_timeout != 0;
836}
837
Chuck Lever9903cd12005-08-11 16:25:26 -0400838/**
839 * xprt_prepare_transmit - reserve the transport before sending a request
840 * @task: RPC task about to send a request
841 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 */
Chuck Lever9903cd12005-08-11 16:25:26 -0400843int xprt_prepare_transmit(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844{
845 struct rpc_rqst *req = task->tk_rqstp;
846 struct rpc_xprt *xprt = req->rq_xprt;
847 int err = 0;
848
Chuck Lever46121cf2007-01-31 12:14:08 -0500849 dprintk("RPC: %5u xprt_prepare_transmit\n", task->tk_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400851 spin_lock_bh(&xprt->transport_lock);
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -0400852 if (req->rq_reply_bytes_recvd && !req->rq_bytes_sent) {
853 err = req->rq_reply_bytes_recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 goto out_unlock;
855 }
Trond Myklebust2a491992009-03-11 14:38:00 -0400856 if (!xprt->ops->reserve_xprt(task))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 err = -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858out_unlock:
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400859 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 return err;
861}
862
Trond Myklebuste0ab53d2006-07-27 17:22:50 -0400863void xprt_end_transmit(struct rpc_task *task)
Trond Myklebust5e5ce5b2005-10-18 14:20:11 -0700864{
Rahul Iyer343952f2009-04-01 09:23:17 -0400865 xprt_release_write(task->tk_rqstp->rq_xprt, task);
Trond Myklebust5e5ce5b2005-10-18 14:20:11 -0700866}
867
Chuck Lever9903cd12005-08-11 16:25:26 -0400868/**
869 * xprt_transmit - send an RPC request on a transport
870 * @task: controlling RPC task
871 *
872 * We have to copy the iovec because sendmsg fiddles with its contents.
873 */
874void xprt_transmit(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 struct rpc_rqst *req = task->tk_rqstp;
877 struct rpc_xprt *xprt = req->rq_xprt;
Chuck Levera246b012005-08-11 16:25:23 -0400878 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
Chuck Lever46121cf2007-01-31 12:14:08 -0500880 dprintk("RPC: %5u xprt_transmit(%u)\n", task->tk_pid, req->rq_slen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -0400882 if (!req->rq_reply_bytes_recvd) {
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400883 if (list_empty(&req->rq_list) && rpc_reply_expected(task)) {
884 /*
885 * Add to the list only if we're expecting a reply
886 */
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400887 spin_lock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 /* Update the softirq receive buffer */
889 memcpy(&req->rq_private_buf, &req->rq_rcv_buf,
890 sizeof(req->rq_private_buf));
891 /* Add request to the receive list */
892 list_add_tail(&req->rq_list, &xprt->recv);
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400893 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 xprt_reset_majortimeo(req);
Trond Myklebust0f9dc2b2005-06-22 17:16:28 +0000895 /* Turn off autodisconnect */
896 del_singleshot_timer_sync(&xprt->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 }
898 } else if (!req->rq_bytes_sent)
899 return;
900
Trond Myklebust7c1d71c2008-04-17 16:52:57 -0400901 req->rq_connect_cookie = xprt->connect_cookie;
Chuck Leverff839972010-05-07 13:34:47 -0400902 req->rq_xtime = ktime_get();
Chuck Levera246b012005-08-11 16:25:23 -0400903 status = xprt->ops->send_request(task);
Trond Myklebustc8485e42009-03-11 14:37:59 -0400904 if (status != 0) {
905 task->tk_status = status;
Chuck Leverfe3aca22005-08-25 16:25:50 -0700906 return;
907 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Trond Myklebustc8485e42009-03-11 14:37:59 -0400909 dprintk("RPC: %5u xmit complete\n", task->tk_pid);
910 spin_lock_bh(&xprt->transport_lock);
911
912 xprt->ops->set_retrans_timeout(task);
913
914 xprt->stat.sends++;
915 xprt->stat.req_u += xprt->stat.sends - xprt->stat.recvs;
916 xprt->stat.bklog_u += xprt->backlog.qlen;
917
918 /* Don't race with disconnect */
919 if (!xprt_connected(xprt))
920 task->tk_status = -ENOTCONN;
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -0400921 else if (!req->rq_reply_bytes_recvd && rpc_reply_expected(task)) {
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400922 /*
923 * Sleep on the pending queue since
924 * we're expecting a reply.
925 */
Trond Myklebustc8485e42009-03-11 14:37:59 -0400926 rpc_sleep_on(&xprt->pending, task, xprt_timer);
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400927 }
Trond Myklebustc8485e42009-03-11 14:37:59 -0400928 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929}
930
Trond Myklebustee5ebe82010-04-16 16:37:01 -0400931static void xprt_alloc_slot(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932{
933 struct rpc_xprt *xprt = task->tk_xprt;
934
935 task->tk_status = 0;
936 if (task->tk_rqstp)
937 return;
938 if (!list_empty(&xprt->free)) {
939 struct rpc_rqst *req = list_entry(xprt->free.next, struct rpc_rqst, rq_list);
940 list_del_init(&req->rq_list);
941 task->tk_rqstp = req;
942 xprt_request_init(task, xprt);
943 return;
944 }
Chuck Lever46121cf2007-01-31 12:14:08 -0500945 dprintk("RPC: waiting for request slot\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 task->tk_status = -EAGAIN;
947 task->tk_timeout = 0;
Trond Myklebust5d008372008-02-22 16:34:17 -0500948 rpc_sleep_on(&xprt->backlog, task, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949}
950
Trond Myklebustee5ebe82010-04-16 16:37:01 -0400951static void xprt_free_slot(struct rpc_xprt *xprt, struct rpc_rqst *req)
952{
953 memset(req, 0, sizeof(*req)); /* mark unused */
954
955 spin_lock(&xprt->reserve_lock);
956 list_add(&req->rq_list, &xprt->free);
957 rpc_wake_up_next(&xprt->backlog);
958 spin_unlock(&xprt->reserve_lock);
959}
960
Pavel Emelyanov37aa2132010-09-29 16:05:43 +0400961struct rpc_xprt *xprt_alloc(struct net *net, int size, int max_req)
Pavel Emelyanovbd1722d2010-09-29 16:02:43 +0400962{
963 struct rpc_xprt *xprt;
964
965 xprt = kzalloc(size, GFP_KERNEL);
966 if (xprt == NULL)
967 goto out;
968
969 xprt->max_reqs = max_req;
970 xprt->slot = kcalloc(max_req, sizeof(struct rpc_rqst), GFP_KERNEL);
971 if (xprt->slot == NULL)
972 goto out_free;
973
Pavel Emelyanov37aa2132010-09-29 16:05:43 +0400974 xprt->xprt_net = get_net(net);
Pavel Emelyanovbd1722d2010-09-29 16:02:43 +0400975 return xprt;
976
977out_free:
978 kfree(xprt);
979out:
980 return NULL;
981}
982EXPORT_SYMBOL_GPL(xprt_alloc);
983
Pavel Emelyanove204e622010-09-29 16:03:13 +0400984void xprt_free(struct rpc_xprt *xprt)
985{
Pavel Emelyanov37aa2132010-09-29 16:05:43 +0400986 put_net(xprt->xprt_net);
Pavel Emelyanove204e622010-09-29 16:03:13 +0400987 kfree(xprt->slot);
988 kfree(xprt);
989}
990EXPORT_SYMBOL_GPL(xprt_free);
991
Chuck Lever9903cd12005-08-11 16:25:26 -0400992/**
993 * xprt_reserve - allocate an RPC request slot
994 * @task: RPC task requesting a slot allocation
995 *
996 * If no more slots are available, place the task on the transport's
997 * backlog queue.
998 */
999void xprt_reserve(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000{
1001 struct rpc_xprt *xprt = task->tk_xprt;
1002
1003 task->tk_status = -EIO;
Trond Myklebust0065db32006-01-03 09:55:56 +01001004 spin_lock(&xprt->reserve_lock);
Trond Myklebustee5ebe82010-04-16 16:37:01 -04001005 xprt_alloc_slot(task);
Trond Myklebust0065db32006-01-03 09:55:56 +01001006 spin_unlock(&xprt->reserve_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007}
1008
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001009static inline __be32 xprt_alloc_xid(struct rpc_xprt *xprt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010{
Eric Dumazet0eae88f2010-04-20 19:06:52 -07001011 return (__force __be32)xprt->xid++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012}
1013
1014static inline void xprt_init_xid(struct rpc_xprt *xprt)
1015{
Chuck Leverbf3fcf82006-05-25 01:40:51 -04001016 xprt->xid = net_random();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017}
1018
Chuck Lever9903cd12005-08-11 16:25:26 -04001019static void xprt_request_init(struct rpc_task *task, struct rpc_xprt *xprt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020{
1021 struct rpc_rqst *req = task->tk_rqstp;
1022
Trond Myklebustba7392b2007-12-20 16:03:55 -05001023 req->rq_timeout = task->tk_client->cl_timeout->to_initval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 req->rq_task = task;
1025 req->rq_xprt = xprt;
Chuck Lever02107142006-01-03 09:55:49 +01001026 req->rq_buffer = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 req->rq_xid = xprt_alloc_xid(xprt);
J. Bruce Fieldsead5e1c2005-10-13 16:54:43 -04001028 req->rq_release_snd_buf = NULL;
Trond Myklebustda458282006-08-31 15:44:52 -04001029 xprt_reset_majortimeo(req);
Chuck Lever46121cf2007-01-31 12:14:08 -05001030 dprintk("RPC: %5u reserved req %p xid %08x\n", task->tk_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 req, ntohl(req->rq_xid));
1032}
1033
Chuck Lever9903cd12005-08-11 16:25:26 -04001034/**
1035 * xprt_release - release an RPC request slot
1036 * @task: task which is finished with the slot
1037 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 */
Chuck Lever9903cd12005-08-11 16:25:26 -04001039void xprt_release(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040{
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001041 struct rpc_xprt *xprt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 struct rpc_rqst *req;
1043
1044 if (!(req = task->tk_rqstp))
1045 return;
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001046
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001047 xprt = req->rq_xprt;
Chuck Lever11c556b2006-03-20 13:44:22 -05001048 rpc_count_iostats(task);
Chuck Lever4a0f8c02005-08-11 16:25:32 -04001049 spin_lock_bh(&xprt->transport_lock);
Chuck Lever49e9a892005-08-25 16:25:51 -07001050 xprt->ops->release_xprt(xprt, task);
Chuck Levera58dd392005-08-25 16:25:53 -07001051 if (xprt->ops->release_request)
1052 xprt->ops->release_request(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 if (!list_empty(&req->rq_list))
1054 list_del(&req->rq_list);
1055 xprt->last_used = jiffies;
Rahul Iyer4cfc7e62009-09-10 17:32:28 +03001056 if (list_empty(&xprt->recv) && xprt_has_timer(xprt))
Chuck Levera246b012005-08-11 16:25:23 -04001057 mod_timer(&xprt->timer,
Chuck Lever03bf4b72005-08-25 16:25:55 -07001058 xprt->last_used + xprt->idle_timeout);
Chuck Lever4a0f8c02005-08-11 16:25:32 -04001059 spin_unlock_bh(&xprt->transport_lock);
Trond Myklebustee5ebe82010-04-16 16:37:01 -04001060 if (req->rq_buffer)
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001061 xprt->ops->buf_free(req->rq_buffer);
Trond Myklebusta17c2152010-07-31 14:29:08 -04001062 if (req->rq_cred != NULL)
1063 put_rpccred(req->rq_cred);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 task->tk_rqstp = NULL;
J. Bruce Fieldsead5e1c2005-10-13 16:54:43 -04001065 if (req->rq_release_snd_buf)
1066 req->rq_release_snd_buf(req);
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001067
Chuck Lever46121cf2007-01-31 12:14:08 -05001068 dprintk("RPC: %5u release request %p\n", task->tk_pid, req);
Trond Myklebustee5ebe82010-04-16 16:37:01 -04001069 if (likely(!bc_prealloc(req)))
1070 xprt_free_slot(xprt, req);
1071 else
Trond Myklebustc9acb422010-03-19 15:36:22 -04001072 xprt_free_bc_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073}
1074
Chuck Lever9903cd12005-08-11 16:25:26 -04001075/**
Chuck Leverc2866762006-08-22 20:06:20 -04001076 * xprt_create_transport - create an RPC transport
Frank van Maarseveen96802a02007-07-08 13:08:54 +02001077 * @args: rpc transport creation arguments
Chuck Leverc2866762006-08-22 20:06:20 -04001078 *
1079 */
\"Talpey, Thomas\3c341b0b2007-09-10 13:47:07 -04001080struct rpc_xprt *xprt_create_transport(struct xprt_create *args)
Chuck Leverc2866762006-08-22 20:06:20 -04001081{
Chuck Leverc2866762006-08-22 20:06:20 -04001082 struct rpc_xprt *xprt;
1083 struct rpc_rqst *req;
\"Talpey, Thomas\bc255712007-09-10 13:46:39 -04001084 struct xprt_class *t;
Chuck Leverc2866762006-08-22 20:06:20 -04001085
\"Talpey, Thomas\bc255712007-09-10 13:46:39 -04001086 spin_lock(&xprt_list_lock);
1087 list_for_each_entry(t, &xprt_list, list) {
\"Talpey, Thomas\4fa016e2007-09-10 13:47:57 -04001088 if (t->ident == args->ident) {
\"Talpey, Thomas\bc255712007-09-10 13:46:39 -04001089 spin_unlock(&xprt_list_lock);
1090 goto found;
1091 }
Chuck Leverc2866762006-08-22 20:06:20 -04001092 }
\"Talpey, Thomas\bc255712007-09-10 13:46:39 -04001093 spin_unlock(&xprt_list_lock);
\"Talpey, Thomas\4fa016e2007-09-10 13:47:57 -04001094 printk(KERN_ERR "RPC: transport (%d) not supported\n", args->ident);
\"Talpey, Thomas\bc255712007-09-10 13:46:39 -04001095 return ERR_PTR(-EIO);
1096
1097found:
1098 xprt = t->setup(args);
Chuck Leverc8541ec2006-10-17 14:44:27 -04001099 if (IS_ERR(xprt)) {
Chuck Lever46121cf2007-01-31 12:14:08 -05001100 dprintk("RPC: xprt_create_transport: failed, %ld\n",
Chuck Leverc8541ec2006-10-17 14:44:27 -04001101 -PTR_ERR(xprt));
1102 return xprt;
Chuck Leverc2866762006-08-22 20:06:20 -04001103 }
1104
Trond Myklebust6b6ca862006-09-05 12:55:57 -04001105 kref_init(&xprt->kref);
Chuck Leverc2866762006-08-22 20:06:20 -04001106 spin_lock_init(&xprt->transport_lock);
1107 spin_lock_init(&xprt->reserve_lock);
1108
1109 INIT_LIST_HEAD(&xprt->free);
1110 INIT_LIST_HEAD(&xprt->recv);
Ricardo Labiagaf9acac12009-04-01 09:22:59 -04001111#if defined(CONFIG_NFS_V4_1)
1112 spin_lock_init(&xprt->bc_pa_lock);
1113 INIT_LIST_HEAD(&xprt->bc_pa_list);
1114#endif /* CONFIG_NFS_V4_1 */
1115
David Howells65f27f32006-11-22 14:55:48 +00001116 INIT_WORK(&xprt->task_cleanup, xprt_autoclose);
Rahul Iyer4cfc7e62009-09-10 17:32:28 +03001117 if (xprt_has_timer(xprt))
1118 setup_timer(&xprt->timer, xprt_init_autodisconnect,
1119 (unsigned long)xprt);
1120 else
1121 init_timer(&xprt->timer);
Chuck Leverc2866762006-08-22 20:06:20 -04001122 xprt->last_used = jiffies;
1123 xprt->cwnd = RPC_INITCWND;
Chuck Levera5090502007-03-29 16:48:04 -04001124 xprt->bind_index = 0;
Chuck Leverc2866762006-08-22 20:06:20 -04001125
1126 rpc_init_wait_queue(&xprt->binding, "xprt_binding");
1127 rpc_init_wait_queue(&xprt->pending, "xprt_pending");
1128 rpc_init_wait_queue(&xprt->sending, "xprt_sending");
1129 rpc_init_wait_queue(&xprt->resend, "xprt_resend");
1130 rpc_init_priority_wait_queue(&xprt->backlog, "xprt_backlog");
1131
1132 /* initialize free list */
1133 for (req = &xprt->slot[xprt->max_reqs-1]; req >= &xprt->slot[0]; req--)
1134 list_add(&req->rq_list, &xprt->free);
1135
1136 xprt_init_xid(xprt);
1137
Chuck Lever46121cf2007-01-31 12:14:08 -05001138 dprintk("RPC: created transport %p with %u slots\n", xprt,
Chuck Leverc2866762006-08-22 20:06:20 -04001139 xprt->max_reqs);
Chuck Leverc2866762006-08-22 20:06:20 -04001140 return xprt;
1141}
1142
Chuck Lever9903cd12005-08-11 16:25:26 -04001143/**
1144 * xprt_destroy - destroy an RPC transport, killing off all requests.
Trond Myklebust6b6ca862006-09-05 12:55:57 -04001145 * @kref: kref for the transport to destroy
Chuck Lever9903cd12005-08-11 16:25:26 -04001146 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 */
Trond Myklebust6b6ca862006-09-05 12:55:57 -04001148static void xprt_destroy(struct kref *kref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149{
Trond Myklebust6b6ca862006-09-05 12:55:57 -04001150 struct rpc_xprt *xprt = container_of(kref, struct rpc_xprt, kref);
1151
Chuck Lever46121cf2007-01-31 12:14:08 -05001152 dprintk("RPC: destroying transport %p\n", xprt);
Trond Myklebust0065db32006-01-03 09:55:56 +01001153 xprt->shutdown = 1;
1154 del_timer_sync(&xprt->timer);
Chuck Leverc8541ec2006-10-17 14:44:27 -04001155
Trond Myklebustf6a1cc82008-02-22 17:06:55 -05001156 rpc_destroy_wait_queue(&xprt->binding);
1157 rpc_destroy_wait_queue(&xprt->pending);
1158 rpc_destroy_wait_queue(&xprt->sending);
1159 rpc_destroy_wait_queue(&xprt->resend);
1160 rpc_destroy_wait_queue(&xprt->backlog);
J. Bruce Fieldsc3ae62ae2010-08-03 17:22:20 -04001161 cancel_work_sync(&xprt->task_cleanup);
Chuck Leverc8541ec2006-10-17 14:44:27 -04001162 /*
1163 * Tear down transport state and free the rpc_xprt
1164 */
Chuck Levera246b012005-08-11 16:25:23 -04001165 xprt->ops->destroy(xprt);
Trond Myklebust6b6ca862006-09-05 12:55:57 -04001166}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
Trond Myklebust6b6ca862006-09-05 12:55:57 -04001168/**
1169 * xprt_put - release a reference to an RPC transport.
1170 * @xprt: pointer to the transport
1171 *
1172 */
1173void xprt_put(struct rpc_xprt *xprt)
1174{
1175 kref_put(&xprt->kref, xprt_destroy);
1176}
1177
1178/**
1179 * xprt_get - return a reference to an RPC transport.
1180 * @xprt: pointer to the transport
1181 *
1182 */
1183struct rpc_xprt *xprt_get(struct rpc_xprt *xprt)
1184{
1185 kref_get(&xprt->kref);
1186 return xprt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187}