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