blob: 953206d8c6c2b436a95645a8d36faecddd63f2da [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;
202 if (task == NULL)
203 return 0;
204 goto out_sleep;
205 }
206 xprt->snd_task = task;
207 if (req) {
208 req->rq_bytes_sent = 0;
209 req->rq_ntrans++;
210 }
211 return 1;
212
213out_sleep:
Chuck Lever46121cf2007-01-31 12:14:08 -0500214 dprintk("RPC: %5u failed to lock transport %p\n",
Chuck Lever12a80462005-08-25 16:25:51 -0700215 task->tk_pid, xprt);
216 task->tk_timeout = 0;
217 task->tk_status = -EAGAIN;
218 if (req && req->rq_ntrans)
Trond Myklebust5d008372008-02-22 16:34:17 -0500219 rpc_sleep_on(&xprt->resend, task, NULL);
Chuck Lever12a80462005-08-25 16:25:51 -0700220 else
Trond Myklebust5d008372008-02-22 16:34:17 -0500221 rpc_sleep_on(&xprt->sending, task, NULL);
Chuck Lever12a80462005-08-25 16:25:51 -0700222 return 0;
223}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400224EXPORT_SYMBOL_GPL(xprt_reserve_xprt);
Chuck Lever12a80462005-08-25 16:25:51 -0700225
Trond Myklebust632e3bd2006-01-03 09:55:55 +0100226static void xprt_clear_locked(struct rpc_xprt *xprt)
227{
228 xprt->snd_task = NULL;
229 if (!test_bit(XPRT_CLOSE_WAIT, &xprt->state) || xprt->shutdown) {
230 smp_mb__before_clear_bit();
231 clear_bit(XPRT_LOCKED, &xprt->state);
232 smp_mb__after_clear_bit();
233 } else
Trond Myklebustc1384c92007-06-14 18:00:42 -0400234 queue_work(rpciod_workqueue, &xprt->task_cleanup);
Trond Myklebust632e3bd2006-01-03 09:55:55 +0100235}
236
Chuck Lever12a80462005-08-25 16:25:51 -0700237/*
238 * xprt_reserve_xprt_cong - serialize write access to transports
239 * @task: task that is requesting access to the transport
240 *
241 * Same as xprt_reserve_xprt, but Van Jacobson congestion control is
242 * integrated into the decision of whether a request is allowed to be
243 * woken up and given access to the transport.
244 */
245int xprt_reserve_xprt_cong(struct rpc_task *task)
246{
247 struct rpc_xprt *xprt = task->tk_xprt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 struct rpc_rqst *req = task->tk_rqstp;
249
Chuck Lever2226feb2005-08-11 16:25:38 -0400250 if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 if (task == xprt->snd_task)
252 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 goto out_sleep;
254 }
Chuck Lever12a80462005-08-25 16:25:51 -0700255 if (__xprt_get_cong(xprt, task)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 xprt->snd_task = task;
257 if (req) {
258 req->rq_bytes_sent = 0;
259 req->rq_ntrans++;
260 }
261 return 1;
262 }
Trond Myklebust632e3bd2006-01-03 09:55:55 +0100263 xprt_clear_locked(xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264out_sleep:
Chuck Lever46121cf2007-01-31 12:14:08 -0500265 dprintk("RPC: %5u failed to lock transport %p\n", task->tk_pid, xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 task->tk_timeout = 0;
267 task->tk_status = -EAGAIN;
268 if (req && req->rq_ntrans)
Trond Myklebust5d008372008-02-22 16:34:17 -0500269 rpc_sleep_on(&xprt->resend, task, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 else
Trond Myklebust5d008372008-02-22 16:34:17 -0500271 rpc_sleep_on(&xprt->sending, task, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 return 0;
273}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400274EXPORT_SYMBOL_GPL(xprt_reserve_xprt_cong);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Chuck Lever12a80462005-08-25 16:25:51 -0700276static inline int xprt_lock_write(struct rpc_xprt *xprt, struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
278 int retval;
279
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400280 spin_lock_bh(&xprt->transport_lock);
Chuck Lever12a80462005-08-25 16:25:51 -0700281 retval = xprt->ops->reserve_xprt(task);
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400282 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 return retval;
284}
285
Chuck Lever12a80462005-08-25 16:25:51 -0700286static void __xprt_lock_write_next(struct rpc_xprt *xprt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 struct rpc_task *task;
Chuck Lever49e9a892005-08-25 16:25:51 -0700289 struct rpc_rqst *req;
290
291 if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
292 return;
293
294 task = rpc_wake_up_next(&xprt->resend);
295 if (!task) {
296 task = rpc_wake_up_next(&xprt->sending);
297 if (!task)
298 goto out_unlock;
299 }
300
301 req = task->tk_rqstp;
302 xprt->snd_task = task;
303 if (req) {
304 req->rq_bytes_sent = 0;
305 req->rq_ntrans++;
306 }
307 return;
308
309out_unlock:
Trond Myklebust632e3bd2006-01-03 09:55:55 +0100310 xprt_clear_locked(xprt);
Chuck Lever49e9a892005-08-25 16:25:51 -0700311}
312
313static void __xprt_lock_write_next_cong(struct rpc_xprt *xprt)
314{
315 struct rpc_task *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Chuck Lever2226feb2005-08-11 16:25:38 -0400317 if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 return;
Chuck Lever49e9a892005-08-25 16:25:51 -0700319 if (RPCXPRT_CONGESTED(xprt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 goto out_unlock;
321 task = rpc_wake_up_next(&xprt->resend);
322 if (!task) {
323 task = rpc_wake_up_next(&xprt->sending);
324 if (!task)
325 goto out_unlock;
326 }
Chuck Lever49e9a892005-08-25 16:25:51 -0700327 if (__xprt_get_cong(xprt, task)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 struct rpc_rqst *req = task->tk_rqstp;
329 xprt->snd_task = task;
330 if (req) {
331 req->rq_bytes_sent = 0;
332 req->rq_ntrans++;
333 }
334 return;
335 }
336out_unlock:
Trond Myklebust632e3bd2006-01-03 09:55:55 +0100337 xprt_clear_locked(xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338}
339
Chuck Lever49e9a892005-08-25 16:25:51 -0700340/**
341 * xprt_release_xprt - allow other requests to use a transport
342 * @xprt: transport with other tasks potentially waiting
343 * @task: task that is releasing access to the transport
344 *
345 * Note that "task" can be NULL. No congestion control is provided.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 */
Chuck Lever49e9a892005-08-25 16:25:51 -0700347void xprt_release_xprt(struct rpc_xprt *xprt, struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
349 if (xprt->snd_task == task) {
Trond Myklebust632e3bd2006-01-03 09:55:55 +0100350 xprt_clear_locked(xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 __xprt_lock_write_next(xprt);
352 }
353}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400354EXPORT_SYMBOL_GPL(xprt_release_xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Chuck Lever49e9a892005-08-25 16:25:51 -0700356/**
357 * xprt_release_xprt_cong - allow other requests to use a transport
358 * @xprt: transport with other tasks potentially waiting
359 * @task: task that is releasing access to the transport
360 *
361 * Note that "task" can be NULL. Another task is awoken to use the
362 * transport if the transport's congestion window allows it.
363 */
364void xprt_release_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task)
365{
366 if (xprt->snd_task == task) {
Trond Myklebust632e3bd2006-01-03 09:55:55 +0100367 xprt_clear_locked(xprt);
Chuck Lever49e9a892005-08-25 16:25:51 -0700368 __xprt_lock_write_next_cong(xprt);
369 }
370}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400371EXPORT_SYMBOL_GPL(xprt_release_xprt_cong);
Chuck Lever49e9a892005-08-25 16:25:51 -0700372
373static inline void xprt_release_write(struct rpc_xprt *xprt, struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400375 spin_lock_bh(&xprt->transport_lock);
Chuck Lever49e9a892005-08-25 16:25:51 -0700376 xprt->ops->release_xprt(xprt, task);
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400377 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
380/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 * Van Jacobson congestion avoidance. Check if the congestion window
382 * overflowed. Put the task to sleep if this is the case.
383 */
384static int
385__xprt_get_cong(struct rpc_xprt *xprt, struct rpc_task *task)
386{
387 struct rpc_rqst *req = task->tk_rqstp;
388
389 if (req->rq_cong)
390 return 1;
Chuck Lever46121cf2007-01-31 12:14:08 -0500391 dprintk("RPC: %5u xprt_cwnd_limited cong = %lu cwnd = %lu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 task->tk_pid, xprt->cong, xprt->cwnd);
393 if (RPCXPRT_CONGESTED(xprt))
394 return 0;
395 req->rq_cong = 1;
396 xprt->cong += RPC_CWNDSCALE;
397 return 1;
398}
399
400/*
401 * Adjust the congestion window, and wake up the next task
402 * that has been sleeping due to congestion
403 */
404static void
405__xprt_put_cong(struct rpc_xprt *xprt, struct rpc_rqst *req)
406{
407 if (!req->rq_cong)
408 return;
409 req->rq_cong = 0;
410 xprt->cong -= RPC_CWNDSCALE;
Chuck Lever49e9a892005-08-25 16:25:51 -0700411 __xprt_lock_write_next_cong(xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
Chuck Lever46c0ee82005-08-25 16:25:52 -0700414/**
Chuck Levera58dd392005-08-25 16:25:53 -0700415 * xprt_release_rqst_cong - housekeeping when request is complete
416 * @task: RPC request that recently completed
417 *
418 * Useful for transports that require congestion control.
419 */
420void xprt_release_rqst_cong(struct rpc_task *task)
421{
422 __xprt_put_cong(task->tk_xprt, task->tk_rqstp);
423}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400424EXPORT_SYMBOL_GPL(xprt_release_rqst_cong);
Chuck Levera58dd392005-08-25 16:25:53 -0700425
426/**
Chuck Lever46c0ee82005-08-25 16:25:52 -0700427 * xprt_adjust_cwnd - adjust transport congestion window
428 * @task: recently completed RPC request used to adjust window
429 * @result: result code of completed RPC request
430 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 * We use a time-smoothed congestion estimator to avoid heavy oscillation.
432 */
Chuck Lever46c0ee82005-08-25 16:25:52 -0700433void xprt_adjust_cwnd(struct rpc_task *task, int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434{
Chuck Lever46c0ee82005-08-25 16:25:52 -0700435 struct rpc_rqst *req = task->tk_rqstp;
436 struct rpc_xprt *xprt = task->tk_xprt;
437 unsigned long cwnd = xprt->cwnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 if (result >= 0 && cwnd <= xprt->cong) {
440 /* The (cwnd >> 1) term makes sure
441 * the result gets rounded properly. */
442 cwnd += (RPC_CWNDSCALE * RPC_CWNDSCALE + (cwnd >> 1)) / cwnd;
443 if (cwnd > RPC_MAXCWND(xprt))
444 cwnd = RPC_MAXCWND(xprt);
Chuck Lever49e9a892005-08-25 16:25:51 -0700445 __xprt_lock_write_next_cong(xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 } else if (result == -ETIMEDOUT) {
447 cwnd >>= 1;
448 if (cwnd < RPC_CWNDSCALE)
449 cwnd = RPC_CWNDSCALE;
450 }
Chuck Lever46121cf2007-01-31 12:14:08 -0500451 dprintk("RPC: cong %ld, cwnd was %ld, now %ld\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 xprt->cong, xprt->cwnd, cwnd);
453 xprt->cwnd = cwnd;
Chuck Lever46c0ee82005-08-25 16:25:52 -0700454 __xprt_put_cong(xprt, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400456EXPORT_SYMBOL_GPL(xprt_adjust_cwnd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Chuck Lever44fbac22005-08-11 16:25:44 -0400458/**
459 * xprt_wake_pending_tasks - wake all tasks on a transport's pending queue
460 * @xprt: transport with waiting tasks
461 * @status: result code to plant in each task before waking it
462 *
463 */
464void xprt_wake_pending_tasks(struct rpc_xprt *xprt, int status)
465{
466 if (status < 0)
467 rpc_wake_up_status(&xprt->pending, status);
468 else
469 rpc_wake_up(&xprt->pending);
470}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400471EXPORT_SYMBOL_GPL(xprt_wake_pending_tasks);
Chuck Lever44fbac22005-08-11 16:25:44 -0400472
Chuck Leverc7b2cae2005-08-11 16:25:50 -0400473/**
474 * xprt_wait_for_buffer_space - wait for transport output buffer to clear
475 * @task: task to be put to sleep
Randy Dunlap0b80ae42008-04-26 22:59:02 -0700476 * @action: function pointer to be executed after wait
Chuck Leverc7b2cae2005-08-11 16:25:50 -0400477 */
Trond Myklebustb6ddf642008-04-17 18:52:19 -0400478void xprt_wait_for_buffer_space(struct rpc_task *task, rpc_action action)
Chuck Leverc7b2cae2005-08-11 16:25:50 -0400479{
480 struct rpc_rqst *req = task->tk_rqstp;
481 struct rpc_xprt *xprt = req->rq_xprt;
482
483 task->tk_timeout = req->rq_timeout;
Trond Myklebustb6ddf642008-04-17 18:52:19 -0400484 rpc_sleep_on(&xprt->pending, task, action);
Chuck Leverc7b2cae2005-08-11 16:25:50 -0400485}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400486EXPORT_SYMBOL_GPL(xprt_wait_for_buffer_space);
Chuck Leverc7b2cae2005-08-11 16:25:50 -0400487
488/**
489 * xprt_write_space - wake the task waiting for transport output buffer space
490 * @xprt: transport with waiting tasks
491 *
492 * Can be called in a soft IRQ context, so xprt_write_space never sleeps.
493 */
494void xprt_write_space(struct rpc_xprt *xprt)
495{
496 if (unlikely(xprt->shutdown))
497 return;
498
499 spin_lock_bh(&xprt->transport_lock);
500 if (xprt->snd_task) {
Chuck Lever46121cf2007-01-31 12:14:08 -0500501 dprintk("RPC: write space: waking waiting task on "
502 "xprt %p\n", xprt);
Trond Myklebustfda13932008-02-22 16:34:12 -0500503 rpc_wake_up_queued_task(&xprt->pending, xprt->snd_task);
Chuck Leverc7b2cae2005-08-11 16:25:50 -0400504 }
505 spin_unlock_bh(&xprt->transport_lock);
506}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400507EXPORT_SYMBOL_GPL(xprt_write_space);
Chuck Leverc7b2cae2005-08-11 16:25:50 -0400508
Chuck Leverfe3aca22005-08-25 16:25:50 -0700509/**
510 * xprt_set_retrans_timeout_def - set a request's retransmit timeout
511 * @task: task whose timeout is to be set
512 *
513 * Set a request's retransmit timeout based on the transport's
514 * default timeout parameters. Used by transports that don't adjust
515 * the retransmit timeout based on round-trip time estimation.
516 */
517void xprt_set_retrans_timeout_def(struct rpc_task *task)
518{
519 task->tk_timeout = task->tk_rqstp->rq_timeout;
520}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400521EXPORT_SYMBOL_GPL(xprt_set_retrans_timeout_def);
Chuck Leverfe3aca22005-08-25 16:25:50 -0700522
523/*
524 * xprt_set_retrans_timeout_rtt - set a request's retransmit timeout
525 * @task: task whose timeout is to be set
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800526 *
Chuck Leverfe3aca22005-08-25 16:25:50 -0700527 * Set a request's retransmit timeout using the RTT estimator.
528 */
529void xprt_set_retrans_timeout_rtt(struct rpc_task *task)
530{
531 int timer = task->tk_msg.rpc_proc->p_timer;
Trond Myklebustba7392b2007-12-20 16:03:55 -0500532 struct rpc_clnt *clnt = task->tk_client;
533 struct rpc_rtt *rtt = clnt->cl_rtt;
Chuck Leverfe3aca22005-08-25 16:25:50 -0700534 struct rpc_rqst *req = task->tk_rqstp;
Trond Myklebustba7392b2007-12-20 16:03:55 -0500535 unsigned long max_timeout = clnt->cl_timeout->to_maxval;
Chuck Leverfe3aca22005-08-25 16:25:50 -0700536
537 task->tk_timeout = rpc_calc_rto(rtt, timer);
538 task->tk_timeout <<= rpc_ntimeo(rtt, timer) + req->rq_retries;
539 if (task->tk_timeout > max_timeout || task->tk_timeout == 0)
540 task->tk_timeout = max_timeout;
541}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400542EXPORT_SYMBOL_GPL(xprt_set_retrans_timeout_rtt);
Chuck Leverfe3aca22005-08-25 16:25:50 -0700543
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544static void xprt_reset_majortimeo(struct rpc_rqst *req)
545{
Trond Myklebustba7392b2007-12-20 16:03:55 -0500546 const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 req->rq_majortimeo = req->rq_timeout;
549 if (to->to_exponential)
550 req->rq_majortimeo <<= to->to_retries;
551 else
552 req->rq_majortimeo += to->to_increment * to->to_retries;
553 if (req->rq_majortimeo > to->to_maxval || req->rq_majortimeo == 0)
554 req->rq_majortimeo = to->to_maxval;
555 req->rq_majortimeo += jiffies;
556}
557
Chuck Lever9903cd12005-08-11 16:25:26 -0400558/**
559 * xprt_adjust_timeout - adjust timeout values for next retransmit
560 * @req: RPC request containing parameters to use for the adjustment
561 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 */
563int xprt_adjust_timeout(struct rpc_rqst *req)
564{
565 struct rpc_xprt *xprt = req->rq_xprt;
Trond Myklebustba7392b2007-12-20 16:03:55 -0500566 const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 int status = 0;
568
569 if (time_before(jiffies, req->rq_majortimeo)) {
570 if (to->to_exponential)
571 req->rq_timeout <<= 1;
572 else
573 req->rq_timeout += to->to_increment;
574 if (to->to_maxval && req->rq_timeout >= to->to_maxval)
575 req->rq_timeout = to->to_maxval;
576 req->rq_retries++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 } else {
578 req->rq_timeout = to->to_initval;
579 req->rq_retries = 0;
580 xprt_reset_majortimeo(req);
581 /* Reset the RTT counters == "slow start" */
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400582 spin_lock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 rpc_init_rtt(req->rq_task->tk_client->cl_rtt, to->to_initval);
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400584 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 status = -ETIMEDOUT;
586 }
587
588 if (req->rq_timeout == 0) {
589 printk(KERN_WARNING "xprt_adjust_timeout: rq_timeout = 0!\n");
590 req->rq_timeout = 5 * HZ;
591 }
592 return status;
593}
594
David Howells65f27f32006-11-22 14:55:48 +0000595static void xprt_autoclose(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596{
David Howells65f27f32006-11-22 14:55:48 +0000597 struct rpc_xprt *xprt =
598 container_of(work, struct rpc_xprt, task_cleanup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Chuck Levera246b012005-08-11 16:25:23 -0400600 xprt->ops->close(xprt);
Trond Myklebust66af1e52007-11-06 10:18:36 -0500601 clear_bit(XPRT_CLOSE_WAIT, &xprt->state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 xprt_release_write(xprt, NULL);
603}
604
Chuck Lever9903cd12005-08-11 16:25:26 -0400605/**
Trond Myklebust62da3b22007-11-06 18:44:20 -0500606 * xprt_disconnect_done - mark a transport as disconnected
Chuck Lever9903cd12005-08-11 16:25:26 -0400607 * @xprt: transport to flag for disconnect
608 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 */
Trond Myklebust62da3b22007-11-06 18:44:20 -0500610void xprt_disconnect_done(struct rpc_xprt *xprt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
Chuck Lever46121cf2007-01-31 12:14:08 -0500612 dprintk("RPC: disconnected transport %p\n", xprt);
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400613 spin_lock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 xprt_clear_connected(xprt);
Trond Myklebust2a491992009-03-11 14:38:00 -0400615 xprt_wake_pending_tasks(xprt, -EAGAIN);
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400616 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617}
Trond Myklebust62da3b22007-11-06 18:44:20 -0500618EXPORT_SYMBOL_GPL(xprt_disconnect_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Trond Myklebust66af1e52007-11-06 10:18:36 -0500620/**
621 * xprt_force_disconnect - force a transport to disconnect
622 * @xprt: transport to disconnect
623 *
624 */
625void xprt_force_disconnect(struct rpc_xprt *xprt)
626{
627 /* Don't race with the test_bit() in xprt_clear_locked() */
628 spin_lock_bh(&xprt->transport_lock);
629 set_bit(XPRT_CLOSE_WAIT, &xprt->state);
630 /* Try to schedule an autoclose RPC call */
631 if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
632 queue_work(rpciod_workqueue, &xprt->task_cleanup);
Trond Myklebust2a491992009-03-11 14:38:00 -0400633 xprt_wake_pending_tasks(xprt, -EAGAIN);
Trond Myklebust66af1e52007-11-06 10:18:36 -0500634 spin_unlock_bh(&xprt->transport_lock);
635}
Trond Myklebust66af1e52007-11-06 10:18:36 -0500636
Trond Myklebust7c1d71c2008-04-17 16:52:57 -0400637/**
638 * xprt_conditional_disconnect - force a transport to disconnect
639 * @xprt: transport to disconnect
640 * @cookie: 'connection cookie'
641 *
642 * This attempts to break the connection if and only if 'cookie' matches
643 * the current transport 'connection cookie'. It ensures that we don't
644 * try to break the connection more than once when we need to retransmit
645 * a batch of RPC requests.
646 *
647 */
648void xprt_conditional_disconnect(struct rpc_xprt *xprt, unsigned int cookie)
649{
650 /* Don't race with the test_bit() in xprt_clear_locked() */
651 spin_lock_bh(&xprt->transport_lock);
652 if (cookie != xprt->connect_cookie)
653 goto out;
654 if (test_bit(XPRT_CLOSING, &xprt->state) || !xprt_connected(xprt))
655 goto out;
656 set_bit(XPRT_CLOSE_WAIT, &xprt->state);
657 /* Try to schedule an autoclose RPC call */
658 if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
659 queue_work(rpciod_workqueue, &xprt->task_cleanup);
Trond Myklebust2a491992009-03-11 14:38:00 -0400660 xprt_wake_pending_tasks(xprt, -EAGAIN);
Trond Myklebust7c1d71c2008-04-17 16:52:57 -0400661out:
662 spin_unlock_bh(&xprt->transport_lock);
663}
664
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665static void
666xprt_init_autodisconnect(unsigned long data)
667{
668 struct rpc_xprt *xprt = (struct rpc_xprt *)data;
669
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400670 spin_lock(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 if (!list_empty(&xprt->recv) || xprt->shutdown)
672 goto out_abort;
Chuck Lever2226feb2005-08-11 16:25:38 -0400673 if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 goto out_abort;
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400675 spin_unlock(&xprt->transport_lock);
Trond Myklebustf75e6742009-04-21 17:18:20 -0400676 set_bit(XPRT_CONNECTION_CLOSE, &xprt->state);
677 queue_work(rpciod_workqueue, &xprt->task_cleanup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 return;
679out_abort:
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400680 spin_unlock(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
Chuck Lever9903cd12005-08-11 16:25:26 -0400683/**
684 * xprt_connect - schedule a transport connect operation
685 * @task: RPC task that is requesting the connect
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 *
687 */
688void xprt_connect(struct rpc_task *task)
689{
690 struct rpc_xprt *xprt = task->tk_xprt;
691
Chuck Lever46121cf2007-01-31 12:14:08 -0500692 dprintk("RPC: %5u xprt_connect xprt %p %s connected\n", task->tk_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 xprt, (xprt_connected(xprt) ? "is" : "is not"));
694
Chuck Leverec739ef2006-08-22 20:06:15 -0400695 if (!xprt_bound(xprt)) {
Trond Myklebust01d37c42009-03-11 14:09:39 -0400696 task->tk_status = -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 return;
698 }
699 if (!xprt_lock_write(xprt, task))
700 return;
Trond Myklebustfeb8ca32009-12-03 08:10:17 -0500701
702 if (test_and_clear_bit(XPRT_CLOSE_WAIT, &xprt->state))
703 xprt->ops->close(xprt);
704
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 if (xprt_connected(xprt))
Chuck Levera246b012005-08-11 16:25:23 -0400706 xprt_release_write(xprt, task);
707 else {
708 if (task->tk_rqstp)
709 task->tk_rqstp->rq_bytes_sent = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Trond Myklebusta8ce4a82010-04-16 16:42:12 -0400711 task->tk_timeout = task->tk_rqstp->rq_timeout;
Trond Myklebust5d008372008-02-22 16:34:17 -0500712 rpc_sleep_on(&xprt->pending, task, xprt_connect_status);
Trond Myklebust0b9e7942010-04-16 16:41:57 -0400713
714 if (test_bit(XPRT_CLOSING, &xprt->state))
715 return;
716 if (xprt_test_and_set_connecting(xprt))
717 return;
Chuck Lever262ca072006-03-20 13:44:16 -0500718 xprt->stat.connect_start = jiffies;
Chuck Levera246b012005-08-11 16:25:23 -0400719 xprt->ops->connect(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721}
722
Chuck Lever9903cd12005-08-11 16:25:26 -0400723static void xprt_connect_status(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724{
725 struct rpc_xprt *xprt = task->tk_xprt;
726
Chuck Levercd983ef2008-06-11 17:56:13 -0400727 if (task->tk_status == 0) {
Chuck Lever262ca072006-03-20 13:44:16 -0500728 xprt->stat.connect_count++;
729 xprt->stat.connect_time += (long)jiffies - xprt->stat.connect_start;
Chuck Lever46121cf2007-01-31 12:14:08 -0500730 dprintk("RPC: %5u xprt_connect_status: connection established\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 task->tk_pid);
732 return;
733 }
734
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 switch (task->tk_status) {
Trond Myklebust2a491992009-03-11 14:38:00 -0400736 case -EAGAIN:
737 dprintk("RPC: %5u xprt_connect_status: retrying\n", task->tk_pid);
Chuck Lever23475d62005-08-11 16:25:08 -0400738 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 case -ETIMEDOUT:
Chuck Lever46121cf2007-01-31 12:14:08 -0500740 dprintk("RPC: %5u xprt_connect_status: connect attempt timed "
741 "out\n", task->tk_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 break;
743 default:
Chuck Lever46121cf2007-01-31 12:14:08 -0500744 dprintk("RPC: %5u xprt_connect_status: error %d connecting to "
745 "server %s\n", task->tk_pid, -task->tk_status,
746 task->tk_client->cl_server);
Chuck Lever23475d62005-08-11 16:25:08 -0400747 xprt_release_write(xprt, task);
748 task->tk_status = -EIO;
Chuck Lever23475d62005-08-11 16:25:08 -0400749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750}
751
Chuck Lever9903cd12005-08-11 16:25:26 -0400752/**
753 * xprt_lookup_rqst - find an RPC request corresponding to an XID
754 * @xprt: transport on which the original request was transmitted
755 * @xid: RPC XID of incoming reply
756 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 */
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700758struct rpc_rqst *xprt_lookup_rqst(struct rpc_xprt *xprt, __be32 xid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759{
760 struct list_head *pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 list_for_each(pos, &xprt->recv) {
763 struct rpc_rqst *entry = list_entry(pos, struct rpc_rqst, rq_list);
Chuck Lever262ca072006-03-20 13:44:16 -0500764 if (entry->rq_xid == xid)
765 return entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 }
Chuck Lever46121cf2007-01-31 12:14:08 -0500767
768 dprintk("RPC: xprt_lookup_rqst did not find xid %08x\n",
769 ntohl(xid));
Chuck Lever262ca072006-03-20 13:44:16 -0500770 xprt->stat.bad_xids++;
771 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400773EXPORT_SYMBOL_GPL(xprt_lookup_rqst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Chuck Leverbbc72ce2010-05-07 13:34:27 -0400775static void xprt_update_rtt(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776{
Chuck Lever1570c1e2005-08-25 16:25:52 -0700777 struct rpc_rqst *req = task->tk_rqstp;
778 struct rpc_rtt *rtt = task->tk_client->cl_rtt;
779 unsigned timer = task->tk_msg.rpc_proc->p_timer;
Trond Myklebustd60dbb22010-05-13 12:51:49 -0400780 long m = usecs_to_jiffies(ktime_to_us(req->rq_rtt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Chuck Lever1570c1e2005-08-25 16:25:52 -0700782 if (timer) {
783 if (req->rq_ntrans == 1)
Chuck Leverff839972010-05-07 13:34:47 -0400784 rpc_update_rtt(rtt, timer, m);
Chuck Lever1570c1e2005-08-25 16:25:52 -0700785 rpc_set_timeo(rtt, timer, req->rq_ntrans - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 }
Chuck Lever1570c1e2005-08-25 16:25:52 -0700787}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
Chuck Lever1570c1e2005-08-25 16:25:52 -0700789/**
790 * xprt_complete_rqst - called when reply processing is complete
791 * @task: RPC request that recently completed
792 * @copied: actual number of bytes received from the transport
793 *
794 * Caller holds transport lock.
795 */
796void xprt_complete_rqst(struct rpc_task *task, int copied)
797{
798 struct rpc_rqst *req = task->tk_rqstp;
Trond Myklebustfda13932008-02-22 16:34:12 -0500799 struct rpc_xprt *xprt = req->rq_xprt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Chuck Lever1570c1e2005-08-25 16:25:52 -0700801 dprintk("RPC: %5u xid %08x complete (%d bytes received)\n",
802 task->tk_pid, ntohl(req->rq_xid), copied);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Trond Myklebustfda13932008-02-22 16:34:12 -0500804 xprt->stat.recvs++;
Trond Myklebustd60dbb22010-05-13 12:51:49 -0400805 req->rq_rtt = ktime_sub(ktime_get(), req->rq_xtime);
Chuck Leverbbc72ce2010-05-07 13:34:27 -0400806 if (xprt->ops->timer != NULL)
807 xprt_update_rtt(task);
Chuck Leveref759a22006-03-20 13:44:17 -0500808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 list_del_init(&req->rq_list);
Trond Myklebust1e799b62008-03-21 16:19:41 -0400810 req->rq_private_buf.len = copied;
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -0400811 /* Ensure all writes are done before we update */
812 /* req->rq_reply_bytes_recvd */
Trond Myklebust43ac3f22006-03-20 13:44:51 -0500813 smp_wmb();
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -0400814 req->rq_reply_bytes_recvd = copied;
Trond Myklebustfda13932008-02-22 16:34:12 -0500815 rpc_wake_up_queued_task(&xprt->pending, task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400817EXPORT_SYMBOL_GPL(xprt_complete_rqst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Chuck Lever46c0ee82005-08-25 16:25:52 -0700819static void xprt_timer(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
Chuck Lever46c0ee82005-08-25 16:25:52 -0700821 struct rpc_rqst *req = task->tk_rqstp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 struct rpc_xprt *xprt = req->rq_xprt;
823
Trond Myklebust5d008372008-02-22 16:34:17 -0500824 if (task->tk_status != -ETIMEDOUT)
825 return;
Chuck Lever46121cf2007-01-31 12:14:08 -0500826 dprintk("RPC: %5u xprt_timer\n", task->tk_pid);
Chuck Lever46c0ee82005-08-25 16:25:52 -0700827
Trond Myklebust5d008372008-02-22 16:34:17 -0500828 spin_lock_bh(&xprt->transport_lock);
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -0400829 if (!req->rq_reply_bytes_recvd) {
Chuck Lever46c0ee82005-08-25 16:25:52 -0700830 if (xprt->ops->timer)
831 xprt->ops->timer(task);
Trond Myklebust5d008372008-02-22 16:34:17 -0500832 } else
833 task->tk_status = 0;
834 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835}
836
Rahul Iyer4cfc7e62009-09-10 17:32:28 +0300837static inline int xprt_has_timer(struct rpc_xprt *xprt)
838{
839 return xprt->idle_timeout != 0;
840}
841
Chuck Lever9903cd12005-08-11 16:25:26 -0400842/**
843 * xprt_prepare_transmit - reserve the transport before sending a request
844 * @task: RPC task about to send a request
845 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 */
Chuck Lever9903cd12005-08-11 16:25:26 -0400847int xprt_prepare_transmit(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848{
849 struct rpc_rqst *req = task->tk_rqstp;
850 struct rpc_xprt *xprt = req->rq_xprt;
851 int err = 0;
852
Chuck Lever46121cf2007-01-31 12:14:08 -0500853 dprintk("RPC: %5u xprt_prepare_transmit\n", task->tk_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400855 spin_lock_bh(&xprt->transport_lock);
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -0400856 if (req->rq_reply_bytes_recvd && !req->rq_bytes_sent) {
857 err = req->rq_reply_bytes_recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 goto out_unlock;
859 }
Trond Myklebust2a491992009-03-11 14:38:00 -0400860 if (!xprt->ops->reserve_xprt(task))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 err = -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862out_unlock:
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400863 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 return err;
865}
866
Trond Myklebuste0ab53d2006-07-27 17:22:50 -0400867void xprt_end_transmit(struct rpc_task *task)
Trond Myklebust5e5ce5b2005-10-18 14:20:11 -0700868{
Rahul Iyer343952f2009-04-01 09:23:17 -0400869 xprt_release_write(task->tk_rqstp->rq_xprt, task);
Trond Myklebust5e5ce5b2005-10-18 14:20:11 -0700870}
871
Chuck Lever9903cd12005-08-11 16:25:26 -0400872/**
873 * xprt_transmit - send an RPC request on a transport
874 * @task: controlling RPC task
875 *
876 * We have to copy the iovec because sendmsg fiddles with its contents.
877 */
878void xprt_transmit(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 struct rpc_rqst *req = task->tk_rqstp;
881 struct rpc_xprt *xprt = req->rq_xprt;
Chuck Levera246b012005-08-11 16:25:23 -0400882 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
Chuck Lever46121cf2007-01-31 12:14:08 -0500884 dprintk("RPC: %5u xprt_transmit(%u)\n", task->tk_pid, req->rq_slen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -0400886 if (!req->rq_reply_bytes_recvd) {
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400887 if (list_empty(&req->rq_list) && rpc_reply_expected(task)) {
888 /*
889 * Add to the list only if we're expecting a reply
890 */
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400891 spin_lock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 /* Update the softirq receive buffer */
893 memcpy(&req->rq_private_buf, &req->rq_rcv_buf,
894 sizeof(req->rq_private_buf));
895 /* Add request to the receive list */
896 list_add_tail(&req->rq_list, &xprt->recv);
Chuck Lever4a0f8c02005-08-11 16:25:32 -0400897 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 xprt_reset_majortimeo(req);
Trond Myklebust0f9dc2b2005-06-22 17:16:28 +0000899 /* Turn off autodisconnect */
900 del_singleshot_timer_sync(&xprt->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 }
902 } else if (!req->rq_bytes_sent)
903 return;
904
Trond Myklebust7c1d71c2008-04-17 16:52:57 -0400905 req->rq_connect_cookie = xprt->connect_cookie;
Chuck Leverff839972010-05-07 13:34:47 -0400906 req->rq_xtime = ktime_get();
Chuck Levera246b012005-08-11 16:25:23 -0400907 status = xprt->ops->send_request(task);
Trond Myklebustc8485e42009-03-11 14:37:59 -0400908 if (status != 0) {
909 task->tk_status = status;
Chuck Leverfe3aca22005-08-25 16:25:50 -0700910 return;
911 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Trond Myklebustc8485e42009-03-11 14:37:59 -0400913 dprintk("RPC: %5u xmit complete\n", task->tk_pid);
914 spin_lock_bh(&xprt->transport_lock);
915
916 xprt->ops->set_retrans_timeout(task);
917
918 xprt->stat.sends++;
919 xprt->stat.req_u += xprt->stat.sends - xprt->stat.recvs;
920 xprt->stat.bklog_u += xprt->backlog.qlen;
921
922 /* Don't race with disconnect */
923 if (!xprt_connected(xprt))
924 task->tk_status = -ENOTCONN;
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -0400925 else if (!req->rq_reply_bytes_recvd && rpc_reply_expected(task)) {
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400926 /*
927 * Sleep on the pending queue since
928 * we're expecting a reply.
929 */
Trond Myklebustc8485e42009-03-11 14:37:59 -0400930 rpc_sleep_on(&xprt->pending, task, xprt_timer);
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400931 }
Trond Myklebustc8485e42009-03-11 14:37:59 -0400932 spin_unlock_bh(&xprt->transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933}
934
Trond Myklebustee5ebe82010-04-16 16:37:01 -0400935static void xprt_alloc_slot(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936{
937 struct rpc_xprt *xprt = task->tk_xprt;
938
939 task->tk_status = 0;
940 if (task->tk_rqstp)
941 return;
942 if (!list_empty(&xprt->free)) {
943 struct rpc_rqst *req = list_entry(xprt->free.next, struct rpc_rqst, rq_list);
944 list_del_init(&req->rq_list);
945 task->tk_rqstp = req;
946 xprt_request_init(task, xprt);
947 return;
948 }
Chuck Lever46121cf2007-01-31 12:14:08 -0500949 dprintk("RPC: waiting for request slot\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 task->tk_status = -EAGAIN;
951 task->tk_timeout = 0;
Trond Myklebust5d008372008-02-22 16:34:17 -0500952 rpc_sleep_on(&xprt->backlog, task, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953}
954
Trond Myklebustee5ebe82010-04-16 16:37:01 -0400955static void xprt_free_slot(struct rpc_xprt *xprt, struct rpc_rqst *req)
956{
957 memset(req, 0, sizeof(*req)); /* mark unused */
958
959 spin_lock(&xprt->reserve_lock);
960 list_add(&req->rq_list, &xprt->free);
961 rpc_wake_up_next(&xprt->backlog);
962 spin_unlock(&xprt->reserve_lock);
963}
964
Pavel Emelyanov37aa2132010-09-29 16:05:43 +0400965struct rpc_xprt *xprt_alloc(struct net *net, int size, int max_req)
Pavel Emelyanovbd1722d2010-09-29 16:02:43 +0400966{
967 struct rpc_xprt *xprt;
968
969 xprt = kzalloc(size, GFP_KERNEL);
970 if (xprt == NULL)
971 goto out;
972
973 xprt->max_reqs = max_req;
974 xprt->slot = kcalloc(max_req, sizeof(struct rpc_rqst), GFP_KERNEL);
975 if (xprt->slot == NULL)
976 goto out_free;
977
Pavel Emelyanov37aa2132010-09-29 16:05:43 +0400978 xprt->xprt_net = get_net(net);
Pavel Emelyanovbd1722d2010-09-29 16:02:43 +0400979 return xprt;
980
981out_free:
982 kfree(xprt);
983out:
984 return NULL;
985}
986EXPORT_SYMBOL_GPL(xprt_alloc);
987
Pavel Emelyanove204e622010-09-29 16:03:13 +0400988void xprt_free(struct rpc_xprt *xprt)
989{
Pavel Emelyanov37aa2132010-09-29 16:05:43 +0400990 put_net(xprt->xprt_net);
Pavel Emelyanove204e622010-09-29 16:03:13 +0400991 kfree(xprt->slot);
992 kfree(xprt);
993}
994EXPORT_SYMBOL_GPL(xprt_free);
995
Chuck Lever9903cd12005-08-11 16:25:26 -0400996/**
997 * xprt_reserve - allocate an RPC request slot
998 * @task: RPC task requesting a slot allocation
999 *
1000 * If no more slots are available, place the task on the transport's
1001 * backlog queue.
1002 */
1003void xprt_reserve(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004{
1005 struct rpc_xprt *xprt = task->tk_xprt;
1006
1007 task->tk_status = -EIO;
Trond Myklebust0065db32006-01-03 09:55:56 +01001008 spin_lock(&xprt->reserve_lock);
Trond Myklebustee5ebe82010-04-16 16:37:01 -04001009 xprt_alloc_slot(task);
Trond Myklebust0065db32006-01-03 09:55:56 +01001010 spin_unlock(&xprt->reserve_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011}
1012
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001013static inline __be32 xprt_alloc_xid(struct rpc_xprt *xprt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014{
Eric Dumazet0eae88f2010-04-20 19:06:52 -07001015 return (__force __be32)xprt->xid++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016}
1017
1018static inline void xprt_init_xid(struct rpc_xprt *xprt)
1019{
Chuck Leverbf3fcf82006-05-25 01:40:51 -04001020 xprt->xid = net_random();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021}
1022
Chuck Lever9903cd12005-08-11 16:25:26 -04001023static void xprt_request_init(struct rpc_task *task, struct rpc_xprt *xprt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024{
1025 struct rpc_rqst *req = task->tk_rqstp;
1026
Trond Myklebustba7392b2007-12-20 16:03:55 -05001027 req->rq_timeout = task->tk_client->cl_timeout->to_initval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 req->rq_task = task;
1029 req->rq_xprt = xprt;
Chuck Lever02107142006-01-03 09:55:49 +01001030 req->rq_buffer = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 req->rq_xid = xprt_alloc_xid(xprt);
J. Bruce Fieldsead5e1c2005-10-13 16:54:43 -04001032 req->rq_release_snd_buf = NULL;
Trond Myklebustda458282006-08-31 15:44:52 -04001033 xprt_reset_majortimeo(req);
Chuck Lever46121cf2007-01-31 12:14:08 -05001034 dprintk("RPC: %5u reserved req %p xid %08x\n", task->tk_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 req, ntohl(req->rq_xid));
1036}
1037
Chuck Lever9903cd12005-08-11 16:25:26 -04001038/**
1039 * xprt_release - release an RPC request slot
1040 * @task: task which is finished with the slot
1041 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 */
Chuck Lever9903cd12005-08-11 16:25:26 -04001043void xprt_release(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044{
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001045 struct rpc_xprt *xprt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 struct rpc_rqst *req;
1047
1048 if (!(req = task->tk_rqstp))
1049 return;
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001050
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001051 xprt = req->rq_xprt;
Chuck Lever11c556b2006-03-20 13:44:22 -05001052 rpc_count_iostats(task);
Chuck Lever4a0f8c02005-08-11 16:25:32 -04001053 spin_lock_bh(&xprt->transport_lock);
Chuck Lever49e9a892005-08-25 16:25:51 -07001054 xprt->ops->release_xprt(xprt, task);
Chuck Levera58dd392005-08-25 16:25:53 -07001055 if (xprt->ops->release_request)
1056 xprt->ops->release_request(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 if (!list_empty(&req->rq_list))
1058 list_del(&req->rq_list);
1059 xprt->last_used = jiffies;
Rahul Iyer4cfc7e62009-09-10 17:32:28 +03001060 if (list_empty(&xprt->recv) && xprt_has_timer(xprt))
Chuck Levera246b012005-08-11 16:25:23 -04001061 mod_timer(&xprt->timer,
Chuck Lever03bf4b72005-08-25 16:25:55 -07001062 xprt->last_used + xprt->idle_timeout);
Chuck Lever4a0f8c02005-08-11 16:25:32 -04001063 spin_unlock_bh(&xprt->transport_lock);
Trond Myklebustee5ebe82010-04-16 16:37:01 -04001064 if (req->rq_buffer)
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001065 xprt->ops->buf_free(req->rq_buffer);
Trond Myklebusta17c2152010-07-31 14:29:08 -04001066 if (req->rq_cred != NULL)
1067 put_rpccred(req->rq_cred);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 task->tk_rqstp = NULL;
J. Bruce Fieldsead5e1c2005-10-13 16:54:43 -04001069 if (req->rq_release_snd_buf)
1070 req->rq_release_snd_buf(req);
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001071
Chuck Lever46121cf2007-01-31 12:14:08 -05001072 dprintk("RPC: %5u release request %p\n", task->tk_pid, req);
Trond Myklebustee5ebe82010-04-16 16:37:01 -04001073 if (likely(!bc_prealloc(req)))
1074 xprt_free_slot(xprt, req);
1075 else
Trond Myklebustc9acb422010-03-19 15:36:22 -04001076 xprt_free_bc_request(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077}
1078
Chuck Lever9903cd12005-08-11 16:25:26 -04001079/**
Chuck Leverc2866762006-08-22 20:06:20 -04001080 * xprt_create_transport - create an RPC transport
Frank van Maarseveen96802a02007-07-08 13:08:54 +02001081 * @args: rpc transport creation arguments
Chuck Leverc2866762006-08-22 20:06:20 -04001082 *
1083 */
\"Talpey, Thomas\3c341b0b2007-09-10 13:47:07 -04001084struct rpc_xprt *xprt_create_transport(struct xprt_create *args)
Chuck Leverc2866762006-08-22 20:06:20 -04001085{
Chuck Leverc2866762006-08-22 20:06:20 -04001086 struct rpc_xprt *xprt;
1087 struct rpc_rqst *req;
\"Talpey, Thomas\bc255712007-09-10 13:46:39 -04001088 struct xprt_class *t;
Chuck Leverc2866762006-08-22 20:06:20 -04001089
\"Talpey, Thomas\bc255712007-09-10 13:46:39 -04001090 spin_lock(&xprt_list_lock);
1091 list_for_each_entry(t, &xprt_list, list) {
\"Talpey, Thomas\4fa016e2007-09-10 13:47:57 -04001092 if (t->ident == args->ident) {
\"Talpey, Thomas\bc255712007-09-10 13:46:39 -04001093 spin_unlock(&xprt_list_lock);
1094 goto found;
1095 }
Chuck Leverc2866762006-08-22 20:06:20 -04001096 }
\"Talpey, Thomas\bc255712007-09-10 13:46:39 -04001097 spin_unlock(&xprt_list_lock);
\"Talpey, Thomas\4fa016e2007-09-10 13:47:57 -04001098 printk(KERN_ERR "RPC: transport (%d) not supported\n", args->ident);
\"Talpey, Thomas\bc255712007-09-10 13:46:39 -04001099 return ERR_PTR(-EIO);
1100
1101found:
1102 xprt = t->setup(args);
Chuck Leverc8541ec2006-10-17 14:44:27 -04001103 if (IS_ERR(xprt)) {
Chuck Lever46121cf2007-01-31 12:14:08 -05001104 dprintk("RPC: xprt_create_transport: failed, %ld\n",
Chuck Leverc8541ec2006-10-17 14:44:27 -04001105 -PTR_ERR(xprt));
1106 return xprt;
Chuck Leverc2866762006-08-22 20:06:20 -04001107 }
1108
Trond Myklebust6b6ca862006-09-05 12:55:57 -04001109 kref_init(&xprt->kref);
Chuck Leverc2866762006-08-22 20:06:20 -04001110 spin_lock_init(&xprt->transport_lock);
1111 spin_lock_init(&xprt->reserve_lock);
1112
1113 INIT_LIST_HEAD(&xprt->free);
1114 INIT_LIST_HEAD(&xprt->recv);
Ricardo Labiagaf9acac12009-04-01 09:22:59 -04001115#if defined(CONFIG_NFS_V4_1)
1116 spin_lock_init(&xprt->bc_pa_lock);
1117 INIT_LIST_HEAD(&xprt->bc_pa_list);
1118#endif /* CONFIG_NFS_V4_1 */
1119
David Howells65f27f32006-11-22 14:55:48 +00001120 INIT_WORK(&xprt->task_cleanup, xprt_autoclose);
Rahul Iyer4cfc7e62009-09-10 17:32:28 +03001121 if (xprt_has_timer(xprt))
1122 setup_timer(&xprt->timer, xprt_init_autodisconnect,
1123 (unsigned long)xprt);
1124 else
1125 init_timer(&xprt->timer);
Chuck Leverc2866762006-08-22 20:06:20 -04001126 xprt->last_used = jiffies;
1127 xprt->cwnd = RPC_INITCWND;
Chuck Levera5090502007-03-29 16:48:04 -04001128 xprt->bind_index = 0;
Chuck Leverc2866762006-08-22 20:06:20 -04001129
1130 rpc_init_wait_queue(&xprt->binding, "xprt_binding");
1131 rpc_init_wait_queue(&xprt->pending, "xprt_pending");
1132 rpc_init_wait_queue(&xprt->sending, "xprt_sending");
1133 rpc_init_wait_queue(&xprt->resend, "xprt_resend");
1134 rpc_init_priority_wait_queue(&xprt->backlog, "xprt_backlog");
1135
1136 /* initialize free list */
1137 for (req = &xprt->slot[xprt->max_reqs-1]; req >= &xprt->slot[0]; req--)
1138 list_add(&req->rq_list, &xprt->free);
1139
1140 xprt_init_xid(xprt);
1141
Chuck Lever46121cf2007-01-31 12:14:08 -05001142 dprintk("RPC: created transport %p with %u slots\n", xprt,
Chuck Leverc2866762006-08-22 20:06:20 -04001143 xprt->max_reqs);
Chuck Leverc2866762006-08-22 20:06:20 -04001144 return xprt;
1145}
1146
Chuck Lever9903cd12005-08-11 16:25:26 -04001147/**
1148 * xprt_destroy - destroy an RPC transport, killing off all requests.
Trond Myklebust6b6ca862006-09-05 12:55:57 -04001149 * @kref: kref for the transport to destroy
Chuck Lever9903cd12005-08-11 16:25:26 -04001150 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 */
Trond Myklebust6b6ca862006-09-05 12:55:57 -04001152static void xprt_destroy(struct kref *kref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153{
Trond Myklebust6b6ca862006-09-05 12:55:57 -04001154 struct rpc_xprt *xprt = container_of(kref, struct rpc_xprt, kref);
1155
Chuck Lever46121cf2007-01-31 12:14:08 -05001156 dprintk("RPC: destroying transport %p\n", xprt);
Trond Myklebust0065db32006-01-03 09:55:56 +01001157 xprt->shutdown = 1;
1158 del_timer_sync(&xprt->timer);
Chuck Leverc8541ec2006-10-17 14:44:27 -04001159
Trond Myklebustf6a1cc82008-02-22 17:06:55 -05001160 rpc_destroy_wait_queue(&xprt->binding);
1161 rpc_destroy_wait_queue(&xprt->pending);
1162 rpc_destroy_wait_queue(&xprt->sending);
1163 rpc_destroy_wait_queue(&xprt->resend);
1164 rpc_destroy_wait_queue(&xprt->backlog);
J. Bruce Fieldsc3ae62ae2010-08-03 17:22:20 -04001165 cancel_work_sync(&xprt->task_cleanup);
Chuck Leverc8541ec2006-10-17 14:44:27 -04001166 /*
1167 * Tear down transport state and free the rpc_xprt
1168 */
Chuck Levera246b012005-08-11 16:25:23 -04001169 xprt->ops->destroy(xprt);
Trond Myklebust6b6ca862006-09-05 12:55:57 -04001170}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Trond Myklebust6b6ca862006-09-05 12:55:57 -04001172/**
1173 * xprt_put - release a reference to an RPC transport.
1174 * @xprt: pointer to the transport
1175 *
1176 */
1177void xprt_put(struct rpc_xprt *xprt)
1178{
1179 kref_put(&xprt->kref, xprt_destroy);
1180}
1181
1182/**
1183 * xprt_get - return a reference to an RPC transport.
1184 * @xprt: pointer to the transport
1185 *
1186 */
1187struct rpc_xprt *xprt_get(struct rpc_xprt *xprt)
1188{
1189 kref_get(&xprt->kref);
1190 return xprt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191}