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 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * Copyright (C) 1992,1993 Rick Sladkey <jrs@world.std.com> |
| 17 | * Copyright (C) 1995,1996 Olaf Kirch <okir@monad.swb.de> |
| 18 | */ |
| 19 | |
| 20 | #include <asm/system.h> |
| 21 | |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/types.h> |
Chuck Lever | cb3997b | 2008-05-21 17:09:41 -0400 | [diff] [blame] | 24 | #include <linux/kallsyms.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/mm.h> |
Trond Myklebust | 23ac658 | 2009-08-09 15:14:25 -0400 | [diff] [blame] | 26 | #include <linux/namei.h> |
| 27 | #include <linux/mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/utsname.h> |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 30 | #include <linux/workqueue.h> |
Chuck Lever | 176e21e | 2011-05-09 15:22:44 -0400 | [diff] [blame] | 31 | #include <linux/in.h> |
Chuck Lever | 510deb0 | 2007-12-10 14:56:24 -0500 | [diff] [blame] | 32 | #include <linux/in6.h> |
Chuck Lever | 176e21e | 2011-05-09 15:22:44 -0400 | [diff] [blame] | 33 | #include <linux/un.h> |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 34 | #include <linux/rcupdate.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #include <linux/sunrpc/clnt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/sunrpc/rpc_pipe_fs.h> |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 38 | #include <linux/sunrpc/metrics.h> |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 39 | #include <linux/sunrpc/bc_xprt.h> |
Steve Dickson | 5753cba | 2012-02-06 10:08:08 -0500 | [diff] [blame] | 40 | #include <trace/events/sunrpc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 42 | #include "sunrpc.h" |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 43 | #include "netns.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #ifdef RPC_DEBUG |
| 46 | # define RPCDBG_FACILITY RPCDBG_CALL |
| 47 | #endif |
| 48 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 49 | #define dprint_status(t) \ |
| 50 | dprintk("RPC: %5u %s (status %d)\n", t->tk_pid, \ |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 51 | __func__, t->tk_status) |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 52 | |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 53 | /* |
| 54 | * All RPC clients are linked into this list |
| 55 | */ |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | static DECLARE_WAIT_QUEUE_HEAD(destroy_wait); |
| 58 | |
| 59 | |
| 60 | static void call_start(struct rpc_task *task); |
| 61 | static void call_reserve(struct rpc_task *task); |
| 62 | static void call_reserveresult(struct rpc_task *task); |
| 63 | static void call_allocate(struct rpc_task *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | static void call_decode(struct rpc_task *task); |
| 65 | static void call_bind(struct rpc_task *task); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 66 | static void call_bind_status(struct rpc_task *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | static void call_transmit(struct rpc_task *task); |
Trond Myklebust | 9e00abc | 2011-07-13 19:20:49 -0400 | [diff] [blame] | 68 | #if defined(CONFIG_SUNRPC_BACKCHANNEL) |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 69 | static void call_bc_transmit(struct rpc_task *task); |
Trond Myklebust | 9e00abc | 2011-07-13 19:20:49 -0400 | [diff] [blame] | 70 | #endif /* CONFIG_SUNRPC_BACKCHANNEL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | static void call_status(struct rpc_task *task); |
Trond Myklebust | 940e331 | 2005-11-09 21:45:24 -0500 | [diff] [blame] | 72 | static void call_transmit_status(struct rpc_task *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | static void call_refresh(struct rpc_task *task); |
| 74 | static void call_refreshresult(struct rpc_task *task); |
| 75 | static void call_timeout(struct rpc_task *task); |
| 76 | static void call_connect(struct rpc_task *task); |
| 77 | static void call_connect_status(struct rpc_task *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Chuck Lever | b0e1c57 | 2008-05-21 17:09:19 -0400 | [diff] [blame] | 79 | static __be32 *rpc_encode_header(struct rpc_task *task); |
| 80 | static __be32 *rpc_verify_header(struct rpc_task *task); |
Chuck Lever | caabea8 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 81 | static int rpc_ping(struct rpc_clnt *clnt); |
Trond Myklebust | 64c91a1 | 2007-06-23 10:17:16 -0400 | [diff] [blame] | 82 | |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 83 | static void rpc_register_client(struct rpc_clnt *clnt) |
| 84 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 85 | struct net *net = rpc_net_ns(clnt); |
| 86 | struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 87 | |
| 88 | spin_lock(&sn->rpc_client_lock); |
| 89 | list_add(&clnt->cl_clients, &sn->all_clients); |
| 90 | spin_unlock(&sn->rpc_client_lock); |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static void rpc_unregister_client(struct rpc_clnt *clnt) |
| 94 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 95 | struct net *net = rpc_net_ns(clnt); |
| 96 | struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 97 | |
| 98 | spin_lock(&sn->rpc_client_lock); |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 99 | list_del(&clnt->cl_clients); |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 100 | spin_unlock(&sn->rpc_client_lock); |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 101 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 103 | static void __rpc_clnt_remove_pipedir(struct rpc_clnt *clnt) |
| 104 | { |
Stanislav Kinsbursky | 30507f5 | 2012-01-11 19:18:42 +0400 | [diff] [blame] | 105 | if (clnt->cl_dentry) { |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 106 | if (clnt->cl_auth && clnt->cl_auth->au_ops->pipes_destroy) |
| 107 | clnt->cl_auth->au_ops->pipes_destroy(clnt->cl_auth); |
Stanislav Kinsbursky | 30507f5 | 2012-01-11 19:18:42 +0400 | [diff] [blame] | 108 | rpc_remove_client_dir(clnt->cl_dentry); |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 109 | } |
Stanislav Kinsbursky | 30507f5 | 2012-01-11 19:18:42 +0400 | [diff] [blame] | 110 | clnt->cl_dentry = NULL; |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static void rpc_clnt_remove_pipedir(struct rpc_clnt *clnt) |
| 114 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 115 | struct net *net = rpc_net_ns(clnt); |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 116 | struct super_block *pipefs_sb; |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 117 | |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 118 | pipefs_sb = rpc_get_sb_net(net); |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 119 | if (pipefs_sb) { |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 120 | __rpc_clnt_remove_pipedir(clnt); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 121 | rpc_put_sb_net(net); |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 122 | } |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static struct dentry *rpc_setup_pipedir_sb(struct super_block *sb, |
Trond Myklebust | 080b794 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 126 | struct rpc_clnt *clnt, |
| 127 | const char *dir_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 129 | static uint32_t clntid; |
Trond Myklebust | 23ac658 | 2009-08-09 15:14:25 -0400 | [diff] [blame] | 130 | char name[15]; |
| 131 | struct qstr q = { |
| 132 | .name = name, |
| 133 | }; |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 134 | struct dentry *dir, *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | int error; |
| 136 | |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 137 | dir = rpc_d_lookup_sb(sb, dir_name); |
| 138 | if (dir == NULL) |
| 139 | return dir; |
| 140 | for (;;) { |
| 141 | q.len = snprintf(name, sizeof(name), "clnt%x", (unsigned int)clntid++); |
| 142 | name[sizeof(name) - 1] = '\0'; |
| 143 | q.hash = full_name_hash(q.name, q.len); |
| 144 | dentry = rpc_create_client_dir(dir, &q, clnt); |
| 145 | if (!IS_ERR(dentry)) |
| 146 | break; |
| 147 | error = PTR_ERR(dentry); |
| 148 | if (error != -EEXIST) { |
| 149 | printk(KERN_INFO "RPC: Couldn't create pipefs entry" |
| 150 | " %s/%s, error %d\n", |
| 151 | dir_name, name, error); |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | dput(dir); |
| 156 | return dentry; |
| 157 | } |
| 158 | |
| 159 | static int |
Trond Myklebust | 080b794 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 160 | rpc_setup_pipedir(struct rpc_clnt *clnt, const char *dir_name) |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 161 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 162 | struct net *net = rpc_net_ns(clnt); |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 163 | struct super_block *pipefs_sb; |
Stanislav Kinsbursky | 30507f5 | 2012-01-11 19:18:42 +0400 | [diff] [blame] | 164 | struct dentry *dentry; |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 165 | |
Stanislav Kinsbursky | 30507f5 | 2012-01-11 19:18:42 +0400 | [diff] [blame] | 166 | clnt->cl_dentry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | if (dir_name == NULL) |
| 168 | return 0; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 169 | pipefs_sb = rpc_get_sb_net(net); |
Stanislav Kinsbursky | 70fe25b | 2012-01-11 19:18:34 +0400 | [diff] [blame] | 170 | if (!pipefs_sb) |
| 171 | return 0; |
Stanislav Kinsbursky | 30507f5 | 2012-01-11 19:18:42 +0400 | [diff] [blame] | 172 | dentry = rpc_setup_pipedir_sb(pipefs_sb, clnt, dir_name); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 173 | rpc_put_sb_net(net); |
Stanislav Kinsbursky | 30507f5 | 2012-01-11 19:18:42 +0400 | [diff] [blame] | 174 | if (IS_ERR(dentry)) |
| 175 | return PTR_ERR(dentry); |
| 176 | clnt->cl_dentry = dentry; |
Trond Myklebust | 23ac658 | 2009-08-09 15:14:25 -0400 | [diff] [blame] | 177 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 180 | static int __rpc_pipefs_event(struct rpc_clnt *clnt, unsigned long event, |
| 181 | struct super_block *sb) |
| 182 | { |
| 183 | struct dentry *dentry; |
| 184 | int err = 0; |
| 185 | |
| 186 | switch (event) { |
| 187 | case RPC_PIPEFS_MOUNT: |
| 188 | if (clnt->cl_program->pipe_dir_name == NULL) |
| 189 | break; |
| 190 | dentry = rpc_setup_pipedir_sb(sb, clnt, |
| 191 | clnt->cl_program->pipe_dir_name); |
| 192 | BUG_ON(dentry == NULL); |
| 193 | if (IS_ERR(dentry)) |
| 194 | return PTR_ERR(dentry); |
Stanislav Kinsbursky | 30507f5 | 2012-01-11 19:18:42 +0400 | [diff] [blame] | 195 | clnt->cl_dentry = dentry; |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 196 | if (clnt->cl_auth->au_ops->pipes_create) { |
| 197 | err = clnt->cl_auth->au_ops->pipes_create(clnt->cl_auth); |
| 198 | if (err) |
| 199 | __rpc_clnt_remove_pipedir(clnt); |
| 200 | } |
| 201 | break; |
| 202 | case RPC_PIPEFS_UMOUNT: |
| 203 | __rpc_clnt_remove_pipedir(clnt); |
| 204 | break; |
| 205 | default: |
| 206 | printk(KERN_ERR "%s: unknown event: %ld\n", __func__, event); |
| 207 | return -ENOTSUPP; |
| 208 | } |
| 209 | return err; |
| 210 | } |
| 211 | |
Stanislav Kinsbursky | da3b462 | 2012-02-27 22:05:29 +0400 | [diff] [blame] | 212 | static struct rpc_clnt *rpc_get_client_for_event(struct net *net, int event) |
| 213 | { |
| 214 | struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); |
| 215 | struct rpc_clnt *clnt; |
| 216 | |
| 217 | spin_lock(&sn->rpc_client_lock); |
| 218 | list_for_each_entry(clnt, &sn->all_clients, cl_clients) { |
| 219 | if (((event == RPC_PIPEFS_MOUNT) && clnt->cl_dentry) || |
| 220 | ((event == RPC_PIPEFS_UMOUNT) && !clnt->cl_dentry)) |
| 221 | continue; |
| 222 | atomic_inc(&clnt->cl_count); |
| 223 | spin_unlock(&sn->rpc_client_lock); |
| 224 | return clnt; |
| 225 | } |
| 226 | spin_unlock(&sn->rpc_client_lock); |
| 227 | return NULL; |
| 228 | } |
| 229 | |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 230 | static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event, |
| 231 | void *ptr) |
| 232 | { |
| 233 | struct super_block *sb = ptr; |
| 234 | struct rpc_clnt *clnt; |
| 235 | int error = 0; |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 236 | |
Stanislav Kinsbursky | da3b462 | 2012-02-27 22:05:29 +0400 | [diff] [blame] | 237 | while ((clnt = rpc_get_client_for_event(sb->s_fs_info, event))) { |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 238 | error = __rpc_pipefs_event(clnt, event, sb); |
Stanislav Kinsbursky | da3b462 | 2012-02-27 22:05:29 +0400 | [diff] [blame] | 239 | rpc_release_client(clnt); |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 240 | if (error) |
| 241 | break; |
| 242 | } |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 243 | return error; |
| 244 | } |
| 245 | |
| 246 | static struct notifier_block rpc_clients_block = { |
| 247 | .notifier_call = rpc_pipefs_event, |
Stanislav Kinsbursky | eee1732 | 2012-01-10 16:13:19 +0400 | [diff] [blame] | 248 | .priority = SUNRPC_PIPEFS_RPC_PRIO, |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | int rpc_clients_notifier_register(void) |
| 252 | { |
| 253 | return rpc_pipefs_notifier_register(&rpc_clients_block); |
| 254 | } |
| 255 | |
| 256 | void rpc_clients_notifier_unregister(void) |
| 257 | { |
| 258 | return rpc_pipefs_notifier_unregister(&rpc_clients_block); |
| 259 | } |
| 260 | |
Trond Myklebust | 698b6d0 | 2007-12-20 16:03:53 -0500 | [diff] [blame] | 261 | static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, struct rpc_xprt *xprt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | { |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 263 | const struct rpc_program *program = args->program; |
| 264 | const struct rpc_version *version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | struct rpc_clnt *clnt = NULL; |
J. Bruce Fields | 6a19275 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 266 | struct rpc_auth *auth; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | int err; |
Chuck Lever | 06b8d25 | 2007-09-11 18:00:20 -0400 | [diff] [blame] | 268 | |
| 269 | /* sanity check the name before trying to print it */ |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 270 | dprintk("RPC: creating %s client for %s (xprt %p)\n", |
Trond Myklebust | 698b6d0 | 2007-12-20 16:03:53 -0500 | [diff] [blame] | 271 | program->name, args->servername, xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
Trond Myklebust | 4ada539 | 2007-06-14 17:26:17 -0400 | [diff] [blame] | 273 | err = rpciod_up(); |
| 274 | if (err) |
| 275 | goto out_no_rpciod; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | err = -EINVAL; |
| 277 | if (!xprt) |
Adrian Bunk | 712917d | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 278 | goto out_no_xprt; |
Trond Myklebust | 698b6d0 | 2007-12-20 16:03:53 -0500 | [diff] [blame] | 279 | |
| 280 | if (args->version >= program->nrvers) |
| 281 | goto out_err; |
| 282 | version = program->version[args->version]; |
| 283 | if (version == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | goto out_err; |
| 285 | |
| 286 | err = -ENOMEM; |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 287 | clnt = kzalloc(sizeof(*clnt), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | if (!clnt) |
| 289 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | clnt->cl_parent = clnt; |
| 291 | |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 292 | rcu_assign_pointer(clnt->cl_xprt, xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | clnt->cl_procinfo = version->procs; |
| 294 | clnt->cl_maxproc = version->nrprocs; |
| 295 | clnt->cl_protname = program->name; |
Benny Halevy | d5b337b | 2008-09-28 09:21:26 +0300 | [diff] [blame] | 296 | clnt->cl_prog = args->prognumber ? : program->number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | clnt->cl_vers = version->number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | clnt->cl_stats = program->stats; |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 299 | clnt->cl_metrics = rpc_alloc_iostats(clnt); |
Trond Myklebust | 23bf85b | 2006-11-21 10:40:23 -0500 | [diff] [blame] | 300 | err = -ENOMEM; |
| 301 | if (clnt->cl_metrics == NULL) |
| 302 | goto out_no_stats; |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 303 | clnt->cl_program = program; |
Trond Myklebust | 6529eba | 2007-06-14 16:40:14 -0400 | [diff] [blame] | 304 | INIT_LIST_HEAD(&clnt->cl_tasks); |
Trond Myklebust | 4bef61f | 2007-06-16 14:17:01 -0400 | [diff] [blame] | 305 | spin_lock_init(&clnt->cl_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 307 | if (!xprt_bound(xprt)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | clnt->cl_autobind = 1; |
| 309 | |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 310 | clnt->cl_timeout = xprt->timeout; |
| 311 | if (args->timeout != NULL) { |
| 312 | memcpy(&clnt->cl_timeout_default, args->timeout, |
| 313 | sizeof(clnt->cl_timeout_default)); |
| 314 | clnt->cl_timeout = &clnt->cl_timeout_default; |
| 315 | } |
| 316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | clnt->cl_rtt = &clnt->cl_rtt_default; |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 318 | rpc_init_rtt(&clnt->cl_rtt_default, clnt->cl_timeout->to_initval); |
Olga Kornievskaia | 608207e | 2008-12-23 16:17:40 -0500 | [diff] [blame] | 319 | clnt->cl_principal = NULL; |
| 320 | if (args->client_name) { |
| 321 | clnt->cl_principal = kstrdup(args->client_name, GFP_KERNEL); |
| 322 | if (!clnt->cl_principal) |
| 323 | goto out_no_principal; |
| 324 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 326 | atomic_set(&clnt->cl_count, 1); |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | err = rpc_setup_pipedir(clnt, program->pipe_dir_name); |
| 329 | if (err < 0) |
| 330 | goto out_no_path; |
| 331 | |
Trond Myklebust | 698b6d0 | 2007-12-20 16:03:53 -0500 | [diff] [blame] | 332 | auth = rpcauth_create(args->authflavor, clnt); |
J. Bruce Fields | 6a19275 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 333 | if (IS_ERR(auth)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | printk(KERN_INFO "RPC: Couldn't create auth handle (flavor %u)\n", |
Trond Myklebust | 698b6d0 | 2007-12-20 16:03:53 -0500 | [diff] [blame] | 335 | args->authflavor); |
J. Bruce Fields | 6a19275 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 336 | err = PTR_ERR(auth); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | goto out_no_auth; |
| 338 | } |
| 339 | |
| 340 | /* save the nodename */ |
Cedric Le Goater | 63ffc23 | 2008-10-03 23:41:51 -0400 | [diff] [blame] | 341 | clnt->cl_nodelen = strlen(init_utsname()->nodename); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | if (clnt->cl_nodelen > UNX_MAXNODENAME) |
| 343 | clnt->cl_nodelen = UNX_MAXNODENAME; |
Cedric Le Goater | 63ffc23 | 2008-10-03 23:41:51 -0400 | [diff] [blame] | 344 | memcpy(clnt->cl_nodename, init_utsname()->nodename, clnt->cl_nodelen); |
Trond Myklebust | 6529eba | 2007-06-14 16:40:14 -0400 | [diff] [blame] | 345 | rpc_register_client(clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | return clnt; |
| 347 | |
| 348 | out_no_auth: |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 349 | rpc_clnt_remove_pipedir(clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | out_no_path: |
Olga Kornievskaia | 608207e | 2008-12-23 16:17:40 -0500 | [diff] [blame] | 351 | kfree(clnt->cl_principal); |
| 352 | out_no_principal: |
Trond Myklebust | 23bf85b | 2006-11-21 10:40:23 -0500 | [diff] [blame] | 353 | rpc_free_iostats(clnt->cl_metrics); |
| 354 | out_no_stats: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | kfree(clnt); |
| 356 | out_err: |
Trond Myklebust | 6b6ca86 | 2006-09-05 12:55:57 -0400 | [diff] [blame] | 357 | xprt_put(xprt); |
Adrian Bunk | 712917d | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 358 | out_no_xprt: |
Trond Myklebust | 4ada539 | 2007-06-14 17:26:17 -0400 | [diff] [blame] | 359 | rpciod_down(); |
| 360 | out_no_rpciod: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | return ERR_PTR(err); |
| 362 | } |
| 363 | |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 364 | /* |
| 365 | * rpc_create - create an RPC client and transport with one call |
| 366 | * @args: rpc_clnt create argument structure |
| 367 | * |
| 368 | * Creates and initializes an RPC transport and an RPC client. |
| 369 | * |
| 370 | * It can ping the server in order to determine if it is up, and to see if |
| 371 | * it supports this program and version. RPC_CLNT_CREATE_NOPING disables |
| 372 | * this behavior so asynchronous tasks can also use rpc_create. |
| 373 | */ |
| 374 | struct rpc_clnt *rpc_create(struct rpc_create_args *args) |
| 375 | { |
| 376 | struct rpc_xprt *xprt; |
| 377 | struct rpc_clnt *clnt; |
\"Talpey, Thomas\ | 3c341b0b | 2007-09-10 13:47:07 -0400 | [diff] [blame] | 378 | struct xprt_create xprtargs = { |
Pavel Emelyanov | 9a23e33 | 2010-09-29 16:05:12 +0400 | [diff] [blame] | 379 | .net = args->net, |
\"Talpey, Thomas\ | 4fa016e | 2007-09-10 13:47:57 -0400 | [diff] [blame] | 380 | .ident = args->protocol, |
Frank van Maarseveen | d3bc9a1 | 2007-07-09 22:23:35 +0200 | [diff] [blame] | 381 | .srcaddr = args->saddress, |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 382 | .dstaddr = args->address, |
| 383 | .addrlen = args->addrsize, |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 384 | .servername = args->servername, |
Alexandros Batsakis | f300bab | 2009-09-10 17:33:30 +0300 | [diff] [blame] | 385 | .bc_xprt = args->bc_xprt, |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 386 | }; |
Chuck Lever | 510deb0 | 2007-12-10 14:56:24 -0500 | [diff] [blame] | 387 | char servername[48]; |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 388 | |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 389 | /* |
Chuck Lever | 43780b8 | 2007-07-01 12:13:22 -0400 | [diff] [blame] | 390 | * If the caller chooses not to specify a hostname, whip |
| 391 | * up a string representation of the passed-in address. |
| 392 | */ |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 393 | if (xprtargs.servername == NULL) { |
Chuck Lever | 176e21e | 2011-05-09 15:22:44 -0400 | [diff] [blame] | 394 | struct sockaddr_un *sun = |
| 395 | (struct sockaddr_un *)args->address; |
Chuck Lever | da09eb9 | 2011-05-09 15:22:25 -0400 | [diff] [blame] | 396 | struct sockaddr_in *sin = |
| 397 | (struct sockaddr_in *)args->address; |
| 398 | struct sockaddr_in6 *sin6 = |
| 399 | (struct sockaddr_in6 *)args->address; |
| 400 | |
Chuck Lever | 510deb0 | 2007-12-10 14:56:24 -0500 | [diff] [blame] | 401 | servername[0] = '\0'; |
| 402 | switch (args->address->sa_family) { |
Chuck Lever | 176e21e | 2011-05-09 15:22:44 -0400 | [diff] [blame] | 403 | case AF_LOCAL: |
| 404 | snprintf(servername, sizeof(servername), "%s", |
| 405 | sun->sun_path); |
| 406 | break; |
Chuck Lever | da09eb9 | 2011-05-09 15:22:25 -0400 | [diff] [blame] | 407 | case AF_INET: |
Harvey Harrison | 21454aa | 2008-10-31 00:54:56 -0700 | [diff] [blame] | 408 | snprintf(servername, sizeof(servername), "%pI4", |
| 409 | &sin->sin_addr.s_addr); |
Chuck Lever | 510deb0 | 2007-12-10 14:56:24 -0500 | [diff] [blame] | 410 | break; |
Chuck Lever | da09eb9 | 2011-05-09 15:22:25 -0400 | [diff] [blame] | 411 | case AF_INET6: |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 412 | snprintf(servername, sizeof(servername), "%pI6", |
Chuck Lever | da09eb9 | 2011-05-09 15:22:25 -0400 | [diff] [blame] | 413 | &sin6->sin6_addr); |
Chuck Lever | 510deb0 | 2007-12-10 14:56:24 -0500 | [diff] [blame] | 414 | break; |
Chuck Lever | 510deb0 | 2007-12-10 14:56:24 -0500 | [diff] [blame] | 415 | default: |
| 416 | /* caller wants default server name, but |
| 417 | * address family isn't recognized. */ |
| 418 | return ERR_PTR(-EINVAL); |
| 419 | } |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 420 | xprtargs.servername = servername; |
Chuck Lever | 43780b8 | 2007-07-01 12:13:22 -0400 | [diff] [blame] | 421 | } |
| 422 | |
Chuck Lever | 510deb0 | 2007-12-10 14:56:24 -0500 | [diff] [blame] | 423 | xprt = xprt_create_transport(&xprtargs); |
| 424 | if (IS_ERR(xprt)) |
| 425 | return (struct rpc_clnt *)xprt; |
| 426 | |
Chuck Lever | 43780b8 | 2007-07-01 12:13:22 -0400 | [diff] [blame] | 427 | /* |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 428 | * By default, kernel RPC client connects from a reserved port. |
| 429 | * CAP_NET_BIND_SERVICE will not be set for unprivileged requesters, |
| 430 | * but it is always enabled for rpciod, which handles the connect |
| 431 | * operation. |
| 432 | */ |
| 433 | xprt->resvport = 1; |
| 434 | if (args->flags & RPC_CLNT_CREATE_NONPRIVPORT) |
| 435 | xprt->resvport = 0; |
| 436 | |
Trond Myklebust | 698b6d0 | 2007-12-20 16:03:53 -0500 | [diff] [blame] | 437 | clnt = rpc_new_client(args, xprt); |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 438 | if (IS_ERR(clnt)) |
| 439 | return clnt; |
| 440 | |
| 441 | if (!(args->flags & RPC_CLNT_CREATE_NOPING)) { |
Chuck Lever | caabea8 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 442 | int err = rpc_ping(clnt); |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 443 | if (err != 0) { |
| 444 | rpc_shutdown_client(clnt); |
| 445 | return ERR_PTR(err); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | clnt->cl_softrtry = 1; |
| 450 | if (args->flags & RPC_CLNT_CREATE_HARDRTRY) |
| 451 | clnt->cl_softrtry = 0; |
| 452 | |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 453 | if (args->flags & RPC_CLNT_CREATE_AUTOBIND) |
| 454 | clnt->cl_autobind = 1; |
Chuck Lever | 43d78ef | 2007-02-06 18:26:11 -0500 | [diff] [blame] | 455 | if (args->flags & RPC_CLNT_CREATE_DISCRTRY) |
| 456 | clnt->cl_discrtry = 1; |
Olga Kornievskaia | b6b6152 | 2008-06-09 16:51:31 -0400 | [diff] [blame] | 457 | if (!(args->flags & RPC_CLNT_CREATE_QUIET)) |
| 458 | clnt->cl_chatty = 1; |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 459 | |
| 460 | return clnt; |
| 461 | } |
Chuck Lever | b86acd5 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 462 | EXPORT_SYMBOL_GPL(rpc_create); |
Chuck Lever | c286676 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | /* |
| 465 | * This function clones the RPC client structure. It allows us to share the |
| 466 | * same transport while varying parameters such as the authentication |
| 467 | * flavour. |
| 468 | */ |
| 469 | struct rpc_clnt * |
| 470 | rpc_clone_client(struct rpc_clnt *clnt) |
| 471 | { |
| 472 | struct rpc_clnt *new; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 473 | struct rpc_xprt *xprt; |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 474 | int err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
Arnaldo Carvalho de Melo | e69062b | 2006-11-21 01:21:34 -0200 | [diff] [blame] | 476 | new = kmemdup(clnt, sizeof(*new), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | if (!new) |
| 478 | goto out_no_clnt; |
Trond Myklebust | d431a555 | 2007-06-17 17:07:54 -0400 | [diff] [blame] | 479 | new->cl_parent = clnt; |
| 480 | /* Turn off autobind on clones */ |
| 481 | new->cl_autobind = 0; |
| 482 | INIT_LIST_HEAD(&new->cl_tasks); |
| 483 | spin_lock_init(&new->cl_lock); |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 484 | rpc_init_rtt(&new->cl_rtt_default, clnt->cl_timeout->to_initval); |
Trond Myklebust | 23bf85b | 2006-11-21 10:40:23 -0500 | [diff] [blame] | 485 | new->cl_metrics = rpc_alloc_iostats(clnt); |
| 486 | if (new->cl_metrics == NULL) |
| 487 | goto out_no_stats; |
Olga Kornievskaia | 608207e | 2008-12-23 16:17:40 -0500 | [diff] [blame] | 488 | if (clnt->cl_principal) { |
| 489 | new->cl_principal = kstrdup(clnt->cl_principal, GFP_KERNEL); |
| 490 | if (new->cl_principal == NULL) |
| 491 | goto out_no_principal; |
| 492 | } |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 493 | rcu_read_lock(); |
| 494 | xprt = xprt_get(rcu_dereference(clnt->cl_xprt)); |
| 495 | rcu_read_unlock(); |
| 496 | if (xprt == NULL) |
| 497 | goto out_no_transport; |
| 498 | rcu_assign_pointer(new->cl_xprt, xprt); |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 499 | atomic_set(&new->cl_count, 1); |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 500 | err = rpc_setup_pipedir(new, clnt->cl_program->pipe_dir_name); |
| 501 | if (err != 0) |
| 502 | goto out_no_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | if (new->cl_auth) |
| 504 | atomic_inc(&new->cl_auth->au_count); |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 505 | atomic_inc(&clnt->cl_count); |
Trond Myklebust | 6529eba | 2007-06-14 16:40:14 -0400 | [diff] [blame] | 506 | rpc_register_client(new); |
Trond Myklebust | 4ada539 | 2007-06-14 17:26:17 -0400 | [diff] [blame] | 507 | rpciod_up(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | return new; |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 509 | out_no_path: |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 510 | xprt_put(xprt); |
| 511 | out_no_transport: |
Olga Kornievskaia | 608207e | 2008-12-23 16:17:40 -0500 | [diff] [blame] | 512 | kfree(new->cl_principal); |
| 513 | out_no_principal: |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 514 | rpc_free_iostats(new->cl_metrics); |
Trond Myklebust | 23bf85b | 2006-11-21 10:40:23 -0500 | [diff] [blame] | 515 | out_no_stats: |
| 516 | kfree(new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | out_no_clnt: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 518 | dprintk("RPC: %s: returned error %d\n", __func__, err); |
Trond Myklebust | 3e32a5d | 2006-11-16 11:37:27 -0500 | [diff] [blame] | 519 | return ERR_PTR(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 521 | EXPORT_SYMBOL_GPL(rpc_clone_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
| 523 | /* |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 524 | * Kill all tasks for the given client. |
| 525 | * XXX: kill their descendants as well? |
| 526 | */ |
| 527 | void rpc_killall_tasks(struct rpc_clnt *clnt) |
| 528 | { |
| 529 | struct rpc_task *rovr; |
| 530 | |
| 531 | |
| 532 | if (list_empty(&clnt->cl_tasks)) |
| 533 | return; |
| 534 | dprintk("RPC: killing all tasks for client %p\n", clnt); |
| 535 | /* |
| 536 | * Spin lock all_tasks to prevent changes... |
| 537 | */ |
| 538 | spin_lock(&clnt->cl_lock); |
| 539 | list_for_each_entry(rovr, &clnt->cl_tasks, tk_task) { |
| 540 | if (!RPC_IS_ACTIVATED(rovr)) |
| 541 | continue; |
| 542 | if (!(rovr->tk_flags & RPC_TASK_KILLED)) { |
| 543 | rovr->tk_flags |= RPC_TASK_KILLED; |
| 544 | rpc_exit(rovr, -EIO); |
Stanislav Kinsbursky | 8e26de2 | 2011-03-17 18:54:23 +0300 | [diff] [blame] | 545 | if (RPC_IS_QUEUED(rovr)) |
| 546 | rpc_wake_up_queued_task(rovr->tk_waitqueue, |
| 547 | rovr); |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | spin_unlock(&clnt->cl_lock); |
| 551 | } |
| 552 | EXPORT_SYMBOL_GPL(rpc_killall_tasks); |
| 553 | |
| 554 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | * Properly shut down an RPC client, terminating all outstanding |
Trond Myklebust | 90c5755 | 2007-06-09 19:49:36 -0400 | [diff] [blame] | 556 | * requests. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | */ |
Trond Myklebust | 4c402b4 | 2007-06-14 16:40:32 -0400 | [diff] [blame] | 558 | void rpc_shutdown_client(struct rpc_clnt *clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | { |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 560 | dprintk_rcu("RPC: shutting down %s client for %s\n", |
| 561 | clnt->cl_protname, |
| 562 | rcu_dereference(clnt->cl_xprt)->servername); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 564 | while (!list_empty(&clnt->cl_tasks)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | rpc_killall_tasks(clnt); |
Ingo Molnar | 532347e | 2006-01-09 20:52:53 -0800 | [diff] [blame] | 566 | wait_event_timeout(destroy_wait, |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 567 | list_empty(&clnt->cl_tasks), 1*HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } |
| 569 | |
Trond Myklebust | 4c402b4 | 2007-06-14 16:40:32 -0400 | [diff] [blame] | 570 | rpc_release_client(clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 572 | EXPORT_SYMBOL_GPL(rpc_shutdown_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | |
| 574 | /* |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 575 | * Free an RPC client |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | */ |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 577 | static void |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 578 | rpc_free_client(struct rpc_clnt *clnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | { |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 580 | dprintk_rcu("RPC: destroying %s client for %s\n", |
| 581 | clnt->cl_protname, |
| 582 | rcu_dereference(clnt->cl_xprt)->servername); |
Trond Myklebust | 6eac7d3 | 2012-01-20 13:53:37 -0500 | [diff] [blame] | 583 | if (clnt->cl_parent != clnt) |
Trond Myklebust | 8ad7c89 | 2007-06-14 16:40:32 -0400 | [diff] [blame] | 584 | rpc_release_client(clnt->cl_parent); |
Trond Myklebust | 6529eba | 2007-06-14 16:40:14 -0400 | [diff] [blame] | 585 | rpc_unregister_client(clnt); |
Stanislav Kinsbursky | f513125 | 2012-01-11 19:18:26 +0400 | [diff] [blame] | 586 | rpc_clnt_remove_pipedir(clnt); |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 587 | rpc_free_iostats(clnt->cl_metrics); |
Olga Kornievskaia | 608207e | 2008-12-23 16:17:40 -0500 | [diff] [blame] | 588 | kfree(clnt->cl_principal); |
Chuck Lever | 11c556b | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 589 | clnt->cl_metrics = NULL; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 590 | xprt_put(rcu_dereference_raw(clnt->cl_xprt)); |
Trond Myklebust | 4ada539 | 2007-06-14 17:26:17 -0400 | [diff] [blame] | 591 | rpciod_down(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | kfree(clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | /* |
Trond Myklebust | 1dd17ec | 2007-06-26 16:57:41 -0400 | [diff] [blame] | 596 | * Free an RPC client |
| 597 | */ |
| 598 | static void |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 599 | rpc_free_auth(struct rpc_clnt *clnt) |
Trond Myklebust | 1dd17ec | 2007-06-26 16:57:41 -0400 | [diff] [blame] | 600 | { |
Trond Myklebust | 1dd17ec | 2007-06-26 16:57:41 -0400 | [diff] [blame] | 601 | if (clnt->cl_auth == NULL) { |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 602 | rpc_free_client(clnt); |
Trond Myklebust | 1dd17ec | 2007-06-26 16:57:41 -0400 | [diff] [blame] | 603 | return; |
| 604 | } |
| 605 | |
| 606 | /* |
| 607 | * Note: RPCSEC_GSS may need to send NULL RPC calls in order to |
| 608 | * release remaining GSS contexts. This mechanism ensures |
| 609 | * that it can do so safely. |
| 610 | */ |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 611 | atomic_inc(&clnt->cl_count); |
Trond Myklebust | 1dd17ec | 2007-06-26 16:57:41 -0400 | [diff] [blame] | 612 | rpcauth_release(clnt->cl_auth); |
| 613 | clnt->cl_auth = NULL; |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 614 | if (atomic_dec_and_test(&clnt->cl_count)) |
| 615 | rpc_free_client(clnt); |
Trond Myklebust | 1dd17ec | 2007-06-26 16:57:41 -0400 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /* |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 619 | * Release reference to the RPC client |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | */ |
| 621 | void |
| 622 | rpc_release_client(struct rpc_clnt *clnt) |
| 623 | { |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 624 | dprintk("RPC: rpc_release_client(%p)\n", clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 626 | if (list_empty(&clnt->cl_tasks)) |
| 627 | wake_up(&destroy_wait); |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 628 | if (atomic_dec_and_test(&clnt->cl_count)) |
| 629 | rpc_free_auth(clnt); |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 630 | } |
| 631 | |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 632 | /** |
| 633 | * rpc_bind_new_program - bind a new RPC program to an existing client |
Randy Dunlap | 65b6e42 | 2008-02-13 15:03:23 -0800 | [diff] [blame] | 634 | * @old: old rpc_client |
| 635 | * @program: rpc program to set |
| 636 | * @vers: rpc program version |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 637 | * |
| 638 | * Clones the rpc client and sets up a new RPC program. This is mainly |
| 639 | * of use for enabling different RPC programs to share the same transport. |
| 640 | * The Sun NFSv2/v3 ACL protocol can do this. |
| 641 | */ |
| 642 | struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *old, |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 643 | const struct rpc_program *program, |
Chuck Lever | 89eb21c | 2007-09-11 18:00:09 -0400 | [diff] [blame] | 644 | u32 vers) |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 645 | { |
| 646 | struct rpc_clnt *clnt; |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 647 | const struct rpc_version *version; |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 648 | int err; |
| 649 | |
| 650 | BUG_ON(vers >= program->nrvers || !program->version[vers]); |
| 651 | version = program->version[vers]; |
| 652 | clnt = rpc_clone_client(old); |
| 653 | if (IS_ERR(clnt)) |
| 654 | goto out; |
| 655 | clnt->cl_procinfo = version->procs; |
| 656 | clnt->cl_maxproc = version->nrprocs; |
| 657 | clnt->cl_protname = program->name; |
| 658 | clnt->cl_prog = program->number; |
| 659 | clnt->cl_vers = version->number; |
| 660 | clnt->cl_stats = program->stats; |
Chuck Lever | caabea8 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 661 | err = rpc_ping(clnt); |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 662 | if (err != 0) { |
| 663 | rpc_shutdown_client(clnt); |
| 664 | clnt = ERR_PTR(err); |
| 665 | } |
YOSHIFUJI Hideaki | cca5172 | 2007-02-09 15:38:13 -0800 | [diff] [blame] | 666 | out: |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 667 | return clnt; |
| 668 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 669 | EXPORT_SYMBOL_GPL(rpc_bind_new_program); |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 670 | |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 671 | void rpc_task_release_client(struct rpc_task *task) |
| 672 | { |
| 673 | struct rpc_clnt *clnt = task->tk_client; |
| 674 | |
| 675 | if (clnt != NULL) { |
| 676 | /* Remove from client task list */ |
| 677 | spin_lock(&clnt->cl_lock); |
| 678 | list_del(&task->tk_task); |
| 679 | spin_unlock(&clnt->cl_lock); |
| 680 | task->tk_client = NULL; |
| 681 | |
| 682 | rpc_release_client(clnt); |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | static |
| 687 | void rpc_task_set_client(struct rpc_task *task, struct rpc_clnt *clnt) |
| 688 | { |
| 689 | if (clnt != NULL) { |
| 690 | rpc_task_release_client(task); |
| 691 | task->tk_client = clnt; |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 692 | atomic_inc(&clnt->cl_count); |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 693 | if (clnt->cl_softrtry) |
| 694 | task->tk_flags |= RPC_TASK_SOFT; |
| 695 | /* Add to the client's list of all tasks */ |
| 696 | spin_lock(&clnt->cl_lock); |
| 697 | list_add_tail(&task->tk_task, &clnt->cl_tasks); |
| 698 | spin_unlock(&clnt->cl_lock); |
| 699 | } |
| 700 | } |
| 701 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 702 | void rpc_task_reset_client(struct rpc_task *task, struct rpc_clnt *clnt) |
| 703 | { |
| 704 | rpc_task_release_client(task); |
| 705 | rpc_task_set_client(task, clnt); |
| 706 | } |
| 707 | EXPORT_SYMBOL_GPL(rpc_task_reset_client); |
| 708 | |
| 709 | |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 710 | static void |
| 711 | rpc_task_set_rpc_message(struct rpc_task *task, const struct rpc_message *msg) |
| 712 | { |
| 713 | if (msg != NULL) { |
| 714 | task->tk_msg.rpc_proc = msg->rpc_proc; |
| 715 | task->tk_msg.rpc_argp = msg->rpc_argp; |
| 716 | task->tk_msg.rpc_resp = msg->rpc_resp; |
Trond Myklebust | a17c215 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 717 | if (msg->rpc_cred != NULL) |
| 718 | task->tk_msg.rpc_cred = get_rpccred(msg->rpc_cred); |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | /* |
| 723 | * Default callback for async RPC calls |
| 724 | */ |
| 725 | static void |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 726 | rpc_default_callback(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | { |
| 728 | } |
| 729 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 730 | static const struct rpc_call_ops rpc_default_ops = { |
| 731 | .rpc_call_done = rpc_default_callback, |
| 732 | }; |
| 733 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 734 | /** |
| 735 | * rpc_run_task - Allocate a new RPC task, then run rpc_execute against it |
| 736 | * @task_setup_data: pointer to task initialisation data |
| 737 | */ |
| 738 | struct rpc_task *rpc_run_task(const struct rpc_task_setup *task_setup_data) |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 739 | { |
Trond Myklebust | 19445b9 | 2010-04-16 16:41:10 -0400 | [diff] [blame] | 740 | struct rpc_task *task; |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 741 | |
Trond Myklebust | 84115e1 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 742 | task = rpc_new_task(task_setup_data); |
Trond Myklebust | 19445b9 | 2010-04-16 16:41:10 -0400 | [diff] [blame] | 743 | if (IS_ERR(task)) |
Trond Myklebust | 5085925 | 2007-10-25 18:19:37 -0400 | [diff] [blame] | 744 | goto out; |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 745 | |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 746 | rpc_task_set_client(task, task_setup_data->rpc_client); |
| 747 | rpc_task_set_rpc_message(task, task_setup_data->rpc_message); |
| 748 | |
Trond Myklebust | 58f9612 | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 749 | if (task->tk_action == NULL) |
| 750 | rpc_call_start(task); |
| 751 | |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 752 | atomic_inc(&task->tk_count); |
| 753 | rpc_execute(task); |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 754 | out: |
Trond Myklebust | 19445b9 | 2010-04-16 16:41:10 -0400 | [diff] [blame] | 755 | return task; |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 756 | } |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 757 | EXPORT_SYMBOL_GPL(rpc_run_task); |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 758 | |
| 759 | /** |
| 760 | * rpc_call_sync - Perform a synchronous RPC call |
| 761 | * @clnt: pointer to RPC client |
| 762 | * @msg: RPC call parameters |
| 763 | * @flags: RPC call flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | */ |
Trond Myklebust | cbc2005 | 2008-02-14 11:11:30 -0500 | [diff] [blame] | 765 | int rpc_call_sync(struct rpc_clnt *clnt, const struct rpc_message *msg, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | { |
| 767 | struct rpc_task *task; |
Trond Myklebust | 84115e1 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 768 | struct rpc_task_setup task_setup_data = { |
| 769 | .rpc_client = clnt, |
| 770 | .rpc_message = msg, |
| 771 | .callback_ops = &rpc_default_ops, |
| 772 | .flags = flags, |
| 773 | }; |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 774 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | BUG_ON(flags & RPC_TASK_ASYNC); |
| 777 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 778 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 779 | if (IS_ERR(task)) |
| 780 | return PTR_ERR(task); |
Trond Myklebust | e60859a | 2006-01-03 09:55:10 +0100 | [diff] [blame] | 781 | status = task->tk_status; |
Trond Myklebust | bde8f00 | 2007-01-24 11:54:53 -0800 | [diff] [blame] | 782 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | return status; |
| 784 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 785 | EXPORT_SYMBOL_GPL(rpc_call_sync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 787 | /** |
| 788 | * rpc_call_async - Perform an asynchronous RPC call |
| 789 | * @clnt: pointer to RPC client |
| 790 | * @msg: RPC call parameters |
| 791 | * @flags: RPC call flags |
Randy Dunlap | 65b6e42 | 2008-02-13 15:03:23 -0800 | [diff] [blame] | 792 | * @tk_ops: RPC call ops |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 793 | * @data: user call data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | */ |
| 795 | int |
Trond Myklebust | cbc2005 | 2008-02-14 11:11:30 -0500 | [diff] [blame] | 796 | rpc_call_async(struct rpc_clnt *clnt, const struct rpc_message *msg, int flags, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 797 | const struct rpc_call_ops *tk_ops, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | { |
| 799 | struct rpc_task *task; |
Trond Myklebust | 84115e1 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 800 | struct rpc_task_setup task_setup_data = { |
| 801 | .rpc_client = clnt, |
| 802 | .rpc_message = msg, |
| 803 | .callback_ops = tk_ops, |
| 804 | .callback_data = data, |
| 805 | .flags = flags|RPC_TASK_ASYNC, |
| 806 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 808 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 6e5b70e | 2007-06-12 10:02:37 -0400 | [diff] [blame] | 809 | if (IS_ERR(task)) |
| 810 | return PTR_ERR(task); |
| 811 | rpc_put_task(task); |
| 812 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 814 | EXPORT_SYMBOL_GPL(rpc_call_async); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
Trond Myklebust | 9e00abc | 2011-07-13 19:20:49 -0400 | [diff] [blame] | 816 | #if defined(CONFIG_SUNRPC_BACKCHANNEL) |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 817 | /** |
| 818 | * rpc_run_bc_task - Allocate a new RPC task for backchannel use, then run |
| 819 | * rpc_execute against it |
Jaswinder Singh Rajput | 7a73fdd | 2009-09-24 14:58:42 -0400 | [diff] [blame] | 820 | * @req: RPC request |
| 821 | * @tk_ops: RPC call ops |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 822 | */ |
| 823 | struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req, |
Jaswinder Singh Rajput | 7a73fdd | 2009-09-24 14:58:42 -0400 | [diff] [blame] | 824 | const struct rpc_call_ops *tk_ops) |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 825 | { |
| 826 | struct rpc_task *task; |
| 827 | struct xdr_buf *xbufp = &req->rq_snd_buf; |
| 828 | struct rpc_task_setup task_setup_data = { |
| 829 | .callback_ops = tk_ops, |
| 830 | }; |
| 831 | |
| 832 | dprintk("RPC: rpc_run_bc_task req= %p\n", req); |
| 833 | /* |
| 834 | * Create an rpc_task to send the data |
| 835 | */ |
| 836 | task = rpc_new_task(&task_setup_data); |
Trond Myklebust | 19445b9 | 2010-04-16 16:41:10 -0400 | [diff] [blame] | 837 | if (IS_ERR(task)) { |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 838 | xprt_free_bc_request(req); |
| 839 | goto out; |
| 840 | } |
| 841 | task->tk_rqstp = req; |
| 842 | |
| 843 | /* |
| 844 | * Set up the xdr_buf length. |
| 845 | * This also indicates that the buffer is XDR encoded already. |
| 846 | */ |
| 847 | xbufp->len = xbufp->head[0].iov_len + xbufp->page_len + |
| 848 | xbufp->tail[0].iov_len; |
| 849 | |
| 850 | task->tk_action = call_bc_transmit; |
| 851 | atomic_inc(&task->tk_count); |
| 852 | BUG_ON(atomic_read(&task->tk_count) != 2); |
| 853 | rpc_execute(task); |
| 854 | |
| 855 | out: |
| 856 | dprintk("RPC: rpc_run_bc_task: task= %p\n", task); |
| 857 | return task; |
| 858 | } |
Trond Myklebust | 9e00abc | 2011-07-13 19:20:49 -0400 | [diff] [blame] | 859 | #endif /* CONFIG_SUNRPC_BACKCHANNEL */ |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 860 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | void |
Trond Myklebust | 77de2c5 | 2007-10-25 18:40:21 -0400 | [diff] [blame] | 862 | rpc_call_start(struct rpc_task *task) |
| 863 | { |
| 864 | task->tk_action = call_start; |
| 865 | } |
| 866 | EXPORT_SYMBOL_GPL(rpc_call_start); |
| 867 | |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 868 | /** |
| 869 | * rpc_peeraddr - extract remote peer address from clnt's xprt |
| 870 | * @clnt: RPC client structure |
| 871 | * @buf: target buffer |
Randy Dunlap | 65b6e42 | 2008-02-13 15:03:23 -0800 | [diff] [blame] | 872 | * @bufsize: length of target buffer |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 873 | * |
| 874 | * Returns the number of bytes that are actually in the stored address. |
| 875 | */ |
| 876 | size_t rpc_peeraddr(struct rpc_clnt *clnt, struct sockaddr *buf, size_t bufsize) |
| 877 | { |
| 878 | size_t bytes; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 879 | struct rpc_xprt *xprt; |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 880 | |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 881 | rcu_read_lock(); |
| 882 | xprt = rcu_dereference(clnt->cl_xprt); |
| 883 | |
| 884 | bytes = xprt->addrlen; |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 885 | if (bytes > bufsize) |
| 886 | bytes = bufsize; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 887 | memcpy(buf, &xprt->addr, bytes); |
| 888 | rcu_read_unlock(); |
| 889 | |
| 890 | return bytes; |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 891 | } |
Chuck Lever | b86acd5 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 892 | EXPORT_SYMBOL_GPL(rpc_peeraddr); |
Chuck Lever | ed39440 | 2006-08-22 20:06:17 -0400 | [diff] [blame] | 893 | |
Chuck Lever | f425eba | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 894 | /** |
| 895 | * rpc_peeraddr2str - return remote peer address in printable format |
| 896 | * @clnt: RPC client structure |
| 897 | * @format: address format |
| 898 | * |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 899 | * NB: the lifetime of the memory referenced by the returned pointer is |
| 900 | * the same as the rpc_xprt itself. As long as the caller uses this |
| 901 | * pointer, it must hold the RCU read lock. |
Chuck Lever | f425eba | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 902 | */ |
Chuck Lever | b454ae9 | 2008-01-07 18:34:48 -0500 | [diff] [blame] | 903 | const char *rpc_peeraddr2str(struct rpc_clnt *clnt, |
| 904 | enum rpc_display_format_t format) |
Chuck Lever | f425eba | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 905 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 906 | struct rpc_xprt *xprt; |
| 907 | |
| 908 | xprt = rcu_dereference(clnt->cl_xprt); |
Chuck Lever | 7559c7a | 2006-12-05 16:35:37 -0500 | [diff] [blame] | 909 | |
| 910 | if (xprt->address_strings[format] != NULL) |
| 911 | return xprt->address_strings[format]; |
| 912 | else |
| 913 | return "unprintable"; |
Chuck Lever | f425eba | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 914 | } |
Chuck Lever | b86acd5 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 915 | EXPORT_SYMBOL_GPL(rpc_peeraddr2str); |
Chuck Lever | f425eba | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | void |
| 918 | rpc_setbufsize(struct rpc_clnt *clnt, unsigned int sndsize, unsigned int rcvsize) |
| 919 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 920 | struct rpc_xprt *xprt; |
| 921 | |
| 922 | rcu_read_lock(); |
| 923 | xprt = rcu_dereference(clnt->cl_xprt); |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 924 | if (xprt->ops->set_buffer_size) |
| 925 | xprt->ops->set_buffer_size(xprt, sndsize, rcvsize); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 926 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 928 | EXPORT_SYMBOL_GPL(rpc_setbufsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 930 | /** |
| 931 | * rpc_protocol - Get transport protocol number for an RPC client |
| 932 | * @clnt: RPC client to query |
| 933 | * |
| 934 | */ |
| 935 | int rpc_protocol(struct rpc_clnt *clnt) |
| 936 | { |
| 937 | int protocol; |
| 938 | |
| 939 | rcu_read_lock(); |
| 940 | protocol = rcu_dereference(clnt->cl_xprt)->prot; |
| 941 | rcu_read_unlock(); |
| 942 | return protocol; |
| 943 | } |
| 944 | EXPORT_SYMBOL_GPL(rpc_protocol); |
| 945 | |
| 946 | /** |
| 947 | * rpc_net_ns - Get the network namespace for this RPC client |
| 948 | * @clnt: RPC client to query |
| 949 | * |
| 950 | */ |
| 951 | struct net *rpc_net_ns(struct rpc_clnt *clnt) |
| 952 | { |
| 953 | struct net *ret; |
| 954 | |
| 955 | rcu_read_lock(); |
| 956 | ret = rcu_dereference(clnt->cl_xprt)->xprt_net; |
| 957 | rcu_read_unlock(); |
| 958 | return ret; |
| 959 | } |
| 960 | EXPORT_SYMBOL_GPL(rpc_net_ns); |
| 961 | |
| 962 | /** |
| 963 | * rpc_max_payload - Get maximum payload size for a transport, in bytes |
| 964 | * @clnt: RPC client to query |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | * |
| 966 | * For stream transports, this is one RPC record fragment (see RFC |
| 967 | * 1831), as we don't support multi-record requests yet. For datagram |
| 968 | * transports, this is the size of an IP packet minus the IP, UDP, and |
| 969 | * RPC header sizes. |
| 970 | */ |
| 971 | size_t rpc_max_payload(struct rpc_clnt *clnt) |
| 972 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 973 | size_t ret; |
| 974 | |
| 975 | rcu_read_lock(); |
| 976 | ret = rcu_dereference(clnt->cl_xprt)->max_payload; |
| 977 | rcu_read_unlock(); |
| 978 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | } |
Chuck Lever | b86acd5 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 980 | EXPORT_SYMBOL_GPL(rpc_max_payload); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 982 | /** |
| 983 | * rpc_force_rebind - force transport to check that remote port is unchanged |
| 984 | * @clnt: client to rebind |
| 985 | * |
| 986 | */ |
| 987 | void rpc_force_rebind(struct rpc_clnt *clnt) |
| 988 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 989 | if (clnt->cl_autobind) { |
| 990 | rcu_read_lock(); |
| 991 | xprt_clear_bound(rcu_dereference(clnt->cl_xprt)); |
| 992 | rcu_read_unlock(); |
| 993 | } |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 994 | } |
Chuck Lever | b86acd5 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 995 | EXPORT_SYMBOL_GPL(rpc_force_rebind); |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | /* |
Andy Adamson | aae2006 | 2009-04-01 09:22:40 -0400 | [diff] [blame] | 998 | * Restart an (async) RPC call from the call_prepare state. |
| 999 | * Usually called from within the exit handler. |
| 1000 | */ |
Trond Myklebust | f1f88fc | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 1001 | int |
Andy Adamson | aae2006 | 2009-04-01 09:22:40 -0400 | [diff] [blame] | 1002 | rpc_restart_call_prepare(struct rpc_task *task) |
| 1003 | { |
| 1004 | if (RPC_ASSASSINATED(task)) |
Trond Myklebust | f1f88fc | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 1005 | return 0; |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 1006 | task->tk_action = call_start; |
| 1007 | if (task->tk_ops->rpc_call_prepare != NULL) |
| 1008 | task->tk_action = rpc_prepare_task; |
Trond Myklebust | f1f88fc | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 1009 | return 1; |
Andy Adamson | aae2006 | 2009-04-01 09:22:40 -0400 | [diff] [blame] | 1010 | } |
| 1011 | EXPORT_SYMBOL_GPL(rpc_restart_call_prepare); |
| 1012 | |
| 1013 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | * Restart an (async) RPC call. Usually called from within the |
| 1015 | * exit handler. |
| 1016 | */ |
Trond Myklebust | f1f88fc | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 1017 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | rpc_restart_call(struct rpc_task *task) |
| 1019 | { |
| 1020 | if (RPC_ASSASSINATED(task)) |
Trond Myklebust | f1f88fc | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 1021 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | task->tk_action = call_start; |
Trond Myklebust | f1f88fc | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 1023 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1025 | EXPORT_SYMBOL_GPL(rpc_restart_call); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | |
Chuck Lever | 3748f1e | 2008-05-21 17:09:12 -0400 | [diff] [blame] | 1027 | #ifdef RPC_DEBUG |
| 1028 | static const char *rpc_proc_name(const struct rpc_task *task) |
| 1029 | { |
| 1030 | const struct rpc_procinfo *proc = task->tk_msg.rpc_proc; |
| 1031 | |
| 1032 | if (proc) { |
| 1033 | if (proc->p_name) |
| 1034 | return proc->p_name; |
| 1035 | else |
| 1036 | return "NULL"; |
| 1037 | } else |
| 1038 | return "no proc"; |
| 1039 | } |
| 1040 | #endif |
| 1041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | /* |
| 1043 | * 0. Initial state |
| 1044 | * |
| 1045 | * Other FSM states can be visited zero or more times, but |
| 1046 | * this state is visited exactly once for each RPC. |
| 1047 | */ |
| 1048 | static void |
| 1049 | call_start(struct rpc_task *task) |
| 1050 | { |
| 1051 | struct rpc_clnt *clnt = task->tk_client; |
| 1052 | |
Chuck Lever | 3748f1e | 2008-05-21 17:09:12 -0400 | [diff] [blame] | 1053 | dprintk("RPC: %5u call_start %s%d proc %s (%s)\n", task->tk_pid, |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1054 | clnt->cl_protname, clnt->cl_vers, |
Chuck Lever | 3748f1e | 2008-05-21 17:09:12 -0400 | [diff] [blame] | 1055 | rpc_proc_name(task), |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1056 | (RPC_IS_ASYNC(task) ? "async" : "sync")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | |
| 1058 | /* Increment call count */ |
| 1059 | task->tk_msg.rpc_proc->p_count++; |
| 1060 | clnt->cl_stats->rpccnt++; |
| 1061 | task->tk_action = call_reserve; |
| 1062 | } |
| 1063 | |
| 1064 | /* |
| 1065 | * 1. Reserve an RPC call slot |
| 1066 | */ |
| 1067 | static void |
| 1068 | call_reserve(struct rpc_task *task) |
| 1069 | { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1070 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | task->tk_status = 0; |
| 1073 | task->tk_action = call_reserveresult; |
| 1074 | xprt_reserve(task); |
| 1075 | } |
| 1076 | |
| 1077 | /* |
| 1078 | * 1b. Grok the result of xprt_reserve() |
| 1079 | */ |
| 1080 | static void |
| 1081 | call_reserveresult(struct rpc_task *task) |
| 1082 | { |
| 1083 | int status = task->tk_status; |
| 1084 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1085 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | |
| 1087 | /* |
| 1088 | * After a call to xprt_reserve(), we must have either |
| 1089 | * a request slot or else an error status. |
| 1090 | */ |
| 1091 | task->tk_status = 0; |
| 1092 | if (status >= 0) { |
| 1093 | if (task->tk_rqstp) { |
J. Bruce Fields | f2d47d0 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 1094 | task->tk_action = call_refresh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | return; |
| 1096 | } |
| 1097 | |
| 1098 | printk(KERN_ERR "%s: status=%d, but no request slot, exiting\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1099 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | rpc_exit(task, -EIO); |
| 1101 | return; |
| 1102 | } |
| 1103 | |
| 1104 | /* |
| 1105 | * Even though there was an error, we may have acquired |
| 1106 | * a request slot somehow. Make sure not to leak it. |
| 1107 | */ |
| 1108 | if (task->tk_rqstp) { |
| 1109 | printk(KERN_ERR "%s: status=%d, request allocated anyway\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1110 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | xprt_release(task); |
| 1112 | } |
| 1113 | |
| 1114 | switch (status) { |
| 1115 | case -EAGAIN: /* woken up; retry */ |
| 1116 | task->tk_action = call_reserve; |
| 1117 | return; |
| 1118 | case -EIO: /* probably a shutdown */ |
| 1119 | break; |
| 1120 | default: |
| 1121 | printk(KERN_ERR "%s: unrecognized error %d, exiting\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1122 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | break; |
| 1124 | } |
| 1125 | rpc_exit(task, status); |
| 1126 | } |
| 1127 | |
| 1128 | /* |
J. Bruce Fields | 5557624 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 1129 | * 2. Bind and/or refresh the credentials |
| 1130 | */ |
| 1131 | static void |
| 1132 | call_refresh(struct rpc_task *task) |
| 1133 | { |
| 1134 | dprint_status(task); |
| 1135 | |
| 1136 | task->tk_action = call_refreshresult; |
| 1137 | task->tk_status = 0; |
| 1138 | task->tk_client->cl_stats->rpcauthrefresh++; |
| 1139 | rpcauth_refreshcred(task); |
| 1140 | } |
| 1141 | |
| 1142 | /* |
| 1143 | * 2a. Process the results of a credential refresh |
| 1144 | */ |
| 1145 | static void |
| 1146 | call_refreshresult(struct rpc_task *task) |
| 1147 | { |
| 1148 | int status = task->tk_status; |
| 1149 | |
| 1150 | dprint_status(task); |
| 1151 | |
| 1152 | task->tk_status = 0; |
Trond Myklebust | 5fc4397 | 2010-11-20 11:13:31 -0500 | [diff] [blame] | 1153 | task->tk_action = call_refresh; |
J. Bruce Fields | 5557624 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 1154 | switch (status) { |
Trond Myklebust | 5fc4397 | 2010-11-20 11:13:31 -0500 | [diff] [blame] | 1155 | case 0: |
| 1156 | if (rpcauth_uptodatecred(task)) |
| 1157 | task->tk_action = call_allocate; |
J. Bruce Fields | 5557624 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 1158 | return; |
| 1159 | case -ETIMEDOUT: |
| 1160 | rpc_delay(task, 3*HZ); |
Trond Myklebust | 5fc4397 | 2010-11-20 11:13:31 -0500 | [diff] [blame] | 1161 | case -EAGAIN: |
| 1162 | status = -EACCES; |
| 1163 | if (!task->tk_cred_retry) |
| 1164 | break; |
| 1165 | task->tk_cred_retry--; |
| 1166 | dprintk("RPC: %5u %s: retry refresh creds\n", |
| 1167 | task->tk_pid, __func__); |
| 1168 | return; |
J. Bruce Fields | 5557624 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 1169 | } |
Trond Myklebust | 5fc4397 | 2010-11-20 11:13:31 -0500 | [diff] [blame] | 1170 | dprintk("RPC: %5u %s: refresh creds failed with error %d\n", |
| 1171 | task->tk_pid, __func__, status); |
| 1172 | rpc_exit(task, status); |
J. Bruce Fields | 5557624 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | /* |
| 1176 | * 2b. Allocate the buffer. For details, see sched.c:rpc_malloc. |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 1177 | * (Note: buffer memory is freed in xprt_release). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | */ |
| 1179 | static void |
| 1180 | call_allocate(struct rpc_task *task) |
| 1181 | { |
J. Bruce Fields | f2d47d0 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 1182 | unsigned int slack = task->tk_rqstp->rq_cred->cr_auth->au_cslack; |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 1183 | struct rpc_rqst *req = task->tk_rqstp; |
| 1184 | struct rpc_xprt *xprt = task->tk_xprt; |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1185 | struct rpc_procinfo *proc = task->tk_msg.rpc_proc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1187 | dprint_status(task); |
| 1188 | |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1189 | task->tk_status = 0; |
J. Bruce Fields | f2d47d0 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 1190 | task->tk_action = call_bind; |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1191 | |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 1192 | if (req->rq_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | return; |
| 1194 | |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1195 | if (proc->p_proc != 0) { |
| 1196 | BUG_ON(proc->p_arglen == 0); |
| 1197 | if (proc->p_decode != NULL) |
| 1198 | BUG_ON(proc->p_replen == 0); |
| 1199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1201 | /* |
| 1202 | * Calculate the size (in quads) of the RPC call |
| 1203 | * and reply headers, and convert both values |
| 1204 | * to byte sizes. |
| 1205 | */ |
| 1206 | req->rq_callsize = RPC_CALLHDRSIZE + (slack << 1) + proc->p_arglen; |
| 1207 | req->rq_callsize <<= 2; |
| 1208 | req->rq_rcvsize = RPC_REPHDRSIZE + slack + proc->p_replen; |
| 1209 | req->rq_rcvsize <<= 2; |
| 1210 | |
Chuck Lever | c5a4dd8 | 2007-03-29 16:47:58 -0400 | [diff] [blame] | 1211 | req->rq_buffer = xprt->ops->buf_alloc(task, |
| 1212 | req->rq_callsize + req->rq_rcvsize); |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1213 | if (req->rq_buffer != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | return; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1215 | |
| 1216 | dprintk("RPC: %5u rpc_buffer allocation failed\n", task->tk_pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | |
Trond Myklebust | 5afa913 | 2011-06-17 10:14:59 -0400 | [diff] [blame] | 1218 | if (RPC_IS_ASYNC(task) || !fatal_signal_pending(current)) { |
Trond Myklebust | b6e9c71 | 2007-10-01 12:06:44 -0400 | [diff] [blame] | 1219 | task->tk_action = call_allocate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | rpc_delay(task, HZ>>4); |
| 1221 | return; |
| 1222 | } |
| 1223 | |
| 1224 | rpc_exit(task, -ERESTARTSYS); |
| 1225 | } |
| 1226 | |
Trond Myklebust | 940e331 | 2005-11-09 21:45:24 -0500 | [diff] [blame] | 1227 | static inline int |
| 1228 | rpc_task_need_encode(struct rpc_task *task) |
| 1229 | { |
| 1230 | return task->tk_rqstp->rq_snd_buf.len == 0; |
| 1231 | } |
| 1232 | |
| 1233 | static inline void |
| 1234 | rpc_task_force_reencode(struct rpc_task *task) |
| 1235 | { |
| 1236 | task->tk_rqstp->rq_snd_buf.len = 0; |
Trond Myklebust | 2574cc9 | 2009-08-28 11:12:12 -0400 | [diff] [blame] | 1237 | task->tk_rqstp->rq_bytes_sent = 0; |
Trond Myklebust | 940e331 | 2005-11-09 21:45:24 -0500 | [diff] [blame] | 1238 | } |
| 1239 | |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1240 | static inline void |
| 1241 | rpc_xdr_buf_init(struct xdr_buf *buf, void *start, size_t len) |
| 1242 | { |
| 1243 | buf->head[0].iov_base = start; |
| 1244 | buf->head[0].iov_len = len; |
| 1245 | buf->tail[0].iov_len = 0; |
| 1246 | buf->page_len = 0; |
\"Talpey, Thomas\ | 4f22ccc | 2007-09-10 13:44:58 -0400 | [diff] [blame] | 1247 | buf->flags = 0; |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1248 | buf->len = 0; |
| 1249 | buf->buflen = len; |
| 1250 | } |
| 1251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | /* |
| 1253 | * 3. Encode arguments of an RPC call |
| 1254 | */ |
| 1255 | static void |
Chuck Lever | b0e1c57 | 2008-05-21 17:09:19 -0400 | [diff] [blame] | 1256 | rpc_xdr_encode(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | struct rpc_rqst *req = task->tk_rqstp; |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 1259 | kxdreproc_t encode; |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1260 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1262 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 1264 | rpc_xdr_buf_init(&req->rq_snd_buf, |
| 1265 | req->rq_buffer, |
| 1266 | req->rq_callsize); |
| 1267 | rpc_xdr_buf_init(&req->rq_rcv_buf, |
| 1268 | (char *)req->rq_buffer + req->rq_callsize, |
| 1269 | req->rq_rcvsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | |
Chuck Lever | b0e1c57 | 2008-05-21 17:09:19 -0400 | [diff] [blame] | 1271 | p = rpc_encode_header(task); |
| 1272 | if (p == NULL) { |
| 1273 | printk(KERN_INFO "RPC: couldn't encode RPC header, exit EIO\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | rpc_exit(task, -EIO); |
| 1275 | return; |
| 1276 | } |
Chuck Lever | b0e1c57 | 2008-05-21 17:09:19 -0400 | [diff] [blame] | 1277 | |
| 1278 | encode = task->tk_msg.rpc_proc->p_encode; |
J. Bruce Fields | f368031 | 2005-10-13 16:54:48 -0400 | [diff] [blame] | 1279 | if (encode == NULL) |
| 1280 | return; |
| 1281 | |
| 1282 | task->tk_status = rpcauth_wrap_req(task, encode, req, p, |
| 1283 | task->tk_msg.rpc_argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | /* |
| 1287 | * 4. Get the server port number if not yet set |
| 1288 | */ |
| 1289 | static void |
| 1290 | call_bind(struct rpc_task *task) |
| 1291 | { |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 1292 | struct rpc_xprt *xprt = task->tk_xprt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1294 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1296 | task->tk_action = call_connect; |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 1297 | if (!xprt_bound(xprt)) { |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1298 | task->tk_action = call_bind_status; |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 1299 | task->tk_timeout = xprt->bind_timeout; |
Chuck Lever | bbf7c1d | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 1300 | xprt->ops->rpcbind(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | /* |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1305 | * 4a. Sort out bind result |
| 1306 | */ |
| 1307 | static void |
| 1308 | call_bind_status(struct rpc_task *task) |
| 1309 | { |
Chuck Lever | 906462a | 2007-09-11 18:00:47 -0400 | [diff] [blame] | 1310 | int status = -EIO; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1311 | |
| 1312 | if (task->tk_status >= 0) { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1313 | dprint_status(task); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1314 | task->tk_status = 0; |
| 1315 | task->tk_action = call_connect; |
| 1316 | return; |
| 1317 | } |
| 1318 | |
Steve Dickson | 5753cba | 2012-02-06 10:08:08 -0500 | [diff] [blame] | 1319 | trace_rpc_bind_status(task); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1320 | switch (task->tk_status) { |
Trond Myklebust | 381ba74 | 2008-07-07 12:18:53 -0400 | [diff] [blame] | 1321 | case -ENOMEM: |
| 1322 | dprintk("RPC: %5u rpcbind out of memory\n", task->tk_pid); |
| 1323 | rpc_delay(task, HZ >> 2); |
Chuck Lever | 2429cbf | 2007-09-11 18:00:41 -0400 | [diff] [blame] | 1324 | goto retry_timeout; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1325 | case -EACCES: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1326 | dprintk("RPC: %5u remote rpcbind: RPC program/version " |
| 1327 | "unavailable\n", task->tk_pid); |
Chuck Lever | b79dc8c | 2007-09-11 18:00:52 -0400 | [diff] [blame] | 1328 | /* fail immediately if this is an RPC ping */ |
| 1329 | if (task->tk_msg.rpc_proc->p_proc == 0) { |
| 1330 | status = -EOPNOTSUPP; |
| 1331 | break; |
| 1332 | } |
Trond Myklebust | 0b76011 | 2011-05-31 15:15:34 -0400 | [diff] [blame] | 1333 | if (task->tk_rebind_retry == 0) |
| 1334 | break; |
| 1335 | task->tk_rebind_retry--; |
Chuck Lever | ea635a5 | 2005-10-06 23:12:58 -0400 | [diff] [blame] | 1336 | rpc_delay(task, 3*HZ); |
Trond Myklebust | da45828 | 2006-08-31 15:44:52 -0400 | [diff] [blame] | 1337 | goto retry_timeout; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1338 | case -ETIMEDOUT: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1339 | dprintk("RPC: %5u rpcbind request timed out\n", |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1340 | task->tk_pid); |
Trond Myklebust | da45828 | 2006-08-31 15:44:52 -0400 | [diff] [blame] | 1341 | goto retry_timeout; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1342 | case -EPFNOSUPPORT: |
Chuck Lever | 906462a | 2007-09-11 18:00:47 -0400 | [diff] [blame] | 1343 | /* server doesn't support any rpcbind version we know of */ |
Chuck Lever | 012da15 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1344 | dprintk("RPC: %5u unrecognized remote rpcbind service\n", |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1345 | task->tk_pid); |
| 1346 | break; |
| 1347 | case -EPROTONOSUPPORT: |
Chuck Lever | 00a6e7b | 2007-03-29 16:48:33 -0400 | [diff] [blame] | 1348 | dprintk("RPC: %5u remote rpcbind version unavailable, retrying\n", |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1349 | task->tk_pid); |
Chuck Lever | 00a6e7b | 2007-03-29 16:48:33 -0400 | [diff] [blame] | 1350 | task->tk_status = 0; |
| 1351 | task->tk_action = call_bind; |
| 1352 | return; |
Chuck Lever | 012da15 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1353 | case -ECONNREFUSED: /* connection problems */ |
| 1354 | case -ECONNRESET: |
| 1355 | case -ENOTCONN: |
| 1356 | case -EHOSTDOWN: |
| 1357 | case -EHOSTUNREACH: |
| 1358 | case -ENETUNREACH: |
| 1359 | case -EPIPE: |
| 1360 | dprintk("RPC: %5u remote rpcbind unreachable: %d\n", |
| 1361 | task->tk_pid, task->tk_status); |
| 1362 | if (!RPC_IS_SOFTCONN(task)) { |
| 1363 | rpc_delay(task, 5*HZ); |
| 1364 | goto retry_timeout; |
| 1365 | } |
| 1366 | status = task->tk_status; |
| 1367 | break; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1368 | default: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1369 | dprintk("RPC: %5u unrecognized rpcbind error (%d)\n", |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1370 | task->tk_pid, -task->tk_status); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | rpc_exit(task, status); |
| 1374 | return; |
| 1375 | |
Trond Myklebust | da45828 | 2006-08-31 15:44:52 -0400 | [diff] [blame] | 1376 | retry_timeout: |
| 1377 | task->tk_action = call_timeout; |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | /* |
| 1381 | * 4b. Connect to the RPC server |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | */ |
| 1383 | static void |
| 1384 | call_connect(struct rpc_task *task) |
| 1385 | { |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1386 | struct rpc_xprt *xprt = task->tk_xprt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1388 | dprintk("RPC: %5u call_connect xprt %p %s connected\n", |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1389 | task->tk_pid, xprt, |
| 1390 | (xprt_connected(xprt) ? "is" : "is not")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1392 | task->tk_action = call_transmit; |
| 1393 | if (!xprt_connected(xprt)) { |
| 1394 | task->tk_action = call_connect_status; |
| 1395 | if (task->tk_status < 0) |
| 1396 | return; |
| 1397 | xprt_connect(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | /* |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1402 | * 4c. Sort out connect result |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | */ |
| 1404 | static void |
| 1405 | call_connect_status(struct rpc_task *task) |
| 1406 | { |
| 1407 | struct rpc_clnt *clnt = task->tk_client; |
| 1408 | int status = task->tk_status; |
| 1409 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1410 | dprint_status(task); |
Chuck Lever | da35187 | 2005-08-11 16:25:11 -0400 | [diff] [blame] | 1411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | task->tk_status = 0; |
Trond Myklebust | 2a49199 | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 1413 | if (status >= 0 || status == -EAGAIN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | clnt->cl_stats->netreconn++; |
| 1415 | task->tk_action = call_transmit; |
| 1416 | return; |
| 1417 | } |
| 1418 | |
Steve Dickson | 5753cba | 2012-02-06 10:08:08 -0500 | [diff] [blame] | 1419 | trace_rpc_connect_status(task, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | switch (status) { |
Trond Myklebust | da45828 | 2006-08-31 15:44:52 -0400 | [diff] [blame] | 1421 | /* if soft mounted, test if we've timed out */ |
| 1422 | case -ETIMEDOUT: |
| 1423 | task->tk_action = call_timeout; |
Trond Myklebust | 2a49199 | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 1424 | break; |
| 1425 | default: |
| 1426 | rpc_exit(task, -EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | /* |
| 1431 | * 5. Transmit the RPC request, and wait for reply |
| 1432 | */ |
| 1433 | static void |
| 1434 | call_transmit(struct rpc_task *task) |
| 1435 | { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1436 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | |
| 1438 | task->tk_action = call_status; |
| 1439 | if (task->tk_status < 0) |
| 1440 | return; |
| 1441 | task->tk_status = xprt_prepare_transmit(task); |
| 1442 | if (task->tk_status != 0) |
| 1443 | return; |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 1444 | task->tk_action = call_transmit_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | /* Encode here so that rpcsec_gss can use correct sequence number. */ |
Trond Myklebust | 940e331 | 2005-11-09 21:45:24 -0500 | [diff] [blame] | 1446 | if (rpc_task_need_encode(task)) { |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 1447 | BUG_ON(task->tk_rqstp->rq_bytes_sent != 0); |
Chuck Lever | b0e1c57 | 2008-05-21 17:09:19 -0400 | [diff] [blame] | 1448 | rpc_xdr_encode(task); |
Trond Myklebust | 5e5ce5b | 2005-10-18 14:20:11 -0700 | [diff] [blame] | 1449 | /* Did the encode result in an error condition? */ |
Trond Myklebust | 8b39f2b | 2008-05-14 19:48:25 -0700 | [diff] [blame] | 1450 | if (task->tk_status != 0) { |
| 1451 | /* Was the error nonfatal? */ |
| 1452 | if (task->tk_status == -EAGAIN) |
| 1453 | rpc_delay(task, HZ >> 4); |
| 1454 | else |
| 1455 | rpc_exit(task, task->tk_status); |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 1456 | return; |
Trond Myklebust | 8b39f2b | 2008-05-14 19:48:25 -0700 | [diff] [blame] | 1457 | } |
Trond Myklebust | 5e5ce5b | 2005-10-18 14:20:11 -0700 | [diff] [blame] | 1458 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | xprt_transmit(task); |
| 1460 | if (task->tk_status < 0) |
| 1461 | return; |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 1462 | /* |
| 1463 | * On success, ensure that we call xprt_end_transmit() before sleeping |
| 1464 | * in order to allow access to the socket to other RPC requests. |
| 1465 | */ |
| 1466 | call_transmit_status(task); |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1467 | if (rpc_reply_expected(task)) |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 1468 | return; |
| 1469 | task->tk_action = rpc_exit_task; |
Trond Myklebust | fda1393 | 2008-02-22 16:34:12 -0500 | [diff] [blame] | 1470 | rpc_wake_up_queued_task(&task->tk_xprt->pending, task); |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | /* |
| 1474 | * 5a. Handle cleanup after a transmission |
| 1475 | */ |
| 1476 | static void |
| 1477 | call_transmit_status(struct rpc_task *task) |
| 1478 | { |
| 1479 | task->tk_action = call_status; |
Chuck Lever | 206a134 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1480 | |
| 1481 | /* |
| 1482 | * Common case: success. Force the compiler to put this |
| 1483 | * test first. |
| 1484 | */ |
| 1485 | if (task->tk_status == 0) { |
| 1486 | xprt_end_transmit(task); |
| 1487 | rpc_task_force_reencode(task); |
| 1488 | return; |
| 1489 | } |
| 1490 | |
Trond Myklebust | 15f081c | 2009-03-11 14:37:57 -0400 | [diff] [blame] | 1491 | switch (task->tk_status) { |
| 1492 | case -EAGAIN: |
| 1493 | break; |
| 1494 | default: |
Chuck Lever | 206a134 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1495 | dprint_status(task); |
Trond Myklebust | 15f081c | 2009-03-11 14:37:57 -0400 | [diff] [blame] | 1496 | xprt_end_transmit(task); |
Chuck Lever | 09a21c4 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1497 | rpc_task_force_reencode(task); |
| 1498 | break; |
Trond Myklebust | 15f081c | 2009-03-11 14:37:57 -0400 | [diff] [blame] | 1499 | /* |
| 1500 | * Special cases: if we've been waiting on the |
| 1501 | * socket's write_space() callback, or if the |
| 1502 | * socket just returned a connection error, |
| 1503 | * then hold onto the transport lock. |
| 1504 | */ |
| 1505 | case -ECONNREFUSED: |
Trond Myklebust | 15f081c | 2009-03-11 14:37:57 -0400 | [diff] [blame] | 1506 | case -EHOSTDOWN: |
| 1507 | case -EHOSTUNREACH: |
| 1508 | case -ENETUNREACH: |
Chuck Lever | 09a21c4 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1509 | if (RPC_IS_SOFTCONN(task)) { |
| 1510 | xprt_end_transmit(task); |
| 1511 | rpc_exit(task, task->tk_status); |
| 1512 | break; |
| 1513 | } |
| 1514 | case -ECONNRESET: |
| 1515 | case -ENOTCONN: |
Trond Myklebust | c8485e4 | 2009-03-11 14:37:59 -0400 | [diff] [blame] | 1516 | case -EPIPE: |
Trond Myklebust | 15f081c | 2009-03-11 14:37:57 -0400 | [diff] [blame] | 1517 | rpc_task_force_reencode(task); |
| 1518 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
Trond Myklebust | 9e00abc | 2011-07-13 19:20:49 -0400 | [diff] [blame] | 1521 | #if defined(CONFIG_SUNRPC_BACKCHANNEL) |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1522 | /* |
| 1523 | * 5b. Send the backchannel RPC reply. On error, drop the reply. In |
| 1524 | * addition, disconnect on connectivity errors. |
| 1525 | */ |
| 1526 | static void |
| 1527 | call_bc_transmit(struct rpc_task *task) |
| 1528 | { |
| 1529 | struct rpc_rqst *req = task->tk_rqstp; |
| 1530 | |
| 1531 | BUG_ON(task->tk_status != 0); |
| 1532 | task->tk_status = xprt_prepare_transmit(task); |
| 1533 | if (task->tk_status == -EAGAIN) { |
| 1534 | /* |
| 1535 | * Could not reserve the transport. Try again after the |
| 1536 | * transport is released. |
| 1537 | */ |
| 1538 | task->tk_status = 0; |
| 1539 | task->tk_action = call_bc_transmit; |
| 1540 | return; |
| 1541 | } |
| 1542 | |
| 1543 | task->tk_action = rpc_exit_task; |
| 1544 | if (task->tk_status < 0) { |
| 1545 | printk(KERN_NOTICE "RPC: Could not send backchannel reply " |
| 1546 | "error: %d\n", task->tk_status); |
| 1547 | return; |
| 1548 | } |
| 1549 | |
| 1550 | xprt_transmit(task); |
| 1551 | xprt_end_transmit(task); |
| 1552 | dprint_status(task); |
| 1553 | switch (task->tk_status) { |
| 1554 | case 0: |
| 1555 | /* Success */ |
| 1556 | break; |
| 1557 | case -EHOSTDOWN: |
| 1558 | case -EHOSTUNREACH: |
| 1559 | case -ENETUNREACH: |
| 1560 | case -ETIMEDOUT: |
| 1561 | /* |
| 1562 | * Problem reaching the server. Disconnect and let the |
| 1563 | * forechannel reestablish the connection. The server will |
| 1564 | * have to retransmit the backchannel request and we'll |
| 1565 | * reprocess it. Since these ops are idempotent, there's no |
| 1566 | * need to cache our reply at this time. |
| 1567 | */ |
| 1568 | printk(KERN_NOTICE "RPC: Could not send backchannel reply " |
| 1569 | "error: %d\n", task->tk_status); |
| 1570 | xprt_conditional_disconnect(task->tk_xprt, |
| 1571 | req->rq_connect_cookie); |
| 1572 | break; |
| 1573 | default: |
| 1574 | /* |
| 1575 | * We were unable to reply and will have to drop the |
| 1576 | * request. The server should reconnect and retransmit. |
| 1577 | */ |
| 1578 | BUG_ON(task->tk_status == -EAGAIN); |
| 1579 | printk(KERN_NOTICE "RPC: Could not send backchannel reply " |
| 1580 | "error: %d\n", task->tk_status); |
| 1581 | break; |
| 1582 | } |
| 1583 | rpc_wake_up_queued_task(&req->rq_xprt->pending, task); |
| 1584 | } |
Trond Myklebust | 9e00abc | 2011-07-13 19:20:49 -0400 | [diff] [blame] | 1585 | #endif /* CONFIG_SUNRPC_BACKCHANNEL */ |
Ricardo Labiaga | 55ae1aa | 2009-04-01 09:23:03 -0400 | [diff] [blame] | 1586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | /* |
| 1588 | * 6. Sort out the RPC call status |
| 1589 | */ |
| 1590 | static void |
| 1591 | call_status(struct rpc_task *task) |
| 1592 | { |
| 1593 | struct rpc_clnt *clnt = task->tk_client; |
| 1594 | struct rpc_rqst *req = task->tk_rqstp; |
| 1595 | int status; |
| 1596 | |
Ricardo Labiaga | dd2b63d | 2009-04-01 09:23:28 -0400 | [diff] [blame] | 1597 | if (req->rq_reply_bytes_recvd > 0 && !req->rq_bytes_sent) |
| 1598 | task->tk_status = req->rq_reply_bytes_recvd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1600 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | |
| 1602 | status = task->tk_status; |
| 1603 | if (status >= 0) { |
| 1604 | task->tk_action = call_decode; |
| 1605 | return; |
| 1606 | } |
| 1607 | |
Steve Dickson | 5753cba | 2012-02-06 10:08:08 -0500 | [diff] [blame] | 1608 | trace_rpc_call_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | task->tk_status = 0; |
| 1610 | switch(status) { |
Trond Myklebust | 7630399 | 2006-08-30 14:32:49 -0400 | [diff] [blame] | 1611 | case -EHOSTDOWN: |
| 1612 | case -EHOSTUNREACH: |
| 1613 | case -ENETUNREACH: |
| 1614 | /* |
| 1615 | * Delay any retries for 3 seconds, then handle as if it |
| 1616 | * were a timeout. |
| 1617 | */ |
| 1618 | rpc_delay(task, 3*HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | case -ETIMEDOUT: |
| 1620 | task->tk_action = call_timeout; |
Trond Myklebust | 241c39b | 2007-04-20 16:12:55 -0400 | [diff] [blame] | 1621 | if (task->tk_client->cl_discrtry) |
Trond Myklebust | 7c1d71c | 2008-04-17 16:52:57 -0400 | [diff] [blame] | 1622 | xprt_conditional_disconnect(task->tk_xprt, |
| 1623 | req->rq_connect_cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | break; |
Trond Myklebust | c8485e4 | 2009-03-11 14:37:59 -0400 | [diff] [blame] | 1625 | case -ECONNRESET: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | case -ECONNREFUSED: |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 1627 | rpc_force_rebind(clnt); |
Trond Myklebust | c8485e4 | 2009-03-11 14:37:59 -0400 | [diff] [blame] | 1628 | rpc_delay(task, 3*HZ); |
| 1629 | case -EPIPE: |
| 1630 | case -ENOTCONN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | task->tk_action = call_bind; |
| 1632 | break; |
| 1633 | case -EAGAIN: |
| 1634 | task->tk_action = call_transmit; |
| 1635 | break; |
| 1636 | case -EIO: |
| 1637 | /* shutdown or soft timeout */ |
| 1638 | rpc_exit(task, status); |
| 1639 | break; |
| 1640 | default: |
Olga Kornievskaia | b6b6152 | 2008-06-09 16:51:31 -0400 | [diff] [blame] | 1641 | if (clnt->cl_chatty) |
| 1642 | printk("%s: RPC call returned error %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | clnt->cl_protname, -status); |
| 1644 | rpc_exit(task, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | /* |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 1649 | * 6a. Handle RPC timeout |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | * We do not release the request slot, so we keep using the |
| 1651 | * same XID for all retransmits. |
| 1652 | */ |
| 1653 | static void |
| 1654 | call_timeout(struct rpc_task *task) |
| 1655 | { |
| 1656 | struct rpc_clnt *clnt = task->tk_client; |
| 1657 | |
| 1658 | if (xprt_adjust_timeout(task->tk_rqstp) == 0) { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1659 | dprintk("RPC: %5u call_timeout (minor)\n", task->tk_pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | goto retry; |
| 1661 | } |
| 1662 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1663 | dprintk("RPC: %5u call_timeout (major)\n", task->tk_pid); |
Chuck Lever | ef759a2 | 2006-03-20 13:44:17 -0500 | [diff] [blame] | 1664 | task->tk_timeouts++; |
| 1665 | |
Chuck Lever | 3a28bec | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1666 | if (RPC_IS_SOFTCONN(task)) { |
| 1667 | rpc_exit(task, -ETIMEDOUT); |
| 1668 | return; |
| 1669 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | if (RPC_IS_SOFT(task)) { |
Olga Kornievskaia | b6b6152 | 2008-06-09 16:51:31 -0400 | [diff] [blame] | 1671 | if (clnt->cl_chatty) |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 1672 | rcu_read_lock(); |
Olga Kornievskaia | b6b6152 | 2008-06-09 16:51:31 -0400 | [diff] [blame] | 1673 | printk(KERN_NOTICE "%s: server %s not responding, timed out\n", |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 1674 | clnt->cl_protname, |
| 1675 | rcu_dereference(clnt->cl_xprt)->servername); |
| 1676 | rcu_read_unlock(); |
Trond Myklebust | 7494d00 | 2011-04-24 14:28:45 -0400 | [diff] [blame] | 1677 | if (task->tk_flags & RPC_TASK_TIMEOUT) |
| 1678 | rpc_exit(task, -ETIMEDOUT); |
| 1679 | else |
| 1680 | rpc_exit(task, -EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | return; |
| 1682 | } |
| 1683 | |
Chuck Lever | f518e35a | 2006-01-03 09:55:52 +0100 | [diff] [blame] | 1684 | if (!(task->tk_flags & RPC_CALL_MAJORSEEN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | task->tk_flags |= RPC_CALL_MAJORSEEN; |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 1686 | if (clnt->cl_chatty) { |
| 1687 | rcu_read_lock(); |
Olga Kornievskaia | b6b6152 | 2008-06-09 16:51:31 -0400 | [diff] [blame] | 1688 | printk(KERN_NOTICE "%s: server %s not responding, still trying\n", |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 1689 | clnt->cl_protname, |
| 1690 | rcu_dereference(clnt->cl_xprt)->servername); |
| 1691 | rcu_read_unlock(); |
| 1692 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | } |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 1694 | rpc_force_rebind(clnt); |
Trond Myklebust | b48633b | 2008-04-22 16:47:55 -0400 | [diff] [blame] | 1695 | /* |
| 1696 | * Did our request time out due to an RPCSEC_GSS out-of-sequence |
| 1697 | * event? RFC2203 requires the server to drop all such requests. |
| 1698 | */ |
| 1699 | rpcauth_invalcred(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | |
| 1701 | retry: |
| 1702 | clnt->cl_stats->rpcretrans++; |
| 1703 | task->tk_action = call_bind; |
| 1704 | task->tk_status = 0; |
| 1705 | } |
| 1706 | |
| 1707 | /* |
| 1708 | * 7. Decode the RPC reply |
| 1709 | */ |
| 1710 | static void |
| 1711 | call_decode(struct rpc_task *task) |
| 1712 | { |
| 1713 | struct rpc_clnt *clnt = task->tk_client; |
| 1714 | struct rpc_rqst *req = task->tk_rqstp; |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 1715 | kxdrdproc_t decode = task->tk_msg.rpc_proc->p_decode; |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1716 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | |
Vasily Averin | 726fd6a | 2011-06-01 16:23:59 +0400 | [diff] [blame] | 1718 | dprint_status(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | |
Chuck Lever | f518e35a | 2006-01-03 09:55:52 +0100 | [diff] [blame] | 1720 | if (task->tk_flags & RPC_CALL_MAJORSEEN) { |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 1721 | if (clnt->cl_chatty) { |
| 1722 | rcu_read_lock(); |
Olga Kornievskaia | b6b6152 | 2008-06-09 16:51:31 -0400 | [diff] [blame] | 1723 | printk(KERN_NOTICE "%s: server %s OK\n", |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 1724 | clnt->cl_protname, |
| 1725 | rcu_dereference(clnt->cl_xprt)->servername); |
| 1726 | rcu_read_unlock(); |
| 1727 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | task->tk_flags &= ~RPC_CALL_MAJORSEEN; |
| 1729 | } |
| 1730 | |
Trond Myklebust | 43ac3f2 | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 1731 | /* |
| 1732 | * Ensure that we see all writes made by xprt_complete_rqst() |
Ricardo Labiaga | dd2b63d | 2009-04-01 09:23:28 -0400 | [diff] [blame] | 1733 | * before it changed req->rq_reply_bytes_recvd. |
Trond Myklebust | 43ac3f2 | 2006-03-20 13:44:51 -0500 | [diff] [blame] | 1734 | */ |
| 1735 | smp_rmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | req->rq_rcv_buf.len = req->rq_private_buf.len; |
| 1737 | |
| 1738 | /* Check that the softirq receive buffer is valid */ |
| 1739 | WARN_ON(memcmp(&req->rq_rcv_buf, &req->rq_private_buf, |
| 1740 | sizeof(req->rq_rcv_buf)) != 0); |
| 1741 | |
Trond Myklebust | 1e799b6 | 2008-03-21 16:19:41 -0400 | [diff] [blame] | 1742 | if (req->rq_rcv_buf.len < 12) { |
| 1743 | if (!RPC_IS_SOFT(task)) { |
| 1744 | task->tk_action = call_bind; |
| 1745 | clnt->cl_stats->rpcretrans++; |
| 1746 | goto out_retry; |
| 1747 | } |
| 1748 | dprintk("RPC: %s: too small RPC reply size (%d bytes)\n", |
| 1749 | clnt->cl_protname, task->tk_status); |
| 1750 | task->tk_action = call_timeout; |
| 1751 | goto out_retry; |
| 1752 | } |
| 1753 | |
Chuck Lever | b0e1c57 | 2008-05-21 17:09:19 -0400 | [diff] [blame] | 1754 | p = rpc_verify_header(task); |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1755 | if (IS_ERR(p)) { |
| 1756 | if (p == ERR_PTR(-EAGAIN)) |
| 1757 | goto out_retry; |
| 1758 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1761 | task->tk_action = rpc_exit_task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | |
Trond Myklebust | 6d5fcb5 | 2006-10-18 16:01:06 -0400 | [diff] [blame] | 1763 | if (decode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | task->tk_status = rpcauth_unwrap_resp(task, decode, req, p, |
| 1765 | task->tk_msg.rpc_resp); |
Trond Myklebust | 6d5fcb5 | 2006-10-18 16:01:06 -0400 | [diff] [blame] | 1766 | } |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1767 | dprintk("RPC: %5u call_decode result %d\n", task->tk_pid, |
| 1768 | task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | return; |
| 1770 | out_retry: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | task->tk_status = 0; |
Chuck Lever | b0e1c57 | 2008-05-21 17:09:19 -0400 | [diff] [blame] | 1772 | /* Note: rpc_verify_header() may have freed the RPC slot */ |
Trond Myklebust | 24b74bf | 2008-04-19 13:15:47 -0400 | [diff] [blame] | 1773 | if (task->tk_rqstp == req) { |
Ricardo Labiaga | dd2b63d | 2009-04-01 09:23:28 -0400 | [diff] [blame] | 1774 | req->rq_reply_bytes_recvd = req->rq_rcv_buf.len = 0; |
Trond Myklebust | 24b74bf | 2008-04-19 13:15:47 -0400 | [diff] [blame] | 1775 | if (task->tk_client->cl_discrtry) |
Trond Myklebust | 7c1d71c | 2008-04-17 16:52:57 -0400 | [diff] [blame] | 1776 | xprt_conditional_disconnect(task->tk_xprt, |
| 1777 | req->rq_connect_cookie); |
Trond Myklebust | 24b74bf | 2008-04-19 13:15:47 -0400 | [diff] [blame] | 1778 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1781 | static __be32 * |
Chuck Lever | b0e1c57 | 2008-05-21 17:09:19 -0400 | [diff] [blame] | 1782 | rpc_encode_header(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | { |
| 1784 | struct rpc_clnt *clnt = task->tk_client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | struct rpc_rqst *req = task->tk_rqstp; |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1786 | __be32 *p = req->rq_svec[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | |
| 1788 | /* FIXME: check buffer size? */ |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 1789 | |
| 1790 | p = xprt_skip_transport_header(task->tk_xprt, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | *p++ = req->rq_xid; /* XID */ |
| 1792 | *p++ = htonl(RPC_CALL); /* CALL */ |
| 1793 | *p++ = htonl(RPC_VERSION); /* RPC version */ |
| 1794 | *p++ = htonl(clnt->cl_prog); /* program number */ |
| 1795 | *p++ = htonl(clnt->cl_vers); /* program version */ |
| 1796 | *p++ = htonl(task->tk_msg.rpc_proc->p_proc); /* procedure */ |
Trond Myklebust | 334ccfd | 2005-06-22 17:16:19 +0000 | [diff] [blame] | 1797 | p = rpcauth_marshcred(task, p); |
| 1798 | req->rq_slen = xdr_adjust_iovec(&req->rq_svec[0], p); |
| 1799 | return p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1802 | static __be32 * |
Chuck Lever | b0e1c57 | 2008-05-21 17:09:19 -0400 | [diff] [blame] | 1803 | rpc_verify_header(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | { |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 1805 | struct rpc_clnt *clnt = task->tk_client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | struct kvec *iov = &task->tk_rqstp->rq_rcv_buf.head[0]; |
| 1807 | int len = task->tk_rqstp->rq_rcv_buf.len >> 2; |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1808 | __be32 *p = iov->iov_base; |
| 1809 | u32 n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | int error = -EACCES; |
| 1811 | |
David Howells | e889649 | 2006-08-24 15:44:19 -0400 | [diff] [blame] | 1812 | if ((task->tk_rqstp->rq_rcv_buf.len & 3) != 0) { |
| 1813 | /* RFC-1014 says that the representation of XDR data must be a |
| 1814 | * multiple of four bytes |
| 1815 | * - if it isn't pointer subtraction in the NFS client may give |
| 1816 | * undefined results |
| 1817 | */ |
Trond Myklebust | 8a702bb | 2007-06-27 18:30:26 -0400 | [diff] [blame] | 1818 | dprintk("RPC: %5u %s: XDR representation not a multiple of" |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1819 | " 4 bytes: 0x%x\n", task->tk_pid, __func__, |
Trond Myklebust | 8a702bb | 2007-06-27 18:30:26 -0400 | [diff] [blame] | 1820 | task->tk_rqstp->rq_rcv_buf.len); |
David Howells | e889649 | 2006-08-24 15:44:19 -0400 | [diff] [blame] | 1821 | goto out_eio; |
| 1822 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | if ((len -= 3) < 0) |
| 1824 | goto out_overflow; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | |
Ricardo Labiaga | f4a2e41 | 2009-04-01 09:22:54 -0400 | [diff] [blame] | 1826 | p += 1; /* skip XID */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | if ((n = ntohl(*p++)) != RPC_REPLY) { |
Trond Myklebust | 8a702bb | 2007-06-27 18:30:26 -0400 | [diff] [blame] | 1828 | dprintk("RPC: %5u %s: not an RPC reply: %x\n", |
Ricardo Labiaga | f4a2e41 | 2009-04-01 09:22:54 -0400 | [diff] [blame] | 1829 | task->tk_pid, __func__, n); |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1830 | goto out_garbage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | } |
Ricardo Labiaga | f4a2e41 | 2009-04-01 09:22:54 -0400 | [diff] [blame] | 1832 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | if ((n = ntohl(*p++)) != RPC_MSG_ACCEPTED) { |
| 1834 | if (--len < 0) |
| 1835 | goto out_overflow; |
| 1836 | switch ((n = ntohl(*p++))) { |
Joe Perches | 89f0e4f | 2011-07-01 09:43:12 +0000 | [diff] [blame] | 1837 | case RPC_AUTH_ERROR: |
| 1838 | break; |
| 1839 | case RPC_MISMATCH: |
| 1840 | dprintk("RPC: %5u %s: RPC call version mismatch!\n", |
| 1841 | task->tk_pid, __func__); |
| 1842 | error = -EPROTONOSUPPORT; |
| 1843 | goto out_err; |
| 1844 | default: |
| 1845 | dprintk("RPC: %5u %s: RPC call rejected, " |
| 1846 | "unknown error: %x\n", |
| 1847 | task->tk_pid, __func__, n); |
| 1848 | goto out_eio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | } |
| 1850 | if (--len < 0) |
| 1851 | goto out_overflow; |
| 1852 | switch ((n = ntohl(*p++))) { |
| 1853 | case RPC_AUTH_REJECTEDCRED: |
| 1854 | case RPC_AUTH_REJECTEDVERF: |
| 1855 | case RPCSEC_GSS_CREDPROBLEM: |
| 1856 | case RPCSEC_GSS_CTXPROBLEM: |
| 1857 | if (!task->tk_cred_retry) |
| 1858 | break; |
| 1859 | task->tk_cred_retry--; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1860 | dprintk("RPC: %5u %s: retry stale creds\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1861 | task->tk_pid, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | rpcauth_invalcred(task); |
Trond Myklebust | 220bcc2 | 2007-10-01 12:06:48 -0400 | [diff] [blame] | 1863 | /* Ensure we obtain a new XID! */ |
| 1864 | xprt_release(task); |
Trond Myklebust | 118df3d | 2010-10-24 17:17:31 -0400 | [diff] [blame] | 1865 | task->tk_action = call_reserve; |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1866 | goto out_retry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | case RPC_AUTH_BADCRED: |
| 1868 | case RPC_AUTH_BADVERF: |
| 1869 | /* possibly garbled cred/verf? */ |
| 1870 | if (!task->tk_garb_retry) |
| 1871 | break; |
| 1872 | task->tk_garb_retry--; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1873 | dprintk("RPC: %5u %s: retry garbled creds\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1874 | task->tk_pid, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | task->tk_action = call_bind; |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1876 | goto out_retry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | case RPC_AUTH_TOOWEAK: |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 1878 | rcu_read_lock(); |
Chuck Lever | b0e1c57 | 2008-05-21 17:09:19 -0400 | [diff] [blame] | 1879 | printk(KERN_NOTICE "RPC: server %s requires stronger " |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 1880 | "authentication.\n", |
| 1881 | rcu_dereference(clnt->cl_xprt)->servername); |
| 1882 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | break; |
| 1884 | default: |
Trond Myklebust | 8a702bb | 2007-06-27 18:30:26 -0400 | [diff] [blame] | 1885 | dprintk("RPC: %5u %s: unknown auth error: %x\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1886 | task->tk_pid, __func__, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | error = -EIO; |
| 1888 | } |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1889 | dprintk("RPC: %5u %s: call rejected %d\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1890 | task->tk_pid, __func__, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | goto out_err; |
| 1892 | } |
| 1893 | if (!(p = rpcauth_checkverf(task, p))) { |
Trond Myklebust | 8a702bb | 2007-06-27 18:30:26 -0400 | [diff] [blame] | 1894 | dprintk("RPC: %5u %s: auth check failed\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1895 | task->tk_pid, __func__); |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1896 | goto out_garbage; /* bad verifier, retry */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | } |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 1898 | len = p - (__be32 *)iov->iov_base - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | if (len < 0) |
| 1900 | goto out_overflow; |
| 1901 | switch ((n = ntohl(*p++))) { |
| 1902 | case RPC_SUCCESS: |
| 1903 | return p; |
| 1904 | case RPC_PROG_UNAVAIL: |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 1905 | dprintk_rcu("RPC: %5u %s: program %u is unsupported " |
| 1906 | "by server %s\n", task->tk_pid, __func__, |
| 1907 | (unsigned int)clnt->cl_prog, |
| 1908 | rcu_dereference(clnt->cl_xprt)->servername); |
Andreas Gruenbacher | cdf4770 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 1909 | error = -EPFNOSUPPORT; |
| 1910 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | case RPC_PROG_MISMATCH: |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 1912 | dprintk_rcu("RPC: %5u %s: program %u, version %u unsupported " |
| 1913 | "by server %s\n", task->tk_pid, __func__, |
| 1914 | (unsigned int)clnt->cl_prog, |
| 1915 | (unsigned int)clnt->cl_vers, |
| 1916 | rcu_dereference(clnt->cl_xprt)->servername); |
Andreas Gruenbacher | cdf4770 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 1917 | error = -EPROTONOSUPPORT; |
| 1918 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | case RPC_PROC_UNAVAIL: |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 1920 | dprintk_rcu("RPC: %5u %s: proc %s unsupported by program %u, " |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1921 | "version %u on server %s\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1922 | task->tk_pid, __func__, |
Chuck Lever | 3748f1e | 2008-05-21 17:09:12 -0400 | [diff] [blame] | 1923 | rpc_proc_name(task), |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 1924 | clnt->cl_prog, clnt->cl_vers, |
| 1925 | rcu_dereference(clnt->cl_xprt)->servername); |
Andreas Gruenbacher | cdf4770 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 1926 | error = -EOPNOTSUPP; |
| 1927 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | case RPC_GARBAGE_ARGS: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1929 | dprintk("RPC: %5u %s: server saw garbage\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1930 | task->tk_pid, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | break; /* retry */ |
| 1932 | default: |
Trond Myklebust | 8a702bb | 2007-06-27 18:30:26 -0400 | [diff] [blame] | 1933 | dprintk("RPC: %5u %s: server accept status: %x\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1934 | task->tk_pid, __func__, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | /* Also retry */ |
| 1936 | } |
| 1937 | |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1938 | out_garbage: |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame^] | 1939 | clnt->cl_stats->rpcgarbage++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | if (task->tk_garb_retry) { |
| 1941 | task->tk_garb_retry--; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1942 | dprintk("RPC: %5u %s: retrying\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1943 | task->tk_pid, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | task->tk_action = call_bind; |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1945 | out_retry: |
| 1946 | return ERR_PTR(-EAGAIN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | out_eio: |
| 1949 | error = -EIO; |
| 1950 | out_err: |
| 1951 | rpc_exit(task, error); |
Trond Myklebust | 8a702bb | 2007-06-27 18:30:26 -0400 | [diff] [blame] | 1952 | dprintk("RPC: %5u %s: call failed with error %d\n", task->tk_pid, |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1953 | __func__, error); |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1954 | return ERR_PTR(error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | out_overflow: |
Trond Myklebust | 8a702bb | 2007-06-27 18:30:26 -0400 | [diff] [blame] | 1956 | dprintk("RPC: %5u %s: server reply was truncated.\n", task->tk_pid, |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1957 | __func__); |
Trond Myklebust | abbcf28 | 2006-01-03 09:55:03 +0100 | [diff] [blame] | 1958 | goto out_garbage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | } |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 1960 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 1961 | static void rpcproc_encode_null(void *rqstp, struct xdr_stream *xdr, void *obj) |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 1962 | { |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 1965 | static int rpcproc_decode_null(void *rqstp, struct xdr_stream *xdr, void *obj) |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 1966 | { |
| 1967 | return 0; |
| 1968 | } |
| 1969 | |
| 1970 | static struct rpc_procinfo rpcproc_null = { |
| 1971 | .p_encode = rpcproc_encode_null, |
| 1972 | .p_decode = rpcproc_decode_null, |
| 1973 | }; |
| 1974 | |
Chuck Lever | caabea8 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1975 | static int rpc_ping(struct rpc_clnt *clnt) |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 1976 | { |
| 1977 | struct rpc_message msg = { |
| 1978 | .rpc_proc = &rpcproc_null, |
| 1979 | }; |
| 1980 | int err; |
| 1981 | msg.rpc_cred = authnull_ops.lookup_cred(NULL, NULL, 0); |
Chuck Lever | caabea8 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1982 | err = rpc_call_sync(clnt, &msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN); |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 1983 | put_rpccred(msg.rpc_cred); |
| 1984 | return err; |
| 1985 | } |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 1986 | |
Trond Myklebust | 5e1550d | 2007-06-23 10:17:16 -0400 | [diff] [blame] | 1987 | struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred, int flags) |
| 1988 | { |
| 1989 | struct rpc_message msg = { |
| 1990 | .rpc_proc = &rpcproc_null, |
| 1991 | .rpc_cred = cred, |
| 1992 | }; |
Trond Myklebust | 84115e1 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1993 | struct rpc_task_setup task_setup_data = { |
| 1994 | .rpc_client = clnt, |
| 1995 | .rpc_message = &msg, |
| 1996 | .callback_ops = &rpc_default_ops, |
| 1997 | .flags = flags, |
| 1998 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1999 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | 5e1550d | 2007-06-23 10:17:16 -0400 | [diff] [blame] | 2000 | } |
Trond Myklebust | e8914c6 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2001 | EXPORT_SYMBOL_GPL(rpc_call_null); |
Trond Myklebust | 5e1550d | 2007-06-23 10:17:16 -0400 | [diff] [blame] | 2002 | |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 2003 | #ifdef RPC_DEBUG |
Chuck Lever | 68a23ee | 2008-05-21 17:09:26 -0400 | [diff] [blame] | 2004 | static void rpc_show_header(void) |
| 2005 | { |
Chuck Lever | cb3997b | 2008-05-21 17:09:41 -0400 | [diff] [blame] | 2006 | printk(KERN_INFO "-pid- flgs status -client- --rqstp- " |
| 2007 | "-timeout ---ops--\n"); |
Chuck Lever | 68a23ee | 2008-05-21 17:09:26 -0400 | [diff] [blame] | 2008 | } |
| 2009 | |
Chuck Lever | 38e886e | 2008-05-21 17:09:33 -0400 | [diff] [blame] | 2010 | static void rpc_show_task(const struct rpc_clnt *clnt, |
| 2011 | const struct rpc_task *task) |
| 2012 | { |
| 2013 | const char *rpc_waitq = "none"; |
Chuck Lever | 38e886e | 2008-05-21 17:09:33 -0400 | [diff] [blame] | 2014 | |
| 2015 | if (RPC_IS_QUEUED(task)) |
| 2016 | rpc_waitq = rpc_qname(task->tk_waitqueue); |
| 2017 | |
Joe Perches | b3bceda | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2018 | printk(KERN_INFO "%5u %04x %6d %8p %8p %8ld %8p %sv%u %s a:%ps q:%s\n", |
Chuck Lever | cb3997b | 2008-05-21 17:09:41 -0400 | [diff] [blame] | 2019 | task->tk_pid, task->tk_flags, task->tk_status, |
| 2020 | clnt, task->tk_rqstp, task->tk_timeout, task->tk_ops, |
| 2021 | clnt->cl_protname, clnt->cl_vers, rpc_proc_name(task), |
Joe Perches | b3bceda | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2022 | task->tk_action, rpc_waitq); |
Chuck Lever | 38e886e | 2008-05-21 17:09:33 -0400 | [diff] [blame] | 2023 | } |
| 2024 | |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 2025 | void rpc_show_tasks(struct net *net) |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 2026 | { |
| 2027 | struct rpc_clnt *clnt; |
Chuck Lever | 38e886e | 2008-05-21 17:09:33 -0400 | [diff] [blame] | 2028 | struct rpc_task *task; |
Chuck Lever | 68a23ee | 2008-05-21 17:09:26 -0400 | [diff] [blame] | 2029 | int header = 0; |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 2030 | struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 2031 | |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 2032 | spin_lock(&sn->rpc_client_lock); |
| 2033 | list_for_each_entry(clnt, &sn->all_clients, cl_clients) { |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 2034 | spin_lock(&clnt->cl_lock); |
Chuck Lever | 38e886e | 2008-05-21 17:09:33 -0400 | [diff] [blame] | 2035 | list_for_each_entry(task, &clnt->cl_tasks, tk_task) { |
Chuck Lever | 68a23ee | 2008-05-21 17:09:26 -0400 | [diff] [blame] | 2036 | if (!header) { |
| 2037 | rpc_show_header(); |
| 2038 | header++; |
| 2039 | } |
Chuck Lever | 38e886e | 2008-05-21 17:09:33 -0400 | [diff] [blame] | 2040 | rpc_show_task(clnt, task); |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 2041 | } |
| 2042 | spin_unlock(&clnt->cl_lock); |
| 2043 | } |
Stanislav Kinsbursky | 70abc49 | 2012-01-12 22:07:51 +0400 | [diff] [blame] | 2044 | spin_unlock(&sn->rpc_client_lock); |
Trond Myklebust | 188fef1 | 2007-06-16 14:18:40 -0400 | [diff] [blame] | 2045 | } |
| 2046 | #endif |