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