Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/net/sunrpc/xprt.c |
| 3 | * |
| 4 | * This is a generic RPC call interface supporting congestion avoidance, |
| 5 | * and asynchronous calls. |
| 6 | * |
| 7 | * The interface works like this: |
| 8 | * |
| 9 | * - When a process places a call, it allocates a request slot if |
| 10 | * one is available. Otherwise, it sleeps on the backlog queue |
| 11 | * (xprt_reserve). |
| 12 | * - Next, the caller puts together the RPC message, stuffs it into |
Chuck Lever | 55aa4f5 | 2005-08-11 16:25:47 -0400 | [diff] [blame] | 13 | * the request struct, and calls xprt_transmit(). |
| 14 | * - xprt_transmit sends the message and installs the caller on the |
| 15 | * transport's wait list. At the same time, it installs a timer that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * is run after the packet's timeout has expired. |
| 17 | * - When a packet arrives, the data_ready handler walks the list of |
Chuck Lever | 55aa4f5 | 2005-08-11 16:25:47 -0400 | [diff] [blame] | 18 | * pending requests for that transport. If a matching XID is found, the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * caller is woken up, and the timer removed. |
| 20 | * - When no reply arrives within the timeout interval, the timer is |
| 21 | * fired by the kernel and runs xprt_timer(). It either adjusts the |
| 22 | * timeout values (minor timeout) or wakes up the caller with a status |
| 23 | * of -ETIMEDOUT. |
| 24 | * - When the caller receives a notification from RPC that a reply arrived, |
| 25 | * it should release the RPC slot, and process the reply. |
| 26 | * If the call timed out, it may choose to retry the operation by |
| 27 | * adjusting the initial timeout value, and simply calling rpc_call |
| 28 | * again. |
| 29 | * |
| 30 | * Support for async RPC is done through a set of RPC-specific scheduling |
| 31 | * primitives that `transparently' work for processes as well as async |
| 32 | * tasks that rely on callbacks. |
| 33 | * |
| 34 | * Copyright (C) 1995-1997, Olaf Kirch <okir@monad.swb.de> |
Chuck Lever | 55aa4f5 | 2005-08-11 16:25:47 -0400 | [diff] [blame] | 35 | * |
| 36 | * Transport switch API copyright (C) 2005, Chuck Lever <cel@netapp.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | */ |
| 38 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 39 | #include <linux/module.h> |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/types.h> |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 42 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/workqueue.h> |
Chuck Lever | bf3fcf8 | 2006-05-25 01:40:51 -0400 | [diff] [blame] | 44 | #include <linux/net.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 46 | #include <linux/sunrpc/clnt.h> |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 47 | #include <linux/sunrpc/metrics.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * Local variables |
| 51 | */ |
| 52 | |
| 53 | #ifdef RPC_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | # define RPCDBG_FACILITY RPCDBG_XPRT |
| 55 | #endif |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | /* |
| 58 | * Local functions |
| 59 | */ |
| 60 | static void xprt_request_init(struct rpc_task *, struct rpc_xprt *); |
| 61 | static inline void do_xprt_reserve(struct rpc_task *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | static void xprt_connect_status(struct rpc_task *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | static int __xprt_get_cong(struct rpc_xprt *, struct rpc_task *); |
| 64 | |
Chuck Lever | 555ee3a | 2005-08-25 16:25:54 -0700 | [diff] [blame] | 65 | /* |
| 66 | * The transport code maintains an estimate on the maximum number of out- |
| 67 | * standing RPC requests, using a smoothed version of the congestion |
| 68 | * avoidance implemented in 44BSD. This is basically the Van Jacobson |
| 69 | * congestion algorithm: If a retransmit occurs, the congestion window is |
| 70 | * halved; otherwise, it is incremented by 1/cwnd when |
| 71 | * |
| 72 | * - a reply is received and |
| 73 | * - a full number of requests are outstanding and |
| 74 | * - the congestion window hasn't been updated recently. |
| 75 | */ |
| 76 | #define RPC_CWNDSHIFT (8U) |
| 77 | #define RPC_CWNDSCALE (1U << RPC_CWNDSHIFT) |
| 78 | #define RPC_INITCWND RPC_CWNDSCALE |
| 79 | #define RPC_MAXCWND(xprt) ((xprt)->max_reqs << RPC_CWNDSHIFT) |
| 80 | |
| 81 | #define RPCXPRT_CONGESTED(xprt) ((xprt)->cong >= (xprt)->cwnd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 83 | /** |
| 84 | * xprt_reserve_xprt - serialize write access to transports |
| 85 | * @task: task that is requesting access to the transport |
| 86 | * |
| 87 | * This prevents mixing the payload of separate requests, and prevents |
| 88 | * transport connects from colliding with writes. No congestion control |
| 89 | * is provided. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | */ |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 91 | int xprt_reserve_xprt(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 93 | struct rpc_xprt *xprt = task->tk_xprt; |
| 94 | struct rpc_rqst *req = task->tk_rqstp; |
| 95 | |
| 96 | if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) { |
| 97 | if (task == xprt->snd_task) |
| 98 | return 1; |
| 99 | if (task == NULL) |
| 100 | return 0; |
| 101 | goto out_sleep; |
| 102 | } |
| 103 | xprt->snd_task = task; |
| 104 | if (req) { |
| 105 | req->rq_bytes_sent = 0; |
| 106 | req->rq_ntrans++; |
| 107 | } |
| 108 | return 1; |
| 109 | |
| 110 | out_sleep: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 111 | dprintk("RPC: %5u failed to lock transport %p\n", |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 112 | task->tk_pid, xprt); |
| 113 | task->tk_timeout = 0; |
| 114 | task->tk_status = -EAGAIN; |
| 115 | if (req && req->rq_ntrans) |
| 116 | rpc_sleep_on(&xprt->resend, task, NULL, NULL); |
| 117 | else |
| 118 | rpc_sleep_on(&xprt->sending, task, NULL, NULL); |
| 119 | return 0; |
| 120 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame^] | 121 | EXPORT_SYMBOL_GPL(xprt_reserve_xprt); |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 122 | |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 123 | static void xprt_clear_locked(struct rpc_xprt *xprt) |
| 124 | { |
| 125 | xprt->snd_task = NULL; |
| 126 | if (!test_bit(XPRT_CLOSE_WAIT, &xprt->state) || xprt->shutdown) { |
| 127 | smp_mb__before_clear_bit(); |
| 128 | clear_bit(XPRT_LOCKED, &xprt->state); |
| 129 | smp_mb__after_clear_bit(); |
| 130 | } else |
Trond Myklebust | c1384c9 | 2007-06-14 18:00:42 -0400 | [diff] [blame] | 131 | queue_work(rpciod_workqueue, &xprt->task_cleanup); |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 132 | } |
| 133 | |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 134 | /* |
| 135 | * xprt_reserve_xprt_cong - serialize write access to transports |
| 136 | * @task: task that is requesting access to the transport |
| 137 | * |
| 138 | * Same as xprt_reserve_xprt, but Van Jacobson congestion control is |
| 139 | * integrated into the decision of whether a request is allowed to be |
| 140 | * woken up and given access to the transport. |
| 141 | */ |
| 142 | int xprt_reserve_xprt_cong(struct rpc_task *task) |
| 143 | { |
| 144 | struct rpc_xprt *xprt = task->tk_xprt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | struct rpc_rqst *req = task->tk_rqstp; |
| 146 | |
Chuck Lever | 2226feb | 2005-08-11 16:25:38 -0400 | [diff] [blame] | 147 | if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | if (task == xprt->snd_task) |
| 149 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | goto out_sleep; |
| 151 | } |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 152 | if (__xprt_get_cong(xprt, task)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | xprt->snd_task = task; |
| 154 | if (req) { |
| 155 | req->rq_bytes_sent = 0; |
| 156 | req->rq_ntrans++; |
| 157 | } |
| 158 | return 1; |
| 159 | } |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 160 | xprt_clear_locked(xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | out_sleep: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 162 | dprintk("RPC: %5u failed to lock transport %p\n", task->tk_pid, xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | task->tk_timeout = 0; |
| 164 | task->tk_status = -EAGAIN; |
| 165 | if (req && req->rq_ntrans) |
| 166 | rpc_sleep_on(&xprt->resend, task, NULL, NULL); |
| 167 | else |
| 168 | rpc_sleep_on(&xprt->sending, task, NULL, NULL); |
| 169 | return 0; |
| 170 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame^] | 171 | EXPORT_SYMBOL_GPL(xprt_reserve_xprt_cong); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 173 | static inline int xprt_lock_write(struct rpc_xprt *xprt, struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | { |
| 175 | int retval; |
| 176 | |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 177 | spin_lock_bh(&xprt->transport_lock); |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 178 | retval = xprt->ops->reserve_xprt(task); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 179 | spin_unlock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | return retval; |
| 181 | } |
| 182 | |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 183 | static void __xprt_lock_write_next(struct rpc_xprt *xprt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
| 185 | struct rpc_task *task; |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 186 | struct rpc_rqst *req; |
| 187 | |
| 188 | if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) |
| 189 | return; |
| 190 | |
| 191 | task = rpc_wake_up_next(&xprt->resend); |
| 192 | if (!task) { |
| 193 | task = rpc_wake_up_next(&xprt->sending); |
| 194 | if (!task) |
| 195 | goto out_unlock; |
| 196 | } |
| 197 | |
| 198 | req = task->tk_rqstp; |
| 199 | xprt->snd_task = task; |
| 200 | if (req) { |
| 201 | req->rq_bytes_sent = 0; |
| 202 | req->rq_ntrans++; |
| 203 | } |
| 204 | return; |
| 205 | |
| 206 | out_unlock: |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 207 | xprt_clear_locked(xprt); |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static void __xprt_lock_write_next_cong(struct rpc_xprt *xprt) |
| 211 | { |
| 212 | struct rpc_task *task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Chuck Lever | 2226feb | 2005-08-11 16:25:38 -0400 | [diff] [blame] | 214 | if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | return; |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 216 | if (RPCXPRT_CONGESTED(xprt)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | goto out_unlock; |
| 218 | task = rpc_wake_up_next(&xprt->resend); |
| 219 | if (!task) { |
| 220 | task = rpc_wake_up_next(&xprt->sending); |
| 221 | if (!task) |
| 222 | goto out_unlock; |
| 223 | } |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 224 | if (__xprt_get_cong(xprt, task)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | struct rpc_rqst *req = task->tk_rqstp; |
| 226 | xprt->snd_task = task; |
| 227 | if (req) { |
| 228 | req->rq_bytes_sent = 0; |
| 229 | req->rq_ntrans++; |
| 230 | } |
| 231 | return; |
| 232 | } |
| 233 | out_unlock: |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 234 | xprt_clear_locked(xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 237 | /** |
| 238 | * xprt_release_xprt - allow other requests to use a transport |
| 239 | * @xprt: transport with other tasks potentially waiting |
| 240 | * @task: task that is releasing access to the transport |
| 241 | * |
| 242 | * Note that "task" can be NULL. No congestion control is provided. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | */ |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 244 | void xprt_release_xprt(struct rpc_xprt *xprt, struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { |
| 246 | if (xprt->snd_task == task) { |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 247 | xprt_clear_locked(xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | __xprt_lock_write_next(xprt); |
| 249 | } |
| 250 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame^] | 251 | EXPORT_SYMBOL_GPL(xprt_release_xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 253 | /** |
| 254 | * xprt_release_xprt_cong - allow other requests to use a transport |
| 255 | * @xprt: transport with other tasks potentially waiting |
| 256 | * @task: task that is releasing access to the transport |
| 257 | * |
| 258 | * Note that "task" can be NULL. Another task is awoken to use the |
| 259 | * transport if the transport's congestion window allows it. |
| 260 | */ |
| 261 | void xprt_release_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task) |
| 262 | { |
| 263 | if (xprt->snd_task == task) { |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 264 | xprt_clear_locked(xprt); |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 265 | __xprt_lock_write_next_cong(xprt); |
| 266 | } |
| 267 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame^] | 268 | EXPORT_SYMBOL_GPL(xprt_release_xprt_cong); |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 269 | |
| 270 | static inline void xprt_release_write(struct rpc_xprt *xprt, struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | { |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 272 | spin_lock_bh(&xprt->transport_lock); |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 273 | xprt->ops->release_xprt(xprt, task); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 274 | spin_unlock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | * Van Jacobson congestion avoidance. Check if the congestion window |
| 279 | * overflowed. Put the task to sleep if this is the case. |
| 280 | */ |
| 281 | static int |
| 282 | __xprt_get_cong(struct rpc_xprt *xprt, struct rpc_task *task) |
| 283 | { |
| 284 | struct rpc_rqst *req = task->tk_rqstp; |
| 285 | |
| 286 | if (req->rq_cong) |
| 287 | return 1; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 288 | dprintk("RPC: %5u xprt_cwnd_limited cong = %lu cwnd = %lu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | task->tk_pid, xprt->cong, xprt->cwnd); |
| 290 | if (RPCXPRT_CONGESTED(xprt)) |
| 291 | return 0; |
| 292 | req->rq_cong = 1; |
| 293 | xprt->cong += RPC_CWNDSCALE; |
| 294 | return 1; |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * Adjust the congestion window, and wake up the next task |
| 299 | * that has been sleeping due to congestion |
| 300 | */ |
| 301 | static void |
| 302 | __xprt_put_cong(struct rpc_xprt *xprt, struct rpc_rqst *req) |
| 303 | { |
| 304 | if (!req->rq_cong) |
| 305 | return; |
| 306 | req->rq_cong = 0; |
| 307 | xprt->cong -= RPC_CWNDSCALE; |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 308 | __xprt_lock_write_next_cong(xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 311 | /** |
Chuck Lever | a58dd39 | 2005-08-25 16:25:53 -0700 | [diff] [blame] | 312 | * xprt_release_rqst_cong - housekeeping when request is complete |
| 313 | * @task: RPC request that recently completed |
| 314 | * |
| 315 | * Useful for transports that require congestion control. |
| 316 | */ |
| 317 | void xprt_release_rqst_cong(struct rpc_task *task) |
| 318 | { |
| 319 | __xprt_put_cong(task->tk_xprt, task->tk_rqstp); |
| 320 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame^] | 321 | EXPORT_SYMBOL_GPL(xprt_release_rqst_cong); |
Chuck Lever | a58dd39 | 2005-08-25 16:25:53 -0700 | [diff] [blame] | 322 | |
| 323 | /** |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 324 | * xprt_adjust_cwnd - adjust transport congestion window |
| 325 | * @task: recently completed RPC request used to adjust window |
| 326 | * @result: result code of completed RPC request |
| 327 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | * We use a time-smoothed congestion estimator to avoid heavy oscillation. |
| 329 | */ |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 330 | void xprt_adjust_cwnd(struct rpc_task *task, int result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | { |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 332 | struct rpc_rqst *req = task->tk_rqstp; |
| 333 | struct rpc_xprt *xprt = task->tk_xprt; |
| 334 | unsigned long cwnd = xprt->cwnd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | if (result >= 0 && cwnd <= xprt->cong) { |
| 337 | /* The (cwnd >> 1) term makes sure |
| 338 | * the result gets rounded properly. */ |
| 339 | cwnd += (RPC_CWNDSCALE * RPC_CWNDSCALE + (cwnd >> 1)) / cwnd; |
| 340 | if (cwnd > RPC_MAXCWND(xprt)) |
| 341 | cwnd = RPC_MAXCWND(xprt); |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 342 | __xprt_lock_write_next_cong(xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } else if (result == -ETIMEDOUT) { |
| 344 | cwnd >>= 1; |
| 345 | if (cwnd < RPC_CWNDSCALE) |
| 346 | cwnd = RPC_CWNDSCALE; |
| 347 | } |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 348 | dprintk("RPC: cong %ld, cwnd was %ld, now %ld\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | xprt->cong, xprt->cwnd, cwnd); |
| 350 | xprt->cwnd = cwnd; |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 351 | __xprt_put_cong(xprt, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame^] | 353 | EXPORT_SYMBOL_GPL(xprt_adjust_cwnd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Chuck Lever | 44fbac2 | 2005-08-11 16:25:44 -0400 | [diff] [blame] | 355 | /** |
| 356 | * xprt_wake_pending_tasks - wake all tasks on a transport's pending queue |
| 357 | * @xprt: transport with waiting tasks |
| 358 | * @status: result code to plant in each task before waking it |
| 359 | * |
| 360 | */ |
| 361 | void xprt_wake_pending_tasks(struct rpc_xprt *xprt, int status) |
| 362 | { |
| 363 | if (status < 0) |
| 364 | rpc_wake_up_status(&xprt->pending, status); |
| 365 | else |
| 366 | rpc_wake_up(&xprt->pending); |
| 367 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame^] | 368 | EXPORT_SYMBOL_GPL(xprt_wake_pending_tasks); |
Chuck Lever | 44fbac2 | 2005-08-11 16:25:44 -0400 | [diff] [blame] | 369 | |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 370 | /** |
| 371 | * xprt_wait_for_buffer_space - wait for transport output buffer to clear |
| 372 | * @task: task to be put to sleep |
| 373 | * |
| 374 | */ |
| 375 | void xprt_wait_for_buffer_space(struct rpc_task *task) |
| 376 | { |
| 377 | struct rpc_rqst *req = task->tk_rqstp; |
| 378 | struct rpc_xprt *xprt = req->rq_xprt; |
| 379 | |
| 380 | task->tk_timeout = req->rq_timeout; |
| 381 | rpc_sleep_on(&xprt->pending, task, NULL, NULL); |
| 382 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame^] | 383 | EXPORT_SYMBOL_GPL(xprt_wait_for_buffer_space); |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 384 | |
| 385 | /** |
| 386 | * xprt_write_space - wake the task waiting for transport output buffer space |
| 387 | * @xprt: transport with waiting tasks |
| 388 | * |
| 389 | * Can be called in a soft IRQ context, so xprt_write_space never sleeps. |
| 390 | */ |
| 391 | void xprt_write_space(struct rpc_xprt *xprt) |
| 392 | { |
| 393 | if (unlikely(xprt->shutdown)) |
| 394 | return; |
| 395 | |
| 396 | spin_lock_bh(&xprt->transport_lock); |
| 397 | if (xprt->snd_task) { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 398 | dprintk("RPC: write space: waking waiting task on " |
| 399 | "xprt %p\n", xprt); |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 400 | rpc_wake_up_task(xprt->snd_task); |
| 401 | } |
| 402 | spin_unlock_bh(&xprt->transport_lock); |
| 403 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame^] | 404 | EXPORT_SYMBOL_GPL(xprt_write_space); |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 405 | |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 406 | /** |
| 407 | * xprt_set_retrans_timeout_def - set a request's retransmit timeout |
| 408 | * @task: task whose timeout is to be set |
| 409 | * |
| 410 | * Set a request's retransmit timeout based on the transport's |
| 411 | * default timeout parameters. Used by transports that don't adjust |
| 412 | * the retransmit timeout based on round-trip time estimation. |
| 413 | */ |
| 414 | void xprt_set_retrans_timeout_def(struct rpc_task *task) |
| 415 | { |
| 416 | task->tk_timeout = task->tk_rqstp->rq_timeout; |
| 417 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame^] | 418 | EXPORT_SYMBOL_GPL(xprt_set_retrans_timeout_def); |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 419 | |
| 420 | /* |
| 421 | * xprt_set_retrans_timeout_rtt - set a request's retransmit timeout |
| 422 | * @task: task whose timeout is to be set |
YOSHIFUJI Hideaki | cca5172 | 2007-02-09 15:38:13 -0800 | [diff] [blame] | 423 | * |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 424 | * Set a request's retransmit timeout using the RTT estimator. |
| 425 | */ |
| 426 | void xprt_set_retrans_timeout_rtt(struct rpc_task *task) |
| 427 | { |
| 428 | int timer = task->tk_msg.rpc_proc->p_timer; |
| 429 | struct rpc_rtt *rtt = task->tk_client->cl_rtt; |
| 430 | struct rpc_rqst *req = task->tk_rqstp; |
| 431 | unsigned long max_timeout = req->rq_xprt->timeout.to_maxval; |
| 432 | |
| 433 | task->tk_timeout = rpc_calc_rto(rtt, timer); |
| 434 | task->tk_timeout <<= rpc_ntimeo(rtt, timer) + req->rq_retries; |
| 435 | if (task->tk_timeout > max_timeout || task->tk_timeout == 0) |
| 436 | task->tk_timeout = max_timeout; |
| 437 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame^] | 438 | EXPORT_SYMBOL_GPL(xprt_set_retrans_timeout_rtt); |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | static void xprt_reset_majortimeo(struct rpc_rqst *req) |
| 441 | { |
| 442 | struct rpc_timeout *to = &req->rq_xprt->timeout; |
| 443 | |
| 444 | req->rq_majortimeo = req->rq_timeout; |
| 445 | if (to->to_exponential) |
| 446 | req->rq_majortimeo <<= to->to_retries; |
| 447 | else |
| 448 | req->rq_majortimeo += to->to_increment * to->to_retries; |
| 449 | if (req->rq_majortimeo > to->to_maxval || req->rq_majortimeo == 0) |
| 450 | req->rq_majortimeo = to->to_maxval; |
| 451 | req->rq_majortimeo += jiffies; |
| 452 | } |
| 453 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 454 | /** |
| 455 | * xprt_adjust_timeout - adjust timeout values for next retransmit |
| 456 | * @req: RPC request containing parameters to use for the adjustment |
| 457 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | */ |
| 459 | int xprt_adjust_timeout(struct rpc_rqst *req) |
| 460 | { |
| 461 | struct rpc_xprt *xprt = req->rq_xprt; |
| 462 | struct rpc_timeout *to = &xprt->timeout; |
| 463 | int status = 0; |
| 464 | |
| 465 | if (time_before(jiffies, req->rq_majortimeo)) { |
| 466 | if (to->to_exponential) |
| 467 | req->rq_timeout <<= 1; |
| 468 | else |
| 469 | req->rq_timeout += to->to_increment; |
| 470 | if (to->to_maxval && req->rq_timeout >= to->to_maxval) |
| 471 | req->rq_timeout = to->to_maxval; |
| 472 | req->rq_retries++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | } else { |
| 474 | req->rq_timeout = to->to_initval; |
| 475 | req->rq_retries = 0; |
| 476 | xprt_reset_majortimeo(req); |
| 477 | /* Reset the RTT counters == "slow start" */ |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 478 | spin_lock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | rpc_init_rtt(req->rq_task->tk_client->cl_rtt, to->to_initval); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 480 | spin_unlock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | status = -ETIMEDOUT; |
| 482 | } |
| 483 | |
| 484 | if (req->rq_timeout == 0) { |
| 485 | printk(KERN_WARNING "xprt_adjust_timeout: rq_timeout = 0!\n"); |
| 486 | req->rq_timeout = 5 * HZ; |
| 487 | } |
| 488 | return status; |
| 489 | } |
| 490 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 491 | static void xprt_autoclose(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 493 | struct rpc_xprt *xprt = |
| 494 | container_of(work, struct rpc_xprt, task_cleanup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
| 496 | xprt_disconnect(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 497 | xprt->ops->close(xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | xprt_release_write(xprt, NULL); |
| 499 | } |
| 500 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 501 | /** |
| 502 | * xprt_disconnect - mark a transport as disconnected |
| 503 | * @xprt: transport to flag for disconnect |
| 504 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | */ |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 506 | void xprt_disconnect(struct rpc_xprt *xprt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 508 | dprintk("RPC: disconnected transport %p\n", xprt); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 509 | spin_lock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | xprt_clear_connected(xprt); |
Chuck Lever | 44fbac2 | 2005-08-11 16:25:44 -0400 | [diff] [blame] | 511 | xprt_wake_pending_tasks(xprt, -ENOTCONN); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 512 | spin_unlock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame^] | 514 | EXPORT_SYMBOL_GPL(xprt_disconnect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | static void |
| 517 | xprt_init_autodisconnect(unsigned long data) |
| 518 | { |
| 519 | struct rpc_xprt *xprt = (struct rpc_xprt *)data; |
| 520 | |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 521 | spin_lock(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | if (!list_empty(&xprt->recv) || xprt->shutdown) |
| 523 | goto out_abort; |
Chuck Lever | 2226feb | 2005-08-11 16:25:38 -0400 | [diff] [blame] | 524 | if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | goto out_abort; |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 526 | spin_unlock(&xprt->transport_lock); |
Chuck Lever | 2226feb | 2005-08-11 16:25:38 -0400 | [diff] [blame] | 527 | if (xprt_connecting(xprt)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | xprt_release_write(xprt, NULL); |
| 529 | else |
Trond Myklebust | c1384c9 | 2007-06-14 18:00:42 -0400 | [diff] [blame] | 530 | queue_work(rpciod_workqueue, &xprt->task_cleanup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | return; |
| 532 | out_abort: |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 533 | spin_unlock(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 536 | /** |
| 537 | * xprt_connect - schedule a transport connect operation |
| 538 | * @task: RPC task that is requesting the connect |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | * |
| 540 | */ |
| 541 | void xprt_connect(struct rpc_task *task) |
| 542 | { |
| 543 | struct rpc_xprt *xprt = task->tk_xprt; |
| 544 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 545 | dprintk("RPC: %5u xprt_connect xprt %p %s connected\n", task->tk_pid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | xprt, (xprt_connected(xprt) ? "is" : "is not")); |
| 547 | |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 548 | if (!xprt_bound(xprt)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | task->tk_status = -EIO; |
| 550 | return; |
| 551 | } |
| 552 | if (!xprt_lock_write(xprt, task)) |
| 553 | return; |
| 554 | if (xprt_connected(xprt)) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 555 | xprt_release_write(xprt, task); |
| 556 | else { |
| 557 | if (task->tk_rqstp) |
| 558 | task->tk_rqstp->rq_bytes_sent = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 560 | task->tk_timeout = xprt->connect_timeout; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 561 | rpc_sleep_on(&xprt->pending, task, xprt_connect_status, NULL); |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 562 | xprt->stat.connect_start = jiffies; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 563 | xprt->ops->connect(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } |
| 565 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 568 | static void xprt_connect_status(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | { |
| 570 | struct rpc_xprt *xprt = task->tk_xprt; |
| 571 | |
| 572 | if (task->tk_status >= 0) { |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 573 | xprt->stat.connect_count++; |
| 574 | xprt->stat.connect_time += (long)jiffies - xprt->stat.connect_start; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 575 | dprintk("RPC: %5u xprt_connect_status: connection established\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | task->tk_pid); |
| 577 | return; |
| 578 | } |
| 579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | switch (task->tk_status) { |
| 581 | case -ECONNREFUSED: |
| 582 | case -ECONNRESET: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 583 | dprintk("RPC: %5u xprt_connect_status: server %s refused " |
| 584 | "connection\n", task->tk_pid, |
| 585 | task->tk_client->cl_server); |
Chuck Lever | 23475d6 | 2005-08-11 16:25:08 -0400 | [diff] [blame] | 586 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | case -ENOTCONN: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 588 | dprintk("RPC: %5u xprt_connect_status: connection broken\n", |
Chuck Lever | 23475d6 | 2005-08-11 16:25:08 -0400 | [diff] [blame] | 589 | task->tk_pid); |
| 590 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | case -ETIMEDOUT: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 592 | dprintk("RPC: %5u xprt_connect_status: connect attempt timed " |
| 593 | "out\n", task->tk_pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | break; |
| 595 | default: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 596 | dprintk("RPC: %5u xprt_connect_status: error %d connecting to " |
| 597 | "server %s\n", task->tk_pid, -task->tk_status, |
| 598 | task->tk_client->cl_server); |
Chuck Lever | 23475d6 | 2005-08-11 16:25:08 -0400 | [diff] [blame] | 599 | xprt_release_write(xprt, task); |
| 600 | task->tk_status = -EIO; |
Chuck Lever | 23475d6 | 2005-08-11 16:25:08 -0400 | [diff] [blame] | 601 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 604 | /** |
| 605 | * xprt_lookup_rqst - find an RPC request corresponding to an XID |
| 606 | * @xprt: transport on which the original request was transmitted |
| 607 | * @xid: RPC XID of incoming reply |
| 608 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | */ |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 610 | struct rpc_rqst *xprt_lookup_rqst(struct rpc_xprt *xprt, __be32 xid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | { |
| 612 | struct list_head *pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
| 614 | list_for_each(pos, &xprt->recv) { |
| 615 | struct rpc_rqst *entry = list_entry(pos, struct rpc_rqst, rq_list); |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 616 | if (entry->rq_xid == xid) |
| 617 | return entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | } |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 619 | |
| 620 | dprintk("RPC: xprt_lookup_rqst did not find xid %08x\n", |
| 621 | ntohl(xid)); |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 622 | xprt->stat.bad_xids++; |
| 623 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame^] | 625 | EXPORT_SYMBOL_GPL(xprt_lookup_rqst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 627 | /** |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 628 | * xprt_update_rtt - update an RPC client's RTT state after receiving a reply |
| 629 | * @task: RPC request that recently completed |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 630 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | */ |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 632 | void xprt_update_rtt(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | { |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 634 | struct rpc_rqst *req = task->tk_rqstp; |
| 635 | struct rpc_rtt *rtt = task->tk_client->cl_rtt; |
| 636 | unsigned timer = task->tk_msg.rpc_proc->p_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 638 | if (timer) { |
| 639 | if (req->rq_ntrans == 1) |
| 640 | rpc_update_rtt(rtt, timer, |
| 641 | (long)jiffies - req->rq_xtime); |
| 642 | rpc_set_timeo(rtt, timer, req->rq_ntrans - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | } |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 644 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame^] | 645 | EXPORT_SYMBOL_GPL(xprt_update_rtt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 647 | /** |
| 648 | * xprt_complete_rqst - called when reply processing is complete |
| 649 | * @task: RPC request that recently completed |
| 650 | * @copied: actual number of bytes received from the transport |
| 651 | * |
| 652 | * Caller holds transport lock. |
| 653 | */ |
| 654 | void xprt_complete_rqst(struct rpc_task *task, int copied) |
| 655 | { |
| 656 | struct rpc_rqst *req = task->tk_rqstp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 658 | dprintk("RPC: %5u xid %08x complete (%d bytes received)\n", |
| 659 | task->tk_pid, ntohl(req->rq_xid), copied); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 661 | task->tk_xprt->stat.recvs++; |
Chuck Lever | ef759a2 | 2006-03-20 13:44:17 -0500 | [diff] [blame] | 662 | task->tk_rtt = (long)jiffies - req->rq_xtime; |
| 663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | list_del_init(&req->rq_list); |
Trond Myklebust | 43ac3f2 | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 665 | /* Ensure all writes are done before we update req->rq_received */ |
| 666 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | req->rq_received = req->rq_private_buf.len = copied; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | rpc_wake_up_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame^] | 670 | EXPORT_SYMBOL_GPL(xprt_complete_rqst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 672 | static void xprt_timer(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | { |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 674 | struct rpc_rqst *req = task->tk_rqstp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | struct rpc_xprt *xprt = req->rq_xprt; |
| 676 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 677 | dprintk("RPC: %5u xprt_timer\n", task->tk_pid); |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 678 | |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 679 | spin_lock(&xprt->transport_lock); |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 680 | if (!req->rq_received) { |
| 681 | if (xprt->ops->timer) |
| 682 | xprt->ops->timer(task); |
| 683 | task->tk_status = -ETIMEDOUT; |
| 684 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | task->tk_timeout = 0; |
| 686 | rpc_wake_up_task(task); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 687 | spin_unlock(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 690 | /** |
| 691 | * xprt_prepare_transmit - reserve the transport before sending a request |
| 692 | * @task: RPC task about to send a request |
| 693 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | */ |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 695 | int xprt_prepare_transmit(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | { |
| 697 | struct rpc_rqst *req = task->tk_rqstp; |
| 698 | struct rpc_xprt *xprt = req->rq_xprt; |
| 699 | int err = 0; |
| 700 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 701 | dprintk("RPC: %5u xprt_prepare_transmit\n", task->tk_pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 703 | spin_lock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | if (req->rq_received && !req->rq_bytes_sent) { |
| 705 | err = req->rq_received; |
| 706 | goto out_unlock; |
| 707 | } |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 708 | if (!xprt->ops->reserve_xprt(task)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | err = -EAGAIN; |
| 710 | goto out_unlock; |
| 711 | } |
| 712 | |
| 713 | if (!xprt_connected(xprt)) { |
| 714 | err = -ENOTCONN; |
| 715 | goto out_unlock; |
| 716 | } |
| 717 | out_unlock: |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 718 | spin_unlock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | return err; |
| 720 | } |
| 721 | |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 722 | void xprt_end_transmit(struct rpc_task *task) |
Trond Myklebust | 5e5ce5b | 2005-10-18 14:20:11 -0700 | [diff] [blame] | 723 | { |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 724 | xprt_release_write(task->tk_xprt, task); |
Trond Myklebust | 5e5ce5b | 2005-10-18 14:20:11 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 727 | /** |
| 728 | * xprt_transmit - send an RPC request on a transport |
| 729 | * @task: controlling RPC task |
| 730 | * |
| 731 | * We have to copy the iovec because sendmsg fiddles with its contents. |
| 732 | */ |
| 733 | void xprt_transmit(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | struct rpc_rqst *req = task->tk_rqstp; |
| 736 | struct rpc_xprt *xprt = req->rq_xprt; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 737 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 739 | dprintk("RPC: %5u xprt_transmit(%u)\n", task->tk_pid, req->rq_slen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | if (!req->rq_received) { |
| 742 | if (list_empty(&req->rq_list)) { |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 743 | spin_lock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | /* Update the softirq receive buffer */ |
| 745 | memcpy(&req->rq_private_buf, &req->rq_rcv_buf, |
| 746 | sizeof(req->rq_private_buf)); |
| 747 | /* Add request to the receive list */ |
| 748 | list_add_tail(&req->rq_list, &xprt->recv); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 749 | spin_unlock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | xprt_reset_majortimeo(req); |
Trond Myklebust | 0f9dc2b | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 751 | /* Turn off autodisconnect */ |
| 752 | del_singleshot_timer_sync(&xprt->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
| 754 | } else if (!req->rq_bytes_sent) |
| 755 | return; |
| 756 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 757 | status = xprt->ops->send_request(task); |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 758 | if (status == 0) { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 759 | dprintk("RPC: %5u xmit complete\n", task->tk_pid); |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 760 | spin_lock_bh(&xprt->transport_lock); |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 761 | |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 762 | xprt->ops->set_retrans_timeout(task); |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 763 | |
| 764 | xprt->stat.sends++; |
| 765 | xprt->stat.req_u += xprt->stat.sends - xprt->stat.recvs; |
| 766 | xprt->stat.bklog_u += xprt->backlog.qlen; |
| 767 | |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 768 | /* Don't race with disconnect */ |
| 769 | if (!xprt_connected(xprt)) |
| 770 | task->tk_status = -ENOTCONN; |
| 771 | else if (!req->rq_received) |
| 772 | rpc_sleep_on(&xprt->pending, task, NULL, xprt_timer); |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 773 | spin_unlock_bh(&xprt->transport_lock); |
| 774 | return; |
| 775 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | |
| 777 | /* Note: at this point, task->tk_sleeping has not yet been set, |
| 778 | * hence there is no danger of the waking up task being put on |
| 779 | * schedq, and being picked up by a parallel run of rpciod(). |
| 780 | */ |
| 781 | task->tk_status = status; |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 782 | if (status == -ECONNREFUSED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | rpc_sleep_on(&xprt->sending, task, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | } |
| 785 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 786 | static inline void do_xprt_reserve(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | { |
| 788 | struct rpc_xprt *xprt = task->tk_xprt; |
| 789 | |
| 790 | task->tk_status = 0; |
| 791 | if (task->tk_rqstp) |
| 792 | return; |
| 793 | if (!list_empty(&xprt->free)) { |
| 794 | struct rpc_rqst *req = list_entry(xprt->free.next, struct rpc_rqst, rq_list); |
| 795 | list_del_init(&req->rq_list); |
| 796 | task->tk_rqstp = req; |
| 797 | xprt_request_init(task, xprt); |
| 798 | return; |
| 799 | } |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 800 | dprintk("RPC: waiting for request slot\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | task->tk_status = -EAGAIN; |
| 802 | task->tk_timeout = 0; |
| 803 | rpc_sleep_on(&xprt->backlog, task, NULL, NULL); |
| 804 | } |
| 805 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 806 | /** |
| 807 | * xprt_reserve - allocate an RPC request slot |
| 808 | * @task: RPC task requesting a slot allocation |
| 809 | * |
| 810 | * If no more slots are available, place the task on the transport's |
| 811 | * backlog queue. |
| 812 | */ |
| 813 | void xprt_reserve(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | { |
| 815 | struct rpc_xprt *xprt = task->tk_xprt; |
| 816 | |
| 817 | task->tk_status = -EIO; |
Trond Myklebust | 0065db3 | 2006-01-03 09:55:56 +0100 | [diff] [blame] | 818 | spin_lock(&xprt->reserve_lock); |
| 819 | do_xprt_reserve(task); |
| 820 | spin_unlock(&xprt->reserve_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 823 | static inline __be32 xprt_alloc_xid(struct rpc_xprt *xprt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | { |
| 825 | return xprt->xid++; |
| 826 | } |
| 827 | |
| 828 | static inline void xprt_init_xid(struct rpc_xprt *xprt) |
| 829 | { |
Chuck Lever | bf3fcf8 | 2006-05-25 01:40:51 -0400 | [diff] [blame] | 830 | xprt->xid = net_random(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 833 | static void xprt_request_init(struct rpc_task *task, struct rpc_xprt *xprt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | { |
| 835 | struct rpc_rqst *req = task->tk_rqstp; |
| 836 | |
| 837 | req->rq_timeout = xprt->timeout.to_initval; |
| 838 | req->rq_task = task; |
| 839 | req->rq_xprt = xprt; |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 840 | req->rq_buffer = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | req->rq_xid = xprt_alloc_xid(xprt); |
J. Bruce Fields | ead5e1c | 2005-10-13 16:54:43 -0400 | [diff] [blame] | 842 | req->rq_release_snd_buf = NULL; |
Trond Myklebust | da45828 | 2006-08-31 15:44:52 -0400 | [diff] [blame] | 843 | xprt_reset_majortimeo(req); |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 844 | dprintk("RPC: %5u reserved req %p xid %08x\n", task->tk_pid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | req, ntohl(req->rq_xid)); |
| 846 | } |
| 847 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 848 | /** |
| 849 | * xprt_release - release an RPC request slot |
| 850 | * @task: task which is finished with the slot |
| 851 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | */ |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 853 | void xprt_release(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | { |
| 855 | struct rpc_xprt *xprt = task->tk_xprt; |
| 856 | struct rpc_rqst *req; |
| 857 | |
| 858 | if (!(req = task->tk_rqstp)) |
| 859 | return; |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 860 | rpc_count_iostats(task); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 861 | spin_lock_bh(&xprt->transport_lock); |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 862 | xprt->ops->release_xprt(xprt, task); |
Chuck Lever | a58dd39 | 2005-08-25 16:25:53 -0700 | [diff] [blame] | 863 | if (xprt->ops->release_request) |
| 864 | xprt->ops->release_request(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | if (!list_empty(&req->rq_list)) |
| 866 | list_del(&req->rq_list); |
| 867 | xprt->last_used = jiffies; |
Trond Myklebust | 0065db3 | 2006-01-03 09:55:56 +0100 | [diff] [blame] | 868 | if (list_empty(&xprt->recv)) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 869 | mod_timer(&xprt->timer, |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 870 | xprt->last_used + xprt->idle_timeout); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 871 | spin_unlock_bh(&xprt->transport_lock); |
Chuck Lever | c5a4dd8 | 2007-03-29 16:47:58 -0400 | [diff] [blame] | 872 | xprt->ops->buf_free(req->rq_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | task->tk_rqstp = NULL; |
J. Bruce Fields | ead5e1c | 2005-10-13 16:54:43 -0400 | [diff] [blame] | 874 | if (req->rq_release_snd_buf) |
| 875 | req->rq_release_snd_buf(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | memset(req, 0, sizeof(*req)); /* mark unused */ |
| 877 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 878 | dprintk("RPC: %5u release request %p\n", task->tk_pid, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | |
Chuck Lever | 5dc0772 | 2005-08-11 16:25:35 -0400 | [diff] [blame] | 880 | spin_lock(&xprt->reserve_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | list_add(&req->rq_list, &xprt->free); |
Chuck Lever | 555ee3a | 2005-08-25 16:25:54 -0700 | [diff] [blame] | 882 | rpc_wake_up_next(&xprt->backlog); |
Chuck Lever | 5dc0772 | 2005-08-11 16:25:35 -0400 | [diff] [blame] | 883 | spin_unlock(&xprt->reserve_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 886 | /** |
| 887 | * xprt_set_timeout - set constant RPC timeout |
| 888 | * @to: RPC timeout parameters to set up |
| 889 | * @retr: number of retries |
| 890 | * @incr: amount of increase after each retry |
| 891 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | */ |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 893 | void xprt_set_timeout(struct rpc_timeout *to, unsigned int retr, unsigned long incr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | { |
YOSHIFUJI Hideaki | cca5172 | 2007-02-09 15:38:13 -0800 | [diff] [blame] | 895 | to->to_initval = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | to->to_increment = incr; |
Chuck Lever | eab5c08 | 2005-08-11 16:25:14 -0400 | [diff] [blame] | 897 | to->to_maxval = to->to_initval + (incr * retr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | to->to_retries = retr; |
| 899 | to->to_exponential = 0; |
| 900 | } |
| 901 | |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 902 | /** |
| 903 | * xprt_create_transport - create an RPC transport |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 904 | * @args: rpc transport creation arguments |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 905 | * |
| 906 | */ |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 907 | struct rpc_xprt *xprt_create_transport(struct rpc_xprtsock_create *args) |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 908 | { |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 909 | struct rpc_xprt *xprt; |
| 910 | struct rpc_rqst *req; |
| 911 | |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 912 | switch (args->proto) { |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 913 | case IPPROTO_UDP: |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 914 | xprt = xs_setup_udp(args); |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 915 | break; |
| 916 | case IPPROTO_TCP: |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 917 | xprt = xs_setup_tcp(args); |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 918 | break; |
| 919 | default: |
| 920 | printk(KERN_ERR "RPC: unrecognized transport protocol: %d\n", |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 921 | args->proto); |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 922 | return ERR_PTR(-EIO); |
| 923 | } |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 924 | if (IS_ERR(xprt)) { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 925 | dprintk("RPC: xprt_create_transport: failed, %ld\n", |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 926 | -PTR_ERR(xprt)); |
| 927 | return xprt; |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 928 | } |
| 929 | |
Trond Myklebust | 6b6ca86 | 2006-09-05 12:55:57 -0400 | [diff] [blame] | 930 | kref_init(&xprt->kref); |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 931 | spin_lock_init(&xprt->transport_lock); |
| 932 | spin_lock_init(&xprt->reserve_lock); |
| 933 | |
| 934 | INIT_LIST_HEAD(&xprt->free); |
| 935 | INIT_LIST_HEAD(&xprt->recv); |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 936 | INIT_WORK(&xprt->task_cleanup, xprt_autoclose); |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 937 | init_timer(&xprt->timer); |
| 938 | xprt->timer.function = xprt_init_autodisconnect; |
| 939 | xprt->timer.data = (unsigned long) xprt; |
| 940 | xprt->last_used = jiffies; |
| 941 | xprt->cwnd = RPC_INITCWND; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 942 | xprt->bind_index = 0; |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 943 | |
| 944 | rpc_init_wait_queue(&xprt->binding, "xprt_binding"); |
| 945 | rpc_init_wait_queue(&xprt->pending, "xprt_pending"); |
| 946 | rpc_init_wait_queue(&xprt->sending, "xprt_sending"); |
| 947 | rpc_init_wait_queue(&xprt->resend, "xprt_resend"); |
| 948 | rpc_init_priority_wait_queue(&xprt->backlog, "xprt_backlog"); |
| 949 | |
| 950 | /* initialize free list */ |
| 951 | for (req = &xprt->slot[xprt->max_reqs-1]; req >= &xprt->slot[0]; req--) |
| 952 | list_add(&req->rq_list, &xprt->free); |
| 953 | |
| 954 | xprt_init_xid(xprt); |
| 955 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 956 | dprintk("RPC: created transport %p with %u slots\n", xprt, |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 957 | xprt->max_reqs); |
| 958 | |
| 959 | return xprt; |
| 960 | } |
| 961 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 962 | /** |
| 963 | * xprt_destroy - destroy an RPC transport, killing off all requests. |
Trond Myklebust | 6b6ca86 | 2006-09-05 12:55:57 -0400 | [diff] [blame] | 964 | * @kref: kref for the transport to destroy |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 965 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | */ |
Trond Myklebust | 6b6ca86 | 2006-09-05 12:55:57 -0400 | [diff] [blame] | 967 | static void xprt_destroy(struct kref *kref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | { |
Trond Myklebust | 6b6ca86 | 2006-09-05 12:55:57 -0400 | [diff] [blame] | 969 | struct rpc_xprt *xprt = container_of(kref, struct rpc_xprt, kref); |
| 970 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 971 | dprintk("RPC: destroying transport %p\n", xprt); |
Trond Myklebust | 0065db3 | 2006-01-03 09:55:56 +0100 | [diff] [blame] | 972 | xprt->shutdown = 1; |
| 973 | del_timer_sync(&xprt->timer); |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 974 | |
| 975 | /* |
| 976 | * Tear down transport state and free the rpc_xprt |
| 977 | */ |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 978 | xprt->ops->destroy(xprt); |
Trond Myklebust | 6b6ca86 | 2006-09-05 12:55:57 -0400 | [diff] [blame] | 979 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
Trond Myklebust | 6b6ca86 | 2006-09-05 12:55:57 -0400 | [diff] [blame] | 981 | /** |
| 982 | * xprt_put - release a reference to an RPC transport. |
| 983 | * @xprt: pointer to the transport |
| 984 | * |
| 985 | */ |
| 986 | void xprt_put(struct rpc_xprt *xprt) |
| 987 | { |
| 988 | kref_put(&xprt->kref, xprt_destroy); |
| 989 | } |
| 990 | |
| 991 | /** |
| 992 | * xprt_get - return a reference to an RPC transport. |
| 993 | * @xprt: pointer to the transport |
| 994 | * |
| 995 | */ |
| 996 | struct rpc_xprt *xprt_get(struct rpc_xprt *xprt) |
| 997 | { |
| 998 | kref_get(&xprt->kref); |
| 999 | return xprt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | } |