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