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