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 |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 15 | * transport's wait list. At the same time, if a reply is expected, |
| 16 | * it installs a timer that is run after the packet's timeout has |
| 17 | * expired. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * - When a packet arrives, the data_ready handler walks the list of |
Chuck Lever | 55aa4f5 | 2005-08-11 16:25:47 -0400 | [diff] [blame] | 19 | * pending requests for that transport. If a matching XID is found, the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | * caller is woken up, and the timer removed. |
| 21 | * - When no reply arrives within the timeout interval, the timer is |
| 22 | * fired by the kernel and runs xprt_timer(). It either adjusts the |
| 23 | * timeout values (minor timeout) or wakes up the caller with a status |
| 24 | * of -ETIMEDOUT. |
| 25 | * - When the caller receives a notification from RPC that a reply arrived, |
| 26 | * it should release the RPC slot, and process the reply. |
| 27 | * If the call timed out, it may choose to retry the operation by |
| 28 | * adjusting the initial timeout value, and simply calling rpc_call |
| 29 | * again. |
| 30 | * |
| 31 | * Support for async RPC is done through a set of RPC-specific scheduling |
| 32 | * primitives that `transparently' work for processes as well as async |
| 33 | * tasks that rely on callbacks. |
| 34 | * |
| 35 | * Copyright (C) 1995-1997, Olaf Kirch <okir@monad.swb.de> |
Chuck Lever | 55aa4f5 | 2005-08-11 16:25:47 -0400 | [diff] [blame] | 36 | * |
| 37 | * Transport switch API copyright (C) 2005, Chuck Lever <cel@netapp.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | */ |
| 39 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 40 | #include <linux/module.h> |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/types.h> |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 43 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <linux/workqueue.h> |
Chuck Lever | bf3fcf8 | 2006-05-25 01:40:51 -0400 | [diff] [blame] | 45 | #include <linux/net.h> |
Chuck Lever | ff83997 | 2010-05-07 13:34:47 -0400 | [diff] [blame] | 46 | #include <linux/ktime.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 48 | #include <linux/sunrpc/clnt.h> |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 49 | #include <linux/sunrpc/metrics.h> |
Trond Myklebust | c9acb42 | 2010-03-19 15:36:22 -0400 | [diff] [blame] | 50 | #include <linux/sunrpc/bc_xprt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 52 | #include "sunrpc.h" |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | /* |
| 55 | * Local variables |
| 56 | */ |
| 57 | |
| 58 | #ifdef RPC_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | # define RPCDBG_FACILITY RPCDBG_XPRT |
| 60 | #endif |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | /* |
| 63 | * Local functions |
| 64 | */ |
| 65 | static void xprt_request_init(struct rpc_task *, struct rpc_xprt *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | static void xprt_connect_status(struct rpc_task *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | static int __xprt_get_cong(struct rpc_xprt *, struct rpc_task *); |
| 68 | |
Jiri Slaby | 5ba03e8 | 2007-11-22 19:40:22 +0800 | [diff] [blame] | 69 | static DEFINE_SPINLOCK(xprt_list_lock); |
\"Talpey, Thomas\ | 81c098a | 2007-09-10 13:46:00 -0400 | [diff] [blame] | 70 | static LIST_HEAD(xprt_list); |
| 71 | |
Chuck Lever | 555ee3a | 2005-08-25 16:25:54 -0700 | [diff] [blame] | 72 | /* |
| 73 | * The transport code maintains an estimate on the maximum number of out- |
| 74 | * standing RPC requests, using a smoothed version of the congestion |
| 75 | * avoidance implemented in 44BSD. This is basically the Van Jacobson |
| 76 | * congestion algorithm: If a retransmit occurs, the congestion window is |
| 77 | * halved; otherwise, it is incremented by 1/cwnd when |
| 78 | * |
| 79 | * - a reply is received and |
| 80 | * - a full number of requests are outstanding and |
| 81 | * - the congestion window hasn't been updated recently. |
| 82 | */ |
| 83 | #define RPC_CWNDSHIFT (8U) |
| 84 | #define RPC_CWNDSCALE (1U << RPC_CWNDSHIFT) |
| 85 | #define RPC_INITCWND RPC_CWNDSCALE |
| 86 | #define RPC_MAXCWND(xprt) ((xprt)->max_reqs << RPC_CWNDSHIFT) |
| 87 | |
| 88 | #define RPCXPRT_CONGESTED(xprt) ((xprt)->cong >= (xprt)->cwnd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 90 | /** |
\"Talpey, Thomas\ | 81c098a | 2007-09-10 13:46:00 -0400 | [diff] [blame] | 91 | * xprt_register_transport - register a transport implementation |
| 92 | * @transport: transport to register |
| 93 | * |
| 94 | * If a transport implementation is loaded as a kernel module, it can |
| 95 | * call this interface to make itself known to the RPC client. |
| 96 | * |
| 97 | * Returns: |
| 98 | * 0: transport successfully registered |
| 99 | * -EEXIST: transport already registered |
| 100 | * -EINVAL: transport module being unloaded |
| 101 | */ |
| 102 | int xprt_register_transport(struct xprt_class *transport) |
| 103 | { |
| 104 | struct xprt_class *t; |
| 105 | int result; |
| 106 | |
| 107 | result = -EEXIST; |
| 108 | spin_lock(&xprt_list_lock); |
| 109 | list_for_each_entry(t, &xprt_list, list) { |
| 110 | /* don't register the same transport class twice */ |
\"Talpey, Thomas\ | 4fa016e | 2007-09-10 13:47:57 -0400 | [diff] [blame] | 111 | if (t->ident == transport->ident) |
\"Talpey, Thomas\ | 81c098a | 2007-09-10 13:46:00 -0400 | [diff] [blame] | 112 | goto out; |
| 113 | } |
| 114 | |
Denis V. Lunev | c9f6cde | 2008-07-31 09:53:56 +0400 | [diff] [blame] | 115 | list_add_tail(&transport->list, &xprt_list); |
| 116 | printk(KERN_INFO "RPC: Registered %s transport module.\n", |
| 117 | transport->name); |
| 118 | result = 0; |
\"Talpey, Thomas\ | 81c098a | 2007-09-10 13:46:00 -0400 | [diff] [blame] | 119 | |
| 120 | out: |
| 121 | spin_unlock(&xprt_list_lock); |
| 122 | return result; |
| 123 | } |
| 124 | EXPORT_SYMBOL_GPL(xprt_register_transport); |
| 125 | |
| 126 | /** |
| 127 | * xprt_unregister_transport - unregister a transport implementation |
Randy Dunlap | 65b6e42 | 2008-02-13 15:03:23 -0800 | [diff] [blame] | 128 | * @transport: transport to unregister |
\"Talpey, Thomas\ | 81c098a | 2007-09-10 13:46:00 -0400 | [diff] [blame] | 129 | * |
| 130 | * Returns: |
| 131 | * 0: transport successfully unregistered |
| 132 | * -ENOENT: transport never registered |
| 133 | */ |
| 134 | int xprt_unregister_transport(struct xprt_class *transport) |
| 135 | { |
| 136 | struct xprt_class *t; |
| 137 | int result; |
| 138 | |
| 139 | result = 0; |
| 140 | spin_lock(&xprt_list_lock); |
| 141 | list_for_each_entry(t, &xprt_list, list) { |
| 142 | if (t == transport) { |
| 143 | printk(KERN_INFO |
| 144 | "RPC: Unregistered %s transport module.\n", |
| 145 | transport->name); |
| 146 | list_del_init(&transport->list); |
\"Talpey, Thomas\ | 81c098a | 2007-09-10 13:46:00 -0400 | [diff] [blame] | 147 | goto out; |
| 148 | } |
| 149 | } |
| 150 | result = -ENOENT; |
| 151 | |
| 152 | out: |
| 153 | spin_unlock(&xprt_list_lock); |
| 154 | return result; |
| 155 | } |
| 156 | EXPORT_SYMBOL_GPL(xprt_unregister_transport); |
| 157 | |
| 158 | /** |
Tom Talpey | 441e3e2 | 2009-03-11 14:37:56 -0400 | [diff] [blame] | 159 | * xprt_load_transport - load a transport implementation |
| 160 | * @transport_name: transport to load |
| 161 | * |
| 162 | * Returns: |
| 163 | * 0: transport successfully loaded |
| 164 | * -ENOENT: transport module not available |
| 165 | */ |
| 166 | int xprt_load_transport(const char *transport_name) |
| 167 | { |
| 168 | struct xprt_class *t; |
Tom Talpey | 441e3e2 | 2009-03-11 14:37:56 -0400 | [diff] [blame] | 169 | int result; |
| 170 | |
| 171 | result = 0; |
| 172 | spin_lock(&xprt_list_lock); |
| 173 | list_for_each_entry(t, &xprt_list, list) { |
| 174 | if (strcmp(t->name, transport_name) == 0) { |
| 175 | spin_unlock(&xprt_list_lock); |
| 176 | goto out; |
| 177 | } |
| 178 | } |
| 179 | spin_unlock(&xprt_list_lock); |
Alex Riesen | ef7ffe8 | 2010-05-24 14:33:05 -0700 | [diff] [blame] | 180 | result = request_module("xprt%s", transport_name); |
Tom Talpey | 441e3e2 | 2009-03-11 14:37:56 -0400 | [diff] [blame] | 181 | out: |
| 182 | return result; |
| 183 | } |
| 184 | EXPORT_SYMBOL_GPL(xprt_load_transport); |
| 185 | |
| 186 | /** |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 187 | * xprt_reserve_xprt - serialize write access to transports |
| 188 | * @task: task that is requesting access to the transport |
| 189 | * |
| 190 | * This prevents mixing the payload of separate requests, and prevents |
| 191 | * transport connects from colliding with writes. No congestion control |
| 192 | * is provided. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | */ |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 194 | int xprt_reserve_xprt(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 196 | struct rpc_rqst *req = task->tk_rqstp; |
Rahul Iyer | 343952f | 2009-04-01 09:23:17 -0400 | [diff] [blame] | 197 | struct rpc_xprt *xprt = req->rq_xprt; |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 198 | |
| 199 | if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) { |
| 200 | if (task == xprt->snd_task) |
| 201 | return 1; |
| 202 | if (task == NULL) |
| 203 | return 0; |
| 204 | goto out_sleep; |
| 205 | } |
| 206 | xprt->snd_task = task; |
| 207 | if (req) { |
| 208 | req->rq_bytes_sent = 0; |
| 209 | req->rq_ntrans++; |
| 210 | } |
| 211 | return 1; |
| 212 | |
| 213 | out_sleep: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 214 | dprintk("RPC: %5u failed to lock transport %p\n", |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 215 | task->tk_pid, xprt); |
| 216 | task->tk_timeout = 0; |
| 217 | task->tk_status = -EAGAIN; |
| 218 | if (req && req->rq_ntrans) |
Trond Myklebust | 5d00837 | 2008-02-22 16:34:17 -0500 | [diff] [blame] | 219 | rpc_sleep_on(&xprt->resend, task, NULL); |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 220 | else |
Trond Myklebust | 5d00837 | 2008-02-22 16:34:17 -0500 | [diff] [blame] | 221 | rpc_sleep_on(&xprt->sending, task, NULL); |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 222 | return 0; |
| 223 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame] | 224 | EXPORT_SYMBOL_GPL(xprt_reserve_xprt); |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 225 | |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 226 | static void xprt_clear_locked(struct rpc_xprt *xprt) |
| 227 | { |
| 228 | xprt->snd_task = NULL; |
| 229 | if (!test_bit(XPRT_CLOSE_WAIT, &xprt->state) || xprt->shutdown) { |
| 230 | smp_mb__before_clear_bit(); |
| 231 | clear_bit(XPRT_LOCKED, &xprt->state); |
| 232 | smp_mb__after_clear_bit(); |
| 233 | } else |
Trond Myklebust | c1384c9 | 2007-06-14 18:00:42 -0400 | [diff] [blame] | 234 | queue_work(rpciod_workqueue, &xprt->task_cleanup); |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 235 | } |
| 236 | |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 237 | /* |
| 238 | * xprt_reserve_xprt_cong - serialize write access to transports |
| 239 | * @task: task that is requesting access to the transport |
| 240 | * |
| 241 | * Same as xprt_reserve_xprt, but Van Jacobson congestion control is |
| 242 | * integrated into the decision of whether a request is allowed to be |
| 243 | * woken up and given access to the transport. |
| 244 | */ |
| 245 | int xprt_reserve_xprt_cong(struct rpc_task *task) |
| 246 | { |
| 247 | struct rpc_xprt *xprt = task->tk_xprt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | struct rpc_rqst *req = task->tk_rqstp; |
| 249 | |
Chuck Lever | 2226feb | 2005-08-11 16:25:38 -0400 | [diff] [blame] | 250 | if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | if (task == xprt->snd_task) |
| 252 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | goto out_sleep; |
| 254 | } |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 255 | if (__xprt_get_cong(xprt, task)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | xprt->snd_task = task; |
| 257 | if (req) { |
| 258 | req->rq_bytes_sent = 0; |
| 259 | req->rq_ntrans++; |
| 260 | } |
| 261 | return 1; |
| 262 | } |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 263 | xprt_clear_locked(xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | out_sleep: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 265 | 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] | 266 | task->tk_timeout = 0; |
| 267 | task->tk_status = -EAGAIN; |
| 268 | if (req && req->rq_ntrans) |
Trond Myklebust | 5d00837 | 2008-02-22 16:34:17 -0500 | [diff] [blame] | 269 | rpc_sleep_on(&xprt->resend, task, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | else |
Trond Myklebust | 5d00837 | 2008-02-22 16:34:17 -0500 | [diff] [blame] | 271 | rpc_sleep_on(&xprt->sending, task, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | return 0; |
| 273 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame] | 274 | EXPORT_SYMBOL_GPL(xprt_reserve_xprt_cong); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 276 | 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] | 277 | { |
| 278 | int retval; |
| 279 | |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 280 | spin_lock_bh(&xprt->transport_lock); |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 281 | retval = xprt->ops->reserve_xprt(task); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 282 | spin_unlock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | return retval; |
| 284 | } |
| 285 | |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 286 | static void __xprt_lock_write_next(struct rpc_xprt *xprt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { |
| 288 | struct rpc_task *task; |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 289 | struct rpc_rqst *req; |
| 290 | |
| 291 | if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) |
| 292 | return; |
| 293 | |
| 294 | task = rpc_wake_up_next(&xprt->resend); |
| 295 | if (!task) { |
| 296 | task = rpc_wake_up_next(&xprt->sending); |
| 297 | if (!task) |
| 298 | goto out_unlock; |
| 299 | } |
| 300 | |
| 301 | req = task->tk_rqstp; |
| 302 | xprt->snd_task = task; |
| 303 | if (req) { |
| 304 | req->rq_bytes_sent = 0; |
| 305 | req->rq_ntrans++; |
| 306 | } |
| 307 | return; |
| 308 | |
| 309 | out_unlock: |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 310 | xprt_clear_locked(xprt); |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | static void __xprt_lock_write_next_cong(struct rpc_xprt *xprt) |
| 314 | { |
| 315 | struct rpc_task *task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Chuck Lever | 2226feb | 2005-08-11 16:25:38 -0400 | [diff] [blame] | 317 | if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | return; |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 319 | if (RPCXPRT_CONGESTED(xprt)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | goto out_unlock; |
| 321 | task = rpc_wake_up_next(&xprt->resend); |
| 322 | if (!task) { |
| 323 | task = rpc_wake_up_next(&xprt->sending); |
| 324 | if (!task) |
| 325 | goto out_unlock; |
| 326 | } |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 327 | if (__xprt_get_cong(xprt, task)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | struct rpc_rqst *req = task->tk_rqstp; |
| 329 | xprt->snd_task = task; |
| 330 | if (req) { |
| 331 | req->rq_bytes_sent = 0; |
| 332 | req->rq_ntrans++; |
| 333 | } |
| 334 | return; |
| 335 | } |
| 336 | out_unlock: |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 337 | xprt_clear_locked(xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 340 | /** |
| 341 | * xprt_release_xprt - allow other requests to use a transport |
| 342 | * @xprt: transport with other tasks potentially waiting |
| 343 | * @task: task that is releasing access to the transport |
| 344 | * |
| 345 | * Note that "task" can be NULL. No congestion control is provided. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | */ |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 347 | void xprt_release_xprt(struct rpc_xprt *xprt, struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
| 349 | if (xprt->snd_task == task) { |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 350 | xprt_clear_locked(xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | __xprt_lock_write_next(xprt); |
| 352 | } |
| 353 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame] | 354 | EXPORT_SYMBOL_GPL(xprt_release_xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 356 | /** |
| 357 | * xprt_release_xprt_cong - allow other requests to use a transport |
| 358 | * @xprt: transport with other tasks potentially waiting |
| 359 | * @task: task that is releasing access to the transport |
| 360 | * |
| 361 | * Note that "task" can be NULL. Another task is awoken to use the |
| 362 | * transport if the transport's congestion window allows it. |
| 363 | */ |
| 364 | void xprt_release_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task) |
| 365 | { |
| 366 | if (xprt->snd_task == task) { |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 367 | xprt_clear_locked(xprt); |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 368 | __xprt_lock_write_next_cong(xprt); |
| 369 | } |
| 370 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame] | 371 | EXPORT_SYMBOL_GPL(xprt_release_xprt_cong); |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 372 | |
| 373 | 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] | 374 | { |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 375 | spin_lock_bh(&xprt->transport_lock); |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 376 | xprt->ops->release_xprt(xprt, task); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 377 | spin_unlock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | * Van Jacobson congestion avoidance. Check if the congestion window |
| 382 | * overflowed. Put the task to sleep if this is the case. |
| 383 | */ |
| 384 | static int |
| 385 | __xprt_get_cong(struct rpc_xprt *xprt, struct rpc_task *task) |
| 386 | { |
| 387 | struct rpc_rqst *req = task->tk_rqstp; |
| 388 | |
| 389 | if (req->rq_cong) |
| 390 | return 1; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 391 | dprintk("RPC: %5u xprt_cwnd_limited cong = %lu cwnd = %lu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | task->tk_pid, xprt->cong, xprt->cwnd); |
| 393 | if (RPCXPRT_CONGESTED(xprt)) |
| 394 | return 0; |
| 395 | req->rq_cong = 1; |
| 396 | xprt->cong += RPC_CWNDSCALE; |
| 397 | return 1; |
| 398 | } |
| 399 | |
| 400 | /* |
| 401 | * Adjust the congestion window, and wake up the next task |
| 402 | * that has been sleeping due to congestion |
| 403 | */ |
| 404 | static void |
| 405 | __xprt_put_cong(struct rpc_xprt *xprt, struct rpc_rqst *req) |
| 406 | { |
| 407 | if (!req->rq_cong) |
| 408 | return; |
| 409 | req->rq_cong = 0; |
| 410 | xprt->cong -= RPC_CWNDSCALE; |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 411 | __xprt_lock_write_next_cong(xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 414 | /** |
Chuck Lever | a58dd39 | 2005-08-25 16:25:53 -0700 | [diff] [blame] | 415 | * xprt_release_rqst_cong - housekeeping when request is complete |
| 416 | * @task: RPC request that recently completed |
| 417 | * |
| 418 | * Useful for transports that require congestion control. |
| 419 | */ |
| 420 | void xprt_release_rqst_cong(struct rpc_task *task) |
| 421 | { |
| 422 | __xprt_put_cong(task->tk_xprt, task->tk_rqstp); |
| 423 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame] | 424 | EXPORT_SYMBOL_GPL(xprt_release_rqst_cong); |
Chuck Lever | a58dd39 | 2005-08-25 16:25:53 -0700 | [diff] [blame] | 425 | |
| 426 | /** |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 427 | * xprt_adjust_cwnd - adjust transport congestion window |
| 428 | * @task: recently completed RPC request used to adjust window |
| 429 | * @result: result code of completed RPC request |
| 430 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | * We use a time-smoothed congestion estimator to avoid heavy oscillation. |
| 432 | */ |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 433 | void xprt_adjust_cwnd(struct rpc_task *task, int result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | { |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 435 | struct rpc_rqst *req = task->tk_rqstp; |
| 436 | struct rpc_xprt *xprt = task->tk_xprt; |
| 437 | unsigned long cwnd = xprt->cwnd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | if (result >= 0 && cwnd <= xprt->cong) { |
| 440 | /* The (cwnd >> 1) term makes sure |
| 441 | * the result gets rounded properly. */ |
| 442 | cwnd += (RPC_CWNDSCALE * RPC_CWNDSCALE + (cwnd >> 1)) / cwnd; |
| 443 | if (cwnd > RPC_MAXCWND(xprt)) |
| 444 | cwnd = RPC_MAXCWND(xprt); |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 445 | __xprt_lock_write_next_cong(xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } else if (result == -ETIMEDOUT) { |
| 447 | cwnd >>= 1; |
| 448 | if (cwnd < RPC_CWNDSCALE) |
| 449 | cwnd = RPC_CWNDSCALE; |
| 450 | } |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 451 | dprintk("RPC: cong %ld, cwnd was %ld, now %ld\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | xprt->cong, xprt->cwnd, cwnd); |
| 453 | xprt->cwnd = cwnd; |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 454 | __xprt_put_cong(xprt, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame] | 456 | EXPORT_SYMBOL_GPL(xprt_adjust_cwnd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
Chuck Lever | 44fbac2 | 2005-08-11 16:25:44 -0400 | [diff] [blame] | 458 | /** |
| 459 | * xprt_wake_pending_tasks - wake all tasks on a transport's pending queue |
| 460 | * @xprt: transport with waiting tasks |
| 461 | * @status: result code to plant in each task before waking it |
| 462 | * |
| 463 | */ |
| 464 | void xprt_wake_pending_tasks(struct rpc_xprt *xprt, int status) |
| 465 | { |
| 466 | if (status < 0) |
| 467 | rpc_wake_up_status(&xprt->pending, status); |
| 468 | else |
| 469 | rpc_wake_up(&xprt->pending); |
| 470 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame] | 471 | EXPORT_SYMBOL_GPL(xprt_wake_pending_tasks); |
Chuck Lever | 44fbac2 | 2005-08-11 16:25:44 -0400 | [diff] [blame] | 472 | |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 473 | /** |
| 474 | * xprt_wait_for_buffer_space - wait for transport output buffer to clear |
| 475 | * @task: task to be put to sleep |
Randy Dunlap | 0b80ae4 | 2008-04-26 22:59:02 -0700 | [diff] [blame] | 476 | * @action: function pointer to be executed after wait |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 477 | */ |
Trond Myklebust | b6ddf64 | 2008-04-17 18:52:19 -0400 | [diff] [blame] | 478 | void xprt_wait_for_buffer_space(struct rpc_task *task, rpc_action action) |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 479 | { |
| 480 | struct rpc_rqst *req = task->tk_rqstp; |
| 481 | struct rpc_xprt *xprt = req->rq_xprt; |
| 482 | |
| 483 | task->tk_timeout = req->rq_timeout; |
Trond Myklebust | b6ddf64 | 2008-04-17 18:52:19 -0400 | [diff] [blame] | 484 | rpc_sleep_on(&xprt->pending, task, action); |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 485 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame] | 486 | EXPORT_SYMBOL_GPL(xprt_wait_for_buffer_space); |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 487 | |
| 488 | /** |
| 489 | * xprt_write_space - wake the task waiting for transport output buffer space |
| 490 | * @xprt: transport with waiting tasks |
| 491 | * |
| 492 | * Can be called in a soft IRQ context, so xprt_write_space never sleeps. |
| 493 | */ |
| 494 | void xprt_write_space(struct rpc_xprt *xprt) |
| 495 | { |
| 496 | if (unlikely(xprt->shutdown)) |
| 497 | return; |
| 498 | |
| 499 | spin_lock_bh(&xprt->transport_lock); |
| 500 | if (xprt->snd_task) { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 501 | dprintk("RPC: write space: waking waiting task on " |
| 502 | "xprt %p\n", xprt); |
Trond Myklebust | fda1393 | 2008-02-22 16:34:12 -0500 | [diff] [blame] | 503 | rpc_wake_up_queued_task(&xprt->pending, xprt->snd_task); |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 504 | } |
| 505 | spin_unlock_bh(&xprt->transport_lock); |
| 506 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame] | 507 | EXPORT_SYMBOL_GPL(xprt_write_space); |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 508 | |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 509 | /** |
| 510 | * xprt_set_retrans_timeout_def - set a request's retransmit timeout |
| 511 | * @task: task whose timeout is to be set |
| 512 | * |
| 513 | * Set a request's retransmit timeout based on the transport's |
| 514 | * default timeout parameters. Used by transports that don't adjust |
| 515 | * the retransmit timeout based on round-trip time estimation. |
| 516 | */ |
| 517 | void xprt_set_retrans_timeout_def(struct rpc_task *task) |
| 518 | { |
| 519 | task->tk_timeout = task->tk_rqstp->rq_timeout; |
| 520 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame] | 521 | EXPORT_SYMBOL_GPL(xprt_set_retrans_timeout_def); |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 522 | |
| 523 | /* |
| 524 | * xprt_set_retrans_timeout_rtt - set a request's retransmit timeout |
| 525 | * @task: task whose timeout is to be set |
YOSHIFUJI Hideaki | cca5172 | 2007-02-09 15:38:13 -0800 | [diff] [blame] | 526 | * |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 527 | * Set a request's retransmit timeout using the RTT estimator. |
| 528 | */ |
| 529 | void xprt_set_retrans_timeout_rtt(struct rpc_task *task) |
| 530 | { |
| 531 | int timer = task->tk_msg.rpc_proc->p_timer; |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 532 | struct rpc_clnt *clnt = task->tk_client; |
| 533 | struct rpc_rtt *rtt = clnt->cl_rtt; |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 534 | struct rpc_rqst *req = task->tk_rqstp; |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 535 | unsigned long max_timeout = clnt->cl_timeout->to_maxval; |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 536 | |
| 537 | task->tk_timeout = rpc_calc_rto(rtt, timer); |
| 538 | task->tk_timeout <<= rpc_ntimeo(rtt, timer) + req->rq_retries; |
| 539 | if (task->tk_timeout > max_timeout || task->tk_timeout == 0) |
| 540 | task->tk_timeout = max_timeout; |
| 541 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame] | 542 | EXPORT_SYMBOL_GPL(xprt_set_retrans_timeout_rtt); |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | static void xprt_reset_majortimeo(struct rpc_rqst *req) |
| 545 | { |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 546 | const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
| 548 | req->rq_majortimeo = req->rq_timeout; |
| 549 | if (to->to_exponential) |
| 550 | req->rq_majortimeo <<= to->to_retries; |
| 551 | else |
| 552 | req->rq_majortimeo += to->to_increment * to->to_retries; |
| 553 | if (req->rq_majortimeo > to->to_maxval || req->rq_majortimeo == 0) |
| 554 | req->rq_majortimeo = to->to_maxval; |
| 555 | req->rq_majortimeo += jiffies; |
| 556 | } |
| 557 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 558 | /** |
| 559 | * xprt_adjust_timeout - adjust timeout values for next retransmit |
| 560 | * @req: RPC request containing parameters to use for the adjustment |
| 561 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | */ |
| 563 | int xprt_adjust_timeout(struct rpc_rqst *req) |
| 564 | { |
| 565 | struct rpc_xprt *xprt = req->rq_xprt; |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 566 | const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | int status = 0; |
| 568 | |
| 569 | if (time_before(jiffies, req->rq_majortimeo)) { |
| 570 | if (to->to_exponential) |
| 571 | req->rq_timeout <<= 1; |
| 572 | else |
| 573 | req->rq_timeout += to->to_increment; |
| 574 | if (to->to_maxval && req->rq_timeout >= to->to_maxval) |
| 575 | req->rq_timeout = to->to_maxval; |
| 576 | req->rq_retries++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | } else { |
| 578 | req->rq_timeout = to->to_initval; |
| 579 | req->rq_retries = 0; |
| 580 | xprt_reset_majortimeo(req); |
| 581 | /* Reset the RTT counters == "slow start" */ |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 582 | spin_lock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | 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] | 584 | spin_unlock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | status = -ETIMEDOUT; |
| 586 | } |
| 587 | |
| 588 | if (req->rq_timeout == 0) { |
| 589 | printk(KERN_WARNING "xprt_adjust_timeout: rq_timeout = 0!\n"); |
| 590 | req->rq_timeout = 5 * HZ; |
| 591 | } |
| 592 | return status; |
| 593 | } |
| 594 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 595 | static void xprt_autoclose(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 597 | struct rpc_xprt *xprt = |
| 598 | container_of(work, struct rpc_xprt, task_cleanup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 600 | xprt->ops->close(xprt); |
Trond Myklebust | 66af1e5 | 2007-11-06 10:18:36 -0500 | [diff] [blame] | 601 | clear_bit(XPRT_CLOSE_WAIT, &xprt->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | xprt_release_write(xprt, NULL); |
| 603 | } |
| 604 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 605 | /** |
Trond Myklebust | 62da3b2 | 2007-11-06 18:44:20 -0500 | [diff] [blame] | 606 | * xprt_disconnect_done - mark a transport as disconnected |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 607 | * @xprt: transport to flag for disconnect |
| 608 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | */ |
Trond Myklebust | 62da3b2 | 2007-11-06 18:44:20 -0500 | [diff] [blame] | 610 | void xprt_disconnect_done(struct rpc_xprt *xprt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 612 | dprintk("RPC: disconnected transport %p\n", xprt); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 613 | spin_lock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | xprt_clear_connected(xprt); |
Trond Myklebust | 2a49199 | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 615 | xprt_wake_pending_tasks(xprt, -EAGAIN); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 616 | spin_unlock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | } |
Trond Myklebust | 62da3b2 | 2007-11-06 18:44:20 -0500 | [diff] [blame] | 618 | EXPORT_SYMBOL_GPL(xprt_disconnect_done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
Trond Myklebust | 66af1e5 | 2007-11-06 10:18:36 -0500 | [diff] [blame] | 620 | /** |
| 621 | * xprt_force_disconnect - force a transport to disconnect |
| 622 | * @xprt: transport to disconnect |
| 623 | * |
| 624 | */ |
| 625 | void xprt_force_disconnect(struct rpc_xprt *xprt) |
| 626 | { |
| 627 | /* Don't race with the test_bit() in xprt_clear_locked() */ |
| 628 | spin_lock_bh(&xprt->transport_lock); |
| 629 | set_bit(XPRT_CLOSE_WAIT, &xprt->state); |
| 630 | /* Try to schedule an autoclose RPC call */ |
| 631 | if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0) |
| 632 | queue_work(rpciod_workqueue, &xprt->task_cleanup); |
Trond Myklebust | 2a49199 | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 633 | xprt_wake_pending_tasks(xprt, -EAGAIN); |
Trond Myklebust | 66af1e5 | 2007-11-06 10:18:36 -0500 | [diff] [blame] | 634 | spin_unlock_bh(&xprt->transport_lock); |
| 635 | } |
Trond Myklebust | 66af1e5 | 2007-11-06 10:18:36 -0500 | [diff] [blame] | 636 | |
Trond Myklebust | 7c1d71c | 2008-04-17 16:52:57 -0400 | [diff] [blame] | 637 | /** |
| 638 | * xprt_conditional_disconnect - force a transport to disconnect |
| 639 | * @xprt: transport to disconnect |
| 640 | * @cookie: 'connection cookie' |
| 641 | * |
| 642 | * This attempts to break the connection if and only if 'cookie' matches |
| 643 | * the current transport 'connection cookie'. It ensures that we don't |
| 644 | * try to break the connection more than once when we need to retransmit |
| 645 | * a batch of RPC requests. |
| 646 | * |
| 647 | */ |
| 648 | void xprt_conditional_disconnect(struct rpc_xprt *xprt, unsigned int cookie) |
| 649 | { |
| 650 | /* Don't race with the test_bit() in xprt_clear_locked() */ |
| 651 | spin_lock_bh(&xprt->transport_lock); |
| 652 | if (cookie != xprt->connect_cookie) |
| 653 | goto out; |
| 654 | if (test_bit(XPRT_CLOSING, &xprt->state) || !xprt_connected(xprt)) |
| 655 | goto out; |
| 656 | set_bit(XPRT_CLOSE_WAIT, &xprt->state); |
| 657 | /* Try to schedule an autoclose RPC call */ |
| 658 | if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0) |
| 659 | queue_work(rpciod_workqueue, &xprt->task_cleanup); |
Trond Myklebust | 2a49199 | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 660 | xprt_wake_pending_tasks(xprt, -EAGAIN); |
Trond Myklebust | 7c1d71c | 2008-04-17 16:52:57 -0400 | [diff] [blame] | 661 | out: |
| 662 | spin_unlock_bh(&xprt->transport_lock); |
| 663 | } |
| 664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | static void |
| 666 | xprt_init_autodisconnect(unsigned long data) |
| 667 | { |
| 668 | struct rpc_xprt *xprt = (struct rpc_xprt *)data; |
| 669 | |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 670 | spin_lock(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | if (!list_empty(&xprt->recv) || xprt->shutdown) |
| 672 | goto out_abort; |
Chuck Lever | 2226feb | 2005-08-11 16:25:38 -0400 | [diff] [blame] | 673 | if (test_and_set_bit(XPRT_LOCKED, &xprt->state)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | goto out_abort; |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 675 | spin_unlock(&xprt->transport_lock); |
Trond Myklebust | f75e674 | 2009-04-21 17:18:20 -0400 | [diff] [blame] | 676 | set_bit(XPRT_CONNECTION_CLOSE, &xprt->state); |
| 677 | queue_work(rpciod_workqueue, &xprt->task_cleanup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | return; |
| 679 | out_abort: |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 680 | spin_unlock(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 683 | /** |
| 684 | * xprt_connect - schedule a transport connect operation |
| 685 | * @task: RPC task that is requesting the connect |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | * |
| 687 | */ |
| 688 | void xprt_connect(struct rpc_task *task) |
| 689 | { |
| 690 | struct rpc_xprt *xprt = task->tk_xprt; |
| 691 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 692 | 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] | 693 | xprt, (xprt_connected(xprt) ? "is" : "is not")); |
| 694 | |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 695 | if (!xprt_bound(xprt)) { |
Trond Myklebust | 01d37c4 | 2009-03-11 14:09:39 -0400 | [diff] [blame] | 696 | task->tk_status = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | return; |
| 698 | } |
| 699 | if (!xprt_lock_write(xprt, task)) |
| 700 | return; |
Trond Myklebust | feb8ca3 | 2009-12-03 08:10:17 -0500 | [diff] [blame] | 701 | |
| 702 | if (test_and_clear_bit(XPRT_CLOSE_WAIT, &xprt->state)) |
| 703 | xprt->ops->close(xprt); |
| 704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | if (xprt_connected(xprt)) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 706 | xprt_release_write(xprt, task); |
| 707 | else { |
| 708 | if (task->tk_rqstp) |
| 709 | task->tk_rqstp->rq_bytes_sent = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | |
Trond Myklebust | a8ce4a8 | 2010-04-16 16:42:12 -0400 | [diff] [blame] | 711 | task->tk_timeout = task->tk_rqstp->rq_timeout; |
Trond Myklebust | 5d00837 | 2008-02-22 16:34:17 -0500 | [diff] [blame] | 712 | rpc_sleep_on(&xprt->pending, task, xprt_connect_status); |
Trond Myklebust | 0b9e794 | 2010-04-16 16:41:57 -0400 | [diff] [blame] | 713 | |
| 714 | if (test_bit(XPRT_CLOSING, &xprt->state)) |
| 715 | return; |
| 716 | if (xprt_test_and_set_connecting(xprt)) |
| 717 | return; |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 718 | xprt->stat.connect_start = jiffies; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 719 | xprt->ops->connect(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | } |
| 722 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 723 | static void xprt_connect_status(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | { |
| 725 | struct rpc_xprt *xprt = task->tk_xprt; |
| 726 | |
Chuck Lever | cd983ef | 2008-06-11 17:56:13 -0400 | [diff] [blame] | 727 | if (task->tk_status == 0) { |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 728 | xprt->stat.connect_count++; |
| 729 | xprt->stat.connect_time += (long)jiffies - xprt->stat.connect_start; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 730 | dprintk("RPC: %5u xprt_connect_status: connection established\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | task->tk_pid); |
| 732 | return; |
| 733 | } |
| 734 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | switch (task->tk_status) { |
Trond Myklebust | 2a49199 | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 736 | case -EAGAIN: |
| 737 | dprintk("RPC: %5u xprt_connect_status: retrying\n", task->tk_pid); |
Chuck Lever | 23475d6 | 2005-08-11 16:25:08 -0400 | [diff] [blame] | 738 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | case -ETIMEDOUT: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 740 | dprintk("RPC: %5u xprt_connect_status: connect attempt timed " |
| 741 | "out\n", task->tk_pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | break; |
| 743 | default: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 744 | dprintk("RPC: %5u xprt_connect_status: error %d connecting to " |
| 745 | "server %s\n", task->tk_pid, -task->tk_status, |
| 746 | task->tk_client->cl_server); |
Chuck Lever | 23475d6 | 2005-08-11 16:25:08 -0400 | [diff] [blame] | 747 | xprt_release_write(xprt, task); |
| 748 | task->tk_status = -EIO; |
Chuck Lever | 23475d6 | 2005-08-11 16:25:08 -0400 | [diff] [blame] | 749 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | } |
| 751 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 752 | /** |
| 753 | * xprt_lookup_rqst - find an RPC request corresponding to an XID |
| 754 | * @xprt: transport on which the original request was transmitted |
| 755 | * @xid: RPC XID of incoming reply |
| 756 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | */ |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 758 | struct rpc_rqst *xprt_lookup_rqst(struct rpc_xprt *xprt, __be32 xid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | { |
| 760 | struct list_head *pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
| 762 | list_for_each(pos, &xprt->recv) { |
| 763 | struct rpc_rqst *entry = list_entry(pos, struct rpc_rqst, rq_list); |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 764 | if (entry->rq_xid == xid) |
| 765 | return entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 767 | |
| 768 | dprintk("RPC: xprt_lookup_rqst did not find xid %08x\n", |
| 769 | ntohl(xid)); |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 770 | xprt->stat.bad_xids++; |
| 771 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame] | 773 | EXPORT_SYMBOL_GPL(xprt_lookup_rqst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
Chuck Lever | bbc72ce | 2010-05-07 13:34:27 -0400 | [diff] [blame] | 775 | static void xprt_update_rtt(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | { |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 777 | struct rpc_rqst *req = task->tk_rqstp; |
| 778 | struct rpc_rtt *rtt = task->tk_client->cl_rtt; |
| 779 | unsigned timer = task->tk_msg.rpc_proc->p_timer; |
Trond Myklebust | d60dbb2 | 2010-05-13 12:51:49 -0400 | [diff] [blame] | 780 | long m = usecs_to_jiffies(ktime_to_us(req->rq_rtt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 782 | if (timer) { |
| 783 | if (req->rq_ntrans == 1) |
Chuck Lever | ff83997 | 2010-05-07 13:34:47 -0400 | [diff] [blame] | 784 | rpc_update_rtt(rtt, timer, m); |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 785 | rpc_set_timeo(rtt, timer, req->rq_ntrans - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | } |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 787 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 789 | /** |
| 790 | * xprt_complete_rqst - called when reply processing is complete |
| 791 | * @task: RPC request that recently completed |
| 792 | * @copied: actual number of bytes received from the transport |
| 793 | * |
| 794 | * Caller holds transport lock. |
| 795 | */ |
| 796 | void xprt_complete_rqst(struct rpc_task *task, int copied) |
| 797 | { |
| 798 | struct rpc_rqst *req = task->tk_rqstp; |
Trond Myklebust | fda1393 | 2008-02-22 16:34:12 -0500 | [diff] [blame] | 799 | struct rpc_xprt *xprt = req->rq_xprt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 801 | dprintk("RPC: %5u xid %08x complete (%d bytes received)\n", |
| 802 | task->tk_pid, ntohl(req->rq_xid), copied); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
Trond Myklebust | fda1393 | 2008-02-22 16:34:12 -0500 | [diff] [blame] | 804 | xprt->stat.recvs++; |
Trond Myklebust | d60dbb2 | 2010-05-13 12:51:49 -0400 | [diff] [blame] | 805 | req->rq_rtt = ktime_sub(ktime_get(), req->rq_xtime); |
Chuck Lever | bbc72ce | 2010-05-07 13:34:27 -0400 | [diff] [blame] | 806 | if (xprt->ops->timer != NULL) |
| 807 | xprt_update_rtt(task); |
Chuck Lever | ef759a2 | 2006-03-20 13:44:17 -0500 | [diff] [blame] | 808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | list_del_init(&req->rq_list); |
Trond Myklebust | 1e799b6 | 2008-03-21 16:19:41 -0400 | [diff] [blame] | 810 | req->rq_private_buf.len = copied; |
Ricardo Labiaga | dd2b63d | 2009-04-01 09:23:28 -0400 | [diff] [blame] | 811 | /* Ensure all writes are done before we update */ |
| 812 | /* req->rq_reply_bytes_recvd */ |
Trond Myklebust | 43ac3f2 | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 813 | smp_wmb(); |
Ricardo Labiaga | dd2b63d | 2009-04-01 09:23:28 -0400 | [diff] [blame] | 814 | req->rq_reply_bytes_recvd = copied; |
Trond Myklebust | fda1393 | 2008-02-22 16:34:12 -0500 | [diff] [blame] | 815 | rpc_wake_up_queued_task(&xprt->pending, task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame] | 817 | EXPORT_SYMBOL_GPL(xprt_complete_rqst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 819 | static void xprt_timer(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | { |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 821 | struct rpc_rqst *req = task->tk_rqstp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | struct rpc_xprt *xprt = req->rq_xprt; |
| 823 | |
Trond Myklebust | 5d00837 | 2008-02-22 16:34:17 -0500 | [diff] [blame] | 824 | if (task->tk_status != -ETIMEDOUT) |
| 825 | return; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 826 | dprintk("RPC: %5u xprt_timer\n", task->tk_pid); |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 827 | |
Trond Myklebust | 5d00837 | 2008-02-22 16:34:17 -0500 | [diff] [blame] | 828 | spin_lock_bh(&xprt->transport_lock); |
Ricardo Labiaga | dd2b63d | 2009-04-01 09:23:28 -0400 | [diff] [blame] | 829 | if (!req->rq_reply_bytes_recvd) { |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 830 | if (xprt->ops->timer) |
| 831 | xprt->ops->timer(task); |
Trond Myklebust | 5d00837 | 2008-02-22 16:34:17 -0500 | [diff] [blame] | 832 | } else |
| 833 | task->tk_status = 0; |
| 834 | spin_unlock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Rahul Iyer | 4cfc7e6 | 2009-09-10 17:32:28 +0300 | [diff] [blame] | 837 | static inline int xprt_has_timer(struct rpc_xprt *xprt) |
| 838 | { |
| 839 | return xprt->idle_timeout != 0; |
| 840 | } |
| 841 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 842 | /** |
| 843 | * xprt_prepare_transmit - reserve the transport before sending a request |
| 844 | * @task: RPC task about to send a request |
| 845 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | */ |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 847 | int xprt_prepare_transmit(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | { |
| 849 | struct rpc_rqst *req = task->tk_rqstp; |
| 850 | struct rpc_xprt *xprt = req->rq_xprt; |
| 851 | int err = 0; |
| 852 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 853 | dprintk("RPC: %5u xprt_prepare_transmit\n", task->tk_pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 855 | spin_lock_bh(&xprt->transport_lock); |
Ricardo Labiaga | dd2b63d | 2009-04-01 09:23:28 -0400 | [diff] [blame] | 856 | if (req->rq_reply_bytes_recvd && !req->rq_bytes_sent) { |
| 857 | err = req->rq_reply_bytes_recvd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | goto out_unlock; |
| 859 | } |
Trond Myklebust | 2a49199 | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 860 | if (!xprt->ops->reserve_xprt(task)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | out_unlock: |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 863 | spin_unlock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | return err; |
| 865 | } |
| 866 | |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 867 | void xprt_end_transmit(struct rpc_task *task) |
Trond Myklebust | 5e5ce5b | 2005-10-18 14:20:11 -0700 | [diff] [blame] | 868 | { |
Rahul Iyer | 343952f | 2009-04-01 09:23:17 -0400 | [diff] [blame] | 869 | xprt_release_write(task->tk_rqstp->rq_xprt, task); |
Trond Myklebust | 5e5ce5b | 2005-10-18 14:20:11 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 872 | /** |
| 873 | * xprt_transmit - send an RPC request on a transport |
| 874 | * @task: controlling RPC task |
| 875 | * |
| 876 | * We have to copy the iovec because sendmsg fiddles with its contents. |
| 877 | */ |
| 878 | void xprt_transmit(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | struct rpc_rqst *req = task->tk_rqstp; |
| 881 | struct rpc_xprt *xprt = req->rq_xprt; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 882 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 884 | 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] | 885 | |
Ricardo Labiaga | dd2b63d | 2009-04-01 09:23:28 -0400 | [diff] [blame] | 886 | if (!req->rq_reply_bytes_recvd) { |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 887 | if (list_empty(&req->rq_list) && rpc_reply_expected(task)) { |
| 888 | /* |
| 889 | * Add to the list only if we're expecting a reply |
| 890 | */ |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 891 | spin_lock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | /* Update the softirq receive buffer */ |
| 893 | memcpy(&req->rq_private_buf, &req->rq_rcv_buf, |
| 894 | sizeof(req->rq_private_buf)); |
| 895 | /* Add request to the receive list */ |
| 896 | list_add_tail(&req->rq_list, &xprt->recv); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 897 | spin_unlock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | xprt_reset_majortimeo(req); |
Trond Myklebust | 0f9dc2b | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 899 | /* Turn off autodisconnect */ |
| 900 | del_singleshot_timer_sync(&xprt->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | } |
| 902 | } else if (!req->rq_bytes_sent) |
| 903 | return; |
| 904 | |
Trond Myklebust | 7c1d71c | 2008-04-17 16:52:57 -0400 | [diff] [blame] | 905 | req->rq_connect_cookie = xprt->connect_cookie; |
Chuck Lever | ff83997 | 2010-05-07 13:34:47 -0400 | [diff] [blame] | 906 | req->rq_xtime = ktime_get(); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 907 | status = xprt->ops->send_request(task); |
Trond Myklebust | c8485e4 | 2009-03-11 14:37:59 -0400 | [diff] [blame] | 908 | if (status != 0) { |
| 909 | task->tk_status = status; |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 910 | return; |
| 911 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | |
Trond Myklebust | c8485e4 | 2009-03-11 14:37:59 -0400 | [diff] [blame] | 913 | dprintk("RPC: %5u xmit complete\n", task->tk_pid); |
| 914 | spin_lock_bh(&xprt->transport_lock); |
| 915 | |
| 916 | xprt->ops->set_retrans_timeout(task); |
| 917 | |
| 918 | xprt->stat.sends++; |
| 919 | xprt->stat.req_u += xprt->stat.sends - xprt->stat.recvs; |
| 920 | xprt->stat.bklog_u += xprt->backlog.qlen; |
| 921 | |
| 922 | /* Don't race with disconnect */ |
| 923 | if (!xprt_connected(xprt)) |
| 924 | task->tk_status = -ENOTCONN; |
Ricardo Labiaga | dd2b63d | 2009-04-01 09:23:28 -0400 | [diff] [blame] | 925 | else if (!req->rq_reply_bytes_recvd && rpc_reply_expected(task)) { |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 926 | /* |
| 927 | * Sleep on the pending queue since |
| 928 | * we're expecting a reply. |
| 929 | */ |
Trond Myklebust | c8485e4 | 2009-03-11 14:37:59 -0400 | [diff] [blame] | 930 | rpc_sleep_on(&xprt->pending, task, xprt_timer); |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 931 | } |
Trond Myklebust | c8485e4 | 2009-03-11 14:37:59 -0400 | [diff] [blame] | 932 | spin_unlock_bh(&xprt->transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | } |
| 934 | |
Trond Myklebust | ee5ebe8 | 2010-04-16 16:37:01 -0400 | [diff] [blame] | 935 | static void xprt_alloc_slot(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | { |
| 937 | struct rpc_xprt *xprt = task->tk_xprt; |
| 938 | |
| 939 | task->tk_status = 0; |
| 940 | if (task->tk_rqstp) |
| 941 | return; |
| 942 | if (!list_empty(&xprt->free)) { |
| 943 | struct rpc_rqst *req = list_entry(xprt->free.next, struct rpc_rqst, rq_list); |
| 944 | list_del_init(&req->rq_list); |
| 945 | task->tk_rqstp = req; |
| 946 | xprt_request_init(task, xprt); |
| 947 | return; |
| 948 | } |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 949 | dprintk("RPC: waiting for request slot\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | task->tk_status = -EAGAIN; |
| 951 | task->tk_timeout = 0; |
Trond Myklebust | 5d00837 | 2008-02-22 16:34:17 -0500 | [diff] [blame] | 952 | rpc_sleep_on(&xprt->backlog, task, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | } |
| 954 | |
Trond Myklebust | ee5ebe8 | 2010-04-16 16:37:01 -0400 | [diff] [blame] | 955 | static void xprt_free_slot(struct rpc_xprt *xprt, struct rpc_rqst *req) |
| 956 | { |
| 957 | memset(req, 0, sizeof(*req)); /* mark unused */ |
| 958 | |
| 959 | spin_lock(&xprt->reserve_lock); |
| 960 | list_add(&req->rq_list, &xprt->free); |
| 961 | rpc_wake_up_next(&xprt->backlog); |
| 962 | spin_unlock(&xprt->reserve_lock); |
| 963 | } |
| 964 | |
Pavel Emelyanov | 37aa213 | 2010-09-29 16:05:43 +0400 | [diff] [blame^] | 965 | struct rpc_xprt *xprt_alloc(struct net *net, int size, int max_req) |
Pavel Emelyanov | bd1722d | 2010-09-29 16:02:43 +0400 | [diff] [blame] | 966 | { |
| 967 | struct rpc_xprt *xprt; |
| 968 | |
| 969 | xprt = kzalloc(size, GFP_KERNEL); |
| 970 | if (xprt == NULL) |
| 971 | goto out; |
| 972 | |
| 973 | xprt->max_reqs = max_req; |
| 974 | xprt->slot = kcalloc(max_req, sizeof(struct rpc_rqst), GFP_KERNEL); |
| 975 | if (xprt->slot == NULL) |
| 976 | goto out_free; |
| 977 | |
Pavel Emelyanov | 37aa213 | 2010-09-29 16:05:43 +0400 | [diff] [blame^] | 978 | xprt->xprt_net = get_net(net); |
Pavel Emelyanov | bd1722d | 2010-09-29 16:02:43 +0400 | [diff] [blame] | 979 | return xprt; |
| 980 | |
| 981 | out_free: |
| 982 | kfree(xprt); |
| 983 | out: |
| 984 | return NULL; |
| 985 | } |
| 986 | EXPORT_SYMBOL_GPL(xprt_alloc); |
| 987 | |
Pavel Emelyanov | e204e62 | 2010-09-29 16:03:13 +0400 | [diff] [blame] | 988 | void xprt_free(struct rpc_xprt *xprt) |
| 989 | { |
Pavel Emelyanov | 37aa213 | 2010-09-29 16:05:43 +0400 | [diff] [blame^] | 990 | put_net(xprt->xprt_net); |
Pavel Emelyanov | e204e62 | 2010-09-29 16:03:13 +0400 | [diff] [blame] | 991 | kfree(xprt->slot); |
| 992 | kfree(xprt); |
| 993 | } |
| 994 | EXPORT_SYMBOL_GPL(xprt_free); |
| 995 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 996 | /** |
| 997 | * xprt_reserve - allocate an RPC request slot |
| 998 | * @task: RPC task requesting a slot allocation |
| 999 | * |
| 1000 | * If no more slots are available, place the task on the transport's |
| 1001 | * backlog queue. |
| 1002 | */ |
| 1003 | void xprt_reserve(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | { |
| 1005 | struct rpc_xprt *xprt = task->tk_xprt; |
| 1006 | |
| 1007 | task->tk_status = -EIO; |
Trond Myklebust | 0065db3 | 2006-01-03 09:55:56 +0100 | [diff] [blame] | 1008 | spin_lock(&xprt->reserve_lock); |
Trond Myklebust | ee5ebe8 | 2010-04-16 16:37:01 -0400 | [diff] [blame] | 1009 | xprt_alloc_slot(task); |
Trond Myklebust | 0065db3 | 2006-01-03 09:55:56 +0100 | [diff] [blame] | 1010 | spin_unlock(&xprt->reserve_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1013 | static inline __be32 xprt_alloc_xid(struct rpc_xprt *xprt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | { |
Eric Dumazet | 0eae88f | 2010-04-20 19:06:52 -0700 | [diff] [blame] | 1015 | return (__force __be32)xprt->xid++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | static inline void xprt_init_xid(struct rpc_xprt *xprt) |
| 1019 | { |
Chuck Lever | bf3fcf8 | 2006-05-25 01:40:51 -0400 | [diff] [blame] | 1020 | xprt->xid = net_random(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1023 | 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] | 1024 | { |
| 1025 | struct rpc_rqst *req = task->tk_rqstp; |
| 1026 | |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 1027 | req->rq_timeout = task->tk_client->cl_timeout->to_initval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | req->rq_task = task; |
| 1029 | req->rq_xprt = xprt; |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 1030 | req->rq_buffer = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | req->rq_xid = xprt_alloc_xid(xprt); |
J. Bruce Fields | ead5e1c | 2005-10-13 16:54:43 -0400 | [diff] [blame] | 1032 | req->rq_release_snd_buf = NULL; |
Trond Myklebust | da45828 | 2006-08-31 15:44:52 -0400 | [diff] [blame] | 1033 | xprt_reset_majortimeo(req); |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1034 | dprintk("RPC: %5u reserved req %p xid %08x\n", task->tk_pid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | req, ntohl(req->rq_xid)); |
| 1036 | } |
| 1037 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1038 | /** |
| 1039 | * xprt_release - release an RPC request slot |
| 1040 | * @task: task which is finished with the slot |
| 1041 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | */ |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1043 | void xprt_release(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | { |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1045 | struct rpc_xprt *xprt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | struct rpc_rqst *req; |
| 1047 | |
| 1048 | if (!(req = task->tk_rqstp)) |
| 1049 | return; |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1050 | |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1051 | xprt = req->rq_xprt; |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 1052 | rpc_count_iostats(task); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 1053 | spin_lock_bh(&xprt->transport_lock); |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 1054 | xprt->ops->release_xprt(xprt, task); |
Chuck Lever | a58dd39 | 2005-08-25 16:25:53 -0700 | [diff] [blame] | 1055 | if (xprt->ops->release_request) |
| 1056 | xprt->ops->release_request(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | if (!list_empty(&req->rq_list)) |
| 1058 | list_del(&req->rq_list); |
| 1059 | xprt->last_used = jiffies; |
Rahul Iyer | 4cfc7e6 | 2009-09-10 17:32:28 +0300 | [diff] [blame] | 1060 | if (list_empty(&xprt->recv) && xprt_has_timer(xprt)) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1061 | mod_timer(&xprt->timer, |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1062 | xprt->last_used + xprt->idle_timeout); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 1063 | spin_unlock_bh(&xprt->transport_lock); |
Trond Myklebust | ee5ebe8 | 2010-04-16 16:37:01 -0400 | [diff] [blame] | 1064 | if (req->rq_buffer) |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1065 | xprt->ops->buf_free(req->rq_buffer); |
Trond Myklebust | a17c215 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 1066 | if (req->rq_cred != NULL) |
| 1067 | put_rpccred(req->rq_cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | task->tk_rqstp = NULL; |
J. Bruce Fields | ead5e1c | 2005-10-13 16:54:43 -0400 | [diff] [blame] | 1069 | if (req->rq_release_snd_buf) |
| 1070 | req->rq_release_snd_buf(req); |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1071 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1072 | dprintk("RPC: %5u release request %p\n", task->tk_pid, req); |
Trond Myklebust | ee5ebe8 | 2010-04-16 16:37:01 -0400 | [diff] [blame] | 1073 | if (likely(!bc_prealloc(req))) |
| 1074 | xprt_free_slot(xprt, req); |
| 1075 | else |
Trond Myklebust | c9acb42 | 2010-03-19 15:36:22 -0400 | [diff] [blame] | 1076 | xprt_free_bc_request(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1079 | /** |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 1080 | * xprt_create_transport - create an RPC transport |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 1081 | * @args: rpc transport creation arguments |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 1082 | * |
| 1083 | */ |
\"Talpey, Thomas\ | 3c341b0b | 2007-09-10 13:47:07 -0400 | [diff] [blame] | 1084 | struct rpc_xprt *xprt_create_transport(struct xprt_create *args) |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 1085 | { |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 1086 | struct rpc_xprt *xprt; |
| 1087 | struct rpc_rqst *req; |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 1088 | struct xprt_class *t; |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 1089 | |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 1090 | spin_lock(&xprt_list_lock); |
| 1091 | list_for_each_entry(t, &xprt_list, list) { |
\"Talpey, Thomas\ | 4fa016e | 2007-09-10 13:47:57 -0400 | [diff] [blame] | 1092 | if (t->ident == args->ident) { |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 1093 | spin_unlock(&xprt_list_lock); |
| 1094 | goto found; |
| 1095 | } |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 1096 | } |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 1097 | spin_unlock(&xprt_list_lock); |
\"Talpey, Thomas\ | 4fa016e | 2007-09-10 13:47:57 -0400 | [diff] [blame] | 1098 | printk(KERN_ERR "RPC: transport (%d) not supported\n", args->ident); |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 1099 | return ERR_PTR(-EIO); |
| 1100 | |
| 1101 | found: |
| 1102 | xprt = t->setup(args); |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 1103 | if (IS_ERR(xprt)) { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1104 | dprintk("RPC: xprt_create_transport: failed, %ld\n", |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 1105 | -PTR_ERR(xprt)); |
| 1106 | return xprt; |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 1107 | } |
| 1108 | |
Trond Myklebust | 6b6ca86 | 2006-09-05 12:55:57 -0400 | [diff] [blame] | 1109 | kref_init(&xprt->kref); |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 1110 | spin_lock_init(&xprt->transport_lock); |
| 1111 | spin_lock_init(&xprt->reserve_lock); |
| 1112 | |
| 1113 | INIT_LIST_HEAD(&xprt->free); |
| 1114 | INIT_LIST_HEAD(&xprt->recv); |
Ricardo Labiaga | f9acac1 | 2009-04-01 09:22:59 -0400 | [diff] [blame] | 1115 | #if defined(CONFIG_NFS_V4_1) |
| 1116 | spin_lock_init(&xprt->bc_pa_lock); |
| 1117 | INIT_LIST_HEAD(&xprt->bc_pa_list); |
| 1118 | #endif /* CONFIG_NFS_V4_1 */ |
| 1119 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 1120 | INIT_WORK(&xprt->task_cleanup, xprt_autoclose); |
Rahul Iyer | 4cfc7e6 | 2009-09-10 17:32:28 +0300 | [diff] [blame] | 1121 | if (xprt_has_timer(xprt)) |
| 1122 | setup_timer(&xprt->timer, xprt_init_autodisconnect, |
| 1123 | (unsigned long)xprt); |
| 1124 | else |
| 1125 | init_timer(&xprt->timer); |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 1126 | xprt->last_used = jiffies; |
| 1127 | xprt->cwnd = RPC_INITCWND; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 1128 | xprt->bind_index = 0; |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 1129 | |
| 1130 | rpc_init_wait_queue(&xprt->binding, "xprt_binding"); |
| 1131 | rpc_init_wait_queue(&xprt->pending, "xprt_pending"); |
| 1132 | rpc_init_wait_queue(&xprt->sending, "xprt_sending"); |
| 1133 | rpc_init_wait_queue(&xprt->resend, "xprt_resend"); |
| 1134 | rpc_init_priority_wait_queue(&xprt->backlog, "xprt_backlog"); |
| 1135 | |
| 1136 | /* initialize free list */ |
| 1137 | for (req = &xprt->slot[xprt->max_reqs-1]; req >= &xprt->slot[0]; req--) |
| 1138 | list_add(&req->rq_list, &xprt->free); |
| 1139 | |
| 1140 | xprt_init_xid(xprt); |
| 1141 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1142 | dprintk("RPC: created transport %p with %u slots\n", xprt, |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 1143 | xprt->max_reqs); |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 1144 | return xprt; |
| 1145 | } |
| 1146 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1147 | /** |
| 1148 | * xprt_destroy - destroy an RPC transport, killing off all requests. |
Trond Myklebust | 6b6ca86 | 2006-09-05 12:55:57 -0400 | [diff] [blame] | 1149 | * @kref: kref for the transport to destroy |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1150 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | */ |
Trond Myklebust | 6b6ca86 | 2006-09-05 12:55:57 -0400 | [diff] [blame] | 1152 | static void xprt_destroy(struct kref *kref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | { |
Trond Myklebust | 6b6ca86 | 2006-09-05 12:55:57 -0400 | [diff] [blame] | 1154 | struct rpc_xprt *xprt = container_of(kref, struct rpc_xprt, kref); |
| 1155 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1156 | dprintk("RPC: destroying transport %p\n", xprt); |
Trond Myklebust | 0065db3 | 2006-01-03 09:55:56 +0100 | [diff] [blame] | 1157 | xprt->shutdown = 1; |
| 1158 | del_timer_sync(&xprt->timer); |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 1159 | |
Trond Myklebust | f6a1cc8 | 2008-02-22 17:06:55 -0500 | [diff] [blame] | 1160 | rpc_destroy_wait_queue(&xprt->binding); |
| 1161 | rpc_destroy_wait_queue(&xprt->pending); |
| 1162 | rpc_destroy_wait_queue(&xprt->sending); |
| 1163 | rpc_destroy_wait_queue(&xprt->resend); |
| 1164 | rpc_destroy_wait_queue(&xprt->backlog); |
J. Bruce Fields | c3ae62ae | 2010-08-03 17:22:20 -0400 | [diff] [blame] | 1165 | cancel_work_sync(&xprt->task_cleanup); |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 1166 | /* |
| 1167 | * Tear down transport state and free the rpc_xprt |
| 1168 | */ |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1169 | xprt->ops->destroy(xprt); |
Trond Myklebust | 6b6ca86 | 2006-09-05 12:55:57 -0400 | [diff] [blame] | 1170 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | |
Trond Myklebust | 6b6ca86 | 2006-09-05 12:55:57 -0400 | [diff] [blame] | 1172 | /** |
| 1173 | * xprt_put - release a reference to an RPC transport. |
| 1174 | * @xprt: pointer to the transport |
| 1175 | * |
| 1176 | */ |
| 1177 | void xprt_put(struct rpc_xprt *xprt) |
| 1178 | { |
| 1179 | kref_put(&xprt->kref, xprt_destroy); |
| 1180 | } |
| 1181 | |
| 1182 | /** |
| 1183 | * xprt_get - return a reference to an RPC transport. |
| 1184 | * @xprt: pointer to the transport |
| 1185 | * |
| 1186 | */ |
| 1187 | struct rpc_xprt *xprt_get(struct rpc_xprt *xprt) |
| 1188 | { |
| 1189 | kref_get(&xprt->kref); |
| 1190 | return xprt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | } |