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