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