Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Chuck Lever | 55aa4f5 | 2005-08-11 16:25:47 -0400 | [diff] [blame] | 2 | * linux/net/sunrpc/clnt.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * This file contains the high-level RPC interface. |
| 5 | * It is modeled as a finite state machine to support both synchronous |
| 6 | * and asynchronous requests. |
| 7 | * |
| 8 | * - RPC header generation and argument serialization. |
| 9 | * - Credential refresh. |
| 10 | * - TCP connect handling. |
| 11 | * - Retry of operation when it is suspected the operation failed because |
| 12 | * of uid squashing on the server, or when the credentials were stale |
| 13 | * and need to be refreshed, or when a packet was damaged in transit. |
| 14 | * This may be have to be moved to the VFS layer. |
| 15 | * |
| 16 | * NB: BSD uses a more intelligent approach to guessing when a request |
| 17 | * or reply has been lost by keeping the RTO estimate for each procedure. |
| 18 | * We currently make do with a constant timeout value. |
| 19 | * |
| 20 | * Copyright (C) 1992,1993 Rick Sladkey <jrs@world.std.com> |
| 21 | * Copyright (C) 1995,1996 Olaf Kirch <okir@monad.swb.de> |
| 22 | */ |
| 23 | |
| 24 | #include <asm/system.h> |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/types.h> |
| 28 | #include <linux/mm.h> |
| 29 | #include <linux/slab.h> |
Trond Myklebust | 6d5fcb5 | 2006-10-18 16:01:06 -0400 | [diff] [blame] | 30 | #include <linux/smp_lock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/utsname.h> |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 32 | #include <linux/workqueue.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | #include <linux/sunrpc/clnt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/sunrpc/rpc_pipe_fs.h> |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 36 | #include <linux/sunrpc/metrics.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #ifdef RPC_DEBUG |
| 40 | # define RPCDBG_FACILITY RPCDBG_CALL |
| 41 | #endif |
| 42 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 43 | #define dprint_status(t) \ |
| 44 | dprintk("RPC: %5u %s (status %d)\n", t->tk_pid, \ |
| 45 | __FUNCTION__, t->tk_status) |
| 46 | |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 47 | /* |
| 48 | * All RPC clients are linked into this list |
| 49 | */ |
| 50 | static LIST_HEAD(all_clients); |
| 51 | static DEFINE_SPINLOCK(rpc_client_lock); |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | static DECLARE_WAIT_QUEUE_HEAD(destroy_wait); |
| 54 | |
| 55 | |
| 56 | static void call_start(struct rpc_task *task); |
| 57 | static void call_reserve(struct rpc_task *task); |
| 58 | static void call_reserveresult(struct rpc_task *task); |
| 59 | static void call_allocate(struct rpc_task *task); |
| 60 | static void call_encode(struct rpc_task *task); |
| 61 | static void call_decode(struct rpc_task *task); |
| 62 | static void call_bind(struct rpc_task *task); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 63 | static void call_bind_status(struct rpc_task *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | static void call_transmit(struct rpc_task *task); |
| 65 | static void call_status(struct rpc_task *task); |
Trond Myklebust | 940e331 | 2005-11-09 21:45:24 -0500 | [diff] [blame] | 66 | static void call_transmit_status(struct rpc_task *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | static void call_refresh(struct rpc_task *task); |
| 68 | static void call_refreshresult(struct rpc_task *task); |
| 69 | static void call_timeout(struct rpc_task *task); |
| 70 | static void call_connect(struct rpc_task *task); |
| 71 | static void call_connect_status(struct rpc_task *task); |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 72 | static __be32 * call_header(struct rpc_task *task); |
| 73 | static __be32 * call_verify(struct rpc_task *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 75 | static void rpc_register_client(struct rpc_clnt *clnt) |
| 76 | { |
| 77 | spin_lock(&rpc_client_lock); |
| 78 | list_add(&clnt->cl_clients, &all_clients); |
| 79 | spin_unlock(&rpc_client_lock); |
| 80 | } |
| 81 | |
| 82 | static void rpc_unregister_client(struct rpc_clnt *clnt) |
| 83 | { |
| 84 | spin_lock(&rpc_client_lock); |
| 85 | list_del(&clnt->cl_clients); |
| 86 | spin_unlock(&rpc_client_lock); |
| 87 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | static int |
| 90 | rpc_setup_pipedir(struct rpc_clnt *clnt, char *dir_name) |
| 91 | { |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 92 | static uint32_t clntid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | int error; |
| 94 | |
Trond Myklebust | 5428154 | 2006-03-20 13:44:49 -0500 | [diff] [blame] | 95 | clnt->cl_vfsmnt = ERR_PTR(-ENOENT); |
| 96 | clnt->cl_dentry = ERR_PTR(-ENOENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | if (dir_name == NULL) |
| 98 | return 0; |
Trond Myklebust | 5428154 | 2006-03-20 13:44:49 -0500 | [diff] [blame] | 99 | |
| 100 | clnt->cl_vfsmnt = rpc_get_mount(); |
| 101 | if (IS_ERR(clnt->cl_vfsmnt)) |
| 102 | return PTR_ERR(clnt->cl_vfsmnt); |
| 103 | |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 104 | for (;;) { |
| 105 | snprintf(clnt->cl_pathname, sizeof(clnt->cl_pathname), |
| 106 | "%s/clnt%x", dir_name, |
| 107 | (unsigned int)clntid++); |
| 108 | clnt->cl_pathname[sizeof(clnt->cl_pathname) - 1] = '\0'; |
| 109 | clnt->cl_dentry = rpc_mkdir(clnt->cl_pathname, clnt); |
| 110 | if (!IS_ERR(clnt->cl_dentry)) |
| 111 | return 0; |
Christoph Hellwig | 278c995 | 2005-07-24 23:53:01 +0100 | [diff] [blame] | 112 | error = PTR_ERR(clnt->cl_dentry); |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 113 | if (error != -EEXIST) { |
| 114 | printk(KERN_INFO "RPC: Couldn't create pipefs entry %s, error %d\n", |
| 115 | clnt->cl_pathname, error); |
Trond Myklebust | 5428154 | 2006-03-20 13:44:49 -0500 | [diff] [blame] | 116 | rpc_put_mount(); |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 117 | return error; |
| 118 | } |
Christoph Hellwig | 278c995 | 2005-07-24 23:53:01 +0100 | [diff] [blame] | 119 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Chuck Lever | ff9aa5e | 2006-08-22 20:06:21 -0400 | [diff] [blame] | 122 | static struct rpc_clnt * rpc_new_client(struct rpc_xprt *xprt, char *servname, struct rpc_program *program, u32 vers, rpc_authflavor_t flavor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | struct rpc_version *version; |
| 125 | struct rpc_clnt *clnt = NULL; |
J. Bruce Fields | 6a19275 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 126 | struct rpc_auth *auth; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | int err; |
| 128 | int len; |
| 129 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 130 | dprintk("RPC: creating %s client for %s (xprt %p)\n", |
| 131 | program->name, servname, xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Trond Myklebust | 4ada539 | 2007-06-14 17:26:17 -0400 | [diff] [blame] | 133 | err = rpciod_up(); |
| 134 | if (err) |
| 135 | goto out_no_rpciod; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | err = -EINVAL; |
| 137 | if (!xprt) |
Adrian Bunk | 712917d | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 138 | goto out_no_xprt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | if (vers >= program->nrvers || !(version = program->version[vers])) |
| 140 | goto out_err; |
| 141 | |
| 142 | err = -ENOMEM; |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 143 | clnt = kzalloc(sizeof(*clnt), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | if (!clnt) |
| 145 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | clnt->cl_parent = clnt; |
| 147 | |
| 148 | clnt->cl_server = clnt->cl_inline_name; |
| 149 | len = strlen(servname) + 1; |
| 150 | if (len > sizeof(clnt->cl_inline_name)) { |
| 151 | char *buf = kmalloc(len, GFP_KERNEL); |
| 152 | if (buf != 0) |
| 153 | clnt->cl_server = buf; |
| 154 | else |
| 155 | len = sizeof(clnt->cl_inline_name); |
| 156 | } |
| 157 | strlcpy(clnt->cl_server, servname, len); |
| 158 | |
| 159 | clnt->cl_xprt = xprt; |
| 160 | clnt->cl_procinfo = version->procs; |
| 161 | clnt->cl_maxproc = version->nrprocs; |
| 162 | clnt->cl_protname = program->name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | clnt->cl_prog = program->number; |
| 164 | clnt->cl_vers = version->number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | clnt->cl_stats = program->stats; |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 166 | clnt->cl_metrics = rpc_alloc_iostats(clnt); |
Trond Myklebust | 23bf85b | 2006-11-21 10:40:23 -0500 | [diff] [blame] | 167 | err = -ENOMEM; |
| 168 | if (clnt->cl_metrics == NULL) |
| 169 | goto out_no_stats; |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 170 | clnt->cl_program = program; |
Trond Myklebust | 6529eba | 2007-06-14 16:40:14 -0400 | [diff] [blame] | 171 | INIT_LIST_HEAD(&clnt->cl_tasks); |
Trond Myklebust | 4bef61f | 2007-06-16 14:17:01 -0400 | [diff] [blame] | 172 | spin_lock_init(&clnt->cl_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 174 | if (!xprt_bound(clnt->cl_xprt)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | clnt->cl_autobind = 1; |
| 176 | |
| 177 | clnt->cl_rtt = &clnt->cl_rtt_default; |
| 178 | rpc_init_rtt(&clnt->cl_rtt_default, xprt->timeout.to_initval); |
| 179 | |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 180 | kref_init(&clnt->cl_kref); |
| 181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | err = rpc_setup_pipedir(clnt, program->pipe_dir_name); |
| 183 | if (err < 0) |
| 184 | goto out_no_path; |
| 185 | |
J. Bruce Fields | 6a19275 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 186 | auth = rpcauth_create(flavor, clnt); |
| 187 | if (IS_ERR(auth)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | printk(KERN_INFO "RPC: Couldn't create auth handle (flavor %u)\n", |
| 189 | flavor); |
J. Bruce Fields | 6a19275 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 190 | err = PTR_ERR(auth); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | goto out_no_auth; |
| 192 | } |
| 193 | |
| 194 | /* save the nodename */ |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 195 | clnt->cl_nodelen = strlen(utsname()->nodename); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | if (clnt->cl_nodelen > UNX_MAXNODENAME) |
| 197 | clnt->cl_nodelen = UNX_MAXNODENAME; |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 198 | memcpy(clnt->cl_nodename, utsname()->nodename, clnt->cl_nodelen); |
Trond Myklebust | 6529eba | 2007-06-14 16:40:14 -0400 | [diff] [blame] | 199 | rpc_register_client(clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | return clnt; |
| 201 | |
| 202 | out_no_auth: |
Trond Myklebust | 5428154 | 2006-03-20 13:44:49 -0500 | [diff] [blame] | 203 | if (!IS_ERR(clnt->cl_dentry)) { |
Trond Myklebust | dff02cc | 2006-07-31 14:17:18 -0700 | [diff] [blame] | 204 | rpc_rmdir(clnt->cl_dentry); |
Trond Myklebust | 5428154 | 2006-03-20 13:44:49 -0500 | [diff] [blame] | 205 | rpc_put_mount(); |
| 206 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | out_no_path: |
Trond Myklebust | 23bf85b | 2006-11-21 10:40:23 -0500 | [diff] [blame] | 208 | rpc_free_iostats(clnt->cl_metrics); |
| 209 | out_no_stats: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | if (clnt->cl_server != clnt->cl_inline_name) |
| 211 | kfree(clnt->cl_server); |
| 212 | kfree(clnt); |
| 213 | out_err: |
Trond Myklebust | 6b6ca86 | 2006-09-05 12:55:57 -0400 | [diff] [blame] | 214 | xprt_put(xprt); |
Adrian Bunk | 712917d | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 215 | out_no_xprt: |
Trond Myklebust | 4ada539 | 2007-06-14 17:26:17 -0400 | [diff] [blame] | 216 | rpciod_down(); |
| 217 | out_no_rpciod: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | return ERR_PTR(err); |
| 219 | } |
| 220 | |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 221 | /* |
| 222 | * rpc_create - create an RPC client and transport with one call |
| 223 | * @args: rpc_clnt create argument structure |
| 224 | * |
| 225 | * Creates and initializes an RPC transport and an RPC client. |
| 226 | * |
| 227 | * It can ping the server in order to determine if it is up, and to see if |
| 228 | * it supports this program and version. RPC_CLNT_CREATE_NOPING disables |
| 229 | * this behavior so asynchronous tasks can also use rpc_create. |
| 230 | */ |
| 231 | struct rpc_clnt *rpc_create(struct rpc_create_args *args) |
| 232 | { |
| 233 | struct rpc_xprt *xprt; |
| 234 | struct rpc_clnt *clnt; |
| 235 | |
| 236 | xprt = xprt_create_transport(args->protocol, args->address, |
| 237 | args->addrsize, args->timeout); |
| 238 | if (IS_ERR(xprt)) |
| 239 | return (struct rpc_clnt *)xprt; |
| 240 | |
| 241 | /* |
| 242 | * By default, kernel RPC client connects from a reserved port. |
| 243 | * CAP_NET_BIND_SERVICE will not be set for unprivileged requesters, |
| 244 | * but it is always enabled for rpciod, which handles the connect |
| 245 | * operation. |
| 246 | */ |
| 247 | xprt->resvport = 1; |
| 248 | if (args->flags & RPC_CLNT_CREATE_NONPRIVPORT) |
| 249 | xprt->resvport = 0; |
| 250 | |
| 251 | dprintk("RPC: creating %s client for %s (xprt %p)\n", |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 252 | args->program->name, args->servername, xprt); |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 253 | |
| 254 | clnt = rpc_new_client(xprt, args->servername, args->program, |
| 255 | args->version, args->authflavor); |
| 256 | if (IS_ERR(clnt)) |
| 257 | return clnt; |
| 258 | |
| 259 | if (!(args->flags & RPC_CLNT_CREATE_NOPING)) { |
| 260 | int err = rpc_ping(clnt, RPC_TASK_SOFT|RPC_TASK_NOINTR); |
| 261 | if (err != 0) { |
| 262 | rpc_shutdown_client(clnt); |
| 263 | return ERR_PTR(err); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | clnt->cl_softrtry = 1; |
| 268 | if (args->flags & RPC_CLNT_CREATE_HARDRTRY) |
| 269 | clnt->cl_softrtry = 0; |
| 270 | |
| 271 | if (args->flags & RPC_CLNT_CREATE_INTR) |
| 272 | clnt->cl_intr = 1; |
| 273 | if (args->flags & RPC_CLNT_CREATE_AUTOBIND) |
| 274 | clnt->cl_autobind = 1; |
Chuck Lever | 43d78ef | 2007-02-06 18:26:11 -0500 | [diff] [blame] | 275 | if (args->flags & RPC_CLNT_CREATE_DISCRTRY) |
| 276 | clnt->cl_discrtry = 1; |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 277 | |
| 278 | return clnt; |
| 279 | } |
Chuck Lever | b86acd5 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 280 | EXPORT_SYMBOL_GPL(rpc_create); |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | /* |
| 283 | * This function clones the RPC client structure. It allows us to share the |
| 284 | * same transport while varying parameters such as the authentication |
| 285 | * flavour. |
| 286 | */ |
| 287 | struct rpc_clnt * |
| 288 | rpc_clone_client(struct rpc_clnt *clnt) |
| 289 | { |
| 290 | struct rpc_clnt *new; |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 291 | int err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Arnaldo Carvalho de Melo | e69062b | 2006-11-21 01:21:34 -0200 | [diff] [blame] | 293 | new = kmemdup(clnt, sizeof(*new), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | if (!new) |
| 295 | goto out_no_clnt; |
Trond Myklebust | d431a555 | 2007-06-17 17:07:54 -0400 | [diff] [blame] | 296 | new->cl_parent = clnt; |
| 297 | /* Turn off autobind on clones */ |
| 298 | new->cl_autobind = 0; |
| 299 | INIT_LIST_HEAD(&new->cl_tasks); |
| 300 | spin_lock_init(&new->cl_lock); |
| 301 | rpc_init_rtt(&new->cl_rtt_default, clnt->cl_xprt->timeout.to_initval); |
Trond Myklebust | 23bf85b | 2006-11-21 10:40:23 -0500 | [diff] [blame] | 302 | new->cl_metrics = rpc_alloc_iostats(clnt); |
| 303 | if (new->cl_metrics == NULL) |
| 304 | goto out_no_stats; |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 305 | kref_init(&new->cl_kref); |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 306 | err = rpc_setup_pipedir(new, clnt->cl_program->pipe_dir_name); |
| 307 | if (err != 0) |
| 308 | goto out_no_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | if (new->cl_auth) |
| 310 | atomic_inc(&new->cl_auth->au_count); |
Trond Myklebust | d431a555 | 2007-06-17 17:07:54 -0400 | [diff] [blame] | 311 | xprt_get(clnt->cl_xprt); |
| 312 | kref_get(&clnt->cl_kref); |
Trond Myklebust | 6529eba | 2007-06-14 16:40:14 -0400 | [diff] [blame] | 313 | rpc_register_client(new); |
Trond Myklebust | 4ada539 | 2007-06-14 17:26:17 -0400 | [diff] [blame] | 314 | rpciod_up(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | return new; |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 316 | out_no_path: |
| 317 | rpc_free_iostats(new->cl_metrics); |
Trond Myklebust | 23bf85b | 2006-11-21 10:40:23 -0500 | [diff] [blame] | 318 | out_no_stats: |
| 319 | kfree(new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | out_no_clnt: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 321 | dprintk("RPC: %s: returned error %d\n", __FUNCTION__, err); |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 322 | return ERR_PTR(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /* |
| 326 | * Properly shut down an RPC client, terminating all outstanding |
Trond Myklebust | 90c5755 | 2007-06-09 19:49:36 -0400 | [diff] [blame] | 327 | * requests. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | */ |
Trond Myklebust | 4c402b4 | 2007-06-14 16:40:32 -0400 | [diff] [blame] | 329 | void rpc_shutdown_client(struct rpc_clnt *clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | { |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 331 | dprintk("RPC: shutting down %s client for %s\n", |
| 332 | clnt->cl_protname, clnt->cl_server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 334 | while (!list_empty(&clnt->cl_tasks)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | rpc_killall_tasks(clnt); |
Ingo Molnar | 532347e | 2006-01-09 20:52:53 -0800 | [diff] [blame] | 336 | wait_event_timeout(destroy_wait, |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 337 | list_empty(&clnt->cl_tasks), 1*HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Trond Myklebust | 4c402b4 | 2007-06-14 16:40:32 -0400 | [diff] [blame] | 340 | rpc_release_client(clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | /* |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 344 | * Free an RPC client |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | */ |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 346 | static void |
| 347 | rpc_free_client(struct kref *kref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 349 | struct rpc_clnt *clnt = container_of(kref, struct rpc_clnt, cl_kref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 351 | dprintk("RPC: destroying %s client for %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | clnt->cl_protname, clnt->cl_server); |
| 353 | if (clnt->cl_auth) { |
| 354 | rpcauth_destroy(clnt->cl_auth); |
| 355 | clnt->cl_auth = NULL; |
| 356 | } |
Trond Myklebust | 8f8e7a5 | 2006-08-14 13:11:15 -0400 | [diff] [blame] | 357 | if (!IS_ERR(clnt->cl_dentry)) { |
Trond Myklebust | dff02cc | 2006-07-31 14:17:18 -0700 | [diff] [blame] | 358 | rpc_rmdir(clnt->cl_dentry); |
Trond Myklebust | 8f8e7a5 | 2006-08-14 13:11:15 -0400 | [diff] [blame] | 359 | rpc_put_mount(); |
| 360 | } |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 361 | if (clnt->cl_parent != clnt) { |
Trond Myklebust | 8ad7c89 | 2007-06-14 16:40:32 -0400 | [diff] [blame] | 362 | rpc_release_client(clnt->cl_parent); |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 363 | goto out_free; |
| 364 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | if (clnt->cl_server != clnt->cl_inline_name) |
| 366 | kfree(clnt->cl_server); |
| 367 | out_free: |
Trond Myklebust | 6529eba | 2007-06-14 16:40:14 -0400 | [diff] [blame] | 368 | rpc_unregister_client(clnt); |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 369 | rpc_free_iostats(clnt->cl_metrics); |
| 370 | clnt->cl_metrics = NULL; |
Trond Myklebust | 6b6ca86 | 2006-09-05 12:55:57 -0400 | [diff] [blame] | 371 | xprt_put(clnt->cl_xprt); |
Trond Myklebust | 4ada539 | 2007-06-14 17:26:17 -0400 | [diff] [blame] | 372 | rpciod_down(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | kfree(clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | /* |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 377 | * Release reference to the RPC client |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | */ |
| 379 | void |
| 380 | rpc_release_client(struct rpc_clnt *clnt) |
| 381 | { |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 382 | dprintk("RPC: rpc_release_client(%p)\n", clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 384 | if (list_empty(&clnt->cl_tasks)) |
| 385 | wake_up(&destroy_wait); |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 386 | kref_put(&clnt->cl_kref, rpc_free_client); |
| 387 | } |
| 388 | |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 389 | /** |
| 390 | * rpc_bind_new_program - bind a new RPC program to an existing client |
| 391 | * @old - old rpc_client |
| 392 | * @program - rpc program to set |
| 393 | * @vers - rpc program version |
| 394 | * |
| 395 | * Clones the rpc client and sets up a new RPC program. This is mainly |
| 396 | * of use for enabling different RPC programs to share the same transport. |
| 397 | * The Sun NFSv2/v3 ACL protocol can do this. |
| 398 | */ |
| 399 | struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *old, |
| 400 | struct rpc_program *program, |
| 401 | int vers) |
| 402 | { |
| 403 | struct rpc_clnt *clnt; |
| 404 | struct rpc_version *version; |
| 405 | int err; |
| 406 | |
| 407 | BUG_ON(vers >= program->nrvers || !program->version[vers]); |
| 408 | version = program->version[vers]; |
| 409 | clnt = rpc_clone_client(old); |
| 410 | if (IS_ERR(clnt)) |
| 411 | goto out; |
| 412 | clnt->cl_procinfo = version->procs; |
| 413 | clnt->cl_maxproc = version->nrprocs; |
| 414 | clnt->cl_protname = program->name; |
| 415 | clnt->cl_prog = program->number; |
| 416 | clnt->cl_vers = version->number; |
| 417 | clnt->cl_stats = program->stats; |
| 418 | err = rpc_ping(clnt, RPC_TASK_SOFT|RPC_TASK_NOINTR); |
| 419 | if (err != 0) { |
| 420 | rpc_shutdown_client(clnt); |
| 421 | clnt = ERR_PTR(err); |
| 422 | } |
YOSHIFUJI Hideaki | cca5172 | 2007-02-09 15:38:13 -0800 | [diff] [blame] | 423 | out: |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 424 | return clnt; |
| 425 | } |
| 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | /* |
| 428 | * Default callback for async RPC calls |
| 429 | */ |
| 430 | static void |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 431 | rpc_default_callback(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | { |
| 433 | } |
| 434 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 435 | static const struct rpc_call_ops rpc_default_ops = { |
| 436 | .rpc_call_done = rpc_default_callback, |
| 437 | }; |
| 438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | /* |
Trond Myklebust | 14b218a | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 440 | * Export the signal mask handling for synchronous code that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | * sleeps on RPC calls |
| 442 | */ |
Trond Myklebust | 2bd6157 | 2006-01-03 09:55:19 +0100 | [diff] [blame] | 443 | #define RPC_INTR_SIGNALS (sigmask(SIGHUP) | sigmask(SIGINT) | sigmask(SIGQUIT) | sigmask(SIGTERM)) |
YOSHIFUJI Hideaki | cca5172 | 2007-02-09 15:38:13 -0800 | [diff] [blame] | 444 | |
Trond Myklebust | 14b218a | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 445 | static void rpc_save_sigmask(sigset_t *oldset, int intr) |
| 446 | { |
Trond Myklebust | 2bd6157 | 2006-01-03 09:55:19 +0100 | [diff] [blame] | 447 | unsigned long sigallow = sigmask(SIGKILL); |
Trond Myklebust | 14b218a | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 448 | sigset_t sigmask; |
| 449 | |
| 450 | /* Block all signals except those listed in sigallow */ |
| 451 | if (intr) |
| 452 | sigallow |= RPC_INTR_SIGNALS; |
| 453 | siginitsetinv(&sigmask, sigallow); |
| 454 | sigprocmask(SIG_BLOCK, &sigmask, oldset); |
| 455 | } |
| 456 | |
| 457 | static inline void rpc_task_sigmask(struct rpc_task *task, sigset_t *oldset) |
| 458 | { |
| 459 | rpc_save_sigmask(oldset, !RPC_TASK_UNINTERRUPTIBLE(task)); |
| 460 | } |
| 461 | |
| 462 | static inline void rpc_restore_sigmask(sigset_t *oldset) |
| 463 | { |
| 464 | sigprocmask(SIG_SETMASK, oldset, NULL); |
| 465 | } |
| 466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | void rpc_clnt_sigmask(struct rpc_clnt *clnt, sigset_t *oldset) |
| 468 | { |
Trond Myklebust | 14b218a | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 469 | rpc_save_sigmask(oldset, clnt->cl_intr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | void rpc_clnt_sigunmask(struct rpc_clnt *clnt, sigset_t *oldset) |
| 473 | { |
Trond Myklebust | 14b218a | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 474 | rpc_restore_sigmask(oldset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame^] | 477 | static |
| 478 | struct rpc_task *rpc_do_run_task(struct rpc_clnt *clnt, |
| 479 | struct rpc_message *msg, |
| 480 | int flags, |
| 481 | const struct rpc_call_ops *ops, |
| 482 | void *data) |
| 483 | { |
| 484 | struct rpc_task *task, *ret; |
| 485 | sigset_t oldset; |
| 486 | |
| 487 | task = rpc_new_task(clnt, flags, ops, data); |
| 488 | if (task == NULL) { |
| 489 | rpc_release_calldata(ops, data); |
| 490 | return ERR_PTR(-ENOMEM); |
| 491 | } |
| 492 | |
| 493 | /* Mask signals on synchronous RPC calls and RPCSEC_GSS upcalls */ |
| 494 | rpc_task_sigmask(task, &oldset); |
| 495 | if (msg != NULL) { |
| 496 | rpc_call_setup(task, msg, 0); |
| 497 | if (task->tk_status != 0) { |
| 498 | ret = ERR_PTR(task->tk_status); |
| 499 | rpc_put_task(task); |
| 500 | goto out; |
| 501 | } |
| 502 | } |
| 503 | atomic_inc(&task->tk_count); |
| 504 | rpc_execute(task); |
| 505 | ret = task; |
| 506 | out: |
| 507 | rpc_restore_sigmask(&oldset); |
| 508 | return ret; |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * rpc_call_sync - Perform a synchronous RPC call |
| 513 | * @clnt: pointer to RPC client |
| 514 | * @msg: RPC call parameters |
| 515 | * @flags: RPC call flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | */ |
| 517 | int rpc_call_sync(struct rpc_clnt *clnt, struct rpc_message *msg, int flags) |
| 518 | { |
| 519 | struct rpc_task *task; |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame^] | 520 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | BUG_ON(flags & RPC_TASK_ASYNC); |
| 523 | |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame^] | 524 | task = rpc_do_run_task(clnt, msg, flags, &rpc_default_ops, NULL); |
| 525 | if (IS_ERR(task)) |
| 526 | return PTR_ERR(task); |
Trond Myklebust | e60859a | 2006-01-03 09:55:10 +0100 | [diff] [blame] | 527 | status = task->tk_status; |
Trond Myklebust | bde8f00 | 2007-01-24 11:54:53 -0800 | [diff] [blame] | 528 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | return status; |
| 530 | } |
| 531 | |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame^] | 532 | /** |
| 533 | * rpc_call_async - Perform an asynchronous RPC call |
| 534 | * @clnt: pointer to RPC client |
| 535 | * @msg: RPC call parameters |
| 536 | * @flags: RPC call flags |
| 537 | * @ops: RPC call ops |
| 538 | * @data: user call data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | */ |
| 540 | int |
| 541 | rpc_call_async(struct rpc_clnt *clnt, struct rpc_message *msg, int flags, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 542 | const struct rpc_call_ops *tk_ops, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | { |
| 544 | struct rpc_task *task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame^] | 546 | task = rpc_do_run_task(clnt, msg, flags|RPC_TASK_ASYNC, tk_ops, data); |
| 547 | if (IS_ERR(task)) |
| 548 | return PTR_ERR(task); |
| 549 | rpc_put_task(task); |
| 550 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame^] | 553 | /** |
| 554 | * rpc_run_task - Allocate a new RPC task, then run rpc_execute against it |
| 555 | * @clnt: pointer to RPC client |
| 556 | * @flags: RPC flags |
| 557 | * @ops: RPC call ops |
| 558 | * @data: user call data |
| 559 | */ |
| 560 | struct rpc_task *rpc_run_task(struct rpc_clnt *clnt, int flags, |
| 561 | const struct rpc_call_ops *tk_ops, |
| 562 | void *data) |
| 563 | { |
| 564 | return rpc_do_run_task(clnt, NULL, flags, tk_ops, data); |
| 565 | } |
| 566 | EXPORT_SYMBOL(rpc_run_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
| 568 | void |
| 569 | rpc_call_setup(struct rpc_task *task, struct rpc_message *msg, int flags) |
| 570 | { |
| 571 | task->tk_msg = *msg; |
| 572 | task->tk_flags |= flags; |
| 573 | /* Bind the user cred */ |
| 574 | if (task->tk_msg.rpc_cred != NULL) |
| 575 | rpcauth_holdcred(task); |
| 576 | else |
| 577 | rpcauth_bindcred(task); |
| 578 | |
| 579 | if (task->tk_status == 0) |
| 580 | task->tk_action = call_start; |
| 581 | else |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 582 | task->tk_action = rpc_exit_task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 585 | /** |
| 586 | * rpc_peeraddr - extract remote peer address from clnt's xprt |
| 587 | * @clnt: RPC client structure |
| 588 | * @buf: target buffer |
| 589 | * @size: length of target buffer |
| 590 | * |
| 591 | * Returns the number of bytes that are actually in the stored address. |
| 592 | */ |
| 593 | size_t rpc_peeraddr(struct rpc_clnt *clnt, struct sockaddr *buf, size_t bufsize) |
| 594 | { |
| 595 | size_t bytes; |
| 596 | struct rpc_xprt *xprt = clnt->cl_xprt; |
| 597 | |
| 598 | bytes = sizeof(xprt->addr); |
| 599 | if (bytes > bufsize) |
| 600 | bytes = bufsize; |
| 601 | memcpy(buf, &clnt->cl_xprt->addr, bytes); |
Chuck Lever | c4efcb1 | 2006-08-22 20:06:19 -0400 | [diff] [blame] | 602 | return xprt->addrlen; |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 603 | } |
Chuck Lever | b86acd5 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 604 | EXPORT_SYMBOL_GPL(rpc_peeraddr); |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 605 | |
Chuck Lever | f425eba | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 606 | /** |
| 607 | * rpc_peeraddr2str - return remote peer address in printable format |
| 608 | * @clnt: RPC client structure |
| 609 | * @format: address format |
| 610 | * |
| 611 | */ |
| 612 | char *rpc_peeraddr2str(struct rpc_clnt *clnt, enum rpc_display_format_t format) |
| 613 | { |
| 614 | struct rpc_xprt *xprt = clnt->cl_xprt; |
Chuck Lever | 7559c7a | 2006-12-05 16:35:37 -0500 | [diff] [blame] | 615 | |
| 616 | if (xprt->address_strings[format] != NULL) |
| 617 | return xprt->address_strings[format]; |
| 618 | else |
| 619 | return "unprintable"; |
Chuck Lever | f425eba | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 620 | } |
Chuck Lever | b86acd5 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 621 | EXPORT_SYMBOL_GPL(rpc_peeraddr2str); |
Chuck Lever | f425eba | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | void |
| 624 | rpc_setbufsize(struct rpc_clnt *clnt, unsigned int sndsize, unsigned int rcvsize) |
| 625 | { |
| 626 | struct rpc_xprt *xprt = clnt->cl_xprt; |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 627 | if (xprt->ops->set_buffer_size) |
| 628 | xprt->ops->set_buffer_size(xprt, sndsize, rcvsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | /* |
| 632 | * Return size of largest payload RPC client can support, in bytes |
| 633 | * |
| 634 | * For stream transports, this is one RPC record fragment (see RFC |
| 635 | * 1831), as we don't support multi-record requests yet. For datagram |
| 636 | * transports, this is the size of an IP packet minus the IP, UDP, and |
| 637 | * RPC header sizes. |
| 638 | */ |
| 639 | size_t rpc_max_payload(struct rpc_clnt *clnt) |
| 640 | { |
| 641 | return clnt->cl_xprt->max_payload; |
| 642 | } |
Chuck Lever | b86acd5 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 643 | EXPORT_SYMBOL_GPL(rpc_max_payload); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 645 | /** |
| 646 | * rpc_force_rebind - force transport to check that remote port is unchanged |
| 647 | * @clnt: client to rebind |
| 648 | * |
| 649 | */ |
| 650 | void rpc_force_rebind(struct rpc_clnt *clnt) |
| 651 | { |
| 652 | if (clnt->cl_autobind) |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 653 | xprt_clear_bound(clnt->cl_xprt); |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 654 | } |
Chuck Lever | b86acd5 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 655 | EXPORT_SYMBOL_GPL(rpc_force_rebind); |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | /* |
| 658 | * Restart an (async) RPC call. Usually called from within the |
| 659 | * exit handler. |
| 660 | */ |
| 661 | void |
| 662 | rpc_restart_call(struct rpc_task *task) |
| 663 | { |
| 664 | if (RPC_ASSASSINATED(task)) |
| 665 | return; |
| 666 | |
| 667 | task->tk_action = call_start; |
| 668 | } |
| 669 | |
| 670 | /* |
| 671 | * 0. Initial state |
| 672 | * |
| 673 | * Other FSM states can be visited zero or more times, but |
| 674 | * this state is visited exactly once for each RPC. |
| 675 | */ |
| 676 | static void |
| 677 | call_start(struct rpc_task *task) |
| 678 | { |
| 679 | struct rpc_clnt *clnt = task->tk_client; |
| 680 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 681 | dprintk("RPC: %5u call_start %s%d proc %d (%s)\n", task->tk_pid, |
| 682 | clnt->cl_protname, clnt->cl_vers, |
| 683 | task->tk_msg.rpc_proc->p_proc, |
| 684 | (RPC_IS_ASYNC(task) ? "async" : "sync")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
| 686 | /* Increment call count */ |
| 687 | task->tk_msg.rpc_proc->p_count++; |
| 688 | clnt->cl_stats->rpccnt++; |
| 689 | task->tk_action = call_reserve; |
| 690 | } |
| 691 | |
| 692 | /* |
| 693 | * 1. Reserve an RPC call slot |
| 694 | */ |
| 695 | static void |
| 696 | call_reserve(struct rpc_task *task) |
| 697 | { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 698 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | |
| 700 | if (!rpcauth_uptodatecred(task)) { |
| 701 | task->tk_action = call_refresh; |
| 702 | return; |
| 703 | } |
| 704 | |
| 705 | task->tk_status = 0; |
| 706 | task->tk_action = call_reserveresult; |
| 707 | xprt_reserve(task); |
| 708 | } |
| 709 | |
| 710 | /* |
| 711 | * 1b. Grok the result of xprt_reserve() |
| 712 | */ |
| 713 | static void |
| 714 | call_reserveresult(struct rpc_task *task) |
| 715 | { |
| 716 | int status = task->tk_status; |
| 717 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 718 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
| 720 | /* |
| 721 | * After a call to xprt_reserve(), we must have either |
| 722 | * a request slot or else an error status. |
| 723 | */ |
| 724 | task->tk_status = 0; |
| 725 | if (status >= 0) { |
| 726 | if (task->tk_rqstp) { |
| 727 | task->tk_action = call_allocate; |
| 728 | return; |
| 729 | } |
| 730 | |
| 731 | printk(KERN_ERR "%s: status=%d, but no request slot, exiting\n", |
| 732 | __FUNCTION__, status); |
| 733 | rpc_exit(task, -EIO); |
| 734 | return; |
| 735 | } |
| 736 | |
| 737 | /* |
| 738 | * Even though there was an error, we may have acquired |
| 739 | * a request slot somehow. Make sure not to leak it. |
| 740 | */ |
| 741 | if (task->tk_rqstp) { |
| 742 | printk(KERN_ERR "%s: status=%d, request allocated anyway\n", |
| 743 | __FUNCTION__, status); |
| 744 | xprt_release(task); |
| 745 | } |
| 746 | |
| 747 | switch (status) { |
| 748 | case -EAGAIN: /* woken up; retry */ |
| 749 | task->tk_action = call_reserve; |
| 750 | return; |
| 751 | case -EIO: /* probably a shutdown */ |
| 752 | break; |
| 753 | default: |
| 754 | printk(KERN_ERR "%s: unrecognized error %d, exiting\n", |
| 755 | __FUNCTION__, status); |
| 756 | break; |
| 757 | } |
| 758 | rpc_exit(task, status); |
| 759 | } |
| 760 | |
| 761 | /* |
| 762 | * 2. Allocate the buffer. For details, see sched.c:rpc_malloc. |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 763 | * (Note: buffer memory is freed in xprt_release). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | */ |
| 765 | static void |
| 766 | call_allocate(struct rpc_task *task) |
| 767 | { |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 768 | unsigned int slack = task->tk_auth->au_cslack; |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 769 | struct rpc_rqst *req = task->tk_rqstp; |
| 770 | struct rpc_xprt *xprt = task->tk_xprt; |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 771 | struct rpc_procinfo *proc = task->tk_msg.rpc_proc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 773 | dprint_status(task); |
| 774 | |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 775 | task->tk_status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | task->tk_action = call_bind; |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 777 | |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 778 | if (req->rq_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | return; |
| 780 | |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 781 | if (proc->p_proc != 0) { |
| 782 | BUG_ON(proc->p_arglen == 0); |
| 783 | if (proc->p_decode != NULL) |
| 784 | BUG_ON(proc->p_replen == 0); |
| 785 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 787 | /* |
| 788 | * Calculate the size (in quads) of the RPC call |
| 789 | * and reply headers, and convert both values |
| 790 | * to byte sizes. |
| 791 | */ |
| 792 | req->rq_callsize = RPC_CALLHDRSIZE + (slack << 1) + proc->p_arglen; |
| 793 | req->rq_callsize <<= 2; |
| 794 | req->rq_rcvsize = RPC_REPHDRSIZE + slack + proc->p_replen; |
| 795 | req->rq_rcvsize <<= 2; |
| 796 | |
Chuck Lever | c5a4dd8 | 2007-03-29 16:47:58 -0400 | [diff] [blame] | 797 | req->rq_buffer = xprt->ops->buf_alloc(task, |
| 798 | req->rq_callsize + req->rq_rcvsize); |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 799 | if (req->rq_buffer != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | return; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 801 | |
| 802 | dprintk("RPC: %5u rpc_buffer allocation failed\n", task->tk_pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
Trond Myklebust | 14b218a | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 804 | if (RPC_IS_ASYNC(task) || !signalled()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | xprt_release(task); |
| 806 | task->tk_action = call_reserve; |
| 807 | rpc_delay(task, HZ>>4); |
| 808 | return; |
| 809 | } |
| 810 | |
| 811 | rpc_exit(task, -ERESTARTSYS); |
| 812 | } |
| 813 | |
Trond Myklebust | 940e331 | 2005-11-09 21:45:24 -0500 | [diff] [blame] | 814 | static inline int |
| 815 | rpc_task_need_encode(struct rpc_task *task) |
| 816 | { |
| 817 | return task->tk_rqstp->rq_snd_buf.len == 0; |
| 818 | } |
| 819 | |
| 820 | static inline void |
| 821 | rpc_task_force_reencode(struct rpc_task *task) |
| 822 | { |
| 823 | task->tk_rqstp->rq_snd_buf.len = 0; |
| 824 | } |
| 825 | |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 826 | static inline void |
| 827 | rpc_xdr_buf_init(struct xdr_buf *buf, void *start, size_t len) |
| 828 | { |
| 829 | buf->head[0].iov_base = start; |
| 830 | buf->head[0].iov_len = len; |
| 831 | buf->tail[0].iov_len = 0; |
| 832 | buf->page_len = 0; |
| 833 | buf->len = 0; |
| 834 | buf->buflen = len; |
| 835 | } |
| 836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | /* |
| 838 | * 3. Encode arguments of an RPC call |
| 839 | */ |
| 840 | static void |
| 841 | call_encode(struct rpc_task *task) |
| 842 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | struct rpc_rqst *req = task->tk_rqstp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | kxdrproc_t encode; |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 845 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 847 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 849 | rpc_xdr_buf_init(&req->rq_snd_buf, |
| 850 | req->rq_buffer, |
| 851 | req->rq_callsize); |
| 852 | rpc_xdr_buf_init(&req->rq_rcv_buf, |
| 853 | (char *)req->rq_buffer + req->rq_callsize, |
| 854 | req->rq_rcvsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | |
| 856 | /* Encode header and provided arguments */ |
| 857 | encode = task->tk_msg.rpc_proc->p_encode; |
| 858 | if (!(p = call_header(task))) { |
| 859 | printk(KERN_INFO "RPC: call_header failed, exit EIO\n"); |
| 860 | rpc_exit(task, -EIO); |
| 861 | return; |
| 862 | } |
J. Bruce Fields | f368031 | 2005-10-13 16:54:48 -0400 | [diff] [blame] | 863 | if (encode == NULL) |
| 864 | return; |
| 865 | |
Trond Myklebust | 6d5fcb5 | 2006-10-18 16:01:06 -0400 | [diff] [blame] | 866 | lock_kernel(); |
J. Bruce Fields | f368031 | 2005-10-13 16:54:48 -0400 | [diff] [blame] | 867 | task->tk_status = rpcauth_wrap_req(task, encode, req, p, |
| 868 | task->tk_msg.rpc_argp); |
Trond Myklebust | 6d5fcb5 | 2006-10-18 16:01:06 -0400 | [diff] [blame] | 869 | unlock_kernel(); |
J. Bruce Fields | f368031 | 2005-10-13 16:54:48 -0400 | [diff] [blame] | 870 | if (task->tk_status == -ENOMEM) { |
| 871 | /* XXX: Is this sane? */ |
| 872 | rpc_delay(task, 3*HZ); |
| 873 | task->tk_status = -EAGAIN; |
| 874 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | /* |
| 878 | * 4. Get the server port number if not yet set |
| 879 | */ |
| 880 | static void |
| 881 | call_bind(struct rpc_task *task) |
| 882 | { |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 883 | struct rpc_xprt *xprt = task->tk_xprt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 885 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 887 | task->tk_action = call_connect; |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 888 | if (!xprt_bound(xprt)) { |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 889 | task->tk_action = call_bind_status; |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 890 | task->tk_timeout = xprt->bind_timeout; |
Chuck Lever | bbf7c1d | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 891 | xprt->ops->rpcbind(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | } |
| 893 | } |
| 894 | |
| 895 | /* |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 896 | * 4a. Sort out bind result |
| 897 | */ |
| 898 | static void |
| 899 | call_bind_status(struct rpc_task *task) |
| 900 | { |
| 901 | int status = -EACCES; |
| 902 | |
| 903 | if (task->tk_status >= 0) { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 904 | dprint_status(task); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 905 | task->tk_status = 0; |
| 906 | task->tk_action = call_connect; |
| 907 | return; |
| 908 | } |
| 909 | |
| 910 | switch (task->tk_status) { |
| 911 | case -EACCES: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 912 | dprintk("RPC: %5u remote rpcbind: RPC program/version " |
| 913 | "unavailable\n", task->tk_pid); |
Chuck Lever | ea635a5 | 2005-10-06 23:12:58 -0400 | [diff] [blame] | 914 | rpc_delay(task, 3*HZ); |
Trond Myklebust | da45828 | 2006-08-31 15:44:52 -0400 | [diff] [blame] | 915 | goto retry_timeout; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 916 | case -ETIMEDOUT: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 917 | dprintk("RPC: %5u rpcbind request timed out\n", |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 918 | task->tk_pid); |
Trond Myklebust | da45828 | 2006-08-31 15:44:52 -0400 | [diff] [blame] | 919 | goto retry_timeout; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 920 | case -EPFNOSUPPORT: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 921 | dprintk("RPC: %5u remote rpcbind service unavailable\n", |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 922 | task->tk_pid); |
| 923 | break; |
| 924 | case -EPROTONOSUPPORT: |
Chuck Lever | 00a6e7b | 2007-03-29 16:48:33 -0400 | [diff] [blame] | 925 | dprintk("RPC: %5u remote rpcbind version unavailable, retrying\n", |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 926 | task->tk_pid); |
Chuck Lever | 00a6e7b | 2007-03-29 16:48:33 -0400 | [diff] [blame] | 927 | task->tk_status = 0; |
| 928 | task->tk_action = call_bind; |
| 929 | return; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 930 | default: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 931 | dprintk("RPC: %5u unrecognized rpcbind error (%d)\n", |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 932 | task->tk_pid, -task->tk_status); |
| 933 | status = -EIO; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | rpc_exit(task, status); |
| 937 | return; |
| 938 | |
Trond Myklebust | da45828 | 2006-08-31 15:44:52 -0400 | [diff] [blame] | 939 | retry_timeout: |
| 940 | task->tk_action = call_timeout; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | /* |
| 944 | * 4b. Connect to the RPC server |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | */ |
| 946 | static void |
| 947 | call_connect(struct rpc_task *task) |
| 948 | { |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 949 | struct rpc_xprt *xprt = task->tk_xprt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 951 | dprintk("RPC: %5u call_connect xprt %p %s connected\n", |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 952 | task->tk_pid, xprt, |
| 953 | (xprt_connected(xprt) ? "is" : "is not")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 955 | task->tk_action = call_transmit; |
| 956 | if (!xprt_connected(xprt)) { |
| 957 | task->tk_action = call_connect_status; |
| 958 | if (task->tk_status < 0) |
| 959 | return; |
| 960 | xprt_connect(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | /* |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 965 | * 4c. Sort out connect result |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | */ |
| 967 | static void |
| 968 | call_connect_status(struct rpc_task *task) |
| 969 | { |
| 970 | struct rpc_clnt *clnt = task->tk_client; |
| 971 | int status = task->tk_status; |
| 972 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 973 | dprint_status(task); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 974 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | task->tk_status = 0; |
| 976 | if (status >= 0) { |
| 977 | clnt->cl_stats->netreconn++; |
| 978 | task->tk_action = call_transmit; |
| 979 | return; |
| 980 | } |
| 981 | |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 982 | /* Something failed: remote service port may have changed */ |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 983 | rpc_force_rebind(clnt); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 984 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | switch (status) { |
| 986 | case -ENOTCONN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | case -EAGAIN: |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 988 | task->tk_action = call_bind; |
Trond Myklebust | da45828 | 2006-08-31 15:44:52 -0400 | [diff] [blame] | 989 | if (!RPC_IS_SOFT(task)) |
| 990 | return; |
| 991 | /* if soft mounted, test if we've timed out */ |
| 992 | case -ETIMEDOUT: |
| 993 | task->tk_action = call_timeout; |
| 994 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | } |
Trond Myklebust | da45828 | 2006-08-31 15:44:52 -0400 | [diff] [blame] | 996 | rpc_exit(task, -EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | /* |
| 1000 | * 5. Transmit the RPC request, and wait for reply |
| 1001 | */ |
| 1002 | static void |
| 1003 | call_transmit(struct rpc_task *task) |
| 1004 | { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1005 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | |
| 1007 | task->tk_action = call_status; |
| 1008 | if (task->tk_status < 0) |
| 1009 | return; |
| 1010 | task->tk_status = xprt_prepare_transmit(task); |
| 1011 | if (task->tk_status != 0) |
| 1012 | return; |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 1013 | task->tk_action = call_transmit_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | /* Encode here so that rpcsec_gss can use correct sequence number. */ |
Trond Myklebust | 940e331 | 2005-11-09 21:45:24 -0500 | [diff] [blame] | 1015 | if (rpc_task_need_encode(task)) { |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 1016 | BUG_ON(task->tk_rqstp->rq_bytes_sent != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | call_encode(task); |
Trond Myklebust | 5e5ce5b | 2005-10-18 14:20:11 -0700 | [diff] [blame] | 1018 | /* Did the encode result in an error condition? */ |
| 1019 | if (task->tk_status != 0) |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 1020 | return; |
Trond Myklebust | 5e5ce5b | 2005-10-18 14:20:11 -0700 | [diff] [blame] | 1021 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | xprt_transmit(task); |
| 1023 | if (task->tk_status < 0) |
| 1024 | return; |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 1025 | /* |
| 1026 | * On success, ensure that we call xprt_end_transmit() before sleeping |
| 1027 | * in order to allow access to the socket to other RPC requests. |
| 1028 | */ |
| 1029 | call_transmit_status(task); |
| 1030 | if (task->tk_msg.rpc_proc->p_decode != NULL) |
| 1031 | return; |
| 1032 | task->tk_action = rpc_exit_task; |
| 1033 | rpc_wake_up_task(task); |
| 1034 | } |
| 1035 | |
| 1036 | /* |
| 1037 | * 5a. Handle cleanup after a transmission |
| 1038 | */ |
| 1039 | static void |
| 1040 | call_transmit_status(struct rpc_task *task) |
| 1041 | { |
| 1042 | task->tk_action = call_status; |
| 1043 | /* |
| 1044 | * Special case: if we've been waiting on the socket's write_space() |
| 1045 | * callback, then don't call xprt_end_transmit(). |
| 1046 | */ |
| 1047 | if (task->tk_status == -EAGAIN) |
| 1048 | return; |
| 1049 | xprt_end_transmit(task); |
Trond Myklebust | 940e331 | 2005-11-09 21:45:24 -0500 | [diff] [blame] | 1050 | rpc_task_force_reencode(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | /* |
| 1054 | * 6. Sort out the RPC call status |
| 1055 | */ |
| 1056 | static void |
| 1057 | call_status(struct rpc_task *task) |
| 1058 | { |
| 1059 | struct rpc_clnt *clnt = task->tk_client; |
| 1060 | struct rpc_rqst *req = task->tk_rqstp; |
| 1061 | int status; |
| 1062 | |
| 1063 | if (req->rq_received > 0 && !req->rq_bytes_sent) |
| 1064 | task->tk_status = req->rq_received; |
| 1065 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1066 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | |
| 1068 | status = task->tk_status; |
| 1069 | if (status >= 0) { |
| 1070 | task->tk_action = call_decode; |
| 1071 | return; |
| 1072 | } |
| 1073 | |
| 1074 | task->tk_status = 0; |
| 1075 | switch(status) { |
Trond Myklebust | 7630399 | 2006-08-30 14:32:49 -0400 | [diff] [blame] | 1076 | case -EHOSTDOWN: |
| 1077 | case -EHOSTUNREACH: |
| 1078 | case -ENETUNREACH: |
| 1079 | /* |
| 1080 | * Delay any retries for 3 seconds, then handle as if it |
| 1081 | * were a timeout. |
| 1082 | */ |
| 1083 | rpc_delay(task, 3*HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | case -ETIMEDOUT: |
| 1085 | task->tk_action = call_timeout; |
Trond Myklebust | 241c39b | 2007-04-20 16:12:55 -0400 | [diff] [blame] | 1086 | if (task->tk_client->cl_discrtry) |
| 1087 | xprt_disconnect(task->tk_xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | break; |
| 1089 | case -ECONNREFUSED: |
| 1090 | case -ENOTCONN: |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 1091 | rpc_force_rebind(clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | task->tk_action = call_bind; |
| 1093 | break; |
| 1094 | case -EAGAIN: |
| 1095 | task->tk_action = call_transmit; |
| 1096 | break; |
| 1097 | case -EIO: |
| 1098 | /* shutdown or soft timeout */ |
| 1099 | rpc_exit(task, status); |
| 1100 | break; |
| 1101 | default: |
Chuck Lever | f518e35a | 2006-01-03 09:55:52 +0100 | [diff] [blame] | 1102 | printk("%s: RPC call returned error %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | clnt->cl_protname, -status); |
| 1104 | rpc_exit(task, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | /* |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 1109 | * 6a. Handle RPC timeout |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | * We do not release the request slot, so we keep using the |
| 1111 | * same XID for all retransmits. |
| 1112 | */ |
| 1113 | static void |
| 1114 | call_timeout(struct rpc_task *task) |
| 1115 | { |
| 1116 | struct rpc_clnt *clnt = task->tk_client; |
| 1117 | |
| 1118 | if (xprt_adjust_timeout(task->tk_rqstp) == 0) { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1119 | dprintk("RPC: %5u call_timeout (minor)\n", task->tk_pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | goto retry; |
| 1121 | } |
| 1122 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1123 | dprintk("RPC: %5u call_timeout (major)\n", task->tk_pid); |
Chuck Lever | ef759a2 | 2006-03-20 13:44:17 -0500 | [diff] [blame] | 1124 | task->tk_timeouts++; |
| 1125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | if (RPC_IS_SOFT(task)) { |
Chuck Lever | f518e35a | 2006-01-03 09:55:52 +0100 | [diff] [blame] | 1127 | printk(KERN_NOTICE "%s: server %s not responding, timed out\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | clnt->cl_protname, clnt->cl_server); |
| 1129 | rpc_exit(task, -EIO); |
| 1130 | return; |
| 1131 | } |
| 1132 | |
Chuck Lever | f518e35a | 2006-01-03 09:55:52 +0100 | [diff] [blame] | 1133 | if (!(task->tk_flags & RPC_CALL_MAJORSEEN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | task->tk_flags |= RPC_CALL_MAJORSEEN; |
| 1135 | printk(KERN_NOTICE "%s: server %s not responding, still trying\n", |
| 1136 | clnt->cl_protname, clnt->cl_server); |
| 1137 | } |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 1138 | rpc_force_rebind(clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | |
| 1140 | retry: |
| 1141 | clnt->cl_stats->rpcretrans++; |
| 1142 | task->tk_action = call_bind; |
| 1143 | task->tk_status = 0; |
| 1144 | } |
| 1145 | |
| 1146 | /* |
| 1147 | * 7. Decode the RPC reply |
| 1148 | */ |
| 1149 | static void |
| 1150 | call_decode(struct rpc_task *task) |
| 1151 | { |
| 1152 | struct rpc_clnt *clnt = task->tk_client; |
| 1153 | struct rpc_rqst *req = task->tk_rqstp; |
| 1154 | kxdrproc_t decode = task->tk_msg.rpc_proc->p_decode; |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1155 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1157 | dprintk("RPC: %5u call_decode (status %d)\n", |
| 1158 | task->tk_pid, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | |
Chuck Lever | f518e35a | 2006-01-03 09:55:52 +0100 | [diff] [blame] | 1160 | if (task->tk_flags & RPC_CALL_MAJORSEEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | printk(KERN_NOTICE "%s: server %s OK\n", |
| 1162 | clnt->cl_protname, clnt->cl_server); |
| 1163 | task->tk_flags &= ~RPC_CALL_MAJORSEEN; |
| 1164 | } |
| 1165 | |
| 1166 | if (task->tk_status < 12) { |
| 1167 | if (!RPC_IS_SOFT(task)) { |
| 1168 | task->tk_action = call_bind; |
| 1169 | clnt->cl_stats->rpcretrans++; |
| 1170 | goto out_retry; |
| 1171 | } |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1172 | dprintk("RPC: %s: too small RPC reply size (%d bytes)\n", |
| 1173 | clnt->cl_protname, task->tk_status); |
Trond Myklebust | da45828 | 2006-08-31 15:44:52 -0400 | [diff] [blame] | 1174 | task->tk_action = call_timeout; |
| 1175 | goto out_retry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | } |
| 1177 | |
Trond Myklebust | 43ac3f2 | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 1178 | /* |
| 1179 | * Ensure that we see all writes made by xprt_complete_rqst() |
| 1180 | * before it changed req->rq_received. |
| 1181 | */ |
| 1182 | smp_rmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | req->rq_rcv_buf.len = req->rq_private_buf.len; |
| 1184 | |
| 1185 | /* Check that the softirq receive buffer is valid */ |
| 1186 | WARN_ON(memcmp(&req->rq_rcv_buf, &req->rq_private_buf, |
| 1187 | sizeof(req->rq_rcv_buf)) != 0); |
| 1188 | |
| 1189 | /* Verify the RPC header */ |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1190 | p = call_verify(task); |
| 1191 | if (IS_ERR(p)) { |
| 1192 | if (p == ERR_PTR(-EAGAIN)) |
| 1193 | goto out_retry; |
| 1194 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1197 | task->tk_action = rpc_exit_task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | |
Trond Myklebust | 6d5fcb5 | 2006-10-18 16:01:06 -0400 | [diff] [blame] | 1199 | if (decode) { |
| 1200 | lock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | task->tk_status = rpcauth_unwrap_resp(task, decode, req, p, |
| 1202 | task->tk_msg.rpc_resp); |
Trond Myklebust | 6d5fcb5 | 2006-10-18 16:01:06 -0400 | [diff] [blame] | 1203 | unlock_kernel(); |
| 1204 | } |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1205 | dprintk("RPC: %5u call_decode result %d\n", task->tk_pid, |
| 1206 | task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | return; |
| 1208 | out_retry: |
| 1209 | req->rq_received = req->rq_private_buf.len = 0; |
| 1210 | task->tk_status = 0; |
Trond Myklebust | 241c39b | 2007-04-20 16:12:55 -0400 | [diff] [blame] | 1211 | if (task->tk_client->cl_discrtry) |
| 1212 | xprt_disconnect(task->tk_xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | /* |
| 1216 | * 8. Refresh the credentials if rejected by the server |
| 1217 | */ |
| 1218 | static void |
| 1219 | call_refresh(struct rpc_task *task) |
| 1220 | { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1221 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | |
| 1223 | xprt_release(task); /* Must do to obtain new XID */ |
| 1224 | task->tk_action = call_refreshresult; |
| 1225 | task->tk_status = 0; |
| 1226 | task->tk_client->cl_stats->rpcauthrefresh++; |
| 1227 | rpcauth_refreshcred(task); |
| 1228 | } |
| 1229 | |
| 1230 | /* |
| 1231 | * 8a. Process the results of a credential refresh |
| 1232 | */ |
| 1233 | static void |
| 1234 | call_refreshresult(struct rpc_task *task) |
| 1235 | { |
| 1236 | int status = task->tk_status; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1237 | |
| 1238 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | |
| 1240 | task->tk_status = 0; |
| 1241 | task->tk_action = call_reserve; |
| 1242 | if (status >= 0 && rpcauth_uptodatecred(task)) |
| 1243 | return; |
| 1244 | if (status == -EACCES) { |
| 1245 | rpc_exit(task, -EACCES); |
| 1246 | return; |
| 1247 | } |
| 1248 | task->tk_action = call_refresh; |
| 1249 | if (status != -ETIMEDOUT) |
| 1250 | rpc_delay(task, 3*HZ); |
| 1251 | return; |
| 1252 | } |
| 1253 | |
| 1254 | /* |
| 1255 | * Call header serialization |
| 1256 | */ |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1257 | static __be32 * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | call_header(struct rpc_task *task) |
| 1259 | { |
| 1260 | struct rpc_clnt *clnt = task->tk_client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | struct rpc_rqst *req = task->tk_rqstp; |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1262 | __be32 *p = req->rq_svec[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | |
| 1264 | /* FIXME: check buffer size? */ |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 1265 | |
| 1266 | p = xprt_skip_transport_header(task->tk_xprt, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | *p++ = req->rq_xid; /* XID */ |
| 1268 | *p++ = htonl(RPC_CALL); /* CALL */ |
| 1269 | *p++ = htonl(RPC_VERSION); /* RPC version */ |
| 1270 | *p++ = htonl(clnt->cl_prog); /* program number */ |
| 1271 | *p++ = htonl(clnt->cl_vers); /* program version */ |
| 1272 | *p++ = htonl(task->tk_msg.rpc_proc->p_proc); /* procedure */ |
Trond Myklebust | 334ccfd | 2005-06-22 17:16:19 +0000 | [diff] [blame] | 1273 | p = rpcauth_marshcred(task, p); |
| 1274 | req->rq_slen = xdr_adjust_iovec(&req->rq_svec[0], p); |
| 1275 | return p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | /* |
| 1279 | * Reply header verification |
| 1280 | */ |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1281 | static __be32 * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | call_verify(struct rpc_task *task) |
| 1283 | { |
| 1284 | struct kvec *iov = &task->tk_rqstp->rq_rcv_buf.head[0]; |
| 1285 | int len = task->tk_rqstp->rq_rcv_buf.len >> 2; |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1286 | __be32 *p = iov->iov_base; |
| 1287 | u32 n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | int error = -EACCES; |
| 1289 | |
David Howells | e889649 | 2006-08-24 15:44:19 -0400 | [diff] [blame] | 1290 | if ((task->tk_rqstp->rq_rcv_buf.len & 3) != 0) { |
| 1291 | /* RFC-1014 says that the representation of XDR data must be a |
| 1292 | * multiple of four bytes |
| 1293 | * - if it isn't pointer subtraction in the NFS client may give |
| 1294 | * undefined results |
| 1295 | */ |
| 1296 | printk(KERN_WARNING |
| 1297 | "call_verify: XDR representation not a multiple of" |
| 1298 | " 4 bytes: 0x%x\n", task->tk_rqstp->rq_rcv_buf.len); |
| 1299 | goto out_eio; |
| 1300 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | if ((len -= 3) < 0) |
| 1302 | goto out_overflow; |
| 1303 | p += 1; /* skip XID */ |
| 1304 | |
| 1305 | if ((n = ntohl(*p++)) != RPC_REPLY) { |
| 1306 | printk(KERN_WARNING "call_verify: not an RPC reply: %x\n", n); |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1307 | goto out_garbage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | } |
| 1309 | if ((n = ntohl(*p++)) != RPC_MSG_ACCEPTED) { |
| 1310 | if (--len < 0) |
| 1311 | goto out_overflow; |
| 1312 | switch ((n = ntohl(*p++))) { |
| 1313 | case RPC_AUTH_ERROR: |
| 1314 | break; |
| 1315 | case RPC_MISMATCH: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1316 | dprintk("RPC: %5u %s: RPC call version " |
| 1317 | "mismatch!\n", |
| 1318 | task->tk_pid, __FUNCTION__); |
Andreas Gruenbacher | cdf4770 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 1319 | error = -EPROTONOSUPPORT; |
| 1320 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | default: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1322 | dprintk("RPC: %5u %s: RPC call rejected, " |
| 1323 | "unknown error: %x\n", |
| 1324 | task->tk_pid, __FUNCTION__, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | goto out_eio; |
| 1326 | } |
| 1327 | if (--len < 0) |
| 1328 | goto out_overflow; |
| 1329 | switch ((n = ntohl(*p++))) { |
| 1330 | case RPC_AUTH_REJECTEDCRED: |
| 1331 | case RPC_AUTH_REJECTEDVERF: |
| 1332 | case RPCSEC_GSS_CREDPROBLEM: |
| 1333 | case RPCSEC_GSS_CTXPROBLEM: |
| 1334 | if (!task->tk_cred_retry) |
| 1335 | break; |
| 1336 | task->tk_cred_retry--; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1337 | dprintk("RPC: %5u %s: retry stale creds\n", |
| 1338 | task->tk_pid, __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | rpcauth_invalcred(task); |
| 1340 | task->tk_action = call_refresh; |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1341 | goto out_retry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | case RPC_AUTH_BADCRED: |
| 1343 | case RPC_AUTH_BADVERF: |
| 1344 | /* possibly garbled cred/verf? */ |
| 1345 | if (!task->tk_garb_retry) |
| 1346 | break; |
| 1347 | task->tk_garb_retry--; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1348 | dprintk("RPC: %5u %s: retry garbled creds\n", |
| 1349 | task->tk_pid, __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | task->tk_action = call_bind; |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1351 | goto out_retry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | case RPC_AUTH_TOOWEAK: |
Levent Serinol | 1356b8c | 2006-03-20 13:44:11 -0500 | [diff] [blame] | 1353 | printk(KERN_NOTICE "call_verify: server %s requires stronger " |
| 1354 | "authentication.\n", task->tk_client->cl_server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | break; |
| 1356 | default: |
| 1357 | printk(KERN_WARNING "call_verify: unknown auth error: %x\n", n); |
| 1358 | error = -EIO; |
| 1359 | } |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1360 | dprintk("RPC: %5u %s: call rejected %d\n", |
| 1361 | task->tk_pid, __FUNCTION__, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | goto out_err; |
| 1363 | } |
| 1364 | if (!(p = rpcauth_checkverf(task, p))) { |
| 1365 | printk(KERN_WARNING "call_verify: auth check failed\n"); |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1366 | goto out_garbage; /* bad verifier, retry */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | } |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1368 | len = p - (__be32 *)iov->iov_base - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | if (len < 0) |
| 1370 | goto out_overflow; |
| 1371 | switch ((n = ntohl(*p++))) { |
| 1372 | case RPC_SUCCESS: |
| 1373 | return p; |
| 1374 | case RPC_PROG_UNAVAIL: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1375 | dprintk("RPC: %5u %s: program %u is unsupported by server %s\n", |
| 1376 | task->tk_pid, __FUNCTION__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | (unsigned int)task->tk_client->cl_prog, |
| 1378 | task->tk_client->cl_server); |
Andreas Gruenbacher | cdf4770 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 1379 | error = -EPFNOSUPPORT; |
| 1380 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | case RPC_PROG_MISMATCH: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1382 | dprintk("RPC: %5u %s: program %u, version %u unsupported by " |
| 1383 | "server %s\n", task->tk_pid, __FUNCTION__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | (unsigned int)task->tk_client->cl_prog, |
| 1385 | (unsigned int)task->tk_client->cl_vers, |
| 1386 | task->tk_client->cl_server); |
Andreas Gruenbacher | cdf4770 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 1387 | error = -EPROTONOSUPPORT; |
| 1388 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | case RPC_PROC_UNAVAIL: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1390 | dprintk("RPC: %5u %s: proc %p unsupported by program %u, " |
| 1391 | "version %u on server %s\n", |
| 1392 | task->tk_pid, __FUNCTION__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | task->tk_msg.rpc_proc, |
| 1394 | task->tk_client->cl_prog, |
| 1395 | task->tk_client->cl_vers, |
| 1396 | task->tk_client->cl_server); |
Andreas Gruenbacher | cdf4770 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 1397 | error = -EOPNOTSUPP; |
| 1398 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | case RPC_GARBAGE_ARGS: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1400 | dprintk("RPC: %5u %s: server saw garbage\n", |
| 1401 | task->tk_pid, __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | break; /* retry */ |
| 1403 | default: |
| 1404 | printk(KERN_WARNING "call_verify: server accept status: %x\n", n); |
| 1405 | /* Also retry */ |
| 1406 | } |
| 1407 | |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1408 | out_garbage: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | task->tk_client->cl_stats->rpcgarbage++; |
| 1410 | if (task->tk_garb_retry) { |
| 1411 | task->tk_garb_retry--; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1412 | dprintk("RPC: %5u %s: retrying\n", |
| 1413 | task->tk_pid, __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | task->tk_action = call_bind; |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1415 | out_retry: |
| 1416 | return ERR_PTR(-EAGAIN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | } |
| 1418 | printk(KERN_WARNING "RPC %s: retry failed, exit EIO\n", __FUNCTION__); |
| 1419 | out_eio: |
| 1420 | error = -EIO; |
| 1421 | out_err: |
| 1422 | rpc_exit(task, error); |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1423 | return ERR_PTR(error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | out_overflow: |
| 1425 | printk(KERN_WARNING "RPC %s: server reply was truncated.\n", __FUNCTION__); |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1426 | goto out_garbage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | } |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 1428 | |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1429 | static int rpcproc_encode_null(void *rqstp, __be32 *data, void *obj) |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 1430 | { |
| 1431 | return 0; |
| 1432 | } |
| 1433 | |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1434 | static int rpcproc_decode_null(void *rqstp, __be32 *data, void *obj) |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 1435 | { |
| 1436 | return 0; |
| 1437 | } |
| 1438 | |
| 1439 | static struct rpc_procinfo rpcproc_null = { |
| 1440 | .p_encode = rpcproc_encode_null, |
| 1441 | .p_decode = rpcproc_decode_null, |
| 1442 | }; |
| 1443 | |
| 1444 | int rpc_ping(struct rpc_clnt *clnt, int flags) |
| 1445 | { |
| 1446 | struct rpc_message msg = { |
| 1447 | .rpc_proc = &rpcproc_null, |
| 1448 | }; |
| 1449 | int err; |
| 1450 | msg.rpc_cred = authnull_ops.lookup_cred(NULL, NULL, 0); |
| 1451 | err = rpc_call_sync(clnt, &msg, flags); |
| 1452 | put_rpccred(msg.rpc_cred); |
| 1453 | return err; |
| 1454 | } |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 1455 | |
| 1456 | #ifdef RPC_DEBUG |
| 1457 | void rpc_show_tasks(void) |
| 1458 | { |
| 1459 | struct rpc_clnt *clnt; |
| 1460 | struct rpc_task *t; |
| 1461 | |
| 1462 | spin_lock(&rpc_client_lock); |
| 1463 | if (list_empty(&all_clients)) |
| 1464 | goto out; |
| 1465 | printk("-pid- proc flgs status -client- -prog- --rqstp- -timeout " |
| 1466 | "-rpcwait -action- ---ops--\n"); |
| 1467 | list_for_each_entry(clnt, &all_clients, cl_clients) { |
| 1468 | if (list_empty(&clnt->cl_tasks)) |
| 1469 | continue; |
| 1470 | spin_lock(&clnt->cl_lock); |
| 1471 | list_for_each_entry(t, &clnt->cl_tasks, tk_task) { |
| 1472 | const char *rpc_waitq = "none"; |
| 1473 | |
| 1474 | if (RPC_IS_QUEUED(t)) |
| 1475 | rpc_waitq = rpc_qname(t->u.tk_wait.rpc_waitq); |
| 1476 | |
| 1477 | printk("%5u %04d %04x %6d %8p %6d %8p %8ld %8s %8p %8p\n", |
| 1478 | t->tk_pid, |
| 1479 | (t->tk_msg.rpc_proc ? t->tk_msg.rpc_proc->p_proc : -1), |
| 1480 | t->tk_flags, t->tk_status, |
| 1481 | t->tk_client, |
| 1482 | (t->tk_client ? t->tk_client->cl_prog : 0), |
| 1483 | t->tk_rqstp, t->tk_timeout, |
| 1484 | rpc_waitq, |
| 1485 | t->tk_action, t->tk_ops); |
| 1486 | } |
| 1487 | spin_unlock(&clnt->cl_lock); |
| 1488 | } |
| 1489 | out: |
| 1490 | spin_unlock(&rpc_client_lock); |
| 1491 | } |
| 1492 | #endif |