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