blob: 7783fc0e726361cd711135cb80e778decda44505 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Chuck Lever55aa4f52005-08-11 16:25:47 -04002 * linux/net/sunrpc/clnt.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
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 Torvalds1da177e2005-04-16 15:20:36 -070016 * 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 Levercb3997b2008-05-21 17:09:41 -040024#include <linux/kallsyms.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/mm.h>
Trond Myklebust23ac6582009-08-09 15:14:25 -040026#include <linux/namei.h>
27#include <linux/mount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/utsname.h>
Chuck Lever11c556b2006-03-20 13:44:22 -050030#include <linux/workqueue.h>
Chuck Lever176e21e2011-05-09 15:22:44 -040031#include <linux/in.h>
Chuck Lever510deb02007-12-10 14:56:24 -050032#include <linux/in6.h>
Chuck Lever176e21e2011-05-09 15:22:44 -040033#include <linux/un.h>
Trond Myklebust2446ab62012-03-01 17:00:56 -050034#include <linux/rcupdate.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36#include <linux/sunrpc/clnt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/sunrpc/rpc_pipe_fs.h>
Chuck Lever11c556b2006-03-20 13:44:22 -050038#include <linux/sunrpc/metrics.h>
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -040039#include <linux/sunrpc/bc_xprt.h>
Steve Dickson5753cba2012-02-06 10:08:08 -050040#include <trace/events/sunrpc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -040042#include "sunrpc.h"
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +040043#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#ifdef RPC_DEBUG
46# define RPCDBG_FACILITY RPCDBG_CALL
47#endif
48
Chuck Lever46121cf2007-01-31 12:14:08 -050049#define dprint_status(t) \
50 dprintk("RPC: %5u %s (status %d)\n", t->tk_pid, \
Harvey Harrison0dc47872008-03-05 20:47:47 -080051 __func__, t->tk_status)
Chuck Lever46121cf2007-01-31 12:14:08 -050052
Trond Myklebust188fef12007-06-16 14:18:40 -040053/*
54 * All RPC clients are linked into this list
55 */
Trond Myklebust188fef12007-06-16 14:18:40 -040056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057static DECLARE_WAIT_QUEUE_HEAD(destroy_wait);
58
59
60static void call_start(struct rpc_task *task);
61static void call_reserve(struct rpc_task *task);
62static void call_reserveresult(struct rpc_task *task);
63static void call_allocate(struct rpc_task *task);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static void call_decode(struct rpc_task *task);
65static void call_bind(struct rpc_task *task);
Chuck Leverda351872005-08-11 16:25:11 -040066static void call_bind_status(struct rpc_task *task);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067static void call_transmit(struct rpc_task *task);
Trond Myklebust9e00abc2011-07-13 19:20:49 -040068#if defined(CONFIG_SUNRPC_BACKCHANNEL)
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -040069static void call_bc_transmit(struct rpc_task *task);
Trond Myklebust9e00abc2011-07-13 19:20:49 -040070#endif /* CONFIG_SUNRPC_BACKCHANNEL */
Linus Torvalds1da177e2005-04-16 15:20:36 -070071static void call_status(struct rpc_task *task);
Trond Myklebust940e3312005-11-09 21:45:24 -050072static void call_transmit_status(struct rpc_task *task);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073static void call_refresh(struct rpc_task *task);
74static void call_refreshresult(struct rpc_task *task);
75static void call_timeout(struct rpc_task *task);
76static void call_connect(struct rpc_task *task);
77static void call_connect_status(struct rpc_task *task);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Chuck Leverb0e1c572008-05-21 17:09:19 -040079static __be32 *rpc_encode_header(struct rpc_task *task);
80static __be32 *rpc_verify_header(struct rpc_task *task);
Chuck Levercaabea82009-12-03 15:58:56 -050081static int rpc_ping(struct rpc_clnt *clnt);
Trond Myklebust64c91a12007-06-23 10:17:16 -040082
Trond Myklebust188fef12007-06-16 14:18:40 -040083static void rpc_register_client(struct rpc_clnt *clnt)
84{
Trond Myklebust2446ab62012-03-01 17:00:56 -050085 struct net *net = rpc_net_ns(clnt);
86 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +040087
88 spin_lock(&sn->rpc_client_lock);
89 list_add(&clnt->cl_clients, &sn->all_clients);
90 spin_unlock(&sn->rpc_client_lock);
Trond Myklebust188fef12007-06-16 14:18:40 -040091}
92
93static void rpc_unregister_client(struct rpc_clnt *clnt)
94{
Trond Myklebust2446ab62012-03-01 17:00:56 -050095 struct net *net = rpc_net_ns(clnt);
96 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +040097
98 spin_lock(&sn->rpc_client_lock);
Trond Myklebust188fef12007-06-16 14:18:40 -040099 list_del(&clnt->cl_clients);
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +0400100 spin_unlock(&sn->rpc_client_lock);
Trond Myklebust188fef12007-06-16 14:18:40 -0400101}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Stanislav Kinsbursky0157d022012-01-11 19:18:01 +0400103static void __rpc_clnt_remove_pipedir(struct rpc_clnt *clnt)
104{
Stanislav Kinsbursky30507f52012-01-11 19:18:42 +0400105 if (clnt->cl_dentry) {
Stanislav Kinsbursky80df9d22012-01-11 19:18:17 +0400106 if (clnt->cl_auth && clnt->cl_auth->au_ops->pipes_destroy)
107 clnt->cl_auth->au_ops->pipes_destroy(clnt->cl_auth);
Stanislav Kinsbursky30507f52012-01-11 19:18:42 +0400108 rpc_remove_client_dir(clnt->cl_dentry);
Stanislav Kinsbursky80df9d22012-01-11 19:18:17 +0400109 }
Stanislav Kinsbursky30507f52012-01-11 19:18:42 +0400110 clnt->cl_dentry = NULL;
Stanislav Kinsbursky0157d022012-01-11 19:18:01 +0400111}
112
113static void rpc_clnt_remove_pipedir(struct rpc_clnt *clnt)
114{
Trond Myklebust2446ab62012-03-01 17:00:56 -0500115 struct net *net = rpc_net_ns(clnt);
Stanislav Kinsbursky0157d022012-01-11 19:18:01 +0400116 struct super_block *pipefs_sb;
Stanislav Kinsbursky0157d022012-01-11 19:18:01 +0400117
Trond Myklebust2446ab62012-03-01 17:00:56 -0500118 pipefs_sb = rpc_get_sb_net(net);
Stanislav Kinsbursky0157d022012-01-11 19:18:01 +0400119 if (pipefs_sb) {
Stanislav Kinsbursky0157d022012-01-11 19:18:01 +0400120 __rpc_clnt_remove_pipedir(clnt);
Trond Myklebust2446ab62012-03-01 17:00:56 -0500121 rpc_put_sb_net(net);
Stanislav Kinsbursky0157d022012-01-11 19:18:01 +0400122 }
Stanislav Kinsbursky0157d022012-01-11 19:18:01 +0400123}
124
125static struct dentry *rpc_setup_pipedir_sb(struct super_block *sb,
Trond Myklebust080b7942012-01-20 13:53:56 -0500126 struct rpc_clnt *clnt,
127 const char *dir_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
Trond Myklebustf1345852005-09-23 11:08:25 -0400129 static uint32_t clntid;
Trond Myklebust23ac6582009-08-09 15:14:25 -0400130 char name[15];
131 struct qstr q = {
132 .name = name,
133 };
Stanislav Kinsbursky0157d022012-01-11 19:18:01 +0400134 struct dentry *dir, *dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 int error;
136
Stanislav Kinsbursky0157d022012-01-11 19:18:01 +0400137 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
159static int
Trond Myklebust080b7942012-01-20 13:53:56 -0500160rpc_setup_pipedir(struct rpc_clnt *clnt, const char *dir_name)
Stanislav Kinsbursky0157d022012-01-11 19:18:01 +0400161{
Trond Myklebust2446ab62012-03-01 17:00:56 -0500162 struct net *net = rpc_net_ns(clnt);
Stanislav Kinsbursky0157d022012-01-11 19:18:01 +0400163 struct super_block *pipefs_sb;
Stanislav Kinsbursky30507f52012-01-11 19:18:42 +0400164 struct dentry *dentry;
Stanislav Kinsbursky0157d022012-01-11 19:18:01 +0400165
Stanislav Kinsbursky30507f52012-01-11 19:18:42 +0400166 clnt->cl_dentry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 if (dir_name == NULL)
168 return 0;
Trond Myklebust2446ab62012-03-01 17:00:56 -0500169 pipefs_sb = rpc_get_sb_net(net);
Stanislav Kinsbursky70fe25b2012-01-11 19:18:34 +0400170 if (!pipefs_sb)
171 return 0;
Stanislav Kinsbursky30507f52012-01-11 19:18:42 +0400172 dentry = rpc_setup_pipedir_sb(pipefs_sb, clnt, dir_name);
Trond Myklebust2446ab62012-03-01 17:00:56 -0500173 rpc_put_sb_net(net);
Stanislav Kinsbursky30507f52012-01-11 19:18:42 +0400174 if (IS_ERR(dentry))
175 return PTR_ERR(dentry);
176 clnt->cl_dentry = dentry;
Trond Myklebust23ac6582009-08-09 15:14:25 -0400177 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178}
179
Stanislav Kinsbursky80df9d22012-01-11 19:18:17 +0400180static 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 Kinsbursky30507f52012-01-11 19:18:42 +0400195 clnt->cl_dentry = dentry;
Stanislav Kinsbursky80df9d22012-01-11 19:18:17 +0400196 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 Kinsburskyda3b4622012-02-27 22:05:29 +0400212static 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 Kinsbursky80df9d22012-01-11 19:18:17 +0400230static 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 Kinsbursky80df9d22012-01-11 19:18:17 +0400236
Stanislav Kinsburskyda3b4622012-02-27 22:05:29 +0400237 while ((clnt = rpc_get_client_for_event(sb->s_fs_info, event))) {
Stanislav Kinsbursky80df9d22012-01-11 19:18:17 +0400238 error = __rpc_pipefs_event(clnt, event, sb);
Stanislav Kinsburskyda3b4622012-02-27 22:05:29 +0400239 rpc_release_client(clnt);
Stanislav Kinsbursky80df9d22012-01-11 19:18:17 +0400240 if (error)
241 break;
242 }
Stanislav Kinsbursky80df9d22012-01-11 19:18:17 +0400243 return error;
244}
245
246static struct notifier_block rpc_clients_block = {
247 .notifier_call = rpc_pipefs_event,
Stanislav Kinsburskyeee173252012-01-10 16:13:19 +0400248 .priority = SUNRPC_PIPEFS_RPC_PRIO,
Stanislav Kinsbursky80df9d22012-01-11 19:18:17 +0400249};
250
251int rpc_clients_notifier_register(void)
252{
253 return rpc_pipefs_notifier_register(&rpc_clients_block);
254}
255
256void rpc_clients_notifier_unregister(void)
257{
258 return rpc_pipefs_notifier_unregister(&rpc_clients_block);
259}
260
Trond Myklebust698b6d02007-12-20 16:03:53 -0500261static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, struct rpc_xprt *xprt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
Trond Myklebusta613fa12012-01-20 13:53:56 -0500263 const struct rpc_program *program = args->program;
264 const struct rpc_version *version;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 struct rpc_clnt *clnt = NULL;
J. Bruce Fields6a192752005-06-22 17:16:23 +0000266 struct rpc_auth *auth;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 int err;
Chuck Lever06b8d252007-09-11 18:00:20 -0400268 size_t len;
269
270 /* sanity check the name before trying to print it */
271 err = -EINVAL;
Trond Myklebust698b6d02007-12-20 16:03:53 -0500272 len = strlen(args->servername);
Chuck Lever06b8d252007-09-11 18:00:20 -0400273 if (len > RPC_MAXNETNAMELEN)
274 goto out_no_rpciod;
275 len++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Chuck Lever46121cf2007-01-31 12:14:08 -0500277 dprintk("RPC: creating %s client for %s (xprt %p)\n",
Trond Myklebust698b6d02007-12-20 16:03:53 -0500278 program->name, args->servername, xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Trond Myklebust4ada5392007-06-14 17:26:17 -0400280 err = rpciod_up();
281 if (err)
282 goto out_no_rpciod;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 err = -EINVAL;
284 if (!xprt)
Adrian Bunk712917d2006-03-13 21:20:47 -0800285 goto out_no_xprt;
Trond Myklebust698b6d02007-12-20 16:03:53 -0500286
287 if (args->version >= program->nrvers)
288 goto out_err;
289 version = program->version[args->version];
290 if (version == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 goto out_err;
292
293 err = -ENOMEM;
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700294 clnt = kzalloc(sizeof(*clnt), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 if (!clnt)
296 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 clnt->cl_parent = clnt;
298
Trond Myklebust6eac7d32012-01-20 13:53:37 -0500299 clnt->cl_server = kstrdup(args->servername, GFP_KERNEL);
300 if (clnt->cl_server == NULL)
301 goto out_no_server;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Trond Myklebust2446ab62012-03-01 17:00:56 -0500303 rcu_assign_pointer(clnt->cl_xprt, xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 clnt->cl_procinfo = version->procs;
305 clnt->cl_maxproc = version->nrprocs;
306 clnt->cl_protname = program->name;
Benny Halevyd5b337b2008-09-28 09:21:26 +0300307 clnt->cl_prog = args->prognumber ? : program->number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 clnt->cl_vers = version->number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 clnt->cl_stats = program->stats;
Chuck Lever11c556b2006-03-20 13:44:22 -0500310 clnt->cl_metrics = rpc_alloc_iostats(clnt);
Trond Myklebust23bf85b2006-11-21 10:40:23 -0500311 err = -ENOMEM;
312 if (clnt->cl_metrics == NULL)
313 goto out_no_stats;
Trond Myklebust3e32a5d2006-11-16 11:37:27 -0500314 clnt->cl_program = program;
Trond Myklebust6529eba2007-06-14 16:40:14 -0400315 INIT_LIST_HEAD(&clnt->cl_tasks);
Trond Myklebust4bef61f2007-06-16 14:17:01 -0400316 spin_lock_init(&clnt->cl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Trond Myklebust2446ab62012-03-01 17:00:56 -0500318 if (!xprt_bound(xprt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 clnt->cl_autobind = 1;
320
Trond Myklebustba7392b2007-12-20 16:03:55 -0500321 clnt->cl_timeout = xprt->timeout;
322 if (args->timeout != NULL) {
323 memcpy(&clnt->cl_timeout_default, args->timeout,
324 sizeof(clnt->cl_timeout_default));
325 clnt->cl_timeout = &clnt->cl_timeout_default;
326 }
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 clnt->cl_rtt = &clnt->cl_rtt_default;
Trond Myklebustba7392b2007-12-20 16:03:55 -0500329 rpc_init_rtt(&clnt->cl_rtt_default, clnt->cl_timeout->to_initval);
Olga Kornievskaia608207e2008-12-23 16:17:40 -0500330 clnt->cl_principal = NULL;
331 if (args->client_name) {
332 clnt->cl_principal = kstrdup(args->client_name, GFP_KERNEL);
333 if (!clnt->cl_principal)
334 goto out_no_principal;
335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Trond Myklebust006abe82010-09-12 19:55:25 -0400337 atomic_set(&clnt->cl_count, 1);
Trond Myklebust34f52e32007-06-14 16:40:31 -0400338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 err = rpc_setup_pipedir(clnt, program->pipe_dir_name);
340 if (err < 0)
341 goto out_no_path;
342
Trond Myklebust698b6d02007-12-20 16:03:53 -0500343 auth = rpcauth_create(args->authflavor, clnt);
J. Bruce Fields6a192752005-06-22 17:16:23 +0000344 if (IS_ERR(auth)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 printk(KERN_INFO "RPC: Couldn't create auth handle (flavor %u)\n",
Trond Myklebust698b6d02007-12-20 16:03:53 -0500346 args->authflavor);
J. Bruce Fields6a192752005-06-22 17:16:23 +0000347 err = PTR_ERR(auth);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 goto out_no_auth;
349 }
350
351 /* save the nodename */
Cedric Le Goater63ffc232008-10-03 23:41:51 -0400352 clnt->cl_nodelen = strlen(init_utsname()->nodename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 if (clnt->cl_nodelen > UNX_MAXNODENAME)
354 clnt->cl_nodelen = UNX_MAXNODENAME;
Cedric Le Goater63ffc232008-10-03 23:41:51 -0400355 memcpy(clnt->cl_nodename, init_utsname()->nodename, clnt->cl_nodelen);
Trond Myklebust6529eba2007-06-14 16:40:14 -0400356 rpc_register_client(clnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 return clnt;
358
359out_no_auth:
Stanislav Kinsbursky0157d022012-01-11 19:18:01 +0400360 rpc_clnt_remove_pipedir(clnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361out_no_path:
Olga Kornievskaia608207e2008-12-23 16:17:40 -0500362 kfree(clnt->cl_principal);
363out_no_principal:
Trond Myklebust23bf85b2006-11-21 10:40:23 -0500364 rpc_free_iostats(clnt->cl_metrics);
365out_no_stats:
Trond Myklebust6eac7d32012-01-20 13:53:37 -0500366 kfree(clnt->cl_server);
367out_no_server:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 kfree(clnt);
369out_err:
Trond Myklebust6b6ca862006-09-05 12:55:57 -0400370 xprt_put(xprt);
Adrian Bunk712917d2006-03-13 21:20:47 -0800371out_no_xprt:
Trond Myklebust4ada5392007-06-14 17:26:17 -0400372 rpciod_down();
373out_no_rpciod:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 return ERR_PTR(err);
375}
376
Chuck Leverc2866762006-08-22 20:06:20 -0400377/*
378 * rpc_create - create an RPC client and transport with one call
379 * @args: rpc_clnt create argument structure
380 *
381 * Creates and initializes an RPC transport and an RPC client.
382 *
383 * It can ping the server in order to determine if it is up, and to see if
384 * it supports this program and version. RPC_CLNT_CREATE_NOPING disables
385 * this behavior so asynchronous tasks can also use rpc_create.
386 */
387struct rpc_clnt *rpc_create(struct rpc_create_args *args)
388{
389 struct rpc_xprt *xprt;
390 struct rpc_clnt *clnt;
\"Talpey, Thomas\3c341b0b2007-09-10 13:47:07 -0400391 struct xprt_create xprtargs = {
Pavel Emelyanov9a23e332010-09-29 16:05:12 +0400392 .net = args->net,
\"Talpey, Thomas\4fa016e2007-09-10 13:47:57 -0400393 .ident = args->protocol,
Frank van Maarseveend3bc9a12007-07-09 22:23:35 +0200394 .srcaddr = args->saddress,
Frank van Maarseveen96802a02007-07-08 13:08:54 +0200395 .dstaddr = args->address,
396 .addrlen = args->addrsize,
Alexandros Batsakisf300bab2009-09-10 17:33:30 +0300397 .bc_xprt = args->bc_xprt,
Frank van Maarseveen96802a02007-07-08 13:08:54 +0200398 };
Chuck Lever510deb02007-12-10 14:56:24 -0500399 char servername[48];
Chuck Leverc2866762006-08-22 20:06:20 -0400400
Chuck Leverc2866762006-08-22 20:06:20 -0400401 /*
Chuck Lever43780b82007-07-01 12:13:22 -0400402 * If the caller chooses not to specify a hostname, whip
403 * up a string representation of the passed-in address.
404 */
405 if (args->servername == NULL) {
Chuck Lever176e21e2011-05-09 15:22:44 -0400406 struct sockaddr_un *sun =
407 (struct sockaddr_un *)args->address;
Chuck Leverda09eb92011-05-09 15:22:25 -0400408 struct sockaddr_in *sin =
409 (struct sockaddr_in *)args->address;
410 struct sockaddr_in6 *sin6 =
411 (struct sockaddr_in6 *)args->address;
412
Chuck Lever510deb02007-12-10 14:56:24 -0500413 servername[0] = '\0';
414 switch (args->address->sa_family) {
Chuck Lever176e21e2011-05-09 15:22:44 -0400415 case AF_LOCAL:
416 snprintf(servername, sizeof(servername), "%s",
417 sun->sun_path);
418 break;
Chuck Leverda09eb92011-05-09 15:22:25 -0400419 case AF_INET:
Harvey Harrison21454aa2008-10-31 00:54:56 -0700420 snprintf(servername, sizeof(servername), "%pI4",
421 &sin->sin_addr.s_addr);
Chuck Lever510deb02007-12-10 14:56:24 -0500422 break;
Chuck Leverda09eb92011-05-09 15:22:25 -0400423 case AF_INET6:
Harvey Harrison5b095d9892008-10-29 12:52:50 -0700424 snprintf(servername, sizeof(servername), "%pI6",
Chuck Leverda09eb92011-05-09 15:22:25 -0400425 &sin6->sin6_addr);
Chuck Lever510deb02007-12-10 14:56:24 -0500426 break;
Chuck Lever510deb02007-12-10 14:56:24 -0500427 default:
428 /* caller wants default server name, but
429 * address family isn't recognized. */
430 return ERR_PTR(-EINVAL);
431 }
Chuck Lever43780b82007-07-01 12:13:22 -0400432 args->servername = servername;
433 }
434
Chuck Lever510deb02007-12-10 14:56:24 -0500435 xprt = xprt_create_transport(&xprtargs);
436 if (IS_ERR(xprt))
437 return (struct rpc_clnt *)xprt;
438
Chuck Lever43780b82007-07-01 12:13:22 -0400439 /*
Chuck Leverc2866762006-08-22 20:06:20 -0400440 * By default, kernel RPC client connects from a reserved port.
441 * CAP_NET_BIND_SERVICE will not be set for unprivileged requesters,
442 * but it is always enabled for rpciod, which handles the connect
443 * operation.
444 */
445 xprt->resvport = 1;
446 if (args->flags & RPC_CLNT_CREATE_NONPRIVPORT)
447 xprt->resvport = 0;
448
Trond Myklebust698b6d02007-12-20 16:03:53 -0500449 clnt = rpc_new_client(args, xprt);
Chuck Leverc2866762006-08-22 20:06:20 -0400450 if (IS_ERR(clnt))
451 return clnt;
452
453 if (!(args->flags & RPC_CLNT_CREATE_NOPING)) {
Chuck Levercaabea82009-12-03 15:58:56 -0500454 int err = rpc_ping(clnt);
Chuck Leverc2866762006-08-22 20:06:20 -0400455 if (err != 0) {
456 rpc_shutdown_client(clnt);
457 return ERR_PTR(err);
458 }
459 }
460
461 clnt->cl_softrtry = 1;
462 if (args->flags & RPC_CLNT_CREATE_HARDRTRY)
463 clnt->cl_softrtry = 0;
464
Chuck Leverc2866762006-08-22 20:06:20 -0400465 if (args->flags & RPC_CLNT_CREATE_AUTOBIND)
466 clnt->cl_autobind = 1;
Chuck Lever43d78ef2007-02-06 18:26:11 -0500467 if (args->flags & RPC_CLNT_CREATE_DISCRTRY)
468 clnt->cl_discrtry = 1;
Olga Kornievskaiab6b61522008-06-09 16:51:31 -0400469 if (!(args->flags & RPC_CLNT_CREATE_QUIET))
470 clnt->cl_chatty = 1;
Chuck Leverc2866762006-08-22 20:06:20 -0400471
472 return clnt;
473}
Chuck Leverb86acd52006-08-22 20:06:22 -0400474EXPORT_SYMBOL_GPL(rpc_create);
Chuck Leverc2866762006-08-22 20:06:20 -0400475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476/*
477 * This function clones the RPC client structure. It allows us to share the
478 * same transport while varying parameters such as the authentication
479 * flavour.
480 */
481struct rpc_clnt *
482rpc_clone_client(struct rpc_clnt *clnt)
483{
484 struct rpc_clnt *new;
Trond Myklebust2446ab62012-03-01 17:00:56 -0500485 struct rpc_xprt *xprt;
Trond Myklebust3e32a5d2006-11-16 11:37:27 -0500486 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Arnaldo Carvalho de Meloe69062b2006-11-21 01:21:34 -0200488 new = kmemdup(clnt, sizeof(*new), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 if (!new)
490 goto out_no_clnt;
Trond Myklebust6eac7d32012-01-20 13:53:37 -0500491 new->cl_server = kstrdup(clnt->cl_server, GFP_KERNEL);
492 if (new->cl_server == NULL)
493 goto out_no_server;
Trond Myklebustd431a5552007-06-17 17:07:54 -0400494 new->cl_parent = clnt;
495 /* Turn off autobind on clones */
496 new->cl_autobind = 0;
497 INIT_LIST_HEAD(&new->cl_tasks);
498 spin_lock_init(&new->cl_lock);
Trond Myklebustba7392b2007-12-20 16:03:55 -0500499 rpc_init_rtt(&new->cl_rtt_default, clnt->cl_timeout->to_initval);
Trond Myklebust23bf85b2006-11-21 10:40:23 -0500500 new->cl_metrics = rpc_alloc_iostats(clnt);
501 if (new->cl_metrics == NULL)
502 goto out_no_stats;
Olga Kornievskaia608207e2008-12-23 16:17:40 -0500503 if (clnt->cl_principal) {
504 new->cl_principal = kstrdup(clnt->cl_principal, GFP_KERNEL);
505 if (new->cl_principal == NULL)
506 goto out_no_principal;
507 }
Trond Myklebust2446ab62012-03-01 17:00:56 -0500508 rcu_read_lock();
509 xprt = xprt_get(rcu_dereference(clnt->cl_xprt));
510 rcu_read_unlock();
511 if (xprt == NULL)
512 goto out_no_transport;
513 rcu_assign_pointer(new->cl_xprt, xprt);
Trond Myklebust006abe82010-09-12 19:55:25 -0400514 atomic_set(&new->cl_count, 1);
Trond Myklebust3e32a5d2006-11-16 11:37:27 -0500515 err = rpc_setup_pipedir(new, clnt->cl_program->pipe_dir_name);
516 if (err != 0)
517 goto out_no_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 if (new->cl_auth)
519 atomic_inc(&new->cl_auth->au_count);
Trond Myklebust006abe82010-09-12 19:55:25 -0400520 atomic_inc(&clnt->cl_count);
Trond Myklebust6529eba2007-06-14 16:40:14 -0400521 rpc_register_client(new);
Trond Myklebust4ada5392007-06-14 17:26:17 -0400522 rpciod_up();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 return new;
Trond Myklebust3e32a5d2006-11-16 11:37:27 -0500524out_no_path:
Trond Myklebust2446ab62012-03-01 17:00:56 -0500525 xprt_put(xprt);
526out_no_transport:
Olga Kornievskaia608207e2008-12-23 16:17:40 -0500527 kfree(new->cl_principal);
528out_no_principal:
Trond Myklebust3e32a5d2006-11-16 11:37:27 -0500529 rpc_free_iostats(new->cl_metrics);
Trond Myklebust23bf85b2006-11-21 10:40:23 -0500530out_no_stats:
Trond Myklebust6eac7d32012-01-20 13:53:37 -0500531 kfree(new->cl_server);
532out_no_server:
Trond Myklebust23bf85b2006-11-21 10:40:23 -0500533 kfree(new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534out_no_clnt:
Harvey Harrison0dc47872008-03-05 20:47:47 -0800535 dprintk("RPC: %s: returned error %d\n", __func__, err);
Trond Myklebust3e32a5d2006-11-16 11:37:27 -0500536 return ERR_PTR(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537}
Trond Myklebuste8914c62007-07-14 15:39:59 -0400538EXPORT_SYMBOL_GPL(rpc_clone_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
540/*
Trond Myklebust58f96122010-07-31 14:29:08 -0400541 * Kill all tasks for the given client.
542 * XXX: kill their descendants as well?
543 */
544void rpc_killall_tasks(struct rpc_clnt *clnt)
545{
546 struct rpc_task *rovr;
547
548
549 if (list_empty(&clnt->cl_tasks))
550 return;
551 dprintk("RPC: killing all tasks for client %p\n", clnt);
552 /*
553 * Spin lock all_tasks to prevent changes...
554 */
555 spin_lock(&clnt->cl_lock);
556 list_for_each_entry(rovr, &clnt->cl_tasks, tk_task) {
557 if (!RPC_IS_ACTIVATED(rovr))
558 continue;
559 if (!(rovr->tk_flags & RPC_TASK_KILLED)) {
560 rovr->tk_flags |= RPC_TASK_KILLED;
561 rpc_exit(rovr, -EIO);
Stanislav Kinsbursky8e26de22011-03-17 18:54:23 +0300562 if (RPC_IS_QUEUED(rovr))
563 rpc_wake_up_queued_task(rovr->tk_waitqueue,
564 rovr);
Trond Myklebust58f96122010-07-31 14:29:08 -0400565 }
566 }
567 spin_unlock(&clnt->cl_lock);
568}
569EXPORT_SYMBOL_GPL(rpc_killall_tasks);
570
571/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 * Properly shut down an RPC client, terminating all outstanding
Trond Myklebust90c57552007-06-09 19:49:36 -0400573 * requests.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 */
Trond Myklebust4c402b42007-06-14 16:40:32 -0400575void rpc_shutdown_client(struct rpc_clnt *clnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
Trond Myklebust34f52e32007-06-14 16:40:31 -0400577 dprintk("RPC: shutting down %s client for %s\n",
578 clnt->cl_protname, clnt->cl_server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Trond Myklebust34f52e32007-06-14 16:40:31 -0400580 while (!list_empty(&clnt->cl_tasks)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 rpc_killall_tasks(clnt);
Ingo Molnar532347e2006-01-09 20:52:53 -0800582 wait_event_timeout(destroy_wait,
Trond Myklebust34f52e32007-06-14 16:40:31 -0400583 list_empty(&clnt->cl_tasks), 1*HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 }
585
Trond Myklebust4c402b42007-06-14 16:40:32 -0400586 rpc_release_client(clnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587}
Trond Myklebuste8914c62007-07-14 15:39:59 -0400588EXPORT_SYMBOL_GPL(rpc_shutdown_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590/*
Trond Myklebust34f52e32007-06-14 16:40:31 -0400591 * Free an RPC client
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 */
Trond Myklebust34f52e32007-06-14 16:40:31 -0400593static void
Trond Myklebust006abe82010-09-12 19:55:25 -0400594rpc_free_client(struct rpc_clnt *clnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
Chuck Lever46121cf2007-01-31 12:14:08 -0500596 dprintk("RPC: destroying %s client for %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 clnt->cl_protname, clnt->cl_server);
Trond Myklebust6eac7d32012-01-20 13:53:37 -0500598 if (clnt->cl_parent != clnt)
Trond Myklebust8ad7c892007-06-14 16:40:32 -0400599 rpc_release_client(clnt->cl_parent);
Trond Myklebust6eac7d32012-01-20 13:53:37 -0500600 kfree(clnt->cl_server);
Trond Myklebust6529eba2007-06-14 16:40:14 -0400601 rpc_unregister_client(clnt);
Stanislav Kinsburskyf5131252012-01-11 19:18:26 +0400602 rpc_clnt_remove_pipedir(clnt);
Chuck Lever11c556b2006-03-20 13:44:22 -0500603 rpc_free_iostats(clnt->cl_metrics);
Olga Kornievskaia608207e2008-12-23 16:17:40 -0500604 kfree(clnt->cl_principal);
Chuck Lever11c556b2006-03-20 13:44:22 -0500605 clnt->cl_metrics = NULL;
Trond Myklebust2446ab62012-03-01 17:00:56 -0500606 xprt_put(rcu_dereference_raw(clnt->cl_xprt));
Trond Myklebust4ada5392007-06-14 17:26:17 -0400607 rpciod_down();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 kfree(clnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609}
610
611/*
Trond Myklebust1dd17ec2007-06-26 16:57:41 -0400612 * Free an RPC client
613 */
614static void
Trond Myklebust006abe82010-09-12 19:55:25 -0400615rpc_free_auth(struct rpc_clnt *clnt)
Trond Myklebust1dd17ec2007-06-26 16:57:41 -0400616{
Trond Myklebust1dd17ec2007-06-26 16:57:41 -0400617 if (clnt->cl_auth == NULL) {
Trond Myklebust006abe82010-09-12 19:55:25 -0400618 rpc_free_client(clnt);
Trond Myklebust1dd17ec2007-06-26 16:57:41 -0400619 return;
620 }
621
622 /*
623 * Note: RPCSEC_GSS may need to send NULL RPC calls in order to
624 * release remaining GSS contexts. This mechanism ensures
625 * that it can do so safely.
626 */
Trond Myklebust006abe82010-09-12 19:55:25 -0400627 atomic_inc(&clnt->cl_count);
Trond Myklebust1dd17ec2007-06-26 16:57:41 -0400628 rpcauth_release(clnt->cl_auth);
629 clnt->cl_auth = NULL;
Trond Myklebust006abe82010-09-12 19:55:25 -0400630 if (atomic_dec_and_test(&clnt->cl_count))
631 rpc_free_client(clnt);
Trond Myklebust1dd17ec2007-06-26 16:57:41 -0400632}
633
634/*
Trond Myklebust34f52e32007-06-14 16:40:31 -0400635 * Release reference to the RPC client
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 */
637void
638rpc_release_client(struct rpc_clnt *clnt)
639{
Trond Myklebust34f52e32007-06-14 16:40:31 -0400640 dprintk("RPC: rpc_release_client(%p)\n", clnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Trond Myklebust34f52e32007-06-14 16:40:31 -0400642 if (list_empty(&clnt->cl_tasks))
643 wake_up(&destroy_wait);
Trond Myklebust006abe82010-09-12 19:55:25 -0400644 if (atomic_dec_and_test(&clnt->cl_count))
645 rpc_free_auth(clnt);
Trond Myklebust34f52e32007-06-14 16:40:31 -0400646}
647
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000648/**
649 * rpc_bind_new_program - bind a new RPC program to an existing client
Randy Dunlap65b6e422008-02-13 15:03:23 -0800650 * @old: old rpc_client
651 * @program: rpc program to set
652 * @vers: rpc program version
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000653 *
654 * Clones the rpc client and sets up a new RPC program. This is mainly
655 * of use for enabling different RPC programs to share the same transport.
656 * The Sun NFSv2/v3 ACL protocol can do this.
657 */
658struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *old,
Trond Myklebusta613fa12012-01-20 13:53:56 -0500659 const struct rpc_program *program,
Chuck Lever89eb21c2007-09-11 18:00:09 -0400660 u32 vers)
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000661{
662 struct rpc_clnt *clnt;
Trond Myklebusta613fa12012-01-20 13:53:56 -0500663 const struct rpc_version *version;
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000664 int err;
665
666 BUG_ON(vers >= program->nrvers || !program->version[vers]);
667 version = program->version[vers];
668 clnt = rpc_clone_client(old);
669 if (IS_ERR(clnt))
670 goto out;
671 clnt->cl_procinfo = version->procs;
672 clnt->cl_maxproc = version->nrprocs;
673 clnt->cl_protname = program->name;
674 clnt->cl_prog = program->number;
675 clnt->cl_vers = version->number;
676 clnt->cl_stats = program->stats;
Chuck Levercaabea82009-12-03 15:58:56 -0500677 err = rpc_ping(clnt);
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000678 if (err != 0) {
679 rpc_shutdown_client(clnt);
680 clnt = ERR_PTR(err);
681 }
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800682out:
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000683 return clnt;
684}
Trond Myklebuste8914c62007-07-14 15:39:59 -0400685EXPORT_SYMBOL_GPL(rpc_bind_new_program);
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000686
Trond Myklebust58f96122010-07-31 14:29:08 -0400687void rpc_task_release_client(struct rpc_task *task)
688{
689 struct rpc_clnt *clnt = task->tk_client;
690
691 if (clnt != NULL) {
692 /* Remove from client task list */
693 spin_lock(&clnt->cl_lock);
694 list_del(&task->tk_task);
695 spin_unlock(&clnt->cl_lock);
696 task->tk_client = NULL;
697
698 rpc_release_client(clnt);
699 }
700}
701
702static
703void rpc_task_set_client(struct rpc_task *task, struct rpc_clnt *clnt)
704{
705 if (clnt != NULL) {
706 rpc_task_release_client(task);
707 task->tk_client = clnt;
Trond Myklebust006abe82010-09-12 19:55:25 -0400708 atomic_inc(&clnt->cl_count);
Trond Myklebust58f96122010-07-31 14:29:08 -0400709 if (clnt->cl_softrtry)
710 task->tk_flags |= RPC_TASK_SOFT;
711 /* Add to the client's list of all tasks */
712 spin_lock(&clnt->cl_lock);
713 list_add_tail(&task->tk_task, &clnt->cl_tasks);
714 spin_unlock(&clnt->cl_lock);
715 }
716}
717
Andy Adamsoncbdabc72011-03-01 01:34:20 +0000718void rpc_task_reset_client(struct rpc_task *task, struct rpc_clnt *clnt)
719{
720 rpc_task_release_client(task);
721 rpc_task_set_client(task, clnt);
722}
723EXPORT_SYMBOL_GPL(rpc_task_reset_client);
724
725
Trond Myklebust58f96122010-07-31 14:29:08 -0400726static void
727rpc_task_set_rpc_message(struct rpc_task *task, const struct rpc_message *msg)
728{
729 if (msg != NULL) {
730 task->tk_msg.rpc_proc = msg->rpc_proc;
731 task->tk_msg.rpc_argp = msg->rpc_argp;
732 task->tk_msg.rpc_resp = msg->rpc_resp;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400733 if (msg->rpc_cred != NULL)
734 task->tk_msg.rpc_cred = get_rpccred(msg->rpc_cred);
Trond Myklebust58f96122010-07-31 14:29:08 -0400735 }
736}
737
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738/*
739 * Default callback for async RPC calls
740 */
741static void
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100742rpc_default_callback(struct rpc_task *task, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743{
744}
745
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100746static const struct rpc_call_ops rpc_default_ops = {
747 .rpc_call_done = rpc_default_callback,
748};
749
Trond Myklebustc970aa82007-07-14 15:39:59 -0400750/**
751 * rpc_run_task - Allocate a new RPC task, then run rpc_execute against it
752 * @task_setup_data: pointer to task initialisation data
753 */
754struct rpc_task *rpc_run_task(const struct rpc_task_setup *task_setup_data)
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400755{
Trond Myklebust19445b92010-04-16 16:41:10 -0400756 struct rpc_task *task;
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400757
Trond Myklebust84115e12007-07-14 15:39:59 -0400758 task = rpc_new_task(task_setup_data);
Trond Myklebust19445b92010-04-16 16:41:10 -0400759 if (IS_ERR(task))
Trond Myklebust50859252007-10-25 18:19:37 -0400760 goto out;
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400761
Trond Myklebust58f96122010-07-31 14:29:08 -0400762 rpc_task_set_client(task, task_setup_data->rpc_client);
763 rpc_task_set_rpc_message(task, task_setup_data->rpc_message);
764
Trond Myklebust58f96122010-07-31 14:29:08 -0400765 if (task->tk_action == NULL)
766 rpc_call_start(task);
767
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400768 atomic_inc(&task->tk_count);
769 rpc_execute(task);
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400770out:
Trond Myklebust19445b92010-04-16 16:41:10 -0400771 return task;
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400772}
Trond Myklebustc970aa82007-07-14 15:39:59 -0400773EXPORT_SYMBOL_GPL(rpc_run_task);
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400774
775/**
776 * rpc_call_sync - Perform a synchronous RPC call
777 * @clnt: pointer to RPC client
778 * @msg: RPC call parameters
779 * @flags: RPC call flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 */
Trond Myklebustcbc20052008-02-14 11:11:30 -0500781int rpc_call_sync(struct rpc_clnt *clnt, const struct rpc_message *msg, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782{
783 struct rpc_task *task;
Trond Myklebust84115e12007-07-14 15:39:59 -0400784 struct rpc_task_setup task_setup_data = {
785 .rpc_client = clnt,
786 .rpc_message = msg,
787 .callback_ops = &rpc_default_ops,
788 .flags = flags,
789 };
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400790 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 BUG_ON(flags & RPC_TASK_ASYNC);
793
Trond Myklebustc970aa82007-07-14 15:39:59 -0400794 task = rpc_run_task(&task_setup_data);
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400795 if (IS_ERR(task))
796 return PTR_ERR(task);
Trond Myklebuste60859a2006-01-03 09:55:10 +0100797 status = task->tk_status;
Trond Myklebustbde8f002007-01-24 11:54:53 -0800798 rpc_put_task(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 return status;
800}
Trond Myklebuste8914c62007-07-14 15:39:59 -0400801EXPORT_SYMBOL_GPL(rpc_call_sync);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400803/**
804 * rpc_call_async - Perform an asynchronous RPC call
805 * @clnt: pointer to RPC client
806 * @msg: RPC call parameters
807 * @flags: RPC call flags
Randy Dunlap65b6e422008-02-13 15:03:23 -0800808 * @tk_ops: RPC call ops
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400809 * @data: user call data
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 */
811int
Trond Myklebustcbc20052008-02-14 11:11:30 -0500812rpc_call_async(struct rpc_clnt *clnt, const struct rpc_message *msg, int flags,
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100813 const struct rpc_call_ops *tk_ops, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
815 struct rpc_task *task;
Trond Myklebust84115e12007-07-14 15:39:59 -0400816 struct rpc_task_setup task_setup_data = {
817 .rpc_client = clnt,
818 .rpc_message = msg,
819 .callback_ops = tk_ops,
820 .callback_data = data,
821 .flags = flags|RPC_TASK_ASYNC,
822 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
Trond Myklebustc970aa82007-07-14 15:39:59 -0400824 task = rpc_run_task(&task_setup_data);
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400825 if (IS_ERR(task))
826 return PTR_ERR(task);
827 rpc_put_task(task);
828 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829}
Trond Myklebuste8914c62007-07-14 15:39:59 -0400830EXPORT_SYMBOL_GPL(rpc_call_async);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Trond Myklebust9e00abc2011-07-13 19:20:49 -0400832#if defined(CONFIG_SUNRPC_BACKCHANNEL)
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400833/**
834 * rpc_run_bc_task - Allocate a new RPC task for backchannel use, then run
835 * rpc_execute against it
Jaswinder Singh Rajput7a73fdd2009-09-24 14:58:42 -0400836 * @req: RPC request
837 * @tk_ops: RPC call ops
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400838 */
839struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req,
Jaswinder Singh Rajput7a73fdd2009-09-24 14:58:42 -0400840 const struct rpc_call_ops *tk_ops)
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400841{
842 struct rpc_task *task;
843 struct xdr_buf *xbufp = &req->rq_snd_buf;
844 struct rpc_task_setup task_setup_data = {
845 .callback_ops = tk_ops,
846 };
847
848 dprintk("RPC: rpc_run_bc_task req= %p\n", req);
849 /*
850 * Create an rpc_task to send the data
851 */
852 task = rpc_new_task(&task_setup_data);
Trond Myklebust19445b92010-04-16 16:41:10 -0400853 if (IS_ERR(task)) {
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400854 xprt_free_bc_request(req);
855 goto out;
856 }
857 task->tk_rqstp = req;
858
859 /*
860 * Set up the xdr_buf length.
861 * This also indicates that the buffer is XDR encoded already.
862 */
863 xbufp->len = xbufp->head[0].iov_len + xbufp->page_len +
864 xbufp->tail[0].iov_len;
865
866 task->tk_action = call_bc_transmit;
867 atomic_inc(&task->tk_count);
868 BUG_ON(atomic_read(&task->tk_count) != 2);
869 rpc_execute(task);
870
871out:
872 dprintk("RPC: rpc_run_bc_task: task= %p\n", task);
873 return task;
874}
Trond Myklebust9e00abc2011-07-13 19:20:49 -0400875#endif /* CONFIG_SUNRPC_BACKCHANNEL */
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877void
Trond Myklebust77de2c52007-10-25 18:40:21 -0400878rpc_call_start(struct rpc_task *task)
879{
880 task->tk_action = call_start;
881}
882EXPORT_SYMBOL_GPL(rpc_call_start);
883
Chuck Levered394402006-08-22 20:06:17 -0400884/**
885 * rpc_peeraddr - extract remote peer address from clnt's xprt
886 * @clnt: RPC client structure
887 * @buf: target buffer
Randy Dunlap65b6e422008-02-13 15:03:23 -0800888 * @bufsize: length of target buffer
Chuck Levered394402006-08-22 20:06:17 -0400889 *
890 * Returns the number of bytes that are actually in the stored address.
891 */
892size_t rpc_peeraddr(struct rpc_clnt *clnt, struct sockaddr *buf, size_t bufsize)
893{
894 size_t bytes;
Trond Myklebust2446ab62012-03-01 17:00:56 -0500895 struct rpc_xprt *xprt;
Chuck Levered394402006-08-22 20:06:17 -0400896
Trond Myklebust2446ab62012-03-01 17:00:56 -0500897 rcu_read_lock();
898 xprt = rcu_dereference(clnt->cl_xprt);
899
900 bytes = xprt->addrlen;
Chuck Levered394402006-08-22 20:06:17 -0400901 if (bytes > bufsize)
902 bytes = bufsize;
Trond Myklebust2446ab62012-03-01 17:00:56 -0500903 memcpy(buf, &xprt->addr, bytes);
904 rcu_read_unlock();
905
906 return bytes;
Chuck Levered394402006-08-22 20:06:17 -0400907}
Chuck Leverb86acd52006-08-22 20:06:22 -0400908EXPORT_SYMBOL_GPL(rpc_peeraddr);
Chuck Levered394402006-08-22 20:06:17 -0400909
Chuck Leverf425eba2006-08-22 20:06:18 -0400910/**
911 * rpc_peeraddr2str - return remote peer address in printable format
912 * @clnt: RPC client structure
913 * @format: address format
914 *
Trond Myklebust2446ab62012-03-01 17:00:56 -0500915 * NB: the lifetime of the memory referenced by the returned pointer is
916 * the same as the rpc_xprt itself. As long as the caller uses this
917 * pointer, it must hold the RCU read lock.
Chuck Leverf425eba2006-08-22 20:06:18 -0400918 */
Chuck Leverb454ae92008-01-07 18:34:48 -0500919const char *rpc_peeraddr2str(struct rpc_clnt *clnt,
920 enum rpc_display_format_t format)
Chuck Leverf425eba2006-08-22 20:06:18 -0400921{
Trond Myklebust2446ab62012-03-01 17:00:56 -0500922 struct rpc_xprt *xprt;
923
924 xprt = rcu_dereference(clnt->cl_xprt);
Chuck Lever7559c7a2006-12-05 16:35:37 -0500925
926 if (xprt->address_strings[format] != NULL)
927 return xprt->address_strings[format];
928 else
929 return "unprintable";
Chuck Leverf425eba2006-08-22 20:06:18 -0400930}
Chuck Leverb86acd52006-08-22 20:06:22 -0400931EXPORT_SYMBOL_GPL(rpc_peeraddr2str);
Chuck Leverf425eba2006-08-22 20:06:18 -0400932
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933void
934rpc_setbufsize(struct rpc_clnt *clnt, unsigned int sndsize, unsigned int rcvsize)
935{
Trond Myklebust2446ab62012-03-01 17:00:56 -0500936 struct rpc_xprt *xprt;
937
938 rcu_read_lock();
939 xprt = rcu_dereference(clnt->cl_xprt);
Chuck Lever470056c2005-08-25 16:25:56 -0700940 if (xprt->ops->set_buffer_size)
941 xprt->ops->set_buffer_size(xprt, sndsize, rcvsize);
Trond Myklebust2446ab62012-03-01 17:00:56 -0500942 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943}
Trond Myklebuste8914c62007-07-14 15:39:59 -0400944EXPORT_SYMBOL_GPL(rpc_setbufsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
Trond Myklebust2446ab62012-03-01 17:00:56 -0500946/**
947 * rpc_protocol - Get transport protocol number for an RPC client
948 * @clnt: RPC client to query
949 *
950 */
951int rpc_protocol(struct rpc_clnt *clnt)
952{
953 int protocol;
954
955 rcu_read_lock();
956 protocol = rcu_dereference(clnt->cl_xprt)->prot;
957 rcu_read_unlock();
958 return protocol;
959}
960EXPORT_SYMBOL_GPL(rpc_protocol);
961
962/**
963 * rpc_net_ns - Get the network namespace for this RPC client
964 * @clnt: RPC client to query
965 *
966 */
967struct net *rpc_net_ns(struct rpc_clnt *clnt)
968{
969 struct net *ret;
970
971 rcu_read_lock();
972 ret = rcu_dereference(clnt->cl_xprt)->xprt_net;
973 rcu_read_unlock();
974 return ret;
975}
976EXPORT_SYMBOL_GPL(rpc_net_ns);
977
978/**
979 * rpc_max_payload - Get maximum payload size for a transport, in bytes
980 * @clnt: RPC client to query
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 *
982 * For stream transports, this is one RPC record fragment (see RFC
983 * 1831), as we don't support multi-record requests yet. For datagram
984 * transports, this is the size of an IP packet minus the IP, UDP, and
985 * RPC header sizes.
986 */
987size_t rpc_max_payload(struct rpc_clnt *clnt)
988{
Trond Myklebust2446ab62012-03-01 17:00:56 -0500989 size_t ret;
990
991 rcu_read_lock();
992 ret = rcu_dereference(clnt->cl_xprt)->max_payload;
993 rcu_read_unlock();
994 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995}
Chuck Leverb86acd52006-08-22 20:06:22 -0400996EXPORT_SYMBOL_GPL(rpc_max_payload);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Chuck Lever35f5a422006-01-03 09:55:50 +0100998/**
999 * rpc_force_rebind - force transport to check that remote port is unchanged
1000 * @clnt: client to rebind
1001 *
1002 */
1003void rpc_force_rebind(struct rpc_clnt *clnt)
1004{
Trond Myklebust2446ab62012-03-01 17:00:56 -05001005 if (clnt->cl_autobind) {
1006 rcu_read_lock();
1007 xprt_clear_bound(rcu_dereference(clnt->cl_xprt));
1008 rcu_read_unlock();
1009 }
Chuck Lever35f5a422006-01-03 09:55:50 +01001010}
Chuck Leverb86acd52006-08-22 20:06:22 -04001011EXPORT_SYMBOL_GPL(rpc_force_rebind);
Chuck Lever35f5a422006-01-03 09:55:50 +01001012
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013/*
Andy Adamsonaae20062009-04-01 09:22:40 -04001014 * Restart an (async) RPC call from the call_prepare state.
1015 * Usually called from within the exit handler.
1016 */
Trond Myklebustf1f88fc2010-07-31 14:29:07 -04001017int
Andy Adamsonaae20062009-04-01 09:22:40 -04001018rpc_restart_call_prepare(struct rpc_task *task)
1019{
1020 if (RPC_ASSASSINATED(task))
Trond Myklebustf1f88fc2010-07-31 14:29:07 -04001021 return 0;
Trond Myklebustd00c5d42011-10-19 12:17:29 -07001022 task->tk_action = call_start;
1023 if (task->tk_ops->rpc_call_prepare != NULL)
1024 task->tk_action = rpc_prepare_task;
Trond Myklebustf1f88fc2010-07-31 14:29:07 -04001025 return 1;
Andy Adamsonaae20062009-04-01 09:22:40 -04001026}
1027EXPORT_SYMBOL_GPL(rpc_restart_call_prepare);
1028
1029/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 * Restart an (async) RPC call. Usually called from within the
1031 * exit handler.
1032 */
Trond Myklebustf1f88fc2010-07-31 14:29:07 -04001033int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034rpc_restart_call(struct rpc_task *task)
1035{
1036 if (RPC_ASSASSINATED(task))
Trond Myklebustf1f88fc2010-07-31 14:29:07 -04001037 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 task->tk_action = call_start;
Trond Myklebustf1f88fc2010-07-31 14:29:07 -04001039 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040}
Trond Myklebuste8914c62007-07-14 15:39:59 -04001041EXPORT_SYMBOL_GPL(rpc_restart_call);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
Chuck Lever3748f1e2008-05-21 17:09:12 -04001043#ifdef RPC_DEBUG
1044static const char *rpc_proc_name(const struct rpc_task *task)
1045{
1046 const struct rpc_procinfo *proc = task->tk_msg.rpc_proc;
1047
1048 if (proc) {
1049 if (proc->p_name)
1050 return proc->p_name;
1051 else
1052 return "NULL";
1053 } else
1054 return "no proc";
1055}
1056#endif
1057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058/*
1059 * 0. Initial state
1060 *
1061 * Other FSM states can be visited zero or more times, but
1062 * this state is visited exactly once for each RPC.
1063 */
1064static void
1065call_start(struct rpc_task *task)
1066{
1067 struct rpc_clnt *clnt = task->tk_client;
1068
Chuck Lever3748f1e2008-05-21 17:09:12 -04001069 dprintk("RPC: %5u call_start %s%d proc %s (%s)\n", task->tk_pid,
Chuck Lever46121cf2007-01-31 12:14:08 -05001070 clnt->cl_protname, clnt->cl_vers,
Chuck Lever3748f1e2008-05-21 17:09:12 -04001071 rpc_proc_name(task),
Chuck Lever46121cf2007-01-31 12:14:08 -05001072 (RPC_IS_ASYNC(task) ? "async" : "sync"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
1074 /* Increment call count */
1075 task->tk_msg.rpc_proc->p_count++;
1076 clnt->cl_stats->rpccnt++;
1077 task->tk_action = call_reserve;
1078}
1079
1080/*
1081 * 1. Reserve an RPC call slot
1082 */
1083static void
1084call_reserve(struct rpc_task *task)
1085{
Chuck Lever46121cf2007-01-31 12:14:08 -05001086 dprint_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 task->tk_status = 0;
1089 task->tk_action = call_reserveresult;
1090 xprt_reserve(task);
1091}
1092
1093/*
1094 * 1b. Grok the result of xprt_reserve()
1095 */
1096static void
1097call_reserveresult(struct rpc_task *task)
1098{
1099 int status = task->tk_status;
1100
Chuck Lever46121cf2007-01-31 12:14:08 -05001101 dprint_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
1103 /*
1104 * After a call to xprt_reserve(), we must have either
1105 * a request slot or else an error status.
1106 */
1107 task->tk_status = 0;
1108 if (status >= 0) {
1109 if (task->tk_rqstp) {
J. Bruce Fieldsf2d47d02010-09-12 19:55:25 -04001110 task->tk_action = call_refresh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 return;
1112 }
1113
1114 printk(KERN_ERR "%s: status=%d, but no request slot, exiting\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001115 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 rpc_exit(task, -EIO);
1117 return;
1118 }
1119
1120 /*
1121 * Even though there was an error, we may have acquired
1122 * a request slot somehow. Make sure not to leak it.
1123 */
1124 if (task->tk_rqstp) {
1125 printk(KERN_ERR "%s: status=%d, request allocated anyway\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001126 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 xprt_release(task);
1128 }
1129
1130 switch (status) {
1131 case -EAGAIN: /* woken up; retry */
1132 task->tk_action = call_reserve;
1133 return;
1134 case -EIO: /* probably a shutdown */
1135 break;
1136 default:
1137 printk(KERN_ERR "%s: unrecognized error %d, exiting\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001138 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 break;
1140 }
1141 rpc_exit(task, status);
1142}
1143
1144/*
J. Bruce Fields55576242010-09-12 19:55:25 -04001145 * 2. Bind and/or refresh the credentials
1146 */
1147static void
1148call_refresh(struct rpc_task *task)
1149{
1150 dprint_status(task);
1151
1152 task->tk_action = call_refreshresult;
1153 task->tk_status = 0;
1154 task->tk_client->cl_stats->rpcauthrefresh++;
1155 rpcauth_refreshcred(task);
1156}
1157
1158/*
1159 * 2a. Process the results of a credential refresh
1160 */
1161static void
1162call_refreshresult(struct rpc_task *task)
1163{
1164 int status = task->tk_status;
1165
1166 dprint_status(task);
1167
1168 task->tk_status = 0;
Trond Myklebust5fc43972010-11-20 11:13:31 -05001169 task->tk_action = call_refresh;
J. Bruce Fields55576242010-09-12 19:55:25 -04001170 switch (status) {
Trond Myklebust5fc43972010-11-20 11:13:31 -05001171 case 0:
1172 if (rpcauth_uptodatecred(task))
1173 task->tk_action = call_allocate;
J. Bruce Fields55576242010-09-12 19:55:25 -04001174 return;
1175 case -ETIMEDOUT:
1176 rpc_delay(task, 3*HZ);
Trond Myklebust5fc43972010-11-20 11:13:31 -05001177 case -EAGAIN:
1178 status = -EACCES;
1179 if (!task->tk_cred_retry)
1180 break;
1181 task->tk_cred_retry--;
1182 dprintk("RPC: %5u %s: retry refresh creds\n",
1183 task->tk_pid, __func__);
1184 return;
J. Bruce Fields55576242010-09-12 19:55:25 -04001185 }
Trond Myklebust5fc43972010-11-20 11:13:31 -05001186 dprintk("RPC: %5u %s: refresh creds failed with error %d\n",
1187 task->tk_pid, __func__, status);
1188 rpc_exit(task, status);
J. Bruce Fields55576242010-09-12 19:55:25 -04001189}
1190
1191/*
1192 * 2b. Allocate the buffer. For details, see sched.c:rpc_malloc.
Chuck Lever02107142006-01-03 09:55:49 +01001193 * (Note: buffer memory is freed in xprt_release).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 */
1195static void
1196call_allocate(struct rpc_task *task)
1197{
J. Bruce Fieldsf2d47d02010-09-12 19:55:25 -04001198 unsigned int slack = task->tk_rqstp->rq_cred->cr_auth->au_cslack;
Chuck Lever02107142006-01-03 09:55:49 +01001199 struct rpc_rqst *req = task->tk_rqstp;
1200 struct rpc_xprt *xprt = task->tk_xprt;
Chuck Lever2bea90d2007-03-29 16:47:53 -04001201 struct rpc_procinfo *proc = task->tk_msg.rpc_proc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
Chuck Lever46121cf2007-01-31 12:14:08 -05001203 dprint_status(task);
1204
Chuck Lever2bea90d2007-03-29 16:47:53 -04001205 task->tk_status = 0;
J. Bruce Fieldsf2d47d02010-09-12 19:55:25 -04001206 task->tk_action = call_bind;
Chuck Lever2bea90d2007-03-29 16:47:53 -04001207
Chuck Lever02107142006-01-03 09:55:49 +01001208 if (req->rq_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 return;
1210
Chuck Lever2bea90d2007-03-29 16:47:53 -04001211 if (proc->p_proc != 0) {
1212 BUG_ON(proc->p_arglen == 0);
1213 if (proc->p_decode != NULL)
1214 BUG_ON(proc->p_replen == 0);
1215 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
Chuck Lever2bea90d2007-03-29 16:47:53 -04001217 /*
1218 * Calculate the size (in quads) of the RPC call
1219 * and reply headers, and convert both values
1220 * to byte sizes.
1221 */
1222 req->rq_callsize = RPC_CALLHDRSIZE + (slack << 1) + proc->p_arglen;
1223 req->rq_callsize <<= 2;
1224 req->rq_rcvsize = RPC_REPHDRSIZE + slack + proc->p_replen;
1225 req->rq_rcvsize <<= 2;
1226
Chuck Leverc5a4dd82007-03-29 16:47:58 -04001227 req->rq_buffer = xprt->ops->buf_alloc(task,
1228 req->rq_callsize + req->rq_rcvsize);
Chuck Lever2bea90d2007-03-29 16:47:53 -04001229 if (req->rq_buffer != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 return;
Chuck Lever46121cf2007-01-31 12:14:08 -05001231
1232 dprintk("RPC: %5u rpc_buffer allocation failed\n", task->tk_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Trond Myklebust5afa91332011-06-17 10:14:59 -04001234 if (RPC_IS_ASYNC(task) || !fatal_signal_pending(current)) {
Trond Myklebustb6e9c712007-10-01 12:06:44 -04001235 task->tk_action = call_allocate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 rpc_delay(task, HZ>>4);
1237 return;
1238 }
1239
1240 rpc_exit(task, -ERESTARTSYS);
1241}
1242
Trond Myklebust940e3312005-11-09 21:45:24 -05001243static inline int
1244rpc_task_need_encode(struct rpc_task *task)
1245{
1246 return task->tk_rqstp->rq_snd_buf.len == 0;
1247}
1248
1249static inline void
1250rpc_task_force_reencode(struct rpc_task *task)
1251{
1252 task->tk_rqstp->rq_snd_buf.len = 0;
Trond Myklebust2574cc92009-08-28 11:12:12 -04001253 task->tk_rqstp->rq_bytes_sent = 0;
Trond Myklebust940e3312005-11-09 21:45:24 -05001254}
1255
Chuck Lever2bea90d2007-03-29 16:47:53 -04001256static inline void
1257rpc_xdr_buf_init(struct xdr_buf *buf, void *start, size_t len)
1258{
1259 buf->head[0].iov_base = start;
1260 buf->head[0].iov_len = len;
1261 buf->tail[0].iov_len = 0;
1262 buf->page_len = 0;
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04001263 buf->flags = 0;
Chuck Lever2bea90d2007-03-29 16:47:53 -04001264 buf->len = 0;
1265 buf->buflen = len;
1266}
1267
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268/*
1269 * 3. Encode arguments of an RPC call
1270 */
1271static void
Chuck Leverb0e1c572008-05-21 17:09:19 -04001272rpc_xdr_encode(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 struct rpc_rqst *req = task->tk_rqstp;
Chuck Lever9f06c712010-12-14 14:59:18 +00001275 kxdreproc_t encode;
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001276 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
Chuck Lever46121cf2007-01-31 12:14:08 -05001278 dprint_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Chuck Lever2bea90d2007-03-29 16:47:53 -04001280 rpc_xdr_buf_init(&req->rq_snd_buf,
1281 req->rq_buffer,
1282 req->rq_callsize);
1283 rpc_xdr_buf_init(&req->rq_rcv_buf,
1284 (char *)req->rq_buffer + req->rq_callsize,
1285 req->rq_rcvsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
Chuck Leverb0e1c572008-05-21 17:09:19 -04001287 p = rpc_encode_header(task);
1288 if (p == NULL) {
1289 printk(KERN_INFO "RPC: couldn't encode RPC header, exit EIO\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 rpc_exit(task, -EIO);
1291 return;
1292 }
Chuck Leverb0e1c572008-05-21 17:09:19 -04001293
1294 encode = task->tk_msg.rpc_proc->p_encode;
J. Bruce Fieldsf3680312005-10-13 16:54:48 -04001295 if (encode == NULL)
1296 return;
1297
1298 task->tk_status = rpcauth_wrap_req(task, encode, req, p,
1299 task->tk_msg.rpc_argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300}
1301
1302/*
1303 * 4. Get the server port number if not yet set
1304 */
1305static void
1306call_bind(struct rpc_task *task)
1307{
Chuck Leverec739ef2006-08-22 20:06:15 -04001308 struct rpc_xprt *xprt = task->tk_xprt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
Chuck Lever46121cf2007-01-31 12:14:08 -05001310 dprint_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Chuck Leverda351872005-08-11 16:25:11 -04001312 task->tk_action = call_connect;
Chuck Leverec739ef2006-08-22 20:06:15 -04001313 if (!xprt_bound(xprt)) {
Chuck Leverda351872005-08-11 16:25:11 -04001314 task->tk_action = call_bind_status;
Chuck Leverec739ef2006-08-22 20:06:15 -04001315 task->tk_timeout = xprt->bind_timeout;
Chuck Leverbbf7c1d2006-08-22 20:06:16 -04001316 xprt->ops->rpcbind(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 }
1318}
1319
1320/*
Chuck Leverda351872005-08-11 16:25:11 -04001321 * 4a. Sort out bind result
1322 */
1323static void
1324call_bind_status(struct rpc_task *task)
1325{
Chuck Lever906462a2007-09-11 18:00:47 -04001326 int status = -EIO;
Chuck Leverda351872005-08-11 16:25:11 -04001327
1328 if (task->tk_status >= 0) {
Chuck Lever46121cf2007-01-31 12:14:08 -05001329 dprint_status(task);
Chuck Leverda351872005-08-11 16:25:11 -04001330 task->tk_status = 0;
1331 task->tk_action = call_connect;
1332 return;
1333 }
1334
Steve Dickson5753cba2012-02-06 10:08:08 -05001335 trace_rpc_bind_status(task);
Chuck Leverda351872005-08-11 16:25:11 -04001336 switch (task->tk_status) {
Trond Myklebust381ba742008-07-07 12:18:53 -04001337 case -ENOMEM:
1338 dprintk("RPC: %5u rpcbind out of memory\n", task->tk_pid);
1339 rpc_delay(task, HZ >> 2);
Chuck Lever2429cbf2007-09-11 18:00:41 -04001340 goto retry_timeout;
Chuck Leverda351872005-08-11 16:25:11 -04001341 case -EACCES:
Chuck Lever46121cf2007-01-31 12:14:08 -05001342 dprintk("RPC: %5u remote rpcbind: RPC program/version "
1343 "unavailable\n", task->tk_pid);
Chuck Leverb79dc8c2007-09-11 18:00:52 -04001344 /* fail immediately if this is an RPC ping */
1345 if (task->tk_msg.rpc_proc->p_proc == 0) {
1346 status = -EOPNOTSUPP;
1347 break;
1348 }
Trond Myklebust0b760112011-05-31 15:15:34 -04001349 if (task->tk_rebind_retry == 0)
1350 break;
1351 task->tk_rebind_retry--;
Chuck Leverea635a52005-10-06 23:12:58 -04001352 rpc_delay(task, 3*HZ);
Trond Myklebustda45828e2006-08-31 15:44:52 -04001353 goto retry_timeout;
Chuck Leverda351872005-08-11 16:25:11 -04001354 case -ETIMEDOUT:
Chuck Lever46121cf2007-01-31 12:14:08 -05001355 dprintk("RPC: %5u rpcbind request timed out\n",
Chuck Leverda351872005-08-11 16:25:11 -04001356 task->tk_pid);
Trond Myklebustda45828e2006-08-31 15:44:52 -04001357 goto retry_timeout;
Chuck Leverda351872005-08-11 16:25:11 -04001358 case -EPFNOSUPPORT:
Chuck Lever906462a2007-09-11 18:00:47 -04001359 /* server doesn't support any rpcbind version we know of */
Chuck Lever012da152009-12-03 15:58:56 -05001360 dprintk("RPC: %5u unrecognized remote rpcbind service\n",
Chuck Leverda351872005-08-11 16:25:11 -04001361 task->tk_pid);
1362 break;
1363 case -EPROTONOSUPPORT:
Chuck Lever00a6e7b2007-03-29 16:48:33 -04001364 dprintk("RPC: %5u remote rpcbind version unavailable, retrying\n",
Chuck Leverda351872005-08-11 16:25:11 -04001365 task->tk_pid);
Chuck Lever00a6e7b2007-03-29 16:48:33 -04001366 task->tk_status = 0;
1367 task->tk_action = call_bind;
1368 return;
Chuck Lever012da152009-12-03 15:58:56 -05001369 case -ECONNREFUSED: /* connection problems */
1370 case -ECONNRESET:
1371 case -ENOTCONN:
1372 case -EHOSTDOWN:
1373 case -EHOSTUNREACH:
1374 case -ENETUNREACH:
1375 case -EPIPE:
1376 dprintk("RPC: %5u remote rpcbind unreachable: %d\n",
1377 task->tk_pid, task->tk_status);
1378 if (!RPC_IS_SOFTCONN(task)) {
1379 rpc_delay(task, 5*HZ);
1380 goto retry_timeout;
1381 }
1382 status = task->tk_status;
1383 break;
Chuck Leverda351872005-08-11 16:25:11 -04001384 default:
Chuck Lever46121cf2007-01-31 12:14:08 -05001385 dprintk("RPC: %5u unrecognized rpcbind error (%d)\n",
Chuck Leverda351872005-08-11 16:25:11 -04001386 task->tk_pid, -task->tk_status);
Chuck Leverda351872005-08-11 16:25:11 -04001387 }
1388
1389 rpc_exit(task, status);
1390 return;
1391
Trond Myklebustda45828e2006-08-31 15:44:52 -04001392retry_timeout:
1393 task->tk_action = call_timeout;
Chuck Leverda351872005-08-11 16:25:11 -04001394}
1395
1396/*
1397 * 4b. Connect to the RPC server
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 */
1399static void
1400call_connect(struct rpc_task *task)
1401{
Chuck Leverda351872005-08-11 16:25:11 -04001402 struct rpc_xprt *xprt = task->tk_xprt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Chuck Lever46121cf2007-01-31 12:14:08 -05001404 dprintk("RPC: %5u call_connect xprt %p %s connected\n",
Chuck Leverda351872005-08-11 16:25:11 -04001405 task->tk_pid, xprt,
1406 (xprt_connected(xprt) ? "is" : "is not"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
Chuck Leverda351872005-08-11 16:25:11 -04001408 task->tk_action = call_transmit;
1409 if (!xprt_connected(xprt)) {
1410 task->tk_action = call_connect_status;
1411 if (task->tk_status < 0)
1412 return;
1413 xprt_connect(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415}
1416
1417/*
Chuck Leverda351872005-08-11 16:25:11 -04001418 * 4c. Sort out connect result
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 */
1420static void
1421call_connect_status(struct rpc_task *task)
1422{
1423 struct rpc_clnt *clnt = task->tk_client;
1424 int status = task->tk_status;
1425
Chuck Lever46121cf2007-01-31 12:14:08 -05001426 dprint_status(task);
Chuck Leverda351872005-08-11 16:25:11 -04001427
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 task->tk_status = 0;
Trond Myklebust2a491992009-03-11 14:38:00 -04001429 if (status >= 0 || status == -EAGAIN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 clnt->cl_stats->netreconn++;
1431 task->tk_action = call_transmit;
1432 return;
1433 }
1434
Steve Dickson5753cba2012-02-06 10:08:08 -05001435 trace_rpc_connect_status(task, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 switch (status) {
Trond Myklebustda45828e2006-08-31 15:44:52 -04001437 /* if soft mounted, test if we've timed out */
1438 case -ETIMEDOUT:
1439 task->tk_action = call_timeout;
Trond Myklebust2a491992009-03-11 14:38:00 -04001440 break;
1441 default:
1442 rpc_exit(task, -EIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 }
1444}
1445
1446/*
1447 * 5. Transmit the RPC request, and wait for reply
1448 */
1449static void
1450call_transmit(struct rpc_task *task)
1451{
Chuck Lever46121cf2007-01-31 12:14:08 -05001452 dprint_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
1454 task->tk_action = call_status;
1455 if (task->tk_status < 0)
1456 return;
1457 task->tk_status = xprt_prepare_transmit(task);
1458 if (task->tk_status != 0)
1459 return;
Trond Myklebuste0ab53d2006-07-27 17:22:50 -04001460 task->tk_action = call_transmit_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 /* Encode here so that rpcsec_gss can use correct sequence number. */
Trond Myklebust940e3312005-11-09 21:45:24 -05001462 if (rpc_task_need_encode(task)) {
Trond Myklebuste0ab53d2006-07-27 17:22:50 -04001463 BUG_ON(task->tk_rqstp->rq_bytes_sent != 0);
Chuck Leverb0e1c572008-05-21 17:09:19 -04001464 rpc_xdr_encode(task);
Trond Myklebust5e5ce5b2005-10-18 14:20:11 -07001465 /* Did the encode result in an error condition? */
Trond Myklebust8b39f2b2008-05-14 19:48:25 -07001466 if (task->tk_status != 0) {
1467 /* Was the error nonfatal? */
1468 if (task->tk_status == -EAGAIN)
1469 rpc_delay(task, HZ >> 4);
1470 else
1471 rpc_exit(task, task->tk_status);
Trond Myklebuste0ab53d2006-07-27 17:22:50 -04001472 return;
Trond Myklebust8b39f2b2008-05-14 19:48:25 -07001473 }
Trond Myklebust5e5ce5b2005-10-18 14:20:11 -07001474 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 xprt_transmit(task);
1476 if (task->tk_status < 0)
1477 return;
Trond Myklebuste0ab53d2006-07-27 17:22:50 -04001478 /*
1479 * On success, ensure that we call xprt_end_transmit() before sleeping
1480 * in order to allow access to the socket to other RPC requests.
1481 */
1482 call_transmit_status(task);
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001483 if (rpc_reply_expected(task))
Trond Myklebuste0ab53d2006-07-27 17:22:50 -04001484 return;
1485 task->tk_action = rpc_exit_task;
Trond Myklebustfda13932008-02-22 16:34:12 -05001486 rpc_wake_up_queued_task(&task->tk_xprt->pending, task);
Trond Myklebuste0ab53d2006-07-27 17:22:50 -04001487}
1488
1489/*
1490 * 5a. Handle cleanup after a transmission
1491 */
1492static void
1493call_transmit_status(struct rpc_task *task)
1494{
1495 task->tk_action = call_status;
Chuck Lever206a1342009-12-03 15:58:56 -05001496
1497 /*
1498 * Common case: success. Force the compiler to put this
1499 * test first.
1500 */
1501 if (task->tk_status == 0) {
1502 xprt_end_transmit(task);
1503 rpc_task_force_reencode(task);
1504 return;
1505 }
1506
Trond Myklebust15f081c2009-03-11 14:37:57 -04001507 switch (task->tk_status) {
1508 case -EAGAIN:
1509 break;
1510 default:
Chuck Lever206a1342009-12-03 15:58:56 -05001511 dprint_status(task);
Trond Myklebust15f081c2009-03-11 14:37:57 -04001512 xprt_end_transmit(task);
Chuck Lever09a21c42009-12-03 15:58:56 -05001513 rpc_task_force_reencode(task);
1514 break;
Trond Myklebust15f081c2009-03-11 14:37:57 -04001515 /*
1516 * Special cases: if we've been waiting on the
1517 * socket's write_space() callback, or if the
1518 * socket just returned a connection error,
1519 * then hold onto the transport lock.
1520 */
1521 case -ECONNREFUSED:
Trond Myklebust15f081c2009-03-11 14:37:57 -04001522 case -EHOSTDOWN:
1523 case -EHOSTUNREACH:
1524 case -ENETUNREACH:
Chuck Lever09a21c42009-12-03 15:58:56 -05001525 if (RPC_IS_SOFTCONN(task)) {
1526 xprt_end_transmit(task);
1527 rpc_exit(task, task->tk_status);
1528 break;
1529 }
1530 case -ECONNRESET:
1531 case -ENOTCONN:
Trond Myklebustc8485e42009-03-11 14:37:59 -04001532 case -EPIPE:
Trond Myklebust15f081c2009-03-11 14:37:57 -04001533 rpc_task_force_reencode(task);
1534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535}
1536
Trond Myklebust9e00abc2011-07-13 19:20:49 -04001537#if defined(CONFIG_SUNRPC_BACKCHANNEL)
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001538/*
1539 * 5b. Send the backchannel RPC reply. On error, drop the reply. In
1540 * addition, disconnect on connectivity errors.
1541 */
1542static void
1543call_bc_transmit(struct rpc_task *task)
1544{
1545 struct rpc_rqst *req = task->tk_rqstp;
1546
1547 BUG_ON(task->tk_status != 0);
1548 task->tk_status = xprt_prepare_transmit(task);
1549 if (task->tk_status == -EAGAIN) {
1550 /*
1551 * Could not reserve the transport. Try again after the
1552 * transport is released.
1553 */
1554 task->tk_status = 0;
1555 task->tk_action = call_bc_transmit;
1556 return;
1557 }
1558
1559 task->tk_action = rpc_exit_task;
1560 if (task->tk_status < 0) {
1561 printk(KERN_NOTICE "RPC: Could not send backchannel reply "
1562 "error: %d\n", task->tk_status);
1563 return;
1564 }
1565
1566 xprt_transmit(task);
1567 xprt_end_transmit(task);
1568 dprint_status(task);
1569 switch (task->tk_status) {
1570 case 0:
1571 /* Success */
1572 break;
1573 case -EHOSTDOWN:
1574 case -EHOSTUNREACH:
1575 case -ENETUNREACH:
1576 case -ETIMEDOUT:
1577 /*
1578 * Problem reaching the server. Disconnect and let the
1579 * forechannel reestablish the connection. The server will
1580 * have to retransmit the backchannel request and we'll
1581 * reprocess it. Since these ops are idempotent, there's no
1582 * need to cache our reply at this time.
1583 */
1584 printk(KERN_NOTICE "RPC: Could not send backchannel reply "
1585 "error: %d\n", task->tk_status);
1586 xprt_conditional_disconnect(task->tk_xprt,
1587 req->rq_connect_cookie);
1588 break;
1589 default:
1590 /*
1591 * We were unable to reply and will have to drop the
1592 * request. The server should reconnect and retransmit.
1593 */
1594 BUG_ON(task->tk_status == -EAGAIN);
1595 printk(KERN_NOTICE "RPC: Could not send backchannel reply "
1596 "error: %d\n", task->tk_status);
1597 break;
1598 }
1599 rpc_wake_up_queued_task(&req->rq_xprt->pending, task);
1600}
Trond Myklebust9e00abc2011-07-13 19:20:49 -04001601#endif /* CONFIG_SUNRPC_BACKCHANNEL */
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001602
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603/*
1604 * 6. Sort out the RPC call status
1605 */
1606static void
1607call_status(struct rpc_task *task)
1608{
1609 struct rpc_clnt *clnt = task->tk_client;
1610 struct rpc_rqst *req = task->tk_rqstp;
1611 int status;
1612
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -04001613 if (req->rq_reply_bytes_recvd > 0 && !req->rq_bytes_sent)
1614 task->tk_status = req->rq_reply_bytes_recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
Chuck Lever46121cf2007-01-31 12:14:08 -05001616 dprint_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
1618 status = task->tk_status;
1619 if (status >= 0) {
1620 task->tk_action = call_decode;
1621 return;
1622 }
1623
Steve Dickson5753cba2012-02-06 10:08:08 -05001624 trace_rpc_call_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 task->tk_status = 0;
1626 switch(status) {
Trond Myklebust76303992006-08-30 14:32:49 -04001627 case -EHOSTDOWN:
1628 case -EHOSTUNREACH:
1629 case -ENETUNREACH:
1630 /*
1631 * Delay any retries for 3 seconds, then handle as if it
1632 * were a timeout.
1633 */
1634 rpc_delay(task, 3*HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 case -ETIMEDOUT:
1636 task->tk_action = call_timeout;
Trond Myklebust241c39b2007-04-20 16:12:55 -04001637 if (task->tk_client->cl_discrtry)
Trond Myklebust7c1d71c2008-04-17 16:52:57 -04001638 xprt_conditional_disconnect(task->tk_xprt,
1639 req->rq_connect_cookie);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 break;
Trond Myklebustc8485e42009-03-11 14:37:59 -04001641 case -ECONNRESET:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 case -ECONNREFUSED:
Chuck Lever35f5a422006-01-03 09:55:50 +01001643 rpc_force_rebind(clnt);
Trond Myklebustc8485e42009-03-11 14:37:59 -04001644 rpc_delay(task, 3*HZ);
1645 case -EPIPE:
1646 case -ENOTCONN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 task->tk_action = call_bind;
1648 break;
1649 case -EAGAIN:
1650 task->tk_action = call_transmit;
1651 break;
1652 case -EIO:
1653 /* shutdown or soft timeout */
1654 rpc_exit(task, status);
1655 break;
1656 default:
Olga Kornievskaiab6b61522008-06-09 16:51:31 -04001657 if (clnt->cl_chatty)
1658 printk("%s: RPC call returned error %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 clnt->cl_protname, -status);
1660 rpc_exit(task, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 }
1662}
1663
1664/*
Trond Myklebuste0ab53d2006-07-27 17:22:50 -04001665 * 6a. Handle RPC timeout
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 * We do not release the request slot, so we keep using the
1667 * same XID for all retransmits.
1668 */
1669static void
1670call_timeout(struct rpc_task *task)
1671{
1672 struct rpc_clnt *clnt = task->tk_client;
1673
1674 if (xprt_adjust_timeout(task->tk_rqstp) == 0) {
Chuck Lever46121cf2007-01-31 12:14:08 -05001675 dprintk("RPC: %5u call_timeout (minor)\n", task->tk_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 goto retry;
1677 }
1678
Chuck Lever46121cf2007-01-31 12:14:08 -05001679 dprintk("RPC: %5u call_timeout (major)\n", task->tk_pid);
Chuck Leveref759a22006-03-20 13:44:17 -05001680 task->tk_timeouts++;
1681
Chuck Lever3a28bec2009-12-03 15:58:56 -05001682 if (RPC_IS_SOFTCONN(task)) {
1683 rpc_exit(task, -ETIMEDOUT);
1684 return;
1685 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 if (RPC_IS_SOFT(task)) {
Olga Kornievskaiab6b61522008-06-09 16:51:31 -04001687 if (clnt->cl_chatty)
1688 printk(KERN_NOTICE "%s: server %s not responding, timed out\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 clnt->cl_protname, clnt->cl_server);
Trond Myklebust7494d002011-04-24 14:28:45 -04001690 if (task->tk_flags & RPC_TASK_TIMEOUT)
1691 rpc_exit(task, -ETIMEDOUT);
1692 else
1693 rpc_exit(task, -EIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 return;
1695 }
1696
Chuck Leverf518e35a2006-01-03 09:55:52 +01001697 if (!(task->tk_flags & RPC_CALL_MAJORSEEN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 task->tk_flags |= RPC_CALL_MAJORSEEN;
Olga Kornievskaiab6b61522008-06-09 16:51:31 -04001699 if (clnt->cl_chatty)
1700 printk(KERN_NOTICE "%s: server %s not responding, still trying\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 clnt->cl_protname, clnt->cl_server);
1702 }
Chuck Lever35f5a422006-01-03 09:55:50 +01001703 rpc_force_rebind(clnt);
Trond Myklebustb48633b2008-04-22 16:47:55 -04001704 /*
1705 * Did our request time out due to an RPCSEC_GSS out-of-sequence
1706 * event? RFC2203 requires the server to drop all such requests.
1707 */
1708 rpcauth_invalcred(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
1710retry:
1711 clnt->cl_stats->rpcretrans++;
1712 task->tk_action = call_bind;
1713 task->tk_status = 0;
1714}
1715
1716/*
1717 * 7. Decode the RPC reply
1718 */
1719static void
1720call_decode(struct rpc_task *task)
1721{
1722 struct rpc_clnt *clnt = task->tk_client;
1723 struct rpc_rqst *req = task->tk_rqstp;
Chuck Leverbf269552010-12-14 14:59:29 +00001724 kxdrdproc_t decode = task->tk_msg.rpc_proc->p_decode;
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001725 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
Vasily Averin726fd6a2011-06-01 16:23:59 +04001727 dprint_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728
Chuck Leverf518e35a2006-01-03 09:55:52 +01001729 if (task->tk_flags & RPC_CALL_MAJORSEEN) {
Olga Kornievskaiab6b61522008-06-09 16:51:31 -04001730 if (clnt->cl_chatty)
1731 printk(KERN_NOTICE "%s: server %s OK\n",
1732 clnt->cl_protname, clnt->cl_server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 task->tk_flags &= ~RPC_CALL_MAJORSEEN;
1734 }
1735
Trond Myklebust43ac3f22006-03-20 13:44:51 -05001736 /*
1737 * Ensure that we see all writes made by xprt_complete_rqst()
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -04001738 * before it changed req->rq_reply_bytes_recvd.
Trond Myklebust43ac3f22006-03-20 13:44:51 -05001739 */
1740 smp_rmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 req->rq_rcv_buf.len = req->rq_private_buf.len;
1742
1743 /* Check that the softirq receive buffer is valid */
1744 WARN_ON(memcmp(&req->rq_rcv_buf, &req->rq_private_buf,
1745 sizeof(req->rq_rcv_buf)) != 0);
1746
Trond Myklebust1e799b62008-03-21 16:19:41 -04001747 if (req->rq_rcv_buf.len < 12) {
1748 if (!RPC_IS_SOFT(task)) {
1749 task->tk_action = call_bind;
1750 clnt->cl_stats->rpcretrans++;
1751 goto out_retry;
1752 }
1753 dprintk("RPC: %s: too small RPC reply size (%d bytes)\n",
1754 clnt->cl_protname, task->tk_status);
1755 task->tk_action = call_timeout;
1756 goto out_retry;
1757 }
1758
Chuck Leverb0e1c572008-05-21 17:09:19 -04001759 p = rpc_verify_header(task);
Trond Myklebustabbcf282006-01-03 09:55:03 +01001760 if (IS_ERR(p)) {
1761 if (p == ERR_PTR(-EAGAIN))
1762 goto out_retry;
1763 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 }
1765
Trond Myklebustabbcf282006-01-03 09:55:03 +01001766 task->tk_action = rpc_exit_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767
Trond Myklebust6d5fcb52006-10-18 16:01:06 -04001768 if (decode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 task->tk_status = rpcauth_unwrap_resp(task, decode, req, p,
1770 task->tk_msg.rpc_resp);
Trond Myklebust6d5fcb52006-10-18 16:01:06 -04001771 }
Chuck Lever46121cf2007-01-31 12:14:08 -05001772 dprintk("RPC: %5u call_decode result %d\n", task->tk_pid,
1773 task->tk_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 return;
1775out_retry:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 task->tk_status = 0;
Chuck Leverb0e1c572008-05-21 17:09:19 -04001777 /* Note: rpc_verify_header() may have freed the RPC slot */
Trond Myklebust24b74bf2008-04-19 13:15:47 -04001778 if (task->tk_rqstp == req) {
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -04001779 req->rq_reply_bytes_recvd = req->rq_rcv_buf.len = 0;
Trond Myklebust24b74bf2008-04-19 13:15:47 -04001780 if (task->tk_client->cl_discrtry)
Trond Myklebust7c1d71c2008-04-17 16:52:57 -04001781 xprt_conditional_disconnect(task->tk_xprt,
1782 req->rq_connect_cookie);
Trond Myklebust24b74bf2008-04-19 13:15:47 -04001783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784}
1785
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001786static __be32 *
Chuck Leverb0e1c572008-05-21 17:09:19 -04001787rpc_encode_header(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788{
1789 struct rpc_clnt *clnt = task->tk_client;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 struct rpc_rqst *req = task->tk_rqstp;
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001791 __be32 *p = req->rq_svec[0].iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
1793 /* FIXME: check buffer size? */
Chuck Lever808012f2005-08-25 16:25:49 -07001794
1795 p = xprt_skip_transport_header(task->tk_xprt, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 *p++ = req->rq_xid; /* XID */
1797 *p++ = htonl(RPC_CALL); /* CALL */
1798 *p++ = htonl(RPC_VERSION); /* RPC version */
1799 *p++ = htonl(clnt->cl_prog); /* program number */
1800 *p++ = htonl(clnt->cl_vers); /* program version */
1801 *p++ = htonl(task->tk_msg.rpc_proc->p_proc); /* procedure */
Trond Myklebust334ccfd2005-06-22 17:16:19 +00001802 p = rpcauth_marshcred(task, p);
1803 req->rq_slen = xdr_adjust_iovec(&req->rq_svec[0], p);
1804 return p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805}
1806
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001807static __be32 *
Chuck Leverb0e1c572008-05-21 17:09:19 -04001808rpc_verify_header(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809{
1810 struct kvec *iov = &task->tk_rqstp->rq_rcv_buf.head[0];
1811 int len = task->tk_rqstp->rq_rcv_buf.len >> 2;
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001812 __be32 *p = iov->iov_base;
1813 u32 n;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 int error = -EACCES;
1815
David Howellse8896492006-08-24 15:44:19 -04001816 if ((task->tk_rqstp->rq_rcv_buf.len & 3) != 0) {
1817 /* RFC-1014 says that the representation of XDR data must be a
1818 * multiple of four bytes
1819 * - if it isn't pointer subtraction in the NFS client may give
1820 * undefined results
1821 */
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001822 dprintk("RPC: %5u %s: XDR representation not a multiple of"
Harvey Harrison0dc47872008-03-05 20:47:47 -08001823 " 4 bytes: 0x%x\n", task->tk_pid, __func__,
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001824 task->tk_rqstp->rq_rcv_buf.len);
David Howellse8896492006-08-24 15:44:19 -04001825 goto out_eio;
1826 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 if ((len -= 3) < 0)
1828 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829
Ricardo Labiagaf4a2e412009-04-01 09:22:54 -04001830 p += 1; /* skip XID */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 if ((n = ntohl(*p++)) != RPC_REPLY) {
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001832 dprintk("RPC: %5u %s: not an RPC reply: %x\n",
Ricardo Labiagaf4a2e412009-04-01 09:22:54 -04001833 task->tk_pid, __func__, n);
Trond Myklebustabbcf282006-01-03 09:55:03 +01001834 goto out_garbage;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 }
Ricardo Labiagaf4a2e412009-04-01 09:22:54 -04001836
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 if ((n = ntohl(*p++)) != RPC_MSG_ACCEPTED) {
1838 if (--len < 0)
1839 goto out_overflow;
1840 switch ((n = ntohl(*p++))) {
Joe Perches89f0e4f2011-07-01 09:43:12 +00001841 case RPC_AUTH_ERROR:
1842 break;
1843 case RPC_MISMATCH:
1844 dprintk("RPC: %5u %s: RPC call version mismatch!\n",
1845 task->tk_pid, __func__);
1846 error = -EPROTONOSUPPORT;
1847 goto out_err;
1848 default:
1849 dprintk("RPC: %5u %s: RPC call rejected, "
1850 "unknown error: %x\n",
1851 task->tk_pid, __func__, n);
1852 goto out_eio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 }
1854 if (--len < 0)
1855 goto out_overflow;
1856 switch ((n = ntohl(*p++))) {
1857 case RPC_AUTH_REJECTEDCRED:
1858 case RPC_AUTH_REJECTEDVERF:
1859 case RPCSEC_GSS_CREDPROBLEM:
1860 case RPCSEC_GSS_CTXPROBLEM:
1861 if (!task->tk_cred_retry)
1862 break;
1863 task->tk_cred_retry--;
Chuck Lever46121cf2007-01-31 12:14:08 -05001864 dprintk("RPC: %5u %s: retry stale creds\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001865 task->tk_pid, __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 rpcauth_invalcred(task);
Trond Myklebust220bcc22007-10-01 12:06:48 -04001867 /* Ensure we obtain a new XID! */
1868 xprt_release(task);
Trond Myklebust118df3d2010-10-24 17:17:31 -04001869 task->tk_action = call_reserve;
Trond Myklebustabbcf282006-01-03 09:55:03 +01001870 goto out_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 case RPC_AUTH_BADCRED:
1872 case RPC_AUTH_BADVERF:
1873 /* possibly garbled cred/verf? */
1874 if (!task->tk_garb_retry)
1875 break;
1876 task->tk_garb_retry--;
Chuck Lever46121cf2007-01-31 12:14:08 -05001877 dprintk("RPC: %5u %s: retry garbled creds\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001878 task->tk_pid, __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 task->tk_action = call_bind;
Trond Myklebustabbcf282006-01-03 09:55:03 +01001880 goto out_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 case RPC_AUTH_TOOWEAK:
Chuck Leverb0e1c572008-05-21 17:09:19 -04001882 printk(KERN_NOTICE "RPC: server %s requires stronger "
Levent Serinol1356b8c2006-03-20 13:44:11 -05001883 "authentication.\n", task->tk_client->cl_server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 break;
1885 default:
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001886 dprintk("RPC: %5u %s: unknown auth error: %x\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001887 task->tk_pid, __func__, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 error = -EIO;
1889 }
Chuck Lever46121cf2007-01-31 12:14:08 -05001890 dprintk("RPC: %5u %s: call rejected %d\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001891 task->tk_pid, __func__, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 goto out_err;
1893 }
1894 if (!(p = rpcauth_checkverf(task, p))) {
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001895 dprintk("RPC: %5u %s: auth check failed\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001896 task->tk_pid, __func__);
Trond Myklebustabbcf282006-01-03 09:55:03 +01001897 goto out_garbage; /* bad verifier, retry */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 }
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001899 len = p - (__be32 *)iov->iov_base - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 if (len < 0)
1901 goto out_overflow;
1902 switch ((n = ntohl(*p++))) {
1903 case RPC_SUCCESS:
1904 return p;
1905 case RPC_PROG_UNAVAIL:
Chuck Lever46121cf2007-01-31 12:14:08 -05001906 dprintk("RPC: %5u %s: program %u is unsupported by server %s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001907 task->tk_pid, __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 (unsigned int)task->tk_client->cl_prog,
1909 task->tk_client->cl_server);
Andreas Gruenbachercdf47702005-06-22 17:16:23 +00001910 error = -EPFNOSUPPORT;
1911 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 case RPC_PROG_MISMATCH:
Chuck Lever46121cf2007-01-31 12:14:08 -05001913 dprintk("RPC: %5u %s: program %u, version %u unsupported by "
Harvey Harrison0dc47872008-03-05 20:47:47 -08001914 "server %s\n", task->tk_pid, __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 (unsigned int)task->tk_client->cl_prog,
1916 (unsigned int)task->tk_client->cl_vers,
1917 task->tk_client->cl_server);
Andreas Gruenbachercdf47702005-06-22 17:16:23 +00001918 error = -EPROTONOSUPPORT;
1919 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 case RPC_PROC_UNAVAIL:
Chuck Lever3748f1e2008-05-21 17:09:12 -04001921 dprintk("RPC: %5u %s: proc %s unsupported by program %u, "
Chuck Lever46121cf2007-01-31 12:14:08 -05001922 "version %u on server %s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001923 task->tk_pid, __func__,
Chuck Lever3748f1e2008-05-21 17:09:12 -04001924 rpc_proc_name(task),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 task->tk_client->cl_prog,
1926 task->tk_client->cl_vers,
1927 task->tk_client->cl_server);
Andreas Gruenbachercdf47702005-06-22 17:16:23 +00001928 error = -EOPNOTSUPP;
1929 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 case RPC_GARBAGE_ARGS:
Chuck Lever46121cf2007-01-31 12:14:08 -05001931 dprintk("RPC: %5u %s: server saw garbage\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001932 task->tk_pid, __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 break; /* retry */
1934 default:
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001935 dprintk("RPC: %5u %s: server accept status: %x\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001936 task->tk_pid, __func__, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 /* Also retry */
1938 }
1939
Trond Myklebustabbcf282006-01-03 09:55:03 +01001940out_garbage:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 task->tk_client->cl_stats->rpcgarbage++;
1942 if (task->tk_garb_retry) {
1943 task->tk_garb_retry--;
Chuck Lever46121cf2007-01-31 12:14:08 -05001944 dprintk("RPC: %5u %s: retrying\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001945 task->tk_pid, __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 task->tk_action = call_bind;
Trond Myklebustabbcf282006-01-03 09:55:03 +01001947out_retry:
1948 return ERR_PTR(-EAGAIN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950out_eio:
1951 error = -EIO;
1952out_err:
1953 rpc_exit(task, error);
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001954 dprintk("RPC: %5u %s: call failed with error %d\n", task->tk_pid,
Harvey Harrison0dc47872008-03-05 20:47:47 -08001955 __func__, error);
Trond Myklebustabbcf282006-01-03 09:55:03 +01001956 return ERR_PTR(error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957out_overflow:
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001958 dprintk("RPC: %5u %s: server reply was truncated.\n", task->tk_pid,
Harvey Harrison0dc47872008-03-05 20:47:47 -08001959 __func__);
Trond Myklebustabbcf282006-01-03 09:55:03 +01001960 goto out_garbage;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961}
Trond Myklebust5ee0ed72005-06-22 17:16:20 +00001962
Chuck Lever9f06c712010-12-14 14:59:18 +00001963static void rpcproc_encode_null(void *rqstp, struct xdr_stream *xdr, void *obj)
Trond Myklebust5ee0ed72005-06-22 17:16:20 +00001964{
Trond Myklebust5ee0ed72005-06-22 17:16:20 +00001965}
1966
Chuck Leverbf269552010-12-14 14:59:29 +00001967static int rpcproc_decode_null(void *rqstp, struct xdr_stream *xdr, void *obj)
Trond Myklebust5ee0ed72005-06-22 17:16:20 +00001968{
1969 return 0;
1970}
1971
1972static struct rpc_procinfo rpcproc_null = {
1973 .p_encode = rpcproc_encode_null,
1974 .p_decode = rpcproc_decode_null,
1975};
1976
Chuck Levercaabea82009-12-03 15:58:56 -05001977static int rpc_ping(struct rpc_clnt *clnt)
Trond Myklebust5ee0ed72005-06-22 17:16:20 +00001978{
1979 struct rpc_message msg = {
1980 .rpc_proc = &rpcproc_null,
1981 };
1982 int err;
1983 msg.rpc_cred = authnull_ops.lookup_cred(NULL, NULL, 0);
Chuck Levercaabea82009-12-03 15:58:56 -05001984 err = rpc_call_sync(clnt, &msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN);
Trond Myklebust5ee0ed72005-06-22 17:16:20 +00001985 put_rpccred(msg.rpc_cred);
1986 return err;
1987}
Trond Myklebust188fef12007-06-16 14:18:40 -04001988
Trond Myklebust5e1550d2007-06-23 10:17:16 -04001989struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred, int flags)
1990{
1991 struct rpc_message msg = {
1992 .rpc_proc = &rpcproc_null,
1993 .rpc_cred = cred,
1994 };
Trond Myklebust84115e12007-07-14 15:39:59 -04001995 struct rpc_task_setup task_setup_data = {
1996 .rpc_client = clnt,
1997 .rpc_message = &msg,
1998 .callback_ops = &rpc_default_ops,
1999 .flags = flags,
2000 };
Trond Myklebustc970aa82007-07-14 15:39:59 -04002001 return rpc_run_task(&task_setup_data);
Trond Myklebust5e1550d2007-06-23 10:17:16 -04002002}
Trond Myklebuste8914c62007-07-14 15:39:59 -04002003EXPORT_SYMBOL_GPL(rpc_call_null);
Trond Myklebust5e1550d2007-06-23 10:17:16 -04002004
Trond Myklebust188fef12007-06-16 14:18:40 -04002005#ifdef RPC_DEBUG
Chuck Lever68a23ee2008-05-21 17:09:26 -04002006static void rpc_show_header(void)
2007{
Chuck Levercb3997b2008-05-21 17:09:41 -04002008 printk(KERN_INFO "-pid- flgs status -client- --rqstp- "
2009 "-timeout ---ops--\n");
Chuck Lever68a23ee2008-05-21 17:09:26 -04002010}
2011
Chuck Lever38e886e2008-05-21 17:09:33 -04002012static void rpc_show_task(const struct rpc_clnt *clnt,
2013 const struct rpc_task *task)
2014{
2015 const char *rpc_waitq = "none";
Chuck Lever38e886e2008-05-21 17:09:33 -04002016
2017 if (RPC_IS_QUEUED(task))
2018 rpc_waitq = rpc_qname(task->tk_waitqueue);
2019
Joe Perchesb3bceda2010-12-21 10:52:24 -05002020 printk(KERN_INFO "%5u %04x %6d %8p %8p %8ld %8p %sv%u %s a:%ps q:%s\n",
Chuck Levercb3997b2008-05-21 17:09:41 -04002021 task->tk_pid, task->tk_flags, task->tk_status,
2022 clnt, task->tk_rqstp, task->tk_timeout, task->tk_ops,
2023 clnt->cl_protname, clnt->cl_vers, rpc_proc_name(task),
Joe Perchesb3bceda2010-12-21 10:52:24 -05002024 task->tk_action, rpc_waitq);
Chuck Lever38e886e2008-05-21 17:09:33 -04002025}
2026
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +04002027void rpc_show_tasks(struct net *net)
Trond Myklebust188fef12007-06-16 14:18:40 -04002028{
2029 struct rpc_clnt *clnt;
Chuck Lever38e886e2008-05-21 17:09:33 -04002030 struct rpc_task *task;
Chuck Lever68a23ee2008-05-21 17:09:26 -04002031 int header = 0;
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +04002032 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
Trond Myklebust188fef12007-06-16 14:18:40 -04002033
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +04002034 spin_lock(&sn->rpc_client_lock);
2035 list_for_each_entry(clnt, &sn->all_clients, cl_clients) {
Trond Myklebust188fef12007-06-16 14:18:40 -04002036 spin_lock(&clnt->cl_lock);
Chuck Lever38e886e2008-05-21 17:09:33 -04002037 list_for_each_entry(task, &clnt->cl_tasks, tk_task) {
Chuck Lever68a23ee2008-05-21 17:09:26 -04002038 if (!header) {
2039 rpc_show_header();
2040 header++;
2041 }
Chuck Lever38e886e2008-05-21 17:09:33 -04002042 rpc_show_task(clnt, task);
Trond Myklebust188fef12007-06-16 14:18:40 -04002043 }
2044 spin_unlock(&clnt->cl_lock);
2045 }
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +04002046 spin_unlock(&sn->rpc_client_lock);
Trond Myklebust188fef12007-06-16 14:18:40 -04002047}
2048#endif