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