mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
[linux/fpc-iii.git] / net / sunrpc / clnt.c
blob8724ef8573608027225cfb35b6a031e99ac911f7
1 /*
2 * linux/net/sunrpc/clnt.c
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.
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.
16 * Copyright (C) 1992,1993 Rick Sladkey <jrs@world.std.com>
17 * Copyright (C) 1995,1996 Olaf Kirch <okir@monad.swb.de>
21 #include <linux/module.h>
22 #include <linux/types.h>
23 #include <linux/kallsyms.h>
24 #include <linux/mm.h>
25 #include <linux/namei.h>
26 #include <linux/mount.h>
27 #include <linux/slab.h>
28 #include <linux/utsname.h>
29 #include <linux/workqueue.h>
30 #include <linux/in.h>
31 #include <linux/in6.h>
32 #include <linux/un.h>
33 #include <linux/rcupdate.h>
35 #include <linux/sunrpc/clnt.h>
36 #include <linux/sunrpc/addr.h>
37 #include <linux/sunrpc/rpc_pipe_fs.h>
38 #include <linux/sunrpc/metrics.h>
39 #include <linux/sunrpc/bc_xprt.h>
40 #include <trace/events/sunrpc.h>
42 #include "sunrpc.h"
43 #include "netns.h"
45 #ifdef RPC_DEBUG
46 # define RPCDBG_FACILITY RPCDBG_CALL
47 #endif
49 #define dprint_status(t) \
50 dprintk("RPC: %5u %s (status %d)\n", t->tk_pid, \
51 __func__, t->tk_status)
54 * All RPC clients are linked into this list
57 static DECLARE_WAIT_QUEUE_HEAD(destroy_wait);
60 static void call_start(struct rpc_task *task);
61 static void call_reserve(struct rpc_task *task);
62 static void call_reserveresult(struct rpc_task *task);
63 static void call_allocate(struct rpc_task *task);
64 static void call_decode(struct rpc_task *task);
65 static void call_bind(struct rpc_task *task);
66 static void call_bind_status(struct rpc_task *task);
67 static void call_transmit(struct rpc_task *task);
68 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
69 static void call_bc_transmit(struct rpc_task *task);
70 #endif /* CONFIG_SUNRPC_BACKCHANNEL */
71 static void call_status(struct rpc_task *task);
72 static void call_transmit_status(struct rpc_task *task);
73 static void call_refresh(struct rpc_task *task);
74 static void call_refreshresult(struct rpc_task *task);
75 static void call_timeout(struct rpc_task *task);
76 static void call_connect(struct rpc_task *task);
77 static void call_connect_status(struct rpc_task *task);
79 static __be32 *rpc_encode_header(struct rpc_task *task);
80 static __be32 *rpc_verify_header(struct rpc_task *task);
81 static int rpc_ping(struct rpc_clnt *clnt);
83 static void rpc_register_client(struct rpc_clnt *clnt)
85 struct net *net = rpc_net_ns(clnt);
86 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
88 spin_lock(&sn->rpc_client_lock);
89 list_add(&clnt->cl_clients, &sn->all_clients);
90 spin_unlock(&sn->rpc_client_lock);
93 static void rpc_unregister_client(struct rpc_clnt *clnt)
95 struct net *net = rpc_net_ns(clnt);
96 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
98 spin_lock(&sn->rpc_client_lock);
99 list_del(&clnt->cl_clients);
100 spin_unlock(&sn->rpc_client_lock);
103 static void __rpc_clnt_remove_pipedir(struct rpc_clnt *clnt)
105 rpc_remove_client_dir(clnt);
108 static void rpc_clnt_remove_pipedir(struct rpc_clnt *clnt)
110 struct net *net = rpc_net_ns(clnt);
111 struct super_block *pipefs_sb;
113 pipefs_sb = rpc_get_sb_net(net);
114 if (pipefs_sb) {
115 __rpc_clnt_remove_pipedir(clnt);
116 rpc_put_sb_net(net);
120 static struct dentry *rpc_setup_pipedir_sb(struct super_block *sb,
121 struct rpc_clnt *clnt)
123 static uint32_t clntid;
124 const char *dir_name = clnt->cl_program->pipe_dir_name;
125 char name[15];
126 struct dentry *dir, *dentry;
128 dir = rpc_d_lookup_sb(sb, dir_name);
129 if (dir == NULL) {
130 pr_info("RPC: pipefs directory doesn't exist: %s\n", dir_name);
131 return dir;
133 for (;;) {
134 snprintf(name, sizeof(name), "clnt%x", (unsigned int)clntid++);
135 name[sizeof(name) - 1] = '\0';
136 dentry = rpc_create_client_dir(dir, name, clnt);
137 if (!IS_ERR(dentry))
138 break;
139 if (dentry == ERR_PTR(-EEXIST))
140 continue;
141 printk(KERN_INFO "RPC: Couldn't create pipefs entry"
142 " %s/%s, error %ld\n",
143 dir_name, name, PTR_ERR(dentry));
144 break;
146 dput(dir);
147 return dentry;
150 static int
151 rpc_setup_pipedir(struct super_block *pipefs_sb, struct rpc_clnt *clnt)
153 struct dentry *dentry;
155 if (clnt->cl_program->pipe_dir_name != NULL) {
156 dentry = rpc_setup_pipedir_sb(pipefs_sb, clnt);
157 if (IS_ERR(dentry))
158 return PTR_ERR(dentry);
160 return 0;
163 static int rpc_clnt_skip_event(struct rpc_clnt *clnt, unsigned long event)
165 if (clnt->cl_program->pipe_dir_name == NULL)
166 return 1;
168 switch (event) {
169 case RPC_PIPEFS_MOUNT:
170 if (clnt->cl_pipedir_objects.pdh_dentry != NULL)
171 return 1;
172 if (atomic_read(&clnt->cl_count) == 0)
173 return 1;
174 break;
175 case RPC_PIPEFS_UMOUNT:
176 if (clnt->cl_pipedir_objects.pdh_dentry == NULL)
177 return 1;
178 break;
180 return 0;
183 static int __rpc_clnt_handle_event(struct rpc_clnt *clnt, unsigned long event,
184 struct super_block *sb)
186 struct dentry *dentry;
187 int err = 0;
189 switch (event) {
190 case RPC_PIPEFS_MOUNT:
191 dentry = rpc_setup_pipedir_sb(sb, clnt);
192 if (!dentry)
193 return -ENOENT;
194 if (IS_ERR(dentry))
195 return PTR_ERR(dentry);
196 break;
197 case RPC_PIPEFS_UMOUNT:
198 __rpc_clnt_remove_pipedir(clnt);
199 break;
200 default:
201 printk(KERN_ERR "%s: unknown event: %ld\n", __func__, event);
202 return -ENOTSUPP;
204 return err;
207 static int __rpc_pipefs_event(struct rpc_clnt *clnt, unsigned long event,
208 struct super_block *sb)
210 int error = 0;
212 for (;; clnt = clnt->cl_parent) {
213 if (!rpc_clnt_skip_event(clnt, event))
214 error = __rpc_clnt_handle_event(clnt, event, sb);
215 if (error || clnt == clnt->cl_parent)
216 break;
218 return error;
221 static struct rpc_clnt *rpc_get_client_for_event(struct net *net, int event)
223 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
224 struct rpc_clnt *clnt;
226 spin_lock(&sn->rpc_client_lock);
227 list_for_each_entry(clnt, &sn->all_clients, cl_clients) {
228 if (rpc_clnt_skip_event(clnt, event))
229 continue;
230 spin_unlock(&sn->rpc_client_lock);
231 return clnt;
233 spin_unlock(&sn->rpc_client_lock);
234 return NULL;
237 static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event,
238 void *ptr)
240 struct super_block *sb = ptr;
241 struct rpc_clnt *clnt;
242 int error = 0;
244 while ((clnt = rpc_get_client_for_event(sb->s_fs_info, event))) {
245 error = __rpc_pipefs_event(clnt, event, sb);
246 if (error)
247 break;
249 return error;
252 static struct notifier_block rpc_clients_block = {
253 .notifier_call = rpc_pipefs_event,
254 .priority = SUNRPC_PIPEFS_RPC_PRIO,
257 int rpc_clients_notifier_register(void)
259 return rpc_pipefs_notifier_register(&rpc_clients_block);
262 void rpc_clients_notifier_unregister(void)
264 return rpc_pipefs_notifier_unregister(&rpc_clients_block);
267 static void rpc_clnt_set_nodename(struct rpc_clnt *clnt, const char *nodename)
269 clnt->cl_nodelen = strlen(nodename);
270 if (clnt->cl_nodelen > UNX_MAXNODENAME)
271 clnt->cl_nodelen = UNX_MAXNODENAME;
272 memcpy(clnt->cl_nodename, nodename, clnt->cl_nodelen);
275 static int rpc_client_register(const struct rpc_create_args *args,
276 struct rpc_clnt *clnt)
278 struct rpc_auth_create_args auth_args = {
279 .pseudoflavor = args->authflavor,
280 .target_name = args->client_name,
282 struct rpc_auth *auth;
283 struct net *net = rpc_net_ns(clnt);
284 struct super_block *pipefs_sb;
285 int err;
287 pipefs_sb = rpc_get_sb_net(net);
288 if (pipefs_sb) {
289 err = rpc_setup_pipedir(pipefs_sb, clnt);
290 if (err)
291 goto out;
294 rpc_register_client(clnt);
295 if (pipefs_sb)
296 rpc_put_sb_net(net);
298 auth = rpcauth_create(&auth_args, clnt);
299 if (IS_ERR(auth)) {
300 dprintk("RPC: Couldn't create auth handle (flavor %u)\n",
301 args->authflavor);
302 err = PTR_ERR(auth);
303 goto err_auth;
305 return 0;
306 err_auth:
307 pipefs_sb = rpc_get_sb_net(net);
308 rpc_unregister_client(clnt);
309 __rpc_clnt_remove_pipedir(clnt);
310 out:
311 if (pipefs_sb)
312 rpc_put_sb_net(net);
313 return err;
316 static DEFINE_IDA(rpc_clids);
318 static int rpc_alloc_clid(struct rpc_clnt *clnt)
320 int clid;
322 clid = ida_simple_get(&rpc_clids, 0, 0, GFP_KERNEL);
323 if (clid < 0)
324 return clid;
325 clnt->cl_clid = clid;
326 return 0;
329 static void rpc_free_clid(struct rpc_clnt *clnt)
331 ida_simple_remove(&rpc_clids, clnt->cl_clid);
334 static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args,
335 struct rpc_xprt *xprt,
336 struct rpc_clnt *parent)
338 const struct rpc_program *program = args->program;
339 const struct rpc_version *version;
340 struct rpc_clnt *clnt = NULL;
341 int err;
343 /* sanity check the name before trying to print it */
344 dprintk("RPC: creating %s client for %s (xprt %p)\n",
345 program->name, args->servername, xprt);
347 err = rpciod_up();
348 if (err)
349 goto out_no_rpciod;
351 err = -EINVAL;
352 if (args->version >= program->nrvers)
353 goto out_err;
354 version = program->version[args->version];
355 if (version == NULL)
356 goto out_err;
358 err = -ENOMEM;
359 clnt = kzalloc(sizeof(*clnt), GFP_KERNEL);
360 if (!clnt)
361 goto out_err;
362 clnt->cl_parent = parent ? : clnt;
364 err = rpc_alloc_clid(clnt);
365 if (err)
366 goto out_no_clid;
368 rcu_assign_pointer(clnt->cl_xprt, xprt);
369 clnt->cl_procinfo = version->procs;
370 clnt->cl_maxproc = version->nrprocs;
371 clnt->cl_prog = args->prognumber ? : program->number;
372 clnt->cl_vers = version->number;
373 clnt->cl_stats = program->stats;
374 clnt->cl_metrics = rpc_alloc_iostats(clnt);
375 rpc_init_pipe_dir_head(&clnt->cl_pipedir_objects);
376 err = -ENOMEM;
377 if (clnt->cl_metrics == NULL)
378 goto out_no_stats;
379 clnt->cl_program = program;
380 INIT_LIST_HEAD(&clnt->cl_tasks);
381 spin_lock_init(&clnt->cl_lock);
383 if (!xprt_bound(xprt))
384 clnt->cl_autobind = 1;
386 clnt->cl_timeout = xprt->timeout;
387 if (args->timeout != NULL) {
388 memcpy(&clnt->cl_timeout_default, args->timeout,
389 sizeof(clnt->cl_timeout_default));
390 clnt->cl_timeout = &clnt->cl_timeout_default;
393 clnt->cl_rtt = &clnt->cl_rtt_default;
394 rpc_init_rtt(&clnt->cl_rtt_default, clnt->cl_timeout->to_initval);
396 atomic_set(&clnt->cl_count, 1);
398 /* save the nodename */
399 rpc_clnt_set_nodename(clnt, utsname()->nodename);
401 err = rpc_client_register(args, clnt);
402 if (err)
403 goto out_no_path;
404 if (parent)
405 atomic_inc(&parent->cl_count);
406 return clnt;
408 out_no_path:
409 rpc_free_iostats(clnt->cl_metrics);
410 out_no_stats:
411 rpc_free_clid(clnt);
412 out_no_clid:
413 kfree(clnt);
414 out_err:
415 rpciod_down();
416 out_no_rpciod:
417 xprt_put(xprt);
418 return ERR_PTR(err);
422 * rpc_create - create an RPC client and transport with one call
423 * @args: rpc_clnt create argument structure
425 * Creates and initializes an RPC transport and an RPC client.
427 * It can ping the server in order to determine if it is up, and to see if
428 * it supports this program and version. RPC_CLNT_CREATE_NOPING disables
429 * this behavior so asynchronous tasks can also use rpc_create.
431 struct rpc_clnt *rpc_create(struct rpc_create_args *args)
433 struct rpc_xprt *xprt;
434 struct rpc_clnt *clnt;
435 struct xprt_create xprtargs = {
436 .net = args->net,
437 .ident = args->protocol,
438 .srcaddr = args->saddress,
439 .dstaddr = args->address,
440 .addrlen = args->addrsize,
441 .servername = args->servername,
442 .bc_xprt = args->bc_xprt,
444 char servername[48];
446 if (args->flags & RPC_CLNT_CREATE_INFINITE_SLOTS)
447 xprtargs.flags |= XPRT_CREATE_INFINITE_SLOTS;
448 if (args->flags & RPC_CLNT_CREATE_NO_IDLE_TIMEOUT)
449 xprtargs.flags |= XPRT_CREATE_NO_IDLE_TIMEOUT;
451 * If the caller chooses not to specify a hostname, whip
452 * up a string representation of the passed-in address.
454 if (xprtargs.servername == NULL) {
455 struct sockaddr_un *sun =
456 (struct sockaddr_un *)args->address;
457 struct sockaddr_in *sin =
458 (struct sockaddr_in *)args->address;
459 struct sockaddr_in6 *sin6 =
460 (struct sockaddr_in6 *)args->address;
462 servername[0] = '\0';
463 switch (args->address->sa_family) {
464 case AF_LOCAL:
465 snprintf(servername, sizeof(servername), "%s",
466 sun->sun_path);
467 break;
468 case AF_INET:
469 snprintf(servername, sizeof(servername), "%pI4",
470 &sin->sin_addr.s_addr);
471 break;
472 case AF_INET6:
473 snprintf(servername, sizeof(servername), "%pI6",
474 &sin6->sin6_addr);
475 break;
476 default:
477 /* caller wants default server name, but
478 * address family isn't recognized. */
479 return ERR_PTR(-EINVAL);
481 xprtargs.servername = servername;
484 xprt = xprt_create_transport(&xprtargs);
485 if (IS_ERR(xprt))
486 return (struct rpc_clnt *)xprt;
489 * By default, kernel RPC client connects from a reserved port.
490 * CAP_NET_BIND_SERVICE will not be set for unprivileged requesters,
491 * but it is always enabled for rpciod, which handles the connect
492 * operation.
494 xprt->resvport = 1;
495 if (args->flags & RPC_CLNT_CREATE_NONPRIVPORT)
496 xprt->resvport = 0;
498 clnt = rpc_new_client(args, xprt, NULL);
499 if (IS_ERR(clnt))
500 return clnt;
502 if (!(args->flags & RPC_CLNT_CREATE_NOPING)) {
503 int err = rpc_ping(clnt);
504 if (err != 0) {
505 rpc_shutdown_client(clnt);
506 return ERR_PTR(err);
510 clnt->cl_softrtry = 1;
511 if (args->flags & RPC_CLNT_CREATE_HARDRTRY)
512 clnt->cl_softrtry = 0;
514 if (args->flags & RPC_CLNT_CREATE_AUTOBIND)
515 clnt->cl_autobind = 1;
516 if (args->flags & RPC_CLNT_CREATE_DISCRTRY)
517 clnt->cl_discrtry = 1;
518 if (!(args->flags & RPC_CLNT_CREATE_QUIET))
519 clnt->cl_chatty = 1;
521 return clnt;
523 EXPORT_SYMBOL_GPL(rpc_create);
526 * This function clones the RPC client structure. It allows us to share the
527 * same transport while varying parameters such as the authentication
528 * flavour.
530 static struct rpc_clnt *__rpc_clone_client(struct rpc_create_args *args,
531 struct rpc_clnt *clnt)
533 struct rpc_xprt *xprt;
534 struct rpc_clnt *new;
535 int err;
537 err = -ENOMEM;
538 rcu_read_lock();
539 xprt = xprt_get(rcu_dereference(clnt->cl_xprt));
540 rcu_read_unlock();
541 if (xprt == NULL)
542 goto out_err;
543 args->servername = xprt->servername;
545 new = rpc_new_client(args, xprt, clnt);
546 if (IS_ERR(new)) {
547 err = PTR_ERR(new);
548 goto out_err;
551 /* Turn off autobind on clones */
552 new->cl_autobind = 0;
553 new->cl_softrtry = clnt->cl_softrtry;
554 new->cl_discrtry = clnt->cl_discrtry;
555 new->cl_chatty = clnt->cl_chatty;
556 return new;
558 out_err:
559 dprintk("RPC: %s: returned error %d\n", __func__, err);
560 return ERR_PTR(err);
564 * rpc_clone_client - Clone an RPC client structure
566 * @clnt: RPC client whose parameters are copied
568 * Returns a fresh RPC client or an ERR_PTR.
570 struct rpc_clnt *rpc_clone_client(struct rpc_clnt *clnt)
572 struct rpc_create_args args = {
573 .program = clnt->cl_program,
574 .prognumber = clnt->cl_prog,
575 .version = clnt->cl_vers,
576 .authflavor = clnt->cl_auth->au_flavor,
578 return __rpc_clone_client(&args, clnt);
580 EXPORT_SYMBOL_GPL(rpc_clone_client);
583 * rpc_clone_client_set_auth - Clone an RPC client structure and set its auth
585 * @clnt: RPC client whose parameters are copied
586 * @flavor: security flavor for new client
588 * Returns a fresh RPC client or an ERR_PTR.
590 struct rpc_clnt *
591 rpc_clone_client_set_auth(struct rpc_clnt *clnt, rpc_authflavor_t flavor)
593 struct rpc_create_args args = {
594 .program = clnt->cl_program,
595 .prognumber = clnt->cl_prog,
596 .version = clnt->cl_vers,
597 .authflavor = flavor,
599 return __rpc_clone_client(&args, clnt);
601 EXPORT_SYMBOL_GPL(rpc_clone_client_set_auth);
604 * Kill all tasks for the given client.
605 * XXX: kill their descendants as well?
607 void rpc_killall_tasks(struct rpc_clnt *clnt)
609 struct rpc_task *rovr;
612 if (list_empty(&clnt->cl_tasks))
613 return;
614 dprintk("RPC: killing all tasks for client %p\n", clnt);
616 * Spin lock all_tasks to prevent changes...
618 spin_lock(&clnt->cl_lock);
619 list_for_each_entry(rovr, &clnt->cl_tasks, tk_task) {
620 if (!RPC_IS_ACTIVATED(rovr))
621 continue;
622 if (!(rovr->tk_flags & RPC_TASK_KILLED)) {
623 rovr->tk_flags |= RPC_TASK_KILLED;
624 rpc_exit(rovr, -EIO);
625 if (RPC_IS_QUEUED(rovr))
626 rpc_wake_up_queued_task(rovr->tk_waitqueue,
627 rovr);
630 spin_unlock(&clnt->cl_lock);
632 EXPORT_SYMBOL_GPL(rpc_killall_tasks);
635 * Properly shut down an RPC client, terminating all outstanding
636 * requests.
638 void rpc_shutdown_client(struct rpc_clnt *clnt)
640 might_sleep();
642 dprintk_rcu("RPC: shutting down %s client for %s\n",
643 clnt->cl_program->name,
644 rcu_dereference(clnt->cl_xprt)->servername);
646 while (!list_empty(&clnt->cl_tasks)) {
647 rpc_killall_tasks(clnt);
648 wait_event_timeout(destroy_wait,
649 list_empty(&clnt->cl_tasks), 1*HZ);
652 rpc_release_client(clnt);
654 EXPORT_SYMBOL_GPL(rpc_shutdown_client);
657 * Free an RPC client
659 static struct rpc_clnt *
660 rpc_free_client(struct rpc_clnt *clnt)
662 struct rpc_clnt *parent = NULL;
664 dprintk_rcu("RPC: destroying %s client for %s\n",
665 clnt->cl_program->name,
666 rcu_dereference(clnt->cl_xprt)->servername);
667 if (clnt->cl_parent != clnt)
668 parent = clnt->cl_parent;
669 rpc_clnt_remove_pipedir(clnt);
670 rpc_unregister_client(clnt);
671 rpc_free_iostats(clnt->cl_metrics);
672 clnt->cl_metrics = NULL;
673 xprt_put(rcu_dereference_raw(clnt->cl_xprt));
674 rpciod_down();
675 rpc_free_clid(clnt);
676 kfree(clnt);
677 return parent;
681 * Free an RPC client
683 static struct rpc_clnt *
684 rpc_free_auth(struct rpc_clnt *clnt)
686 if (clnt->cl_auth == NULL)
687 return rpc_free_client(clnt);
690 * Note: RPCSEC_GSS may need to send NULL RPC calls in order to
691 * release remaining GSS contexts. This mechanism ensures
692 * that it can do so safely.
694 atomic_inc(&clnt->cl_count);
695 rpcauth_release(clnt->cl_auth);
696 clnt->cl_auth = NULL;
697 if (atomic_dec_and_test(&clnt->cl_count))
698 return rpc_free_client(clnt);
699 return NULL;
703 * Release reference to the RPC client
705 void
706 rpc_release_client(struct rpc_clnt *clnt)
708 dprintk("RPC: rpc_release_client(%p)\n", clnt);
710 do {
711 if (list_empty(&clnt->cl_tasks))
712 wake_up(&destroy_wait);
713 if (!atomic_dec_and_test(&clnt->cl_count))
714 break;
715 clnt = rpc_free_auth(clnt);
716 } while (clnt != NULL);
718 EXPORT_SYMBOL_GPL(rpc_release_client);
721 * rpc_bind_new_program - bind a new RPC program to an existing client
722 * @old: old rpc_client
723 * @program: rpc program to set
724 * @vers: rpc program version
726 * Clones the rpc client and sets up a new RPC program. This is mainly
727 * of use for enabling different RPC programs to share the same transport.
728 * The Sun NFSv2/v3 ACL protocol can do this.
730 struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *old,
731 const struct rpc_program *program,
732 u32 vers)
734 struct rpc_create_args args = {
735 .program = program,
736 .prognumber = program->number,
737 .version = vers,
738 .authflavor = old->cl_auth->au_flavor,
740 struct rpc_clnt *clnt;
741 int err;
743 clnt = __rpc_clone_client(&args, old);
744 if (IS_ERR(clnt))
745 goto out;
746 err = rpc_ping(clnt);
747 if (err != 0) {
748 rpc_shutdown_client(clnt);
749 clnt = ERR_PTR(err);
751 out:
752 return clnt;
754 EXPORT_SYMBOL_GPL(rpc_bind_new_program);
756 void rpc_task_release_client(struct rpc_task *task)
758 struct rpc_clnt *clnt = task->tk_client;
760 if (clnt != NULL) {
761 /* Remove from client task list */
762 spin_lock(&clnt->cl_lock);
763 list_del(&task->tk_task);
764 spin_unlock(&clnt->cl_lock);
765 task->tk_client = NULL;
767 rpc_release_client(clnt);
771 static
772 void rpc_task_set_client(struct rpc_task *task, struct rpc_clnt *clnt)
774 if (clnt != NULL) {
775 rpc_task_release_client(task);
776 task->tk_client = clnt;
777 atomic_inc(&clnt->cl_count);
778 if (clnt->cl_softrtry)
779 task->tk_flags |= RPC_TASK_SOFT;
780 if (sk_memalloc_socks()) {
781 struct rpc_xprt *xprt;
783 rcu_read_lock();
784 xprt = rcu_dereference(clnt->cl_xprt);
785 if (xprt->swapper)
786 task->tk_flags |= RPC_TASK_SWAPPER;
787 rcu_read_unlock();
789 /* Add to the client's list of all tasks */
790 spin_lock(&clnt->cl_lock);
791 list_add_tail(&task->tk_task, &clnt->cl_tasks);
792 spin_unlock(&clnt->cl_lock);
796 void rpc_task_reset_client(struct rpc_task *task, struct rpc_clnt *clnt)
798 rpc_task_release_client(task);
799 rpc_task_set_client(task, clnt);
801 EXPORT_SYMBOL_GPL(rpc_task_reset_client);
804 static void
805 rpc_task_set_rpc_message(struct rpc_task *task, const struct rpc_message *msg)
807 if (msg != NULL) {
808 task->tk_msg.rpc_proc = msg->rpc_proc;
809 task->tk_msg.rpc_argp = msg->rpc_argp;
810 task->tk_msg.rpc_resp = msg->rpc_resp;
811 if (msg->rpc_cred != NULL)
812 task->tk_msg.rpc_cred = get_rpccred(msg->rpc_cred);
817 * Default callback for async RPC calls
819 static void
820 rpc_default_callback(struct rpc_task *task, void *data)
824 static const struct rpc_call_ops rpc_default_ops = {
825 .rpc_call_done = rpc_default_callback,
829 * rpc_run_task - Allocate a new RPC task, then run rpc_execute against it
830 * @task_setup_data: pointer to task initialisation data
832 struct rpc_task *rpc_run_task(const struct rpc_task_setup *task_setup_data)
834 struct rpc_task *task;
836 task = rpc_new_task(task_setup_data);
837 if (IS_ERR(task))
838 goto out;
840 rpc_task_set_client(task, task_setup_data->rpc_client);
841 rpc_task_set_rpc_message(task, task_setup_data->rpc_message);
843 if (task->tk_action == NULL)
844 rpc_call_start(task);
846 atomic_inc(&task->tk_count);
847 rpc_execute(task);
848 out:
849 return task;
851 EXPORT_SYMBOL_GPL(rpc_run_task);
854 * rpc_call_sync - Perform a synchronous RPC call
855 * @clnt: pointer to RPC client
856 * @msg: RPC call parameters
857 * @flags: RPC call flags
859 int rpc_call_sync(struct rpc_clnt *clnt, const struct rpc_message *msg, int flags)
861 struct rpc_task *task;
862 struct rpc_task_setup task_setup_data = {
863 .rpc_client = clnt,
864 .rpc_message = msg,
865 .callback_ops = &rpc_default_ops,
866 .flags = flags,
868 int status;
870 WARN_ON_ONCE(flags & RPC_TASK_ASYNC);
871 if (flags & RPC_TASK_ASYNC) {
872 rpc_release_calldata(task_setup_data.callback_ops,
873 task_setup_data.callback_data);
874 return -EINVAL;
877 task = rpc_run_task(&task_setup_data);
878 if (IS_ERR(task))
879 return PTR_ERR(task);
880 status = task->tk_status;
881 rpc_put_task(task);
882 return status;
884 EXPORT_SYMBOL_GPL(rpc_call_sync);
887 * rpc_call_async - Perform an asynchronous RPC call
888 * @clnt: pointer to RPC client
889 * @msg: RPC call parameters
890 * @flags: RPC call flags
891 * @tk_ops: RPC call ops
892 * @data: user call data
895 rpc_call_async(struct rpc_clnt *clnt, const struct rpc_message *msg, int flags,
896 const struct rpc_call_ops *tk_ops, void *data)
898 struct rpc_task *task;
899 struct rpc_task_setup task_setup_data = {
900 .rpc_client = clnt,
901 .rpc_message = msg,
902 .callback_ops = tk_ops,
903 .callback_data = data,
904 .flags = flags|RPC_TASK_ASYNC,
907 task = rpc_run_task(&task_setup_data);
908 if (IS_ERR(task))
909 return PTR_ERR(task);
910 rpc_put_task(task);
911 return 0;
913 EXPORT_SYMBOL_GPL(rpc_call_async);
915 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
917 * rpc_run_bc_task - Allocate a new RPC task for backchannel use, then run
918 * rpc_execute against it
919 * @req: RPC request
920 * @tk_ops: RPC call ops
922 struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req,
923 const struct rpc_call_ops *tk_ops)
925 struct rpc_task *task;
926 struct xdr_buf *xbufp = &req->rq_snd_buf;
927 struct rpc_task_setup task_setup_data = {
928 .callback_ops = tk_ops,
931 dprintk("RPC: rpc_run_bc_task req= %p\n", req);
933 * Create an rpc_task to send the data
935 task = rpc_new_task(&task_setup_data);
936 if (IS_ERR(task)) {
937 xprt_free_bc_request(req);
938 goto out;
940 task->tk_rqstp = req;
943 * Set up the xdr_buf length.
944 * This also indicates that the buffer is XDR encoded already.
946 xbufp->len = xbufp->head[0].iov_len + xbufp->page_len +
947 xbufp->tail[0].iov_len;
949 task->tk_action = call_bc_transmit;
950 atomic_inc(&task->tk_count);
951 WARN_ON_ONCE(atomic_read(&task->tk_count) != 2);
952 rpc_execute(task);
954 out:
955 dprintk("RPC: rpc_run_bc_task: task= %p\n", task);
956 return task;
958 #endif /* CONFIG_SUNRPC_BACKCHANNEL */
960 void
961 rpc_call_start(struct rpc_task *task)
963 task->tk_action = call_start;
965 EXPORT_SYMBOL_GPL(rpc_call_start);
968 * rpc_peeraddr - extract remote peer address from clnt's xprt
969 * @clnt: RPC client structure
970 * @buf: target buffer
971 * @bufsize: length of target buffer
973 * Returns the number of bytes that are actually in the stored address.
975 size_t rpc_peeraddr(struct rpc_clnt *clnt, struct sockaddr *buf, size_t bufsize)
977 size_t bytes;
978 struct rpc_xprt *xprt;
980 rcu_read_lock();
981 xprt = rcu_dereference(clnt->cl_xprt);
983 bytes = xprt->addrlen;
984 if (bytes > bufsize)
985 bytes = bufsize;
986 memcpy(buf, &xprt->addr, bytes);
987 rcu_read_unlock();
989 return bytes;
991 EXPORT_SYMBOL_GPL(rpc_peeraddr);
994 * rpc_peeraddr2str - return remote peer address in printable format
995 * @clnt: RPC client structure
996 * @format: address format
998 * NB: the lifetime of the memory referenced by the returned pointer is
999 * the same as the rpc_xprt itself. As long as the caller uses this
1000 * pointer, it must hold the RCU read lock.
1002 const char *rpc_peeraddr2str(struct rpc_clnt *clnt,
1003 enum rpc_display_format_t format)
1005 struct rpc_xprt *xprt;
1007 xprt = rcu_dereference(clnt->cl_xprt);
1009 if (xprt->address_strings[format] != NULL)
1010 return xprt->address_strings[format];
1011 else
1012 return "unprintable";
1014 EXPORT_SYMBOL_GPL(rpc_peeraddr2str);
1016 static const struct sockaddr_in rpc_inaddr_loopback = {
1017 .sin_family = AF_INET,
1018 .sin_addr.s_addr = htonl(INADDR_ANY),
1021 static const struct sockaddr_in6 rpc_in6addr_loopback = {
1022 .sin6_family = AF_INET6,
1023 .sin6_addr = IN6ADDR_ANY_INIT,
1027 * Try a getsockname() on a connected datagram socket. Using a
1028 * connected datagram socket prevents leaving a socket in TIME_WAIT.
1029 * This conserves the ephemeral port number space.
1031 * Returns zero and fills in "buf" if successful; otherwise, a
1032 * negative errno is returned.
1034 static int rpc_sockname(struct net *net, struct sockaddr *sap, size_t salen,
1035 struct sockaddr *buf, int buflen)
1037 struct socket *sock;
1038 int err;
1040 err = __sock_create(net, sap->sa_family,
1041 SOCK_DGRAM, IPPROTO_UDP, &sock, 1);
1042 if (err < 0) {
1043 dprintk("RPC: can't create UDP socket (%d)\n", err);
1044 goto out;
1047 switch (sap->sa_family) {
1048 case AF_INET:
1049 err = kernel_bind(sock,
1050 (struct sockaddr *)&rpc_inaddr_loopback,
1051 sizeof(rpc_inaddr_loopback));
1052 break;
1053 case AF_INET6:
1054 err = kernel_bind(sock,
1055 (struct sockaddr *)&rpc_in6addr_loopback,
1056 sizeof(rpc_in6addr_loopback));
1057 break;
1058 default:
1059 err = -EAFNOSUPPORT;
1060 goto out;
1062 if (err < 0) {
1063 dprintk("RPC: can't bind UDP socket (%d)\n", err);
1064 goto out_release;
1067 err = kernel_connect(sock, sap, salen, 0);
1068 if (err < 0) {
1069 dprintk("RPC: can't connect UDP socket (%d)\n", err);
1070 goto out_release;
1073 err = kernel_getsockname(sock, buf, &buflen);
1074 if (err < 0) {
1075 dprintk("RPC: getsockname failed (%d)\n", err);
1076 goto out_release;
1079 err = 0;
1080 if (buf->sa_family == AF_INET6) {
1081 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)buf;
1082 sin6->sin6_scope_id = 0;
1084 dprintk("RPC: %s succeeded\n", __func__);
1086 out_release:
1087 sock_release(sock);
1088 out:
1089 return err;
1093 * Scraping a connected socket failed, so we don't have a useable
1094 * local address. Fallback: generate an address that will prevent
1095 * the server from calling us back.
1097 * Returns zero and fills in "buf" if successful; otherwise, a
1098 * negative errno is returned.
1100 static int rpc_anyaddr(int family, struct sockaddr *buf, size_t buflen)
1102 switch (family) {
1103 case AF_INET:
1104 if (buflen < sizeof(rpc_inaddr_loopback))
1105 return -EINVAL;
1106 memcpy(buf, &rpc_inaddr_loopback,
1107 sizeof(rpc_inaddr_loopback));
1108 break;
1109 case AF_INET6:
1110 if (buflen < sizeof(rpc_in6addr_loopback))
1111 return -EINVAL;
1112 memcpy(buf, &rpc_in6addr_loopback,
1113 sizeof(rpc_in6addr_loopback));
1114 default:
1115 dprintk("RPC: %s: address family not supported\n",
1116 __func__);
1117 return -EAFNOSUPPORT;
1119 dprintk("RPC: %s: succeeded\n", __func__);
1120 return 0;
1124 * rpc_localaddr - discover local endpoint address for an RPC client
1125 * @clnt: RPC client structure
1126 * @buf: target buffer
1127 * @buflen: size of target buffer, in bytes
1129 * Returns zero and fills in "buf" and "buflen" if successful;
1130 * otherwise, a negative errno is returned.
1132 * This works even if the underlying transport is not currently connected,
1133 * or if the upper layer never previously provided a source address.
1135 * The result of this function call is transient: multiple calls in
1136 * succession may give different results, depending on how local
1137 * networking configuration changes over time.
1139 int rpc_localaddr(struct rpc_clnt *clnt, struct sockaddr *buf, size_t buflen)
1141 struct sockaddr_storage address;
1142 struct sockaddr *sap = (struct sockaddr *)&address;
1143 struct rpc_xprt *xprt;
1144 struct net *net;
1145 size_t salen;
1146 int err;
1148 rcu_read_lock();
1149 xprt = rcu_dereference(clnt->cl_xprt);
1150 salen = xprt->addrlen;
1151 memcpy(sap, &xprt->addr, salen);
1152 net = get_net(xprt->xprt_net);
1153 rcu_read_unlock();
1155 rpc_set_port(sap, 0);
1156 err = rpc_sockname(net, sap, salen, buf, buflen);
1157 put_net(net);
1158 if (err != 0)
1159 /* Couldn't discover local address, return ANYADDR */
1160 return rpc_anyaddr(sap->sa_family, buf, buflen);
1161 return 0;
1163 EXPORT_SYMBOL_GPL(rpc_localaddr);
1165 void
1166 rpc_setbufsize(struct rpc_clnt *clnt, unsigned int sndsize, unsigned int rcvsize)
1168 struct rpc_xprt *xprt;
1170 rcu_read_lock();
1171 xprt = rcu_dereference(clnt->cl_xprt);
1172 if (xprt->ops->set_buffer_size)
1173 xprt->ops->set_buffer_size(xprt, sndsize, rcvsize);
1174 rcu_read_unlock();
1176 EXPORT_SYMBOL_GPL(rpc_setbufsize);
1179 * rpc_protocol - Get transport protocol number for an RPC client
1180 * @clnt: RPC client to query
1183 int rpc_protocol(struct rpc_clnt *clnt)
1185 int protocol;
1187 rcu_read_lock();
1188 protocol = rcu_dereference(clnt->cl_xprt)->prot;
1189 rcu_read_unlock();
1190 return protocol;
1192 EXPORT_SYMBOL_GPL(rpc_protocol);
1195 * rpc_net_ns - Get the network namespace for this RPC client
1196 * @clnt: RPC client to query
1199 struct net *rpc_net_ns(struct rpc_clnt *clnt)
1201 struct net *ret;
1203 rcu_read_lock();
1204 ret = rcu_dereference(clnt->cl_xprt)->xprt_net;
1205 rcu_read_unlock();
1206 return ret;
1208 EXPORT_SYMBOL_GPL(rpc_net_ns);
1211 * rpc_max_payload - Get maximum payload size for a transport, in bytes
1212 * @clnt: RPC client to query
1214 * For stream transports, this is one RPC record fragment (see RFC
1215 * 1831), as we don't support multi-record requests yet. For datagram
1216 * transports, this is the size of an IP packet minus the IP, UDP, and
1217 * RPC header sizes.
1219 size_t rpc_max_payload(struct rpc_clnt *clnt)
1221 size_t ret;
1223 rcu_read_lock();
1224 ret = rcu_dereference(clnt->cl_xprt)->max_payload;
1225 rcu_read_unlock();
1226 return ret;
1228 EXPORT_SYMBOL_GPL(rpc_max_payload);
1231 * rpc_get_timeout - Get timeout for transport in units of HZ
1232 * @clnt: RPC client to query
1234 unsigned long rpc_get_timeout(struct rpc_clnt *clnt)
1236 unsigned long ret;
1238 rcu_read_lock();
1239 ret = rcu_dereference(clnt->cl_xprt)->timeout->to_initval;
1240 rcu_read_unlock();
1241 return ret;
1243 EXPORT_SYMBOL_GPL(rpc_get_timeout);
1246 * rpc_force_rebind - force transport to check that remote port is unchanged
1247 * @clnt: client to rebind
1250 void rpc_force_rebind(struct rpc_clnt *clnt)
1252 if (clnt->cl_autobind) {
1253 rcu_read_lock();
1254 xprt_clear_bound(rcu_dereference(clnt->cl_xprt));
1255 rcu_read_unlock();
1258 EXPORT_SYMBOL_GPL(rpc_force_rebind);
1261 * Restart an (async) RPC call from the call_prepare state.
1262 * Usually called from within the exit handler.
1265 rpc_restart_call_prepare(struct rpc_task *task)
1267 if (RPC_ASSASSINATED(task))
1268 return 0;
1269 task->tk_action = call_start;
1270 if (task->tk_ops->rpc_call_prepare != NULL)
1271 task->tk_action = rpc_prepare_task;
1272 return 1;
1274 EXPORT_SYMBOL_GPL(rpc_restart_call_prepare);
1277 * Restart an (async) RPC call. Usually called from within the
1278 * exit handler.
1281 rpc_restart_call(struct rpc_task *task)
1283 if (RPC_ASSASSINATED(task))
1284 return 0;
1285 task->tk_action = call_start;
1286 return 1;
1288 EXPORT_SYMBOL_GPL(rpc_restart_call);
1290 #ifdef RPC_DEBUG
1291 static const char *rpc_proc_name(const struct rpc_task *task)
1293 const struct rpc_procinfo *proc = task->tk_msg.rpc_proc;
1295 if (proc) {
1296 if (proc->p_name)
1297 return proc->p_name;
1298 else
1299 return "NULL";
1300 } else
1301 return "no proc";
1303 #endif
1306 * 0. Initial state
1308 * Other FSM states can be visited zero or more times, but
1309 * this state is visited exactly once for each RPC.
1311 static void
1312 call_start(struct rpc_task *task)
1314 struct rpc_clnt *clnt = task->tk_client;
1316 dprintk("RPC: %5u call_start %s%d proc %s (%s)\n", task->tk_pid,
1317 clnt->cl_program->name, clnt->cl_vers,
1318 rpc_proc_name(task),
1319 (RPC_IS_ASYNC(task) ? "async" : "sync"));
1321 /* Increment call count */
1322 task->tk_msg.rpc_proc->p_count++;
1323 clnt->cl_stats->rpccnt++;
1324 task->tk_action = call_reserve;
1328 * 1. Reserve an RPC call slot
1330 static void
1331 call_reserve(struct rpc_task *task)
1333 dprint_status(task);
1335 task->tk_status = 0;
1336 task->tk_action = call_reserveresult;
1337 xprt_reserve(task);
1340 static void call_retry_reserve(struct rpc_task *task);
1343 * 1b. Grok the result of xprt_reserve()
1345 static void
1346 call_reserveresult(struct rpc_task *task)
1348 int status = task->tk_status;
1350 dprint_status(task);
1353 * After a call to xprt_reserve(), we must have either
1354 * a request slot or else an error status.
1356 task->tk_status = 0;
1357 if (status >= 0) {
1358 if (task->tk_rqstp) {
1359 task->tk_action = call_refresh;
1360 return;
1363 printk(KERN_ERR "%s: status=%d, but no request slot, exiting\n",
1364 __func__, status);
1365 rpc_exit(task, -EIO);
1366 return;
1370 * Even though there was an error, we may have acquired
1371 * a request slot somehow. Make sure not to leak it.
1373 if (task->tk_rqstp) {
1374 printk(KERN_ERR "%s: status=%d, request allocated anyway\n",
1375 __func__, status);
1376 xprt_release(task);
1379 switch (status) {
1380 case -ENOMEM:
1381 rpc_delay(task, HZ >> 2);
1382 case -EAGAIN: /* woken up; retry */
1383 task->tk_action = call_retry_reserve;
1384 return;
1385 case -EIO: /* probably a shutdown */
1386 break;
1387 default:
1388 printk(KERN_ERR "%s: unrecognized error %d, exiting\n",
1389 __func__, status);
1390 break;
1392 rpc_exit(task, status);
1396 * 1c. Retry reserving an RPC call slot
1398 static void
1399 call_retry_reserve(struct rpc_task *task)
1401 dprint_status(task);
1403 task->tk_status = 0;
1404 task->tk_action = call_reserveresult;
1405 xprt_retry_reserve(task);
1409 * 2. Bind and/or refresh the credentials
1411 static void
1412 call_refresh(struct rpc_task *task)
1414 dprint_status(task);
1416 task->tk_action = call_refreshresult;
1417 task->tk_status = 0;
1418 task->tk_client->cl_stats->rpcauthrefresh++;
1419 rpcauth_refreshcred(task);
1423 * 2a. Process the results of a credential refresh
1425 static void
1426 call_refreshresult(struct rpc_task *task)
1428 int status = task->tk_status;
1430 dprint_status(task);
1432 task->tk_status = 0;
1433 task->tk_action = call_refresh;
1434 switch (status) {
1435 case 0:
1436 if (rpcauth_uptodatecred(task)) {
1437 task->tk_action = call_allocate;
1438 return;
1440 /* Use rate-limiting and a max number of retries if refresh
1441 * had status 0 but failed to update the cred.
1443 case -ETIMEDOUT:
1444 rpc_delay(task, 3*HZ);
1445 case -EAGAIN:
1446 status = -EACCES;
1447 case -EKEYEXPIRED:
1448 if (!task->tk_cred_retry)
1449 break;
1450 task->tk_cred_retry--;
1451 dprintk("RPC: %5u %s: retry refresh creds\n",
1452 task->tk_pid, __func__);
1453 return;
1455 dprintk("RPC: %5u %s: refresh creds failed with error %d\n",
1456 task->tk_pid, __func__, status);
1457 rpc_exit(task, status);
1461 * 2b. Allocate the buffer. For details, see sched.c:rpc_malloc.
1462 * (Note: buffer memory is freed in xprt_release).
1464 static void
1465 call_allocate(struct rpc_task *task)
1467 unsigned int slack = task->tk_rqstp->rq_cred->cr_auth->au_cslack;
1468 struct rpc_rqst *req = task->tk_rqstp;
1469 struct rpc_xprt *xprt = req->rq_xprt;
1470 struct rpc_procinfo *proc = task->tk_msg.rpc_proc;
1472 dprint_status(task);
1474 task->tk_status = 0;
1475 task->tk_action = call_bind;
1477 if (req->rq_buffer)
1478 return;
1480 if (proc->p_proc != 0) {
1481 BUG_ON(proc->p_arglen == 0);
1482 if (proc->p_decode != NULL)
1483 BUG_ON(proc->p_replen == 0);
1487 * Calculate the size (in quads) of the RPC call
1488 * and reply headers, and convert both values
1489 * to byte sizes.
1491 req->rq_callsize = RPC_CALLHDRSIZE + (slack << 1) + proc->p_arglen;
1492 req->rq_callsize <<= 2;
1493 req->rq_rcvsize = RPC_REPHDRSIZE + slack + proc->p_replen;
1494 req->rq_rcvsize <<= 2;
1496 req->rq_buffer = xprt->ops->buf_alloc(task,
1497 req->rq_callsize + req->rq_rcvsize);
1498 if (req->rq_buffer != NULL)
1499 return;
1501 dprintk("RPC: %5u rpc_buffer allocation failed\n", task->tk_pid);
1503 if (RPC_IS_ASYNC(task) || !fatal_signal_pending(current)) {
1504 task->tk_action = call_allocate;
1505 rpc_delay(task, HZ>>4);
1506 return;
1509 rpc_exit(task, -ERESTARTSYS);
1512 static inline int
1513 rpc_task_need_encode(struct rpc_task *task)
1515 return task->tk_rqstp->rq_snd_buf.len == 0;
1518 static inline void
1519 rpc_task_force_reencode(struct rpc_task *task)
1521 task->tk_rqstp->rq_snd_buf.len = 0;
1522 task->tk_rqstp->rq_bytes_sent = 0;
1525 static inline void
1526 rpc_xdr_buf_init(struct xdr_buf *buf, void *start, size_t len)
1528 buf->head[0].iov_base = start;
1529 buf->head[0].iov_len = len;
1530 buf->tail[0].iov_len = 0;
1531 buf->page_len = 0;
1532 buf->flags = 0;
1533 buf->len = 0;
1534 buf->buflen = len;
1538 * 3. Encode arguments of an RPC call
1540 static void
1541 rpc_xdr_encode(struct rpc_task *task)
1543 struct rpc_rqst *req = task->tk_rqstp;
1544 kxdreproc_t encode;
1545 __be32 *p;
1547 dprint_status(task);
1549 rpc_xdr_buf_init(&req->rq_snd_buf,
1550 req->rq_buffer,
1551 req->rq_callsize);
1552 rpc_xdr_buf_init(&req->rq_rcv_buf,
1553 (char *)req->rq_buffer + req->rq_callsize,
1554 req->rq_rcvsize);
1556 p = rpc_encode_header(task);
1557 if (p == NULL) {
1558 printk(KERN_INFO "RPC: couldn't encode RPC header, exit EIO\n");
1559 rpc_exit(task, -EIO);
1560 return;
1563 encode = task->tk_msg.rpc_proc->p_encode;
1564 if (encode == NULL)
1565 return;
1567 task->tk_status = rpcauth_wrap_req(task, encode, req, p,
1568 task->tk_msg.rpc_argp);
1572 * 4. Get the server port number if not yet set
1574 static void
1575 call_bind(struct rpc_task *task)
1577 struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt;
1579 dprint_status(task);
1581 task->tk_action = call_connect;
1582 if (!xprt_bound(xprt)) {
1583 task->tk_action = call_bind_status;
1584 task->tk_timeout = xprt->bind_timeout;
1585 xprt->ops->rpcbind(task);
1590 * 4a. Sort out bind result
1592 static void
1593 call_bind_status(struct rpc_task *task)
1595 int status = -EIO;
1597 if (task->tk_status >= 0) {
1598 dprint_status(task);
1599 task->tk_status = 0;
1600 task->tk_action = call_connect;
1601 return;
1604 trace_rpc_bind_status(task);
1605 switch (task->tk_status) {
1606 case -ENOMEM:
1607 dprintk("RPC: %5u rpcbind out of memory\n", task->tk_pid);
1608 rpc_delay(task, HZ >> 2);
1609 goto retry_timeout;
1610 case -EACCES:
1611 dprintk("RPC: %5u remote rpcbind: RPC program/version "
1612 "unavailable\n", task->tk_pid);
1613 /* fail immediately if this is an RPC ping */
1614 if (task->tk_msg.rpc_proc->p_proc == 0) {
1615 status = -EOPNOTSUPP;
1616 break;
1618 if (task->tk_rebind_retry == 0)
1619 break;
1620 task->tk_rebind_retry--;
1621 rpc_delay(task, 3*HZ);
1622 goto retry_timeout;
1623 case -ETIMEDOUT:
1624 dprintk("RPC: %5u rpcbind request timed out\n",
1625 task->tk_pid);
1626 goto retry_timeout;
1627 case -EPFNOSUPPORT:
1628 /* server doesn't support any rpcbind version we know of */
1629 dprintk("RPC: %5u unrecognized remote rpcbind service\n",
1630 task->tk_pid);
1631 break;
1632 case -EPROTONOSUPPORT:
1633 dprintk("RPC: %5u remote rpcbind version unavailable, retrying\n",
1634 task->tk_pid);
1635 task->tk_status = 0;
1636 task->tk_action = call_bind;
1637 return;
1638 case -ECONNREFUSED: /* connection problems */
1639 case -ECONNRESET:
1640 case -ECONNABORTED:
1641 case -ENOTCONN:
1642 case -EHOSTDOWN:
1643 case -EHOSTUNREACH:
1644 case -ENETUNREACH:
1645 case -ENOBUFS:
1646 case -EPIPE:
1647 dprintk("RPC: %5u remote rpcbind unreachable: %d\n",
1648 task->tk_pid, task->tk_status);
1649 if (!RPC_IS_SOFTCONN(task)) {
1650 rpc_delay(task, 5*HZ);
1651 goto retry_timeout;
1653 status = task->tk_status;
1654 break;
1655 default:
1656 dprintk("RPC: %5u unrecognized rpcbind error (%d)\n",
1657 task->tk_pid, -task->tk_status);
1660 rpc_exit(task, status);
1661 return;
1663 retry_timeout:
1664 task->tk_action = call_timeout;
1668 * 4b. Connect to the RPC server
1670 static void
1671 call_connect(struct rpc_task *task)
1673 struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt;
1675 dprintk("RPC: %5u call_connect xprt %p %s connected\n",
1676 task->tk_pid, xprt,
1677 (xprt_connected(xprt) ? "is" : "is not"));
1679 task->tk_action = call_transmit;
1680 if (!xprt_connected(xprt)) {
1681 task->tk_action = call_connect_status;
1682 if (task->tk_status < 0)
1683 return;
1684 if (task->tk_flags & RPC_TASK_NOCONNECT) {
1685 rpc_exit(task, -ENOTCONN);
1686 return;
1688 xprt_connect(task);
1693 * 4c. Sort out connect result
1695 static void
1696 call_connect_status(struct rpc_task *task)
1698 struct rpc_clnt *clnt = task->tk_client;
1699 int status = task->tk_status;
1701 dprint_status(task);
1703 trace_rpc_connect_status(task, status);
1704 task->tk_status = 0;
1705 switch (status) {
1706 case -ECONNREFUSED:
1707 case -ECONNRESET:
1708 case -ECONNABORTED:
1709 case -ENETUNREACH:
1710 case -EHOSTUNREACH:
1711 case -ENOBUFS:
1712 case -EPIPE:
1713 if (RPC_IS_SOFTCONN(task))
1714 break;
1715 /* retry with existing socket, after a delay */
1716 rpc_delay(task, 3*HZ);
1717 case -EAGAIN:
1718 /* Check for timeouts before looping back to call_bind */
1719 case -ETIMEDOUT:
1720 task->tk_action = call_timeout;
1721 return;
1722 case 0:
1723 clnt->cl_stats->netreconn++;
1724 task->tk_action = call_transmit;
1725 return;
1727 rpc_exit(task, status);
1731 * 5. Transmit the RPC request, and wait for reply
1733 static void
1734 call_transmit(struct rpc_task *task)
1736 dprint_status(task);
1738 task->tk_action = call_status;
1739 if (task->tk_status < 0)
1740 return;
1741 task->tk_status = xprt_prepare_transmit(task);
1742 if (task->tk_status != 0)
1743 return;
1744 task->tk_action = call_transmit_status;
1745 /* Encode here so that rpcsec_gss can use correct sequence number. */
1746 if (rpc_task_need_encode(task)) {
1747 rpc_xdr_encode(task);
1748 /* Did the encode result in an error condition? */
1749 if (task->tk_status != 0) {
1750 /* Was the error nonfatal? */
1751 if (task->tk_status == -EAGAIN)
1752 rpc_delay(task, HZ >> 4);
1753 else
1754 rpc_exit(task, task->tk_status);
1755 return;
1758 xprt_transmit(task);
1759 if (task->tk_status < 0)
1760 return;
1762 * On success, ensure that we call xprt_end_transmit() before sleeping
1763 * in order to allow access to the socket to other RPC requests.
1765 call_transmit_status(task);
1766 if (rpc_reply_expected(task))
1767 return;
1768 task->tk_action = rpc_exit_task;
1769 rpc_wake_up_queued_task(&task->tk_rqstp->rq_xprt->pending, task);
1773 * 5a. Handle cleanup after a transmission
1775 static void
1776 call_transmit_status(struct rpc_task *task)
1778 task->tk_action = call_status;
1781 * Common case: success. Force the compiler to put this
1782 * test first.
1784 if (task->tk_status == 0) {
1785 xprt_end_transmit(task);
1786 rpc_task_force_reencode(task);
1787 return;
1790 switch (task->tk_status) {
1791 case -EAGAIN:
1792 break;
1793 default:
1794 dprint_status(task);
1795 xprt_end_transmit(task);
1796 rpc_task_force_reencode(task);
1797 break;
1799 * Special cases: if we've been waiting on the
1800 * socket's write_space() callback, or if the
1801 * socket just returned a connection error,
1802 * then hold onto the transport lock.
1804 case -ECONNREFUSED:
1805 case -EHOSTDOWN:
1806 case -EHOSTUNREACH:
1807 case -ENETUNREACH:
1808 if (RPC_IS_SOFTCONN(task)) {
1809 xprt_end_transmit(task);
1810 rpc_exit(task, task->tk_status);
1811 break;
1813 case -ECONNRESET:
1814 case -ECONNABORTED:
1815 case -ENOTCONN:
1816 case -ENOBUFS:
1817 case -EPIPE:
1818 rpc_task_force_reencode(task);
1822 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
1824 * 5b. Send the backchannel RPC reply. On error, drop the reply. In
1825 * addition, disconnect on connectivity errors.
1827 static void
1828 call_bc_transmit(struct rpc_task *task)
1830 struct rpc_rqst *req = task->tk_rqstp;
1832 task->tk_status = xprt_prepare_transmit(task);
1833 if (task->tk_status == -EAGAIN) {
1835 * Could not reserve the transport. Try again after the
1836 * transport is released.
1838 task->tk_status = 0;
1839 task->tk_action = call_bc_transmit;
1840 return;
1843 task->tk_action = rpc_exit_task;
1844 if (task->tk_status < 0) {
1845 printk(KERN_NOTICE "RPC: Could not send backchannel reply "
1846 "error: %d\n", task->tk_status);
1847 return;
1850 xprt_transmit(task);
1851 xprt_end_transmit(task);
1852 dprint_status(task);
1853 switch (task->tk_status) {
1854 case 0:
1855 /* Success */
1856 break;
1857 case -EHOSTDOWN:
1858 case -EHOSTUNREACH:
1859 case -ENETUNREACH:
1860 case -ETIMEDOUT:
1862 * Problem reaching the server. Disconnect and let the
1863 * forechannel reestablish the connection. The server will
1864 * have to retransmit the backchannel request and we'll
1865 * reprocess it. Since these ops are idempotent, there's no
1866 * need to cache our reply at this time.
1868 printk(KERN_NOTICE "RPC: Could not send backchannel reply "
1869 "error: %d\n", task->tk_status);
1870 xprt_conditional_disconnect(req->rq_xprt,
1871 req->rq_connect_cookie);
1872 break;
1873 default:
1875 * We were unable to reply and will have to drop the
1876 * request. The server should reconnect and retransmit.
1878 WARN_ON_ONCE(task->tk_status == -EAGAIN);
1879 printk(KERN_NOTICE "RPC: Could not send backchannel reply "
1880 "error: %d\n", task->tk_status);
1881 break;
1883 rpc_wake_up_queued_task(&req->rq_xprt->pending, task);
1885 #endif /* CONFIG_SUNRPC_BACKCHANNEL */
1888 * 6. Sort out the RPC call status
1890 static void
1891 call_status(struct rpc_task *task)
1893 struct rpc_clnt *clnt = task->tk_client;
1894 struct rpc_rqst *req = task->tk_rqstp;
1895 int status;
1897 if (req->rq_reply_bytes_recvd > 0 && !req->rq_bytes_sent)
1898 task->tk_status = req->rq_reply_bytes_recvd;
1900 dprint_status(task);
1902 status = task->tk_status;
1903 if (status >= 0) {
1904 task->tk_action = call_decode;
1905 return;
1908 trace_rpc_call_status(task);
1909 task->tk_status = 0;
1910 switch(status) {
1911 case -EHOSTDOWN:
1912 case -EHOSTUNREACH:
1913 case -ENETUNREACH:
1915 * Delay any retries for 3 seconds, then handle as if it
1916 * were a timeout.
1918 rpc_delay(task, 3*HZ);
1919 case -ETIMEDOUT:
1920 task->tk_action = call_timeout;
1921 if (task->tk_client->cl_discrtry)
1922 xprt_conditional_disconnect(req->rq_xprt,
1923 req->rq_connect_cookie);
1924 break;
1925 case -ECONNREFUSED:
1926 case -ECONNRESET:
1927 case -ECONNABORTED:
1928 rpc_force_rebind(clnt);
1929 case -ENOBUFS:
1930 rpc_delay(task, 3*HZ);
1931 case -EPIPE:
1932 case -ENOTCONN:
1933 task->tk_action = call_bind;
1934 break;
1935 case -EAGAIN:
1936 task->tk_action = call_transmit;
1937 break;
1938 case -EIO:
1939 /* shutdown or soft timeout */
1940 rpc_exit(task, status);
1941 break;
1942 default:
1943 if (clnt->cl_chatty)
1944 printk("%s: RPC call returned error %d\n",
1945 clnt->cl_program->name, -status);
1946 rpc_exit(task, status);
1951 * 6a. Handle RPC timeout
1952 * We do not release the request slot, so we keep using the
1953 * same XID for all retransmits.
1955 static void
1956 call_timeout(struct rpc_task *task)
1958 struct rpc_clnt *clnt = task->tk_client;
1960 if (xprt_adjust_timeout(task->tk_rqstp) == 0) {
1961 dprintk("RPC: %5u call_timeout (minor)\n", task->tk_pid);
1962 goto retry;
1965 dprintk("RPC: %5u call_timeout (major)\n", task->tk_pid);
1966 task->tk_timeouts++;
1968 if (RPC_IS_SOFTCONN(task)) {
1969 rpc_exit(task, -ETIMEDOUT);
1970 return;
1972 if (RPC_IS_SOFT(task)) {
1973 if (clnt->cl_chatty) {
1974 rcu_read_lock();
1975 printk(KERN_NOTICE "%s: server %s not responding, timed out\n",
1976 clnt->cl_program->name,
1977 rcu_dereference(clnt->cl_xprt)->servername);
1978 rcu_read_unlock();
1980 if (task->tk_flags & RPC_TASK_TIMEOUT)
1981 rpc_exit(task, -ETIMEDOUT);
1982 else
1983 rpc_exit(task, -EIO);
1984 return;
1987 if (!(task->tk_flags & RPC_CALL_MAJORSEEN)) {
1988 task->tk_flags |= RPC_CALL_MAJORSEEN;
1989 if (clnt->cl_chatty) {
1990 rcu_read_lock();
1991 printk(KERN_NOTICE "%s: server %s not responding, still trying\n",
1992 clnt->cl_program->name,
1993 rcu_dereference(clnt->cl_xprt)->servername);
1994 rcu_read_unlock();
1997 rpc_force_rebind(clnt);
1999 * Did our request time out due to an RPCSEC_GSS out-of-sequence
2000 * event? RFC2203 requires the server to drop all such requests.
2002 rpcauth_invalcred(task);
2004 retry:
2005 clnt->cl_stats->rpcretrans++;
2006 task->tk_action = call_bind;
2007 task->tk_status = 0;
2011 * 7. Decode the RPC reply
2013 static void
2014 call_decode(struct rpc_task *task)
2016 struct rpc_clnt *clnt = task->tk_client;
2017 struct rpc_rqst *req = task->tk_rqstp;
2018 kxdrdproc_t decode = task->tk_msg.rpc_proc->p_decode;
2019 __be32 *p;
2021 dprint_status(task);
2023 if (task->tk_flags & RPC_CALL_MAJORSEEN) {
2024 if (clnt->cl_chatty) {
2025 rcu_read_lock();
2026 printk(KERN_NOTICE "%s: server %s OK\n",
2027 clnt->cl_program->name,
2028 rcu_dereference(clnt->cl_xprt)->servername);
2029 rcu_read_unlock();
2031 task->tk_flags &= ~RPC_CALL_MAJORSEEN;
2035 * Ensure that we see all writes made by xprt_complete_rqst()
2036 * before it changed req->rq_reply_bytes_recvd.
2038 smp_rmb();
2039 req->rq_rcv_buf.len = req->rq_private_buf.len;
2041 /* Check that the softirq receive buffer is valid */
2042 WARN_ON(memcmp(&req->rq_rcv_buf, &req->rq_private_buf,
2043 sizeof(req->rq_rcv_buf)) != 0);
2045 if (req->rq_rcv_buf.len < 12) {
2046 if (!RPC_IS_SOFT(task)) {
2047 task->tk_action = call_bind;
2048 clnt->cl_stats->rpcretrans++;
2049 goto out_retry;
2051 dprintk("RPC: %s: too small RPC reply size (%d bytes)\n",
2052 clnt->cl_program->name, task->tk_status);
2053 task->tk_action = call_timeout;
2054 goto out_retry;
2057 p = rpc_verify_header(task);
2058 if (IS_ERR(p)) {
2059 if (p == ERR_PTR(-EAGAIN))
2060 goto out_retry;
2061 return;
2064 task->tk_action = rpc_exit_task;
2066 if (decode) {
2067 task->tk_status = rpcauth_unwrap_resp(task, decode, req, p,
2068 task->tk_msg.rpc_resp);
2070 dprintk("RPC: %5u call_decode result %d\n", task->tk_pid,
2071 task->tk_status);
2072 return;
2073 out_retry:
2074 task->tk_status = 0;
2075 /* Note: rpc_verify_header() may have freed the RPC slot */
2076 if (task->tk_rqstp == req) {
2077 req->rq_reply_bytes_recvd = req->rq_rcv_buf.len = 0;
2078 if (task->tk_client->cl_discrtry)
2079 xprt_conditional_disconnect(req->rq_xprt,
2080 req->rq_connect_cookie);
2084 static __be32 *
2085 rpc_encode_header(struct rpc_task *task)
2087 struct rpc_clnt *clnt = task->tk_client;
2088 struct rpc_rqst *req = task->tk_rqstp;
2089 __be32 *p = req->rq_svec[0].iov_base;
2091 /* FIXME: check buffer size? */
2093 p = xprt_skip_transport_header(req->rq_xprt, p);
2094 *p++ = req->rq_xid; /* XID */
2095 *p++ = htonl(RPC_CALL); /* CALL */
2096 *p++ = htonl(RPC_VERSION); /* RPC version */
2097 *p++ = htonl(clnt->cl_prog); /* program number */
2098 *p++ = htonl(clnt->cl_vers); /* program version */
2099 *p++ = htonl(task->tk_msg.rpc_proc->p_proc); /* procedure */
2100 p = rpcauth_marshcred(task, p);
2101 req->rq_slen = xdr_adjust_iovec(&req->rq_svec[0], p);
2102 return p;
2105 static __be32 *
2106 rpc_verify_header(struct rpc_task *task)
2108 struct rpc_clnt *clnt = task->tk_client;
2109 struct kvec *iov = &task->tk_rqstp->rq_rcv_buf.head[0];
2110 int len = task->tk_rqstp->rq_rcv_buf.len >> 2;
2111 __be32 *p = iov->iov_base;
2112 u32 n;
2113 int error = -EACCES;
2115 if ((task->tk_rqstp->rq_rcv_buf.len & 3) != 0) {
2116 /* RFC-1014 says that the representation of XDR data must be a
2117 * multiple of four bytes
2118 * - if it isn't pointer subtraction in the NFS client may give
2119 * undefined results
2121 dprintk("RPC: %5u %s: XDR representation not a multiple of"
2122 " 4 bytes: 0x%x\n", task->tk_pid, __func__,
2123 task->tk_rqstp->rq_rcv_buf.len);
2124 error = -EIO;
2125 goto out_err;
2127 if ((len -= 3) < 0)
2128 goto out_overflow;
2130 p += 1; /* skip XID */
2131 if ((n = ntohl(*p++)) != RPC_REPLY) {
2132 dprintk("RPC: %5u %s: not an RPC reply: %x\n",
2133 task->tk_pid, __func__, n);
2134 error = -EIO;
2135 goto out_garbage;
2138 if ((n = ntohl(*p++)) != RPC_MSG_ACCEPTED) {
2139 if (--len < 0)
2140 goto out_overflow;
2141 switch ((n = ntohl(*p++))) {
2142 case RPC_AUTH_ERROR:
2143 break;
2144 case RPC_MISMATCH:
2145 dprintk("RPC: %5u %s: RPC call version mismatch!\n",
2146 task->tk_pid, __func__);
2147 error = -EPROTONOSUPPORT;
2148 goto out_err;
2149 default:
2150 dprintk("RPC: %5u %s: RPC call rejected, "
2151 "unknown error: %x\n",
2152 task->tk_pid, __func__, n);
2153 error = -EIO;
2154 goto out_err;
2156 if (--len < 0)
2157 goto out_overflow;
2158 switch ((n = ntohl(*p++))) {
2159 case RPC_AUTH_REJECTEDCRED:
2160 case RPC_AUTH_REJECTEDVERF:
2161 case RPCSEC_GSS_CREDPROBLEM:
2162 case RPCSEC_GSS_CTXPROBLEM:
2163 if (!task->tk_cred_retry)
2164 break;
2165 task->tk_cred_retry--;
2166 dprintk("RPC: %5u %s: retry stale creds\n",
2167 task->tk_pid, __func__);
2168 rpcauth_invalcred(task);
2169 /* Ensure we obtain a new XID! */
2170 xprt_release(task);
2171 task->tk_action = call_reserve;
2172 goto out_retry;
2173 case RPC_AUTH_BADCRED:
2174 case RPC_AUTH_BADVERF:
2175 /* possibly garbled cred/verf? */
2176 if (!task->tk_garb_retry)
2177 break;
2178 task->tk_garb_retry--;
2179 dprintk("RPC: %5u %s: retry garbled creds\n",
2180 task->tk_pid, __func__);
2181 task->tk_action = call_bind;
2182 goto out_retry;
2183 case RPC_AUTH_TOOWEAK:
2184 rcu_read_lock();
2185 printk(KERN_NOTICE "RPC: server %s requires stronger "
2186 "authentication.\n",
2187 rcu_dereference(clnt->cl_xprt)->servername);
2188 rcu_read_unlock();
2189 break;
2190 default:
2191 dprintk("RPC: %5u %s: unknown auth error: %x\n",
2192 task->tk_pid, __func__, n);
2193 error = -EIO;
2195 dprintk("RPC: %5u %s: call rejected %d\n",
2196 task->tk_pid, __func__, n);
2197 goto out_err;
2199 p = rpcauth_checkverf(task, p);
2200 if (IS_ERR(p)) {
2201 error = PTR_ERR(p);
2202 dprintk("RPC: %5u %s: auth check failed with %d\n",
2203 task->tk_pid, __func__, error);
2204 goto out_garbage; /* bad verifier, retry */
2206 len = p - (__be32 *)iov->iov_base - 1;
2207 if (len < 0)
2208 goto out_overflow;
2209 switch ((n = ntohl(*p++))) {
2210 case RPC_SUCCESS:
2211 return p;
2212 case RPC_PROG_UNAVAIL:
2213 dprintk_rcu("RPC: %5u %s: program %u is unsupported "
2214 "by server %s\n", task->tk_pid, __func__,
2215 (unsigned int)clnt->cl_prog,
2216 rcu_dereference(clnt->cl_xprt)->servername);
2217 error = -EPFNOSUPPORT;
2218 goto out_err;
2219 case RPC_PROG_MISMATCH:
2220 dprintk_rcu("RPC: %5u %s: program %u, version %u unsupported "
2221 "by server %s\n", task->tk_pid, __func__,
2222 (unsigned int)clnt->cl_prog,
2223 (unsigned int)clnt->cl_vers,
2224 rcu_dereference(clnt->cl_xprt)->servername);
2225 error = -EPROTONOSUPPORT;
2226 goto out_err;
2227 case RPC_PROC_UNAVAIL:
2228 dprintk_rcu("RPC: %5u %s: proc %s unsupported by program %u, "
2229 "version %u on server %s\n",
2230 task->tk_pid, __func__,
2231 rpc_proc_name(task),
2232 clnt->cl_prog, clnt->cl_vers,
2233 rcu_dereference(clnt->cl_xprt)->servername);
2234 error = -EOPNOTSUPP;
2235 goto out_err;
2236 case RPC_GARBAGE_ARGS:
2237 dprintk("RPC: %5u %s: server saw garbage\n",
2238 task->tk_pid, __func__);
2239 break; /* retry */
2240 default:
2241 dprintk("RPC: %5u %s: server accept status: %x\n",
2242 task->tk_pid, __func__, n);
2243 /* Also retry */
2246 out_garbage:
2247 clnt->cl_stats->rpcgarbage++;
2248 if (task->tk_garb_retry) {
2249 task->tk_garb_retry--;
2250 dprintk("RPC: %5u %s: retrying\n",
2251 task->tk_pid, __func__);
2252 task->tk_action = call_bind;
2253 out_retry:
2254 return ERR_PTR(-EAGAIN);
2256 out_err:
2257 rpc_exit(task, error);
2258 dprintk("RPC: %5u %s: call failed with error %d\n", task->tk_pid,
2259 __func__, error);
2260 return ERR_PTR(error);
2261 out_overflow:
2262 dprintk("RPC: %5u %s: server reply was truncated.\n", task->tk_pid,
2263 __func__);
2264 goto out_garbage;
2267 static void rpcproc_encode_null(void *rqstp, struct xdr_stream *xdr, void *obj)
2271 static int rpcproc_decode_null(void *rqstp, struct xdr_stream *xdr, void *obj)
2273 return 0;
2276 static struct rpc_procinfo rpcproc_null = {
2277 .p_encode = rpcproc_encode_null,
2278 .p_decode = rpcproc_decode_null,
2281 static int rpc_ping(struct rpc_clnt *clnt)
2283 struct rpc_message msg = {
2284 .rpc_proc = &rpcproc_null,
2286 int err;
2287 msg.rpc_cred = authnull_ops.lookup_cred(NULL, NULL, 0);
2288 err = rpc_call_sync(clnt, &msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN);
2289 put_rpccred(msg.rpc_cred);
2290 return err;
2293 struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred, int flags)
2295 struct rpc_message msg = {
2296 .rpc_proc = &rpcproc_null,
2297 .rpc_cred = cred,
2299 struct rpc_task_setup task_setup_data = {
2300 .rpc_client = clnt,
2301 .rpc_message = &msg,
2302 .callback_ops = &rpc_default_ops,
2303 .flags = flags,
2305 return rpc_run_task(&task_setup_data);
2307 EXPORT_SYMBOL_GPL(rpc_call_null);
2309 #ifdef RPC_DEBUG
2310 static void rpc_show_header(void)
2312 printk(KERN_INFO "-pid- flgs status -client- --rqstp- "
2313 "-timeout ---ops--\n");
2316 static void rpc_show_task(const struct rpc_clnt *clnt,
2317 const struct rpc_task *task)
2319 const char *rpc_waitq = "none";
2321 if (RPC_IS_QUEUED(task))
2322 rpc_waitq = rpc_qname(task->tk_waitqueue);
2324 printk(KERN_INFO "%5u %04x %6d %8p %8p %8ld %8p %sv%u %s a:%ps q:%s\n",
2325 task->tk_pid, task->tk_flags, task->tk_status,
2326 clnt, task->tk_rqstp, task->tk_timeout, task->tk_ops,
2327 clnt->cl_program->name, clnt->cl_vers, rpc_proc_name(task),
2328 task->tk_action, rpc_waitq);
2331 void rpc_show_tasks(struct net *net)
2333 struct rpc_clnt *clnt;
2334 struct rpc_task *task;
2335 int header = 0;
2336 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
2338 spin_lock(&sn->rpc_client_lock);
2339 list_for_each_entry(clnt, &sn->all_clients, cl_clients) {
2340 spin_lock(&clnt->cl_lock);
2341 list_for_each_entry(task, &clnt->cl_tasks, tk_task) {
2342 if (!header) {
2343 rpc_show_header();
2344 header++;
2346 rpc_show_task(clnt, task);
2348 spin_unlock(&clnt->cl_lock);
2350 spin_unlock(&sn->rpc_client_lock);
2352 #endif