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