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