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