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