blob: e39ace9a4e1df6cee2b656b77eb29e7293ee5d99 [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 Kinsburskyeee17322012-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
269 /* sanity check the name before trying to print it */
Chuck Lever46121cf2007-01-31 12:14:08 -0500270 dprintk("RPC: creating %s client for %s (xprt %p)\n",
Trond Myklebust698b6d02007-12-20 16:03:53 -0500271 program->name, args->servername, xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Trond Myklebust4ada5392007-06-14 17:26:17 -0400273 err = rpciod_up();
274 if (err)
275 goto out_no_rpciod;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 err = -EINVAL;
277 if (!xprt)
Adrian Bunk712917d2006-03-13 21:20:47 -0800278 goto out_no_xprt;
Trond Myklebust698b6d02007-12-20 16:03:53 -0500279
280 if (args->version >= program->nrvers)
281 goto out_err;
282 version = program->version[args->version];
283 if (version == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 goto out_err;
285
286 err = -ENOMEM;
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700287 clnt = kzalloc(sizeof(*clnt), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 if (!clnt)
289 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 clnt->cl_parent = clnt;
291
Trond Myklebust2446ab62012-03-01 17:00:56 -0500292 rcu_assign_pointer(clnt->cl_xprt, xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 clnt->cl_procinfo = version->procs;
294 clnt->cl_maxproc = version->nrprocs;
295 clnt->cl_protname = program->name;
Benny Halevyd5b337b2008-09-28 09:21:26 +0300296 clnt->cl_prog = args->prognumber ? : program->number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 clnt->cl_vers = version->number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 clnt->cl_stats = program->stats;
Chuck Lever11c556b2006-03-20 13:44:22 -0500299 clnt->cl_metrics = rpc_alloc_iostats(clnt);
Trond Myklebust23bf85b2006-11-21 10:40:23 -0500300 err = -ENOMEM;
301 if (clnt->cl_metrics == NULL)
302 goto out_no_stats;
Trond Myklebust3e32a5d2006-11-16 11:37:27 -0500303 clnt->cl_program = program;
Trond Myklebust6529eba2007-06-14 16:40:14 -0400304 INIT_LIST_HEAD(&clnt->cl_tasks);
Trond Myklebust4bef61f2007-06-16 14:17:01 -0400305 spin_lock_init(&clnt->cl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Trond Myklebust2446ab62012-03-01 17:00:56 -0500307 if (!xprt_bound(xprt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 clnt->cl_autobind = 1;
309
Trond Myklebustba7392b2007-12-20 16:03:55 -0500310 clnt->cl_timeout = xprt->timeout;
311 if (args->timeout != NULL) {
312 memcpy(&clnt->cl_timeout_default, args->timeout,
313 sizeof(clnt->cl_timeout_default));
314 clnt->cl_timeout = &clnt->cl_timeout_default;
315 }
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 clnt->cl_rtt = &clnt->cl_rtt_default;
Trond Myklebustba7392b2007-12-20 16:03:55 -0500318 rpc_init_rtt(&clnt->cl_rtt_default, clnt->cl_timeout->to_initval);
Olga Kornievskaia608207e2008-12-23 16:17:40 -0500319 clnt->cl_principal = NULL;
320 if (args->client_name) {
321 clnt->cl_principal = kstrdup(args->client_name, GFP_KERNEL);
322 if (!clnt->cl_principal)
323 goto out_no_principal;
324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
Trond Myklebust006abe82010-09-12 19:55:25 -0400326 atomic_set(&clnt->cl_count, 1);
Trond Myklebust34f52e32007-06-14 16:40:31 -0400327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 err = rpc_setup_pipedir(clnt, program->pipe_dir_name);
329 if (err < 0)
330 goto out_no_path;
331
Trond Myklebust698b6d02007-12-20 16:03:53 -0500332 auth = rpcauth_create(args->authflavor, clnt);
J. Bruce Fields6a192752005-06-22 17:16:23 +0000333 if (IS_ERR(auth)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 printk(KERN_INFO "RPC: Couldn't create auth handle (flavor %u)\n",
Trond Myklebust698b6d02007-12-20 16:03:53 -0500335 args->authflavor);
J. Bruce Fields6a192752005-06-22 17:16:23 +0000336 err = PTR_ERR(auth);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 goto out_no_auth;
338 }
339
340 /* save the nodename */
Cedric Le Goater63ffc232008-10-03 23:41:51 -0400341 clnt->cl_nodelen = strlen(init_utsname()->nodename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 if (clnt->cl_nodelen > UNX_MAXNODENAME)
343 clnt->cl_nodelen = UNX_MAXNODENAME;
Cedric Le Goater63ffc232008-10-03 23:41:51 -0400344 memcpy(clnt->cl_nodename, init_utsname()->nodename, clnt->cl_nodelen);
Trond Myklebust6529eba2007-06-14 16:40:14 -0400345 rpc_register_client(clnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 return clnt;
347
348out_no_auth:
Stanislav Kinsbursky0157d022012-01-11 19:18:01 +0400349 rpc_clnt_remove_pipedir(clnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350out_no_path:
Olga Kornievskaia608207e2008-12-23 16:17:40 -0500351 kfree(clnt->cl_principal);
352out_no_principal:
Trond Myklebust23bf85b2006-11-21 10:40:23 -0500353 rpc_free_iostats(clnt->cl_metrics);
354out_no_stats:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 kfree(clnt);
356out_err:
Trond Myklebust6b6ca862006-09-05 12:55:57 -0400357 xprt_put(xprt);
Adrian Bunk712917d2006-03-13 21:20:47 -0800358out_no_xprt:
Trond Myklebust4ada5392007-06-14 17:26:17 -0400359 rpciod_down();
360out_no_rpciod:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 return ERR_PTR(err);
362}
363
Chuck Leverc2866762006-08-22 20:06:20 -0400364/*
365 * rpc_create - create an RPC client and transport with one call
366 * @args: rpc_clnt create argument structure
367 *
368 * Creates and initializes an RPC transport and an RPC client.
369 *
370 * It can ping the server in order to determine if it is up, and to see if
371 * it supports this program and version. RPC_CLNT_CREATE_NOPING disables
372 * this behavior so asynchronous tasks can also use rpc_create.
373 */
374struct rpc_clnt *rpc_create(struct rpc_create_args *args)
375{
376 struct rpc_xprt *xprt;
377 struct rpc_clnt *clnt;
\"Talpey, Thomas\3c341b0b2007-09-10 13:47:07 -0400378 struct xprt_create xprtargs = {
Pavel Emelyanov9a23e332010-09-29 16:05:12 +0400379 .net = args->net,
\"Talpey, Thomas\4fa016e2007-09-10 13:47:57 -0400380 .ident = args->protocol,
Frank van Maarseveend3bc9a12007-07-09 22:23:35 +0200381 .srcaddr = args->saddress,
Frank van Maarseveen96802a02007-07-08 13:08:54 +0200382 .dstaddr = args->address,
383 .addrlen = args->addrsize,
Trond Myklebust4e0038b2012-03-01 17:01:05 -0500384 .servername = args->servername,
Alexandros Batsakisf300bab2009-09-10 17:33:30 +0300385 .bc_xprt = args->bc_xprt,
Frank van Maarseveen96802a02007-07-08 13:08:54 +0200386 };
Chuck Lever510deb02007-12-10 14:56:24 -0500387 char servername[48];
Chuck Leverc2866762006-08-22 20:06:20 -0400388
Chuck Leverc2866762006-08-22 20:06:20 -0400389 /*
Chuck Lever43780b82007-07-01 12:13:22 -0400390 * If the caller chooses not to specify a hostname, whip
391 * up a string representation of the passed-in address.
392 */
Trond Myklebust4e0038b2012-03-01 17:01:05 -0500393 if (xprtargs.servername == NULL) {
Chuck Lever176e21e2011-05-09 15:22:44 -0400394 struct sockaddr_un *sun =
395 (struct sockaddr_un *)args->address;
Chuck Leverda09eb92011-05-09 15:22:25 -0400396 struct sockaddr_in *sin =
397 (struct sockaddr_in *)args->address;
398 struct sockaddr_in6 *sin6 =
399 (struct sockaddr_in6 *)args->address;
400
Chuck Lever510deb02007-12-10 14:56:24 -0500401 servername[0] = '\0';
402 switch (args->address->sa_family) {
Chuck Lever176e21e2011-05-09 15:22:44 -0400403 case AF_LOCAL:
404 snprintf(servername, sizeof(servername), "%s",
405 sun->sun_path);
406 break;
Chuck Leverda09eb92011-05-09 15:22:25 -0400407 case AF_INET:
Harvey Harrison21454aa2008-10-31 00:54:56 -0700408 snprintf(servername, sizeof(servername), "%pI4",
409 &sin->sin_addr.s_addr);
Chuck Lever510deb02007-12-10 14:56:24 -0500410 break;
Chuck Leverda09eb92011-05-09 15:22:25 -0400411 case AF_INET6:
Harvey Harrison5b095d9892008-10-29 12:52:50 -0700412 snprintf(servername, sizeof(servername), "%pI6",
Chuck Leverda09eb92011-05-09 15:22:25 -0400413 &sin6->sin6_addr);
Chuck Lever510deb02007-12-10 14:56:24 -0500414 break;
Chuck Lever510deb02007-12-10 14:56:24 -0500415 default:
416 /* caller wants default server name, but
417 * address family isn't recognized. */
418 return ERR_PTR(-EINVAL);
419 }
Trond Myklebust4e0038b2012-03-01 17:01:05 -0500420 xprtargs.servername = servername;
Chuck Lever43780b82007-07-01 12:13:22 -0400421 }
422
Chuck Lever510deb02007-12-10 14:56:24 -0500423 xprt = xprt_create_transport(&xprtargs);
424 if (IS_ERR(xprt))
425 return (struct rpc_clnt *)xprt;
426
Chuck Lever43780b82007-07-01 12:13:22 -0400427 /*
Chuck Leverc2866762006-08-22 20:06:20 -0400428 * By default, kernel RPC client connects from a reserved port.
429 * CAP_NET_BIND_SERVICE will not be set for unprivileged requesters,
430 * but it is always enabled for rpciod, which handles the connect
431 * operation.
432 */
433 xprt->resvport = 1;
434 if (args->flags & RPC_CLNT_CREATE_NONPRIVPORT)
435 xprt->resvport = 0;
436
Trond Myklebust698b6d02007-12-20 16:03:53 -0500437 clnt = rpc_new_client(args, xprt);
Chuck Leverc2866762006-08-22 20:06:20 -0400438 if (IS_ERR(clnt))
439 return clnt;
440
441 if (!(args->flags & RPC_CLNT_CREATE_NOPING)) {
Chuck Levercaabea82009-12-03 15:58:56 -0500442 int err = rpc_ping(clnt);
Chuck Leverc2866762006-08-22 20:06:20 -0400443 if (err != 0) {
444 rpc_shutdown_client(clnt);
445 return ERR_PTR(err);
446 }
447 }
448
449 clnt->cl_softrtry = 1;
450 if (args->flags & RPC_CLNT_CREATE_HARDRTRY)
451 clnt->cl_softrtry = 0;
452
Chuck Leverc2866762006-08-22 20:06:20 -0400453 if (args->flags & RPC_CLNT_CREATE_AUTOBIND)
454 clnt->cl_autobind = 1;
Chuck Lever43d78ef2007-02-06 18:26:11 -0500455 if (args->flags & RPC_CLNT_CREATE_DISCRTRY)
456 clnt->cl_discrtry = 1;
Olga Kornievskaiab6b61522008-06-09 16:51:31 -0400457 if (!(args->flags & RPC_CLNT_CREATE_QUIET))
458 clnt->cl_chatty = 1;
Chuck Leverc2866762006-08-22 20:06:20 -0400459
460 return clnt;
461}
Chuck Leverb86acd52006-08-22 20:06:22 -0400462EXPORT_SYMBOL_GPL(rpc_create);
Chuck Leverc2866762006-08-22 20:06:20 -0400463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464/*
465 * This function clones the RPC client structure. It allows us to share the
466 * same transport while varying parameters such as the authentication
467 * flavour.
468 */
469struct rpc_clnt *
470rpc_clone_client(struct rpc_clnt *clnt)
471{
472 struct rpc_clnt *new;
Trond Myklebust2446ab62012-03-01 17:00:56 -0500473 struct rpc_xprt *xprt;
Trond Myklebust3e32a5d2006-11-16 11:37:27 -0500474 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Arnaldo Carvalho de Meloe69062b2006-11-21 01:21:34 -0200476 new = kmemdup(clnt, sizeof(*new), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 if (!new)
478 goto out_no_clnt;
Trond Myklebustd431a5552007-06-17 17:07:54 -0400479 new->cl_parent = clnt;
480 /* Turn off autobind on clones */
481 new->cl_autobind = 0;
482 INIT_LIST_HEAD(&new->cl_tasks);
483 spin_lock_init(&new->cl_lock);
Trond Myklebustba7392b2007-12-20 16:03:55 -0500484 rpc_init_rtt(&new->cl_rtt_default, clnt->cl_timeout->to_initval);
Trond Myklebust23bf85b2006-11-21 10:40:23 -0500485 new->cl_metrics = rpc_alloc_iostats(clnt);
486 if (new->cl_metrics == NULL)
487 goto out_no_stats;
Olga Kornievskaia608207e2008-12-23 16:17:40 -0500488 if (clnt->cl_principal) {
489 new->cl_principal = kstrdup(clnt->cl_principal, GFP_KERNEL);
490 if (new->cl_principal == NULL)
491 goto out_no_principal;
492 }
Trond Myklebust2446ab62012-03-01 17:00:56 -0500493 rcu_read_lock();
494 xprt = xprt_get(rcu_dereference(clnt->cl_xprt));
495 rcu_read_unlock();
496 if (xprt == NULL)
497 goto out_no_transport;
498 rcu_assign_pointer(new->cl_xprt, xprt);
Trond Myklebust006abe82010-09-12 19:55:25 -0400499 atomic_set(&new->cl_count, 1);
Trond Myklebust3e32a5d2006-11-16 11:37:27 -0500500 err = rpc_setup_pipedir(new, clnt->cl_program->pipe_dir_name);
501 if (err != 0)
502 goto out_no_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 if (new->cl_auth)
504 atomic_inc(&new->cl_auth->au_count);
Trond Myklebust006abe82010-09-12 19:55:25 -0400505 atomic_inc(&clnt->cl_count);
Trond Myklebust6529eba2007-06-14 16:40:14 -0400506 rpc_register_client(new);
Trond Myklebust4ada5392007-06-14 17:26:17 -0400507 rpciod_up();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 return new;
Trond Myklebust3e32a5d2006-11-16 11:37:27 -0500509out_no_path:
Trond Myklebust2446ab62012-03-01 17:00:56 -0500510 xprt_put(xprt);
511out_no_transport:
Olga Kornievskaia608207e2008-12-23 16:17:40 -0500512 kfree(new->cl_principal);
513out_no_principal:
Trond Myklebust3e32a5d2006-11-16 11:37:27 -0500514 rpc_free_iostats(new->cl_metrics);
Trond Myklebust23bf85b2006-11-21 10:40:23 -0500515out_no_stats:
516 kfree(new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517out_no_clnt:
Harvey Harrison0dc47872008-03-05 20:47:47 -0800518 dprintk("RPC: %s: returned error %d\n", __func__, err);
Trond Myklebust3e32a5d2006-11-16 11:37:27 -0500519 return ERR_PTR(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520}
Trond Myklebuste8914c62007-07-14 15:39:59 -0400521EXPORT_SYMBOL_GPL(rpc_clone_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
523/*
Trond Myklebust58f96122010-07-31 14:29:08 -0400524 * Kill all tasks for the given client.
525 * XXX: kill their descendants as well?
526 */
527void rpc_killall_tasks(struct rpc_clnt *clnt)
528{
529 struct rpc_task *rovr;
530
531
532 if (list_empty(&clnt->cl_tasks))
533 return;
534 dprintk("RPC: killing all tasks for client %p\n", clnt);
535 /*
536 * Spin lock all_tasks to prevent changes...
537 */
538 spin_lock(&clnt->cl_lock);
539 list_for_each_entry(rovr, &clnt->cl_tasks, tk_task) {
540 if (!RPC_IS_ACTIVATED(rovr))
541 continue;
542 if (!(rovr->tk_flags & RPC_TASK_KILLED)) {
543 rovr->tk_flags |= RPC_TASK_KILLED;
544 rpc_exit(rovr, -EIO);
Stanislav Kinsbursky8e26de22011-03-17 18:54:23 +0300545 if (RPC_IS_QUEUED(rovr))
546 rpc_wake_up_queued_task(rovr->tk_waitqueue,
547 rovr);
Trond Myklebust58f96122010-07-31 14:29:08 -0400548 }
549 }
550 spin_unlock(&clnt->cl_lock);
551}
552EXPORT_SYMBOL_GPL(rpc_killall_tasks);
553
554/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 * Properly shut down an RPC client, terminating all outstanding
Trond Myklebust90c57552007-06-09 19:49:36 -0400556 * requests.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 */
Trond Myklebust4c402b42007-06-14 16:40:32 -0400558void rpc_shutdown_client(struct rpc_clnt *clnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559{
Trond Myklebust4e0038b2012-03-01 17:01:05 -0500560 dprintk_rcu("RPC: shutting down %s client for %s\n",
561 clnt->cl_protname,
562 rcu_dereference(clnt->cl_xprt)->servername);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
Trond Myklebust34f52e32007-06-14 16:40:31 -0400564 while (!list_empty(&clnt->cl_tasks)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 rpc_killall_tasks(clnt);
Ingo Molnar532347e2006-01-09 20:52:53 -0800566 wait_event_timeout(destroy_wait,
Trond Myklebust34f52e32007-06-14 16:40:31 -0400567 list_empty(&clnt->cl_tasks), 1*HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 }
569
Trond Myklebust4c402b42007-06-14 16:40:32 -0400570 rpc_release_client(clnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571}
Trond Myklebuste8914c62007-07-14 15:39:59 -0400572EXPORT_SYMBOL_GPL(rpc_shutdown_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
574/*
Trond Myklebust34f52e32007-06-14 16:40:31 -0400575 * Free an RPC client
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 */
Trond Myklebust34f52e32007-06-14 16:40:31 -0400577static void
Trond Myklebust006abe82010-09-12 19:55:25 -0400578rpc_free_client(struct rpc_clnt *clnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
Trond Myklebust4e0038b2012-03-01 17:01:05 -0500580 dprintk_rcu("RPC: destroying %s client for %s\n",
581 clnt->cl_protname,
582 rcu_dereference(clnt->cl_xprt)->servername);
Trond Myklebust6eac7d32012-01-20 13:53:37 -0500583 if (clnt->cl_parent != clnt)
Trond Myklebust8ad7c892007-06-14 16:40:32 -0400584 rpc_release_client(clnt->cl_parent);
Trond Myklebust6529eba2007-06-14 16:40:14 -0400585 rpc_unregister_client(clnt);
Stanislav Kinsburskyf5131252012-01-11 19:18:26 +0400586 rpc_clnt_remove_pipedir(clnt);
Chuck Lever11c556b2006-03-20 13:44:22 -0500587 rpc_free_iostats(clnt->cl_metrics);
Olga Kornievskaia608207e2008-12-23 16:17:40 -0500588 kfree(clnt->cl_principal);
Chuck Lever11c556b2006-03-20 13:44:22 -0500589 clnt->cl_metrics = NULL;
Trond Myklebust2446ab62012-03-01 17:00:56 -0500590 xprt_put(rcu_dereference_raw(clnt->cl_xprt));
Trond Myklebust4ada5392007-06-14 17:26:17 -0400591 rpciod_down();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 kfree(clnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593}
594
595/*
Trond Myklebust1dd17ec2007-06-26 16:57:41 -0400596 * Free an RPC client
597 */
598static void
Trond Myklebust006abe82010-09-12 19:55:25 -0400599rpc_free_auth(struct rpc_clnt *clnt)
Trond Myklebust1dd17ec2007-06-26 16:57:41 -0400600{
Trond Myklebust1dd17ec2007-06-26 16:57:41 -0400601 if (clnt->cl_auth == NULL) {
Trond Myklebust006abe82010-09-12 19:55:25 -0400602 rpc_free_client(clnt);
Trond Myklebust1dd17ec2007-06-26 16:57:41 -0400603 return;
604 }
605
606 /*
607 * Note: RPCSEC_GSS may need to send NULL RPC calls in order to
608 * release remaining GSS contexts. This mechanism ensures
609 * that it can do so safely.
610 */
Trond Myklebust006abe82010-09-12 19:55:25 -0400611 atomic_inc(&clnt->cl_count);
Trond Myklebust1dd17ec2007-06-26 16:57:41 -0400612 rpcauth_release(clnt->cl_auth);
613 clnt->cl_auth = NULL;
Trond Myklebust006abe82010-09-12 19:55:25 -0400614 if (atomic_dec_and_test(&clnt->cl_count))
615 rpc_free_client(clnt);
Trond Myklebust1dd17ec2007-06-26 16:57:41 -0400616}
617
618/*
Trond Myklebust34f52e32007-06-14 16:40:31 -0400619 * Release reference to the RPC client
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 */
621void
622rpc_release_client(struct rpc_clnt *clnt)
623{
Trond Myklebust34f52e32007-06-14 16:40:31 -0400624 dprintk("RPC: rpc_release_client(%p)\n", clnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Trond Myklebust34f52e32007-06-14 16:40:31 -0400626 if (list_empty(&clnt->cl_tasks))
627 wake_up(&destroy_wait);
Trond Myklebust006abe82010-09-12 19:55:25 -0400628 if (atomic_dec_and_test(&clnt->cl_count))
629 rpc_free_auth(clnt);
Trond Myklebust34f52e32007-06-14 16:40:31 -0400630}
631
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000632/**
633 * rpc_bind_new_program - bind a new RPC program to an existing client
Randy Dunlap65b6e422008-02-13 15:03:23 -0800634 * @old: old rpc_client
635 * @program: rpc program to set
636 * @vers: rpc program version
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000637 *
638 * Clones the rpc client and sets up a new RPC program. This is mainly
639 * of use for enabling different RPC programs to share the same transport.
640 * The Sun NFSv2/v3 ACL protocol can do this.
641 */
642struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *old,
Trond Myklebusta613fa12012-01-20 13:53:56 -0500643 const struct rpc_program *program,
Chuck Lever89eb21c2007-09-11 18:00:09 -0400644 u32 vers)
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000645{
646 struct rpc_clnt *clnt;
Trond Myklebusta613fa12012-01-20 13:53:56 -0500647 const struct rpc_version *version;
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000648 int err;
649
650 BUG_ON(vers >= program->nrvers || !program->version[vers]);
651 version = program->version[vers];
652 clnt = rpc_clone_client(old);
653 if (IS_ERR(clnt))
654 goto out;
655 clnt->cl_procinfo = version->procs;
656 clnt->cl_maxproc = version->nrprocs;
657 clnt->cl_protname = program->name;
658 clnt->cl_prog = program->number;
659 clnt->cl_vers = version->number;
660 clnt->cl_stats = program->stats;
Chuck Levercaabea82009-12-03 15:58:56 -0500661 err = rpc_ping(clnt);
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000662 if (err != 0) {
663 rpc_shutdown_client(clnt);
664 clnt = ERR_PTR(err);
665 }
YOSHIFUJI Hideakicca51722007-02-09 15:38:13 -0800666out:
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000667 return clnt;
668}
Trond Myklebuste8914c62007-07-14 15:39:59 -0400669EXPORT_SYMBOL_GPL(rpc_bind_new_program);
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000670
Trond Myklebust58f96122010-07-31 14:29:08 -0400671void rpc_task_release_client(struct rpc_task *task)
672{
673 struct rpc_clnt *clnt = task->tk_client;
674
675 if (clnt != NULL) {
676 /* Remove from client task list */
677 spin_lock(&clnt->cl_lock);
678 list_del(&task->tk_task);
679 spin_unlock(&clnt->cl_lock);
680 task->tk_client = NULL;
681
682 rpc_release_client(clnt);
683 }
684}
685
686static
687void rpc_task_set_client(struct rpc_task *task, struct rpc_clnt *clnt)
688{
689 if (clnt != NULL) {
690 rpc_task_release_client(task);
691 task->tk_client = clnt;
Trond Myklebust006abe82010-09-12 19:55:25 -0400692 atomic_inc(&clnt->cl_count);
Trond Myklebust58f96122010-07-31 14:29:08 -0400693 if (clnt->cl_softrtry)
694 task->tk_flags |= RPC_TASK_SOFT;
695 /* Add to the client's list of all tasks */
696 spin_lock(&clnt->cl_lock);
697 list_add_tail(&task->tk_task, &clnt->cl_tasks);
698 spin_unlock(&clnt->cl_lock);
699 }
700}
701
Andy Adamsoncbdabc7f2011-03-01 01:34:20 +0000702void rpc_task_reset_client(struct rpc_task *task, struct rpc_clnt *clnt)
703{
704 rpc_task_release_client(task);
705 rpc_task_set_client(task, clnt);
706}
707EXPORT_SYMBOL_GPL(rpc_task_reset_client);
708
709
Trond Myklebust58f96122010-07-31 14:29:08 -0400710static void
711rpc_task_set_rpc_message(struct rpc_task *task, const struct rpc_message *msg)
712{
713 if (msg != NULL) {
714 task->tk_msg.rpc_proc = msg->rpc_proc;
715 task->tk_msg.rpc_argp = msg->rpc_argp;
716 task->tk_msg.rpc_resp = msg->rpc_resp;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400717 if (msg->rpc_cred != NULL)
718 task->tk_msg.rpc_cred = get_rpccred(msg->rpc_cred);
Trond Myklebust58f96122010-07-31 14:29:08 -0400719 }
720}
721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722/*
723 * Default callback for async RPC calls
724 */
725static void
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100726rpc_default_callback(struct rpc_task *task, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727{
728}
729
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100730static const struct rpc_call_ops rpc_default_ops = {
731 .rpc_call_done = rpc_default_callback,
732};
733
Trond Myklebustc970aa82007-07-14 15:39:59 -0400734/**
735 * rpc_run_task - Allocate a new RPC task, then run rpc_execute against it
736 * @task_setup_data: pointer to task initialisation data
737 */
738struct rpc_task *rpc_run_task(const struct rpc_task_setup *task_setup_data)
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400739{
Trond Myklebust19445b92010-04-16 16:41:10 -0400740 struct rpc_task *task;
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400741
Trond Myklebust84115e12007-07-14 15:39:59 -0400742 task = rpc_new_task(task_setup_data);
Trond Myklebust19445b92010-04-16 16:41:10 -0400743 if (IS_ERR(task))
Trond Myklebust50859252007-10-25 18:19:37 -0400744 goto out;
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400745
Trond Myklebust58f96122010-07-31 14:29:08 -0400746 rpc_task_set_client(task, task_setup_data->rpc_client);
747 rpc_task_set_rpc_message(task, task_setup_data->rpc_message);
748
Trond Myklebust58f96122010-07-31 14:29:08 -0400749 if (task->tk_action == NULL)
750 rpc_call_start(task);
751
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400752 atomic_inc(&task->tk_count);
753 rpc_execute(task);
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400754out:
Trond Myklebust19445b92010-04-16 16:41:10 -0400755 return task;
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400756}
Trond Myklebustc970aa82007-07-14 15:39:59 -0400757EXPORT_SYMBOL_GPL(rpc_run_task);
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400758
759/**
760 * rpc_call_sync - Perform a synchronous RPC call
761 * @clnt: pointer to RPC client
762 * @msg: RPC call parameters
763 * @flags: RPC call flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 */
Trond Myklebustcbc20052008-02-14 11:11:30 -0500765int rpc_call_sync(struct rpc_clnt *clnt, const struct rpc_message *msg, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766{
767 struct rpc_task *task;
Trond Myklebust84115e12007-07-14 15:39:59 -0400768 struct rpc_task_setup task_setup_data = {
769 .rpc_client = clnt,
770 .rpc_message = msg,
771 .callback_ops = &rpc_default_ops,
772 .flags = flags,
773 };
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400774 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 BUG_ON(flags & RPC_TASK_ASYNC);
777
Trond Myklebustc970aa82007-07-14 15:39:59 -0400778 task = rpc_run_task(&task_setup_data);
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400779 if (IS_ERR(task))
780 return PTR_ERR(task);
Trond Myklebuste60859a2006-01-03 09:55:10 +0100781 status = task->tk_status;
Trond Myklebustbde8f002007-01-24 11:54:53 -0800782 rpc_put_task(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 return status;
784}
Trond Myklebuste8914c62007-07-14 15:39:59 -0400785EXPORT_SYMBOL_GPL(rpc_call_sync);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400787/**
788 * rpc_call_async - Perform an asynchronous RPC call
789 * @clnt: pointer to RPC client
790 * @msg: RPC call parameters
791 * @flags: RPC call flags
Randy Dunlap65b6e422008-02-13 15:03:23 -0800792 * @tk_ops: RPC call ops
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400793 * @data: user call data
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 */
795int
Trond Myklebustcbc20052008-02-14 11:11:30 -0500796rpc_call_async(struct rpc_clnt *clnt, const struct rpc_message *msg, int flags,
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100797 const struct rpc_call_ops *tk_ops, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798{
799 struct rpc_task *task;
Trond Myklebust84115e12007-07-14 15:39:59 -0400800 struct rpc_task_setup task_setup_data = {
801 .rpc_client = clnt,
802 .rpc_message = msg,
803 .callback_ops = tk_ops,
804 .callback_data = data,
805 .flags = flags|RPC_TASK_ASYNC,
806 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Trond Myklebustc970aa82007-07-14 15:39:59 -0400808 task = rpc_run_task(&task_setup_data);
Trond Myklebust6e5b70e2007-06-12 10:02:37 -0400809 if (IS_ERR(task))
810 return PTR_ERR(task);
811 rpc_put_task(task);
812 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813}
Trond Myklebuste8914c62007-07-14 15:39:59 -0400814EXPORT_SYMBOL_GPL(rpc_call_async);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
Trond Myklebust9e00abc2011-07-13 19:20:49 -0400816#if defined(CONFIG_SUNRPC_BACKCHANNEL)
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400817/**
818 * rpc_run_bc_task - Allocate a new RPC task for backchannel use, then run
819 * rpc_execute against it
Jaswinder Singh Rajput7a73fdd2009-09-24 14:58:42 -0400820 * @req: RPC request
821 * @tk_ops: RPC call ops
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400822 */
823struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req,
Jaswinder Singh Rajput7a73fdd2009-09-24 14:58:42 -0400824 const struct rpc_call_ops *tk_ops)
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400825{
826 struct rpc_task *task;
827 struct xdr_buf *xbufp = &req->rq_snd_buf;
828 struct rpc_task_setup task_setup_data = {
829 .callback_ops = tk_ops,
830 };
831
832 dprintk("RPC: rpc_run_bc_task req= %p\n", req);
833 /*
834 * Create an rpc_task to send the data
835 */
836 task = rpc_new_task(&task_setup_data);
Trond Myklebust19445b92010-04-16 16:41:10 -0400837 if (IS_ERR(task)) {
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400838 xprt_free_bc_request(req);
839 goto out;
840 }
841 task->tk_rqstp = req;
842
843 /*
844 * Set up the xdr_buf length.
845 * This also indicates that the buffer is XDR encoded already.
846 */
847 xbufp->len = xbufp->head[0].iov_len + xbufp->page_len +
848 xbufp->tail[0].iov_len;
849
850 task->tk_action = call_bc_transmit;
851 atomic_inc(&task->tk_count);
852 BUG_ON(atomic_read(&task->tk_count) != 2);
853 rpc_execute(task);
854
855out:
856 dprintk("RPC: rpc_run_bc_task: task= %p\n", task);
857 return task;
858}
Trond Myklebust9e00abc2011-07-13 19:20:49 -0400859#endif /* CONFIG_SUNRPC_BACKCHANNEL */
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -0400860
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861void
Trond Myklebust77de2c52007-10-25 18:40:21 -0400862rpc_call_start(struct rpc_task *task)
863{
864 task->tk_action = call_start;
865}
866EXPORT_SYMBOL_GPL(rpc_call_start);
867
Chuck Levered394402006-08-22 20:06:17 -0400868/**
869 * rpc_peeraddr - extract remote peer address from clnt's xprt
870 * @clnt: RPC client structure
871 * @buf: target buffer
Randy Dunlap65b6e422008-02-13 15:03:23 -0800872 * @bufsize: length of target buffer
Chuck Levered394402006-08-22 20:06:17 -0400873 *
874 * Returns the number of bytes that are actually in the stored address.
875 */
876size_t rpc_peeraddr(struct rpc_clnt *clnt, struct sockaddr *buf, size_t bufsize)
877{
878 size_t bytes;
Trond Myklebust2446ab62012-03-01 17:00:56 -0500879 struct rpc_xprt *xprt;
Chuck Levered394402006-08-22 20:06:17 -0400880
Trond Myklebust2446ab62012-03-01 17:00:56 -0500881 rcu_read_lock();
882 xprt = rcu_dereference(clnt->cl_xprt);
883
884 bytes = xprt->addrlen;
Chuck Levered394402006-08-22 20:06:17 -0400885 if (bytes > bufsize)
886 bytes = bufsize;
Trond Myklebust2446ab62012-03-01 17:00:56 -0500887 memcpy(buf, &xprt->addr, bytes);
888 rcu_read_unlock();
889
890 return bytes;
Chuck Levered394402006-08-22 20:06:17 -0400891}
Chuck Leverb86acd52006-08-22 20:06:22 -0400892EXPORT_SYMBOL_GPL(rpc_peeraddr);
Chuck Levered394402006-08-22 20:06:17 -0400893
Chuck Leverf425eba2006-08-22 20:06:18 -0400894/**
895 * rpc_peeraddr2str - return remote peer address in printable format
896 * @clnt: RPC client structure
897 * @format: address format
898 *
Trond Myklebust2446ab62012-03-01 17:00:56 -0500899 * NB: the lifetime of the memory referenced by the returned pointer is
900 * the same as the rpc_xprt itself. As long as the caller uses this
901 * pointer, it must hold the RCU read lock.
Chuck Leverf425eba2006-08-22 20:06:18 -0400902 */
Chuck Leverb454ae92008-01-07 18:34:48 -0500903const char *rpc_peeraddr2str(struct rpc_clnt *clnt,
904 enum rpc_display_format_t format)
Chuck Leverf425eba2006-08-22 20:06:18 -0400905{
Trond Myklebust2446ab62012-03-01 17:00:56 -0500906 struct rpc_xprt *xprt;
907
908 xprt = rcu_dereference(clnt->cl_xprt);
Chuck Lever7559c7a2006-12-05 16:35:37 -0500909
910 if (xprt->address_strings[format] != NULL)
911 return xprt->address_strings[format];
912 else
913 return "unprintable";
Chuck Leverf425eba2006-08-22 20:06:18 -0400914}
Chuck Leverb86acd52006-08-22 20:06:22 -0400915EXPORT_SYMBOL_GPL(rpc_peeraddr2str);
Chuck Leverf425eba2006-08-22 20:06:18 -0400916
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917void
918rpc_setbufsize(struct rpc_clnt *clnt, unsigned int sndsize, unsigned int rcvsize)
919{
Trond Myklebust2446ab62012-03-01 17:00:56 -0500920 struct rpc_xprt *xprt;
921
922 rcu_read_lock();
923 xprt = rcu_dereference(clnt->cl_xprt);
Chuck Lever470056c2005-08-25 16:25:56 -0700924 if (xprt->ops->set_buffer_size)
925 xprt->ops->set_buffer_size(xprt, sndsize, rcvsize);
Trond Myklebust2446ab62012-03-01 17:00:56 -0500926 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927}
Trond Myklebuste8914c62007-07-14 15:39:59 -0400928EXPORT_SYMBOL_GPL(rpc_setbufsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Trond Myklebust2446ab62012-03-01 17:00:56 -0500930/**
931 * rpc_protocol - Get transport protocol number for an RPC client
932 * @clnt: RPC client to query
933 *
934 */
935int rpc_protocol(struct rpc_clnt *clnt)
936{
937 int protocol;
938
939 rcu_read_lock();
940 protocol = rcu_dereference(clnt->cl_xprt)->prot;
941 rcu_read_unlock();
942 return protocol;
943}
944EXPORT_SYMBOL_GPL(rpc_protocol);
945
946/**
947 * rpc_net_ns - Get the network namespace for this RPC client
948 * @clnt: RPC client to query
949 *
950 */
951struct net *rpc_net_ns(struct rpc_clnt *clnt)
952{
953 struct net *ret;
954
955 rcu_read_lock();
956 ret = rcu_dereference(clnt->cl_xprt)->xprt_net;
957 rcu_read_unlock();
958 return ret;
959}
960EXPORT_SYMBOL_GPL(rpc_net_ns);
961
962/**
963 * rpc_max_payload - Get maximum payload size for a transport, in bytes
964 * @clnt: RPC client to query
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 *
966 * For stream transports, this is one RPC record fragment (see RFC
967 * 1831), as we don't support multi-record requests yet. For datagram
968 * transports, this is the size of an IP packet minus the IP, UDP, and
969 * RPC header sizes.
970 */
971size_t rpc_max_payload(struct rpc_clnt *clnt)
972{
Trond Myklebust2446ab62012-03-01 17:00:56 -0500973 size_t ret;
974
975 rcu_read_lock();
976 ret = rcu_dereference(clnt->cl_xprt)->max_payload;
977 rcu_read_unlock();
978 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979}
Chuck Leverb86acd52006-08-22 20:06:22 -0400980EXPORT_SYMBOL_GPL(rpc_max_payload);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Chuck Lever35f5a422006-01-03 09:55:50 +0100982/**
983 * rpc_force_rebind - force transport to check that remote port is unchanged
984 * @clnt: client to rebind
985 *
986 */
987void rpc_force_rebind(struct rpc_clnt *clnt)
988{
Trond Myklebust2446ab62012-03-01 17:00:56 -0500989 if (clnt->cl_autobind) {
990 rcu_read_lock();
991 xprt_clear_bound(rcu_dereference(clnt->cl_xprt));
992 rcu_read_unlock();
993 }
Chuck Lever35f5a422006-01-03 09:55:50 +0100994}
Chuck Leverb86acd52006-08-22 20:06:22 -0400995EXPORT_SYMBOL_GPL(rpc_force_rebind);
Chuck Lever35f5a422006-01-03 09:55:50 +0100996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997/*
Andy Adamsonaae20062009-04-01 09:22:40 -0400998 * Restart an (async) RPC call from the call_prepare state.
999 * Usually called from within the exit handler.
1000 */
Trond Myklebustf1f88fc2010-07-31 14:29:07 -04001001int
Andy Adamsonaae20062009-04-01 09:22:40 -04001002rpc_restart_call_prepare(struct rpc_task *task)
1003{
1004 if (RPC_ASSASSINATED(task))
Trond Myklebustf1f88fc2010-07-31 14:29:07 -04001005 return 0;
Trond Myklebustd00c5d42011-10-19 12:17:29 -07001006 task->tk_action = call_start;
1007 if (task->tk_ops->rpc_call_prepare != NULL)
1008 task->tk_action = rpc_prepare_task;
Trond Myklebustf1f88fc2010-07-31 14:29:07 -04001009 return 1;
Andy Adamsonaae20062009-04-01 09:22:40 -04001010}
1011EXPORT_SYMBOL_GPL(rpc_restart_call_prepare);
1012
1013/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 * Restart an (async) RPC call. Usually called from within the
1015 * exit handler.
1016 */
Trond Myklebustf1f88fc2010-07-31 14:29:07 -04001017int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018rpc_restart_call(struct rpc_task *task)
1019{
1020 if (RPC_ASSASSINATED(task))
Trond Myklebustf1f88fc2010-07-31 14:29:07 -04001021 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 task->tk_action = call_start;
Trond Myklebustf1f88fc2010-07-31 14:29:07 -04001023 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024}
Trond Myklebuste8914c62007-07-14 15:39:59 -04001025EXPORT_SYMBOL_GPL(rpc_restart_call);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
Chuck Lever3748f1e2008-05-21 17:09:12 -04001027#ifdef RPC_DEBUG
1028static const char *rpc_proc_name(const struct rpc_task *task)
1029{
1030 const struct rpc_procinfo *proc = task->tk_msg.rpc_proc;
1031
1032 if (proc) {
1033 if (proc->p_name)
1034 return proc->p_name;
1035 else
1036 return "NULL";
1037 } else
1038 return "no proc";
1039}
1040#endif
1041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042/*
1043 * 0. Initial state
1044 *
1045 * Other FSM states can be visited zero or more times, but
1046 * this state is visited exactly once for each RPC.
1047 */
1048static void
1049call_start(struct rpc_task *task)
1050{
1051 struct rpc_clnt *clnt = task->tk_client;
1052
Chuck Lever3748f1e2008-05-21 17:09:12 -04001053 dprintk("RPC: %5u call_start %s%d proc %s (%s)\n", task->tk_pid,
Chuck Lever46121cf2007-01-31 12:14:08 -05001054 clnt->cl_protname, clnt->cl_vers,
Chuck Lever3748f1e2008-05-21 17:09:12 -04001055 rpc_proc_name(task),
Chuck Lever46121cf2007-01-31 12:14:08 -05001056 (RPC_IS_ASYNC(task) ? "async" : "sync"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
1058 /* Increment call count */
1059 task->tk_msg.rpc_proc->p_count++;
1060 clnt->cl_stats->rpccnt++;
1061 task->tk_action = call_reserve;
1062}
1063
1064/*
1065 * 1. Reserve an RPC call slot
1066 */
1067static void
1068call_reserve(struct rpc_task *task)
1069{
Chuck Lever46121cf2007-01-31 12:14:08 -05001070 dprint_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 task->tk_status = 0;
1073 task->tk_action = call_reserveresult;
1074 xprt_reserve(task);
1075}
1076
1077/*
1078 * 1b. Grok the result of xprt_reserve()
1079 */
1080static void
1081call_reserveresult(struct rpc_task *task)
1082{
1083 int status = task->tk_status;
1084
Chuck Lever46121cf2007-01-31 12:14:08 -05001085 dprint_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 /*
1088 * After a call to xprt_reserve(), we must have either
1089 * a request slot or else an error status.
1090 */
1091 task->tk_status = 0;
1092 if (status >= 0) {
1093 if (task->tk_rqstp) {
J. Bruce Fieldsf2d47d02010-09-12 19:55:25 -04001094 task->tk_action = call_refresh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 return;
1096 }
1097
1098 printk(KERN_ERR "%s: status=%d, but no request slot, exiting\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001099 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 rpc_exit(task, -EIO);
1101 return;
1102 }
1103
1104 /*
1105 * Even though there was an error, we may have acquired
1106 * a request slot somehow. Make sure not to leak it.
1107 */
1108 if (task->tk_rqstp) {
1109 printk(KERN_ERR "%s: status=%d, request allocated anyway\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001110 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 xprt_release(task);
1112 }
1113
1114 switch (status) {
1115 case -EAGAIN: /* woken up; retry */
1116 task->tk_action = call_reserve;
1117 return;
1118 case -EIO: /* probably a shutdown */
1119 break;
1120 default:
1121 printk(KERN_ERR "%s: unrecognized error %d, exiting\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001122 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 break;
1124 }
1125 rpc_exit(task, status);
1126}
1127
1128/*
J. Bruce Fields55576242010-09-12 19:55:25 -04001129 * 2. Bind and/or refresh the credentials
1130 */
1131static void
1132call_refresh(struct rpc_task *task)
1133{
1134 dprint_status(task);
1135
1136 task->tk_action = call_refreshresult;
1137 task->tk_status = 0;
1138 task->tk_client->cl_stats->rpcauthrefresh++;
1139 rpcauth_refreshcred(task);
1140}
1141
1142/*
1143 * 2a. Process the results of a credential refresh
1144 */
1145static void
1146call_refreshresult(struct rpc_task *task)
1147{
1148 int status = task->tk_status;
1149
1150 dprint_status(task);
1151
1152 task->tk_status = 0;
Trond Myklebust5fc43972010-11-20 11:13:31 -05001153 task->tk_action = call_refresh;
J. Bruce Fields55576242010-09-12 19:55:25 -04001154 switch (status) {
Trond Myklebust5fc43972010-11-20 11:13:31 -05001155 case 0:
1156 if (rpcauth_uptodatecred(task))
1157 task->tk_action = call_allocate;
J. Bruce Fields55576242010-09-12 19:55:25 -04001158 return;
1159 case -ETIMEDOUT:
1160 rpc_delay(task, 3*HZ);
Trond Myklebust5fc43972010-11-20 11:13:31 -05001161 case -EAGAIN:
1162 status = -EACCES;
1163 if (!task->tk_cred_retry)
1164 break;
1165 task->tk_cred_retry--;
1166 dprintk("RPC: %5u %s: retry refresh creds\n",
1167 task->tk_pid, __func__);
1168 return;
J. Bruce Fields55576242010-09-12 19:55:25 -04001169 }
Trond Myklebust5fc43972010-11-20 11:13:31 -05001170 dprintk("RPC: %5u %s: refresh creds failed with error %d\n",
1171 task->tk_pid, __func__, status);
1172 rpc_exit(task, status);
J. Bruce Fields55576242010-09-12 19:55:25 -04001173}
1174
1175/*
1176 * 2b. Allocate the buffer. For details, see sched.c:rpc_malloc.
Chuck Lever02107142006-01-03 09:55:49 +01001177 * (Note: buffer memory is freed in xprt_release).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 */
1179static void
1180call_allocate(struct rpc_task *task)
1181{
J. Bruce Fieldsf2d47d02010-09-12 19:55:25 -04001182 unsigned int slack = task->tk_rqstp->rq_cred->cr_auth->au_cslack;
Chuck Lever02107142006-01-03 09:55:49 +01001183 struct rpc_rqst *req = task->tk_rqstp;
1184 struct rpc_xprt *xprt = task->tk_xprt;
Chuck Lever2bea90d2007-03-29 16:47:53 -04001185 struct rpc_procinfo *proc = task->tk_msg.rpc_proc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
Chuck Lever46121cf2007-01-31 12:14:08 -05001187 dprint_status(task);
1188
Chuck Lever2bea90d2007-03-29 16:47:53 -04001189 task->tk_status = 0;
J. Bruce Fieldsf2d47d02010-09-12 19:55:25 -04001190 task->tk_action = call_bind;
Chuck Lever2bea90d2007-03-29 16:47:53 -04001191
Chuck Lever02107142006-01-03 09:55:49 +01001192 if (req->rq_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 return;
1194
Chuck Lever2bea90d2007-03-29 16:47:53 -04001195 if (proc->p_proc != 0) {
1196 BUG_ON(proc->p_arglen == 0);
1197 if (proc->p_decode != NULL)
1198 BUG_ON(proc->p_replen == 0);
1199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Chuck Lever2bea90d2007-03-29 16:47:53 -04001201 /*
1202 * Calculate the size (in quads) of the RPC call
1203 * and reply headers, and convert both values
1204 * to byte sizes.
1205 */
1206 req->rq_callsize = RPC_CALLHDRSIZE + (slack << 1) + proc->p_arglen;
1207 req->rq_callsize <<= 2;
1208 req->rq_rcvsize = RPC_REPHDRSIZE + slack + proc->p_replen;
1209 req->rq_rcvsize <<= 2;
1210
Chuck Leverc5a4dd82007-03-29 16:47:58 -04001211 req->rq_buffer = xprt->ops->buf_alloc(task,
1212 req->rq_callsize + req->rq_rcvsize);
Chuck Lever2bea90d2007-03-29 16:47:53 -04001213 if (req->rq_buffer != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 return;
Chuck Lever46121cf2007-01-31 12:14:08 -05001215
1216 dprintk("RPC: %5u rpc_buffer allocation failed\n", task->tk_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Trond Myklebust5afa9132011-06-17 10:14:59 -04001218 if (RPC_IS_ASYNC(task) || !fatal_signal_pending(current)) {
Trond Myklebustb6e9c712007-10-01 12:06:44 -04001219 task->tk_action = call_allocate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 rpc_delay(task, HZ>>4);
1221 return;
1222 }
1223
1224 rpc_exit(task, -ERESTARTSYS);
1225}
1226
Trond Myklebust940e3312005-11-09 21:45:24 -05001227static inline int
1228rpc_task_need_encode(struct rpc_task *task)
1229{
1230 return task->tk_rqstp->rq_snd_buf.len == 0;
1231}
1232
1233static inline void
1234rpc_task_force_reencode(struct rpc_task *task)
1235{
1236 task->tk_rqstp->rq_snd_buf.len = 0;
Trond Myklebust2574cc92009-08-28 11:12:12 -04001237 task->tk_rqstp->rq_bytes_sent = 0;
Trond Myklebust940e3312005-11-09 21:45:24 -05001238}
1239
Chuck Lever2bea90d2007-03-29 16:47:53 -04001240static inline void
1241rpc_xdr_buf_init(struct xdr_buf *buf, void *start, size_t len)
1242{
1243 buf->head[0].iov_base = start;
1244 buf->head[0].iov_len = len;
1245 buf->tail[0].iov_len = 0;
1246 buf->page_len = 0;
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04001247 buf->flags = 0;
Chuck Lever2bea90d2007-03-29 16:47:53 -04001248 buf->len = 0;
1249 buf->buflen = len;
1250}
1251
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252/*
1253 * 3. Encode arguments of an RPC call
1254 */
1255static void
Chuck Leverb0e1c572008-05-21 17:09:19 -04001256rpc_xdr_encode(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 struct rpc_rqst *req = task->tk_rqstp;
Chuck Lever9f06c712010-12-14 14:59:18 +00001259 kxdreproc_t encode;
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001260 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Chuck Lever46121cf2007-01-31 12:14:08 -05001262 dprint_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
Chuck Lever2bea90d2007-03-29 16:47:53 -04001264 rpc_xdr_buf_init(&req->rq_snd_buf,
1265 req->rq_buffer,
1266 req->rq_callsize);
1267 rpc_xdr_buf_init(&req->rq_rcv_buf,
1268 (char *)req->rq_buffer + req->rq_callsize,
1269 req->rq_rcvsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
Chuck Leverb0e1c572008-05-21 17:09:19 -04001271 p = rpc_encode_header(task);
1272 if (p == NULL) {
1273 printk(KERN_INFO "RPC: couldn't encode RPC header, exit EIO\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 rpc_exit(task, -EIO);
1275 return;
1276 }
Chuck Leverb0e1c572008-05-21 17:09:19 -04001277
1278 encode = task->tk_msg.rpc_proc->p_encode;
J. Bruce Fieldsf3680312005-10-13 16:54:48 -04001279 if (encode == NULL)
1280 return;
1281
1282 task->tk_status = rpcauth_wrap_req(task, encode, req, p,
1283 task->tk_msg.rpc_argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284}
1285
1286/*
1287 * 4. Get the server port number if not yet set
1288 */
1289static void
1290call_bind(struct rpc_task *task)
1291{
Chuck Leverec739ef2006-08-22 20:06:15 -04001292 struct rpc_xprt *xprt = task->tk_xprt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Chuck Lever46121cf2007-01-31 12:14:08 -05001294 dprint_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Chuck Leverda351872005-08-11 16:25:11 -04001296 task->tk_action = call_connect;
Chuck Leverec739ef2006-08-22 20:06:15 -04001297 if (!xprt_bound(xprt)) {
Chuck Leverda351872005-08-11 16:25:11 -04001298 task->tk_action = call_bind_status;
Chuck Leverec739ef2006-08-22 20:06:15 -04001299 task->tk_timeout = xprt->bind_timeout;
Chuck Leverbbf7c1d2006-08-22 20:06:16 -04001300 xprt->ops->rpcbind(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 }
1302}
1303
1304/*
Chuck Leverda351872005-08-11 16:25:11 -04001305 * 4a. Sort out bind result
1306 */
1307static void
1308call_bind_status(struct rpc_task *task)
1309{
Chuck Lever906462a2007-09-11 18:00:47 -04001310 int status = -EIO;
Chuck Leverda351872005-08-11 16:25:11 -04001311
1312 if (task->tk_status >= 0) {
Chuck Lever46121cf2007-01-31 12:14:08 -05001313 dprint_status(task);
Chuck Leverda351872005-08-11 16:25:11 -04001314 task->tk_status = 0;
1315 task->tk_action = call_connect;
1316 return;
1317 }
1318
Steve Dickson5753cba2012-02-06 10:08:08 -05001319 trace_rpc_bind_status(task);
Chuck Leverda351872005-08-11 16:25:11 -04001320 switch (task->tk_status) {
Trond Myklebust381ba742008-07-07 12:18:53 -04001321 case -ENOMEM:
1322 dprintk("RPC: %5u rpcbind out of memory\n", task->tk_pid);
1323 rpc_delay(task, HZ >> 2);
Chuck Lever2429cbf2007-09-11 18:00:41 -04001324 goto retry_timeout;
Chuck Leverda351872005-08-11 16:25:11 -04001325 case -EACCES:
Chuck Lever46121cf2007-01-31 12:14:08 -05001326 dprintk("RPC: %5u remote rpcbind: RPC program/version "
1327 "unavailable\n", task->tk_pid);
Chuck Leverb79dc8c2007-09-11 18:00:52 -04001328 /* fail immediately if this is an RPC ping */
1329 if (task->tk_msg.rpc_proc->p_proc == 0) {
1330 status = -EOPNOTSUPP;
1331 break;
1332 }
Trond Myklebust0b760112011-05-31 15:15:34 -04001333 if (task->tk_rebind_retry == 0)
1334 break;
1335 task->tk_rebind_retry--;
Chuck Leverea635a52005-10-06 23:12:58 -04001336 rpc_delay(task, 3*HZ);
Trond Myklebustda458282006-08-31 15:44:52 -04001337 goto retry_timeout;
Chuck Leverda351872005-08-11 16:25:11 -04001338 case -ETIMEDOUT:
Chuck Lever46121cf2007-01-31 12:14:08 -05001339 dprintk("RPC: %5u rpcbind request timed out\n",
Chuck Leverda351872005-08-11 16:25:11 -04001340 task->tk_pid);
Trond Myklebustda458282006-08-31 15:44:52 -04001341 goto retry_timeout;
Chuck Leverda351872005-08-11 16:25:11 -04001342 case -EPFNOSUPPORT:
Chuck Lever906462a2007-09-11 18:00:47 -04001343 /* server doesn't support any rpcbind version we know of */
Chuck Lever012da152009-12-03 15:58:56 -05001344 dprintk("RPC: %5u unrecognized remote rpcbind service\n",
Chuck Leverda351872005-08-11 16:25:11 -04001345 task->tk_pid);
1346 break;
1347 case -EPROTONOSUPPORT:
Chuck Lever00a6e7b2007-03-29 16:48:33 -04001348 dprintk("RPC: %5u remote rpcbind version unavailable, retrying\n",
Chuck Leverda351872005-08-11 16:25:11 -04001349 task->tk_pid);
Chuck Lever00a6e7b2007-03-29 16:48:33 -04001350 task->tk_status = 0;
1351 task->tk_action = call_bind;
1352 return;
Chuck Lever012da152009-12-03 15:58:56 -05001353 case -ECONNREFUSED: /* connection problems */
1354 case -ECONNRESET:
1355 case -ENOTCONN:
1356 case -EHOSTDOWN:
1357 case -EHOSTUNREACH:
1358 case -ENETUNREACH:
1359 case -EPIPE:
1360 dprintk("RPC: %5u remote rpcbind unreachable: %d\n",
1361 task->tk_pid, task->tk_status);
1362 if (!RPC_IS_SOFTCONN(task)) {
1363 rpc_delay(task, 5*HZ);
1364 goto retry_timeout;
1365 }
1366 status = task->tk_status;
1367 break;
Chuck Leverda351872005-08-11 16:25:11 -04001368 default:
Chuck Lever46121cf2007-01-31 12:14:08 -05001369 dprintk("RPC: %5u unrecognized rpcbind error (%d)\n",
Chuck Leverda351872005-08-11 16:25:11 -04001370 task->tk_pid, -task->tk_status);
Chuck Leverda351872005-08-11 16:25:11 -04001371 }
1372
1373 rpc_exit(task, status);
1374 return;
1375
Trond Myklebustda458282006-08-31 15:44:52 -04001376retry_timeout:
1377 task->tk_action = call_timeout;
Chuck Leverda351872005-08-11 16:25:11 -04001378}
1379
1380/*
1381 * 4b. Connect to the RPC server
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 */
1383static void
1384call_connect(struct rpc_task *task)
1385{
Chuck Leverda351872005-08-11 16:25:11 -04001386 struct rpc_xprt *xprt = task->tk_xprt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Chuck Lever46121cf2007-01-31 12:14:08 -05001388 dprintk("RPC: %5u call_connect xprt %p %s connected\n",
Chuck Leverda351872005-08-11 16:25:11 -04001389 task->tk_pid, xprt,
1390 (xprt_connected(xprt) ? "is" : "is not"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
Chuck Leverda351872005-08-11 16:25:11 -04001392 task->tk_action = call_transmit;
1393 if (!xprt_connected(xprt)) {
1394 task->tk_action = call_connect_status;
1395 if (task->tk_status < 0)
1396 return;
1397 xprt_connect(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399}
1400
1401/*
Chuck Leverda351872005-08-11 16:25:11 -04001402 * 4c. Sort out connect result
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 */
1404static void
1405call_connect_status(struct rpc_task *task)
1406{
1407 struct rpc_clnt *clnt = task->tk_client;
1408 int status = task->tk_status;
1409
Chuck Lever46121cf2007-01-31 12:14:08 -05001410 dprint_status(task);
Chuck Leverda351872005-08-11 16:25:11 -04001411
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 task->tk_status = 0;
Trond Myklebust2a491992009-03-11 14:38:00 -04001413 if (status >= 0 || status == -EAGAIN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 clnt->cl_stats->netreconn++;
1415 task->tk_action = call_transmit;
1416 return;
1417 }
1418
Steve Dickson5753cba2012-02-06 10:08:08 -05001419 trace_rpc_connect_status(task, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 switch (status) {
Trond Myklebustda458282006-08-31 15:44:52 -04001421 /* if soft mounted, test if we've timed out */
1422 case -ETIMEDOUT:
1423 task->tk_action = call_timeout;
Trond Myklebust2a491992009-03-11 14:38:00 -04001424 break;
1425 default:
1426 rpc_exit(task, -EIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 }
1428}
1429
1430/*
1431 * 5. Transmit the RPC request, and wait for reply
1432 */
1433static void
1434call_transmit(struct rpc_task *task)
1435{
Chuck Lever46121cf2007-01-31 12:14:08 -05001436 dprint_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
1438 task->tk_action = call_status;
1439 if (task->tk_status < 0)
1440 return;
1441 task->tk_status = xprt_prepare_transmit(task);
1442 if (task->tk_status != 0)
1443 return;
Trond Myklebuste0ab53d2006-07-27 17:22:50 -04001444 task->tk_action = call_transmit_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 /* Encode here so that rpcsec_gss can use correct sequence number. */
Trond Myklebust940e3312005-11-09 21:45:24 -05001446 if (rpc_task_need_encode(task)) {
Trond Myklebuste0ab53d2006-07-27 17:22:50 -04001447 BUG_ON(task->tk_rqstp->rq_bytes_sent != 0);
Chuck Leverb0e1c572008-05-21 17:09:19 -04001448 rpc_xdr_encode(task);
Trond Myklebust5e5ce5b2005-10-18 14:20:11 -07001449 /* Did the encode result in an error condition? */
Trond Myklebust8b39f2b2008-05-14 19:48:25 -07001450 if (task->tk_status != 0) {
1451 /* Was the error nonfatal? */
1452 if (task->tk_status == -EAGAIN)
1453 rpc_delay(task, HZ >> 4);
1454 else
1455 rpc_exit(task, task->tk_status);
Trond Myklebuste0ab53d2006-07-27 17:22:50 -04001456 return;
Trond Myklebust8b39f2b2008-05-14 19:48:25 -07001457 }
Trond Myklebust5e5ce5b2005-10-18 14:20:11 -07001458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 xprt_transmit(task);
1460 if (task->tk_status < 0)
1461 return;
Trond Myklebuste0ab53d2006-07-27 17:22:50 -04001462 /*
1463 * On success, ensure that we call xprt_end_transmit() before sleeping
1464 * in order to allow access to the socket to other RPC requests.
1465 */
1466 call_transmit_status(task);
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001467 if (rpc_reply_expected(task))
Trond Myklebuste0ab53d2006-07-27 17:22:50 -04001468 return;
1469 task->tk_action = rpc_exit_task;
Trond Myklebustfda13932008-02-22 16:34:12 -05001470 rpc_wake_up_queued_task(&task->tk_xprt->pending, task);
Trond Myklebuste0ab53d2006-07-27 17:22:50 -04001471}
1472
1473/*
1474 * 5a. Handle cleanup after a transmission
1475 */
1476static void
1477call_transmit_status(struct rpc_task *task)
1478{
1479 task->tk_action = call_status;
Chuck Lever206a1342009-12-03 15:58:56 -05001480
1481 /*
1482 * Common case: success. Force the compiler to put this
1483 * test first.
1484 */
1485 if (task->tk_status == 0) {
1486 xprt_end_transmit(task);
1487 rpc_task_force_reencode(task);
1488 return;
1489 }
1490
Trond Myklebust15f081c2009-03-11 14:37:57 -04001491 switch (task->tk_status) {
1492 case -EAGAIN:
1493 break;
1494 default:
Chuck Lever206a1342009-12-03 15:58:56 -05001495 dprint_status(task);
Trond Myklebust15f081c2009-03-11 14:37:57 -04001496 xprt_end_transmit(task);
Chuck Lever09a21c42009-12-03 15:58:56 -05001497 rpc_task_force_reencode(task);
1498 break;
Trond Myklebust15f081c2009-03-11 14:37:57 -04001499 /*
1500 * Special cases: if we've been waiting on the
1501 * socket's write_space() callback, or if the
1502 * socket just returned a connection error,
1503 * then hold onto the transport lock.
1504 */
1505 case -ECONNREFUSED:
Trond Myklebust15f081c2009-03-11 14:37:57 -04001506 case -EHOSTDOWN:
1507 case -EHOSTUNREACH:
1508 case -ENETUNREACH:
Chuck Lever09a21c42009-12-03 15:58:56 -05001509 if (RPC_IS_SOFTCONN(task)) {
1510 xprt_end_transmit(task);
1511 rpc_exit(task, task->tk_status);
1512 break;
1513 }
1514 case -ECONNRESET:
1515 case -ENOTCONN:
Trond Myklebustc8485e42009-03-11 14:37:59 -04001516 case -EPIPE:
Trond Myklebust15f081c2009-03-11 14:37:57 -04001517 rpc_task_force_reencode(task);
1518 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519}
1520
Trond Myklebust9e00abc2011-07-13 19:20:49 -04001521#if defined(CONFIG_SUNRPC_BACKCHANNEL)
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001522/*
1523 * 5b. Send the backchannel RPC reply. On error, drop the reply. In
1524 * addition, disconnect on connectivity errors.
1525 */
1526static void
1527call_bc_transmit(struct rpc_task *task)
1528{
1529 struct rpc_rqst *req = task->tk_rqstp;
1530
1531 BUG_ON(task->tk_status != 0);
1532 task->tk_status = xprt_prepare_transmit(task);
1533 if (task->tk_status == -EAGAIN) {
1534 /*
1535 * Could not reserve the transport. Try again after the
1536 * transport is released.
1537 */
1538 task->tk_status = 0;
1539 task->tk_action = call_bc_transmit;
1540 return;
1541 }
1542
1543 task->tk_action = rpc_exit_task;
1544 if (task->tk_status < 0) {
1545 printk(KERN_NOTICE "RPC: Could not send backchannel reply "
1546 "error: %d\n", task->tk_status);
1547 return;
1548 }
1549
1550 xprt_transmit(task);
1551 xprt_end_transmit(task);
1552 dprint_status(task);
1553 switch (task->tk_status) {
1554 case 0:
1555 /* Success */
1556 break;
1557 case -EHOSTDOWN:
1558 case -EHOSTUNREACH:
1559 case -ENETUNREACH:
1560 case -ETIMEDOUT:
1561 /*
1562 * Problem reaching the server. Disconnect and let the
1563 * forechannel reestablish the connection. The server will
1564 * have to retransmit the backchannel request and we'll
1565 * reprocess it. Since these ops are idempotent, there's no
1566 * need to cache our reply at this time.
1567 */
1568 printk(KERN_NOTICE "RPC: Could not send backchannel reply "
1569 "error: %d\n", task->tk_status);
1570 xprt_conditional_disconnect(task->tk_xprt,
1571 req->rq_connect_cookie);
1572 break;
1573 default:
1574 /*
1575 * We were unable to reply and will have to drop the
1576 * request. The server should reconnect and retransmit.
1577 */
1578 BUG_ON(task->tk_status == -EAGAIN);
1579 printk(KERN_NOTICE "RPC: Could not send backchannel reply "
1580 "error: %d\n", task->tk_status);
1581 break;
1582 }
1583 rpc_wake_up_queued_task(&req->rq_xprt->pending, task);
1584}
Trond Myklebust9e00abc2011-07-13 19:20:49 -04001585#endif /* CONFIG_SUNRPC_BACKCHANNEL */
Ricardo Labiaga55ae1aa2009-04-01 09:23:03 -04001586
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587/*
1588 * 6. Sort out the RPC call status
1589 */
1590static void
1591call_status(struct rpc_task *task)
1592{
1593 struct rpc_clnt *clnt = task->tk_client;
1594 struct rpc_rqst *req = task->tk_rqstp;
1595 int status;
1596
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -04001597 if (req->rq_reply_bytes_recvd > 0 && !req->rq_bytes_sent)
1598 task->tk_status = req->rq_reply_bytes_recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
Chuck Lever46121cf2007-01-31 12:14:08 -05001600 dprint_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
1602 status = task->tk_status;
1603 if (status >= 0) {
1604 task->tk_action = call_decode;
1605 return;
1606 }
1607
Steve Dickson5753cba2012-02-06 10:08:08 -05001608 trace_rpc_call_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 task->tk_status = 0;
1610 switch(status) {
Trond Myklebust76303992006-08-30 14:32:49 -04001611 case -EHOSTDOWN:
1612 case -EHOSTUNREACH:
1613 case -ENETUNREACH:
1614 /*
1615 * Delay any retries for 3 seconds, then handle as if it
1616 * were a timeout.
1617 */
1618 rpc_delay(task, 3*HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 case -ETIMEDOUT:
1620 task->tk_action = call_timeout;
Trond Myklebust241c39b2007-04-20 16:12:55 -04001621 if (task->tk_client->cl_discrtry)
Trond Myklebust7c1d71c2008-04-17 16:52:57 -04001622 xprt_conditional_disconnect(task->tk_xprt,
1623 req->rq_connect_cookie);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 break;
Trond Myklebustc8485e42009-03-11 14:37:59 -04001625 case -ECONNRESET:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 case -ECONNREFUSED:
Chuck Lever35f5a422006-01-03 09:55:50 +01001627 rpc_force_rebind(clnt);
Trond Myklebustc8485e42009-03-11 14:37:59 -04001628 rpc_delay(task, 3*HZ);
1629 case -EPIPE:
1630 case -ENOTCONN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 task->tk_action = call_bind;
1632 break;
1633 case -EAGAIN:
1634 task->tk_action = call_transmit;
1635 break;
1636 case -EIO:
1637 /* shutdown or soft timeout */
1638 rpc_exit(task, status);
1639 break;
1640 default:
Olga Kornievskaiab6b61522008-06-09 16:51:31 -04001641 if (clnt->cl_chatty)
1642 printk("%s: RPC call returned error %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 clnt->cl_protname, -status);
1644 rpc_exit(task, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 }
1646}
1647
1648/*
Trond Myklebuste0ab53d2006-07-27 17:22:50 -04001649 * 6a. Handle RPC timeout
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 * We do not release the request slot, so we keep using the
1651 * same XID for all retransmits.
1652 */
1653static void
1654call_timeout(struct rpc_task *task)
1655{
1656 struct rpc_clnt *clnt = task->tk_client;
1657
1658 if (xprt_adjust_timeout(task->tk_rqstp) == 0) {
Chuck Lever46121cf2007-01-31 12:14:08 -05001659 dprintk("RPC: %5u call_timeout (minor)\n", task->tk_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 goto retry;
1661 }
1662
Chuck Lever46121cf2007-01-31 12:14:08 -05001663 dprintk("RPC: %5u call_timeout (major)\n", task->tk_pid);
Chuck Leveref759a22006-03-20 13:44:17 -05001664 task->tk_timeouts++;
1665
Chuck Lever3a28bec2009-12-03 15:58:56 -05001666 if (RPC_IS_SOFTCONN(task)) {
1667 rpc_exit(task, -ETIMEDOUT);
1668 return;
1669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 if (RPC_IS_SOFT(task)) {
Olga Kornievskaiab6b61522008-06-09 16:51:31 -04001671 if (clnt->cl_chatty)
Trond Myklebust4e0038b2012-03-01 17:01:05 -05001672 rcu_read_lock();
Olga Kornievskaiab6b61522008-06-09 16:51:31 -04001673 printk(KERN_NOTICE "%s: server %s not responding, timed out\n",
Trond Myklebust4e0038b2012-03-01 17:01:05 -05001674 clnt->cl_protname,
1675 rcu_dereference(clnt->cl_xprt)->servername);
1676 rcu_read_unlock();
Trond Myklebust7494d002011-04-24 14:28:45 -04001677 if (task->tk_flags & RPC_TASK_TIMEOUT)
1678 rpc_exit(task, -ETIMEDOUT);
1679 else
1680 rpc_exit(task, -EIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 return;
1682 }
1683
Chuck Leverf518e35a2006-01-03 09:55:52 +01001684 if (!(task->tk_flags & RPC_CALL_MAJORSEEN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 task->tk_flags |= RPC_CALL_MAJORSEEN;
Trond Myklebust4e0038b2012-03-01 17:01:05 -05001686 if (clnt->cl_chatty) {
1687 rcu_read_lock();
Olga Kornievskaiab6b61522008-06-09 16:51:31 -04001688 printk(KERN_NOTICE "%s: server %s not responding, still trying\n",
Trond Myklebust4e0038b2012-03-01 17:01:05 -05001689 clnt->cl_protname,
1690 rcu_dereference(clnt->cl_xprt)->servername);
1691 rcu_read_unlock();
1692 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 }
Chuck Lever35f5a422006-01-03 09:55:50 +01001694 rpc_force_rebind(clnt);
Trond Myklebustb48633b2008-04-22 16:47:55 -04001695 /*
1696 * Did our request time out due to an RPCSEC_GSS out-of-sequence
1697 * event? RFC2203 requires the server to drop all such requests.
1698 */
1699 rpcauth_invalcred(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
1701retry:
1702 clnt->cl_stats->rpcretrans++;
1703 task->tk_action = call_bind;
1704 task->tk_status = 0;
1705}
1706
1707/*
1708 * 7. Decode the RPC reply
1709 */
1710static void
1711call_decode(struct rpc_task *task)
1712{
1713 struct rpc_clnt *clnt = task->tk_client;
1714 struct rpc_rqst *req = task->tk_rqstp;
Chuck Leverbf269552010-12-14 14:59:29 +00001715 kxdrdproc_t decode = task->tk_msg.rpc_proc->p_decode;
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001716 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717
Vasily Averin726fd6a2011-06-01 16:23:59 +04001718 dprint_status(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
Chuck Leverf518e35a2006-01-03 09:55:52 +01001720 if (task->tk_flags & RPC_CALL_MAJORSEEN) {
Trond Myklebust4e0038b2012-03-01 17:01:05 -05001721 if (clnt->cl_chatty) {
1722 rcu_read_lock();
Olga Kornievskaiab6b61522008-06-09 16:51:31 -04001723 printk(KERN_NOTICE "%s: server %s OK\n",
Trond Myklebust4e0038b2012-03-01 17:01:05 -05001724 clnt->cl_protname,
1725 rcu_dereference(clnt->cl_xprt)->servername);
1726 rcu_read_unlock();
1727 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 task->tk_flags &= ~RPC_CALL_MAJORSEEN;
1729 }
1730
Trond Myklebust43ac3f22006-03-20 13:44:51 -05001731 /*
1732 * Ensure that we see all writes made by xprt_complete_rqst()
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -04001733 * before it changed req->rq_reply_bytes_recvd.
Trond Myklebust43ac3f22006-03-20 13:44:51 -05001734 */
1735 smp_rmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 req->rq_rcv_buf.len = req->rq_private_buf.len;
1737
1738 /* Check that the softirq receive buffer is valid */
1739 WARN_ON(memcmp(&req->rq_rcv_buf, &req->rq_private_buf,
1740 sizeof(req->rq_rcv_buf)) != 0);
1741
Trond Myklebust1e799b62008-03-21 16:19:41 -04001742 if (req->rq_rcv_buf.len < 12) {
1743 if (!RPC_IS_SOFT(task)) {
1744 task->tk_action = call_bind;
1745 clnt->cl_stats->rpcretrans++;
1746 goto out_retry;
1747 }
1748 dprintk("RPC: %s: too small RPC reply size (%d bytes)\n",
1749 clnt->cl_protname, task->tk_status);
1750 task->tk_action = call_timeout;
1751 goto out_retry;
1752 }
1753
Chuck Leverb0e1c572008-05-21 17:09:19 -04001754 p = rpc_verify_header(task);
Trond Myklebustabbcf282006-01-03 09:55:03 +01001755 if (IS_ERR(p)) {
1756 if (p == ERR_PTR(-EAGAIN))
1757 goto out_retry;
1758 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 }
1760
Trond Myklebustabbcf282006-01-03 09:55:03 +01001761 task->tk_action = rpc_exit_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762
Trond Myklebust6d5fcb52006-10-18 16:01:06 -04001763 if (decode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 task->tk_status = rpcauth_unwrap_resp(task, decode, req, p,
1765 task->tk_msg.rpc_resp);
Trond Myklebust6d5fcb52006-10-18 16:01:06 -04001766 }
Chuck Lever46121cf2007-01-31 12:14:08 -05001767 dprintk("RPC: %5u call_decode result %d\n", task->tk_pid,
1768 task->tk_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 return;
1770out_retry:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 task->tk_status = 0;
Chuck Leverb0e1c572008-05-21 17:09:19 -04001772 /* Note: rpc_verify_header() may have freed the RPC slot */
Trond Myklebust24b74bf2008-04-19 13:15:47 -04001773 if (task->tk_rqstp == req) {
Ricardo Labiagadd2b63d2009-04-01 09:23:28 -04001774 req->rq_reply_bytes_recvd = req->rq_rcv_buf.len = 0;
Trond Myklebust24b74bf2008-04-19 13:15:47 -04001775 if (task->tk_client->cl_discrtry)
Trond Myklebust7c1d71c2008-04-17 16:52:57 -04001776 xprt_conditional_disconnect(task->tk_xprt,
1777 req->rq_connect_cookie);
Trond Myklebust24b74bf2008-04-19 13:15:47 -04001778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779}
1780
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001781static __be32 *
Chuck Leverb0e1c572008-05-21 17:09:19 -04001782rpc_encode_header(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783{
1784 struct rpc_clnt *clnt = task->tk_client;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 struct rpc_rqst *req = task->tk_rqstp;
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001786 __be32 *p = req->rq_svec[0].iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
1788 /* FIXME: check buffer size? */
Chuck Lever808012f2005-08-25 16:25:49 -07001789
1790 p = xprt_skip_transport_header(task->tk_xprt, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 *p++ = req->rq_xid; /* XID */
1792 *p++ = htonl(RPC_CALL); /* CALL */
1793 *p++ = htonl(RPC_VERSION); /* RPC version */
1794 *p++ = htonl(clnt->cl_prog); /* program number */
1795 *p++ = htonl(clnt->cl_vers); /* program version */
1796 *p++ = htonl(task->tk_msg.rpc_proc->p_proc); /* procedure */
Trond Myklebust334ccfd2005-06-22 17:16:19 +00001797 p = rpcauth_marshcred(task, p);
1798 req->rq_slen = xdr_adjust_iovec(&req->rq_svec[0], p);
1799 return p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800}
1801
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001802static __be32 *
Chuck Leverb0e1c572008-05-21 17:09:19 -04001803rpc_verify_header(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804{
Trond Myklebust4e0038b2012-03-01 17:01:05 -05001805 struct rpc_clnt *clnt = task->tk_client;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 struct kvec *iov = &task->tk_rqstp->rq_rcv_buf.head[0];
1807 int len = task->tk_rqstp->rq_rcv_buf.len >> 2;
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001808 __be32 *p = iov->iov_base;
1809 u32 n;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 int error = -EACCES;
1811
David Howellse8896492006-08-24 15:44:19 -04001812 if ((task->tk_rqstp->rq_rcv_buf.len & 3) != 0) {
1813 /* RFC-1014 says that the representation of XDR data must be a
1814 * multiple of four bytes
1815 * - if it isn't pointer subtraction in the NFS client may give
1816 * undefined results
1817 */
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001818 dprintk("RPC: %5u %s: XDR representation not a multiple of"
Harvey Harrison0dc47872008-03-05 20:47:47 -08001819 " 4 bytes: 0x%x\n", task->tk_pid, __func__,
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001820 task->tk_rqstp->rq_rcv_buf.len);
David Howellse8896492006-08-24 15:44:19 -04001821 goto out_eio;
1822 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 if ((len -= 3) < 0)
1824 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825
Ricardo Labiagaf4a2e412009-04-01 09:22:54 -04001826 p += 1; /* skip XID */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 if ((n = ntohl(*p++)) != RPC_REPLY) {
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001828 dprintk("RPC: %5u %s: not an RPC reply: %x\n",
Ricardo Labiagaf4a2e412009-04-01 09:22:54 -04001829 task->tk_pid, __func__, n);
Trond Myklebustabbcf282006-01-03 09:55:03 +01001830 goto out_garbage;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 }
Ricardo Labiagaf4a2e412009-04-01 09:22:54 -04001832
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 if ((n = ntohl(*p++)) != RPC_MSG_ACCEPTED) {
1834 if (--len < 0)
1835 goto out_overflow;
1836 switch ((n = ntohl(*p++))) {
Joe Perches89f0e4f2011-07-01 09:43:12 +00001837 case RPC_AUTH_ERROR:
1838 break;
1839 case RPC_MISMATCH:
1840 dprintk("RPC: %5u %s: RPC call version mismatch!\n",
1841 task->tk_pid, __func__);
1842 error = -EPROTONOSUPPORT;
1843 goto out_err;
1844 default:
1845 dprintk("RPC: %5u %s: RPC call rejected, "
1846 "unknown error: %x\n",
1847 task->tk_pid, __func__, n);
1848 goto out_eio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 }
1850 if (--len < 0)
1851 goto out_overflow;
1852 switch ((n = ntohl(*p++))) {
1853 case RPC_AUTH_REJECTEDCRED:
1854 case RPC_AUTH_REJECTEDVERF:
1855 case RPCSEC_GSS_CREDPROBLEM:
1856 case RPCSEC_GSS_CTXPROBLEM:
1857 if (!task->tk_cred_retry)
1858 break;
1859 task->tk_cred_retry--;
Chuck Lever46121cf2007-01-31 12:14:08 -05001860 dprintk("RPC: %5u %s: retry stale creds\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001861 task->tk_pid, __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 rpcauth_invalcred(task);
Trond Myklebust220bcc22007-10-01 12:06:48 -04001863 /* Ensure we obtain a new XID! */
1864 xprt_release(task);
Trond Myklebust118df3d2010-10-24 17:17:31 -04001865 task->tk_action = call_reserve;
Trond Myklebustabbcf282006-01-03 09:55:03 +01001866 goto out_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 case RPC_AUTH_BADCRED:
1868 case RPC_AUTH_BADVERF:
1869 /* possibly garbled cred/verf? */
1870 if (!task->tk_garb_retry)
1871 break;
1872 task->tk_garb_retry--;
Chuck Lever46121cf2007-01-31 12:14:08 -05001873 dprintk("RPC: %5u %s: retry garbled creds\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001874 task->tk_pid, __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 task->tk_action = call_bind;
Trond Myklebustabbcf282006-01-03 09:55:03 +01001876 goto out_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 case RPC_AUTH_TOOWEAK:
Trond Myklebust4e0038b2012-03-01 17:01:05 -05001878 rcu_read_lock();
Chuck Leverb0e1c572008-05-21 17:09:19 -04001879 printk(KERN_NOTICE "RPC: server %s requires stronger "
Trond Myklebust4e0038b2012-03-01 17:01:05 -05001880 "authentication.\n",
1881 rcu_dereference(clnt->cl_xprt)->servername);
1882 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 break;
1884 default:
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001885 dprintk("RPC: %5u %s: unknown auth error: %x\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001886 task->tk_pid, __func__, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 error = -EIO;
1888 }
Chuck Lever46121cf2007-01-31 12:14:08 -05001889 dprintk("RPC: %5u %s: call rejected %d\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001890 task->tk_pid, __func__, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 goto out_err;
1892 }
1893 if (!(p = rpcauth_checkverf(task, p))) {
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001894 dprintk("RPC: %5u %s: auth check failed\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001895 task->tk_pid, __func__);
Trond Myklebustabbcf282006-01-03 09:55:03 +01001896 goto out_garbage; /* bad verifier, retry */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 }
Alexey Dobriyand8ed0292006-09-26 22:29:38 -07001898 len = p - (__be32 *)iov->iov_base - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 if (len < 0)
1900 goto out_overflow;
1901 switch ((n = ntohl(*p++))) {
1902 case RPC_SUCCESS:
1903 return p;
1904 case RPC_PROG_UNAVAIL:
Trond Myklebust4e0038b2012-03-01 17:01:05 -05001905 dprintk_rcu("RPC: %5u %s: program %u is unsupported "
1906 "by server %s\n", task->tk_pid, __func__,
1907 (unsigned int)clnt->cl_prog,
1908 rcu_dereference(clnt->cl_xprt)->servername);
Andreas Gruenbachercdf47702005-06-22 17:16:23 +00001909 error = -EPFNOSUPPORT;
1910 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 case RPC_PROG_MISMATCH:
Trond Myklebust4e0038b2012-03-01 17:01:05 -05001912 dprintk_rcu("RPC: %5u %s: program %u, version %u unsupported "
1913 "by server %s\n", task->tk_pid, __func__,
1914 (unsigned int)clnt->cl_prog,
1915 (unsigned int)clnt->cl_vers,
1916 rcu_dereference(clnt->cl_xprt)->servername);
Andreas Gruenbachercdf47702005-06-22 17:16:23 +00001917 error = -EPROTONOSUPPORT;
1918 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 case RPC_PROC_UNAVAIL:
Trond Myklebust4e0038b2012-03-01 17:01:05 -05001920 dprintk_rcu("RPC: %5u %s: proc %s unsupported by program %u, "
Chuck Lever46121cf2007-01-31 12:14:08 -05001921 "version %u on server %s\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001922 task->tk_pid, __func__,
Chuck Lever3748f1e2008-05-21 17:09:12 -04001923 rpc_proc_name(task),
Trond Myklebust4e0038b2012-03-01 17:01:05 -05001924 clnt->cl_prog, clnt->cl_vers,
1925 rcu_dereference(clnt->cl_xprt)->servername);
Andreas Gruenbachercdf47702005-06-22 17:16:23 +00001926 error = -EOPNOTSUPP;
1927 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 case RPC_GARBAGE_ARGS:
Chuck Lever46121cf2007-01-31 12:14:08 -05001929 dprintk("RPC: %5u %s: server saw garbage\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001930 task->tk_pid, __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 break; /* retry */
1932 default:
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001933 dprintk("RPC: %5u %s: server accept status: %x\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001934 task->tk_pid, __func__, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 /* Also retry */
1936 }
1937
Trond Myklebustabbcf282006-01-03 09:55:03 +01001938out_garbage:
Trond Myklebust4e0038b2012-03-01 17:01:05 -05001939 clnt->cl_stats->rpcgarbage++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 if (task->tk_garb_retry) {
1941 task->tk_garb_retry--;
Chuck Lever46121cf2007-01-31 12:14:08 -05001942 dprintk("RPC: %5u %s: retrying\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -08001943 task->tk_pid, __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 task->tk_action = call_bind;
Trond Myklebustabbcf282006-01-03 09:55:03 +01001945out_retry:
1946 return ERR_PTR(-EAGAIN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948out_eio:
1949 error = -EIO;
1950out_err:
1951 rpc_exit(task, error);
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001952 dprintk("RPC: %5u %s: call failed with error %d\n", task->tk_pid,
Harvey Harrison0dc47872008-03-05 20:47:47 -08001953 __func__, error);
Trond Myklebustabbcf282006-01-03 09:55:03 +01001954 return ERR_PTR(error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955out_overflow:
Trond Myklebust8a702bb2007-06-27 18:30:26 -04001956 dprintk("RPC: %5u %s: server reply was truncated.\n", task->tk_pid,
Harvey Harrison0dc47872008-03-05 20:47:47 -08001957 __func__);
Trond Myklebustabbcf282006-01-03 09:55:03 +01001958 goto out_garbage;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959}
Trond Myklebust5ee0ed72005-06-22 17:16:20 +00001960
Chuck Lever9f06c712010-12-14 14:59:18 +00001961static void rpcproc_encode_null(void *rqstp, struct xdr_stream *xdr, void *obj)
Trond Myklebust5ee0ed72005-06-22 17:16:20 +00001962{
Trond Myklebust5ee0ed72005-06-22 17:16:20 +00001963}
1964
Chuck Leverbf269552010-12-14 14:59:29 +00001965static int rpcproc_decode_null(void *rqstp, struct xdr_stream *xdr, void *obj)
Trond Myklebust5ee0ed72005-06-22 17:16:20 +00001966{
1967 return 0;
1968}
1969
1970static struct rpc_procinfo rpcproc_null = {
1971 .p_encode = rpcproc_encode_null,
1972 .p_decode = rpcproc_decode_null,
1973};
1974
Chuck Levercaabea82009-12-03 15:58:56 -05001975static int rpc_ping(struct rpc_clnt *clnt)
Trond Myklebust5ee0ed72005-06-22 17:16:20 +00001976{
1977 struct rpc_message msg = {
1978 .rpc_proc = &rpcproc_null,
1979 };
1980 int err;
1981 msg.rpc_cred = authnull_ops.lookup_cred(NULL, NULL, 0);
Chuck Levercaabea82009-12-03 15:58:56 -05001982 err = rpc_call_sync(clnt, &msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN);
Trond Myklebust5ee0ed72005-06-22 17:16:20 +00001983 put_rpccred(msg.rpc_cred);
1984 return err;
1985}
Trond Myklebust188fef12007-06-16 14:18:40 -04001986
Trond Myklebust5e1550d2007-06-23 10:17:16 -04001987struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred, int flags)
1988{
1989 struct rpc_message msg = {
1990 .rpc_proc = &rpcproc_null,
1991 .rpc_cred = cred,
1992 };
Trond Myklebust84115e12007-07-14 15:39:59 -04001993 struct rpc_task_setup task_setup_data = {
1994 .rpc_client = clnt,
1995 .rpc_message = &msg,
1996 .callback_ops = &rpc_default_ops,
1997 .flags = flags,
1998 };
Trond Myklebustc970aa82007-07-14 15:39:59 -04001999 return rpc_run_task(&task_setup_data);
Trond Myklebust5e1550d2007-06-23 10:17:16 -04002000}
Trond Myklebuste8914c62007-07-14 15:39:59 -04002001EXPORT_SYMBOL_GPL(rpc_call_null);
Trond Myklebust5e1550d2007-06-23 10:17:16 -04002002
Trond Myklebust188fef12007-06-16 14:18:40 -04002003#ifdef RPC_DEBUG
Chuck Lever68a23ee2008-05-21 17:09:26 -04002004static void rpc_show_header(void)
2005{
Chuck Levercb3997b2008-05-21 17:09:41 -04002006 printk(KERN_INFO "-pid- flgs status -client- --rqstp- "
2007 "-timeout ---ops--\n");
Chuck Lever68a23ee2008-05-21 17:09:26 -04002008}
2009
Chuck Lever38e886e2008-05-21 17:09:33 -04002010static void rpc_show_task(const struct rpc_clnt *clnt,
2011 const struct rpc_task *task)
2012{
2013 const char *rpc_waitq = "none";
Chuck Lever38e886e2008-05-21 17:09:33 -04002014
2015 if (RPC_IS_QUEUED(task))
2016 rpc_waitq = rpc_qname(task->tk_waitqueue);
2017
Joe Perchesb3bceda2010-12-21 10:52:24 -05002018 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 -04002019 task->tk_pid, task->tk_flags, task->tk_status,
2020 clnt, task->tk_rqstp, task->tk_timeout, task->tk_ops,
2021 clnt->cl_protname, clnt->cl_vers, rpc_proc_name(task),
Joe Perchesb3bceda2010-12-21 10:52:24 -05002022 task->tk_action, rpc_waitq);
Chuck Lever38e886e2008-05-21 17:09:33 -04002023}
2024
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +04002025void rpc_show_tasks(struct net *net)
Trond Myklebust188fef12007-06-16 14:18:40 -04002026{
2027 struct rpc_clnt *clnt;
Chuck Lever38e886e2008-05-21 17:09:33 -04002028 struct rpc_task *task;
Chuck Lever68a23ee2008-05-21 17:09:26 -04002029 int header = 0;
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +04002030 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
Trond Myklebust188fef12007-06-16 14:18:40 -04002031
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +04002032 spin_lock(&sn->rpc_client_lock);
2033 list_for_each_entry(clnt, &sn->all_clients, cl_clients) {
Trond Myklebust188fef12007-06-16 14:18:40 -04002034 spin_lock(&clnt->cl_lock);
Chuck Lever38e886e2008-05-21 17:09:33 -04002035 list_for_each_entry(task, &clnt->cl_tasks, tk_task) {
Chuck Lever68a23ee2008-05-21 17:09:26 -04002036 if (!header) {
2037 rpc_show_header();
2038 header++;
2039 }
Chuck Lever38e886e2008-05-21 17:09:33 -04002040 rpc_show_task(clnt, task);
Trond Myklebust188fef12007-06-16 14:18:40 -04002041 }
2042 spin_unlock(&clnt->cl_lock);
2043 }
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +04002044 spin_unlock(&sn->rpc_client_lock);
Trond Myklebust188fef12007-06-16 14:18:40 -04002045}
2046#endif