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