blob: 63bf591310e0ecac8ad172d3358afb4a709f8098 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Chuck Lever55aa4f52005-08-11 16:25:47 -04002 * linux/net/sunrpc/clnt.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/utsname.h>
31
32#include <linux/sunrpc/clnt.h>
33#include <linux/workqueue.h>
34#include <linux/sunrpc/rpc_pipe_fs.h>
35
36#include <linux/nfs.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
45static DECLARE_WAIT_QUEUE_HEAD(destroy_wait);
46
47
48static void call_start(struct rpc_task *task);
49static void call_reserve(struct rpc_task *task);
50static void call_reserveresult(struct rpc_task *task);
51static void call_allocate(struct rpc_task *task);
52static void call_encode(struct rpc_task *task);
53static void call_decode(struct rpc_task *task);
54static void call_bind(struct rpc_task *task);
Chuck Leverda351872005-08-11 16:25:11 -040055static void call_bind_status(struct rpc_task *task);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056static void call_transmit(struct rpc_task *task);
57static void call_status(struct rpc_task *task);
58static void call_refresh(struct rpc_task *task);
59static void call_refreshresult(struct rpc_task *task);
60static void call_timeout(struct rpc_task *task);
61static void call_connect(struct rpc_task *task);
62static void call_connect_status(struct rpc_task *task);
63static u32 * call_header(struct rpc_task *task);
64static u32 * call_verify(struct rpc_task *task);
65
66
67static int
68rpc_setup_pipedir(struct rpc_clnt *clnt, char *dir_name)
69{
Christoph Hellwig278c9952005-07-24 23:53:01 +010070 static unsigned int clntid;
71 char name[128];
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 int error;
73
74 if (dir_name == NULL)
75 return 0;
Christoph Hellwig278c9952005-07-24 23:53:01 +010076
77 retry_parent:
78 clnt->__cl_parent_dentry = rpc_mkdir(NULL, dir_name, NULL);
79 if (IS_ERR(clnt->__cl_parent_dentry)) {
80 error = PTR_ERR(clnt->__cl_parent_dentry);
81 if (error == -EEXIST)
82 goto retry_parent; /* XXX(hch): WTF? */
83
84 printk(KERN_INFO "RPC: Couldn't create pipefs entry %s, error %d\n",
85 dir_name, error);
86 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
Christoph Hellwig278c9952005-07-24 23:53:01 +010088
89
90 retry_child:
91 snprintf(name, sizeof(name), "clnt%x", clntid++);
92 name[sizeof(name) - 1] = '\0';
93
94 clnt->cl_dentry = rpc_mkdir(clnt->__cl_parent_dentry, name, clnt);
95 if (IS_ERR(clnt->cl_dentry)) {
96 error = PTR_ERR(clnt->cl_dentry);
97 if (error == -EEXIST)
98 goto retry_child;
99 printk(KERN_INFO "RPC: Couldn't create pipefs entry %s, error %d\n",
100 name, error);
101 rpc_rmdir(clnt->__cl_parent_dentry);
102 return error;
103 }
104
105 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106}
107
108/*
109 * Create an RPC client
110 * FIXME: This should also take a flags argument (as in task->tk_flags).
111 * It's called (among others) from pmap_create_client, which may in
112 * turn be called by an async task. In this case, rpciod should not be
113 * made to sleep too long.
114 */
115struct rpc_clnt *
Trond Myklebust5ee0ed72005-06-22 17:16:20 +0000116rpc_new_client(struct rpc_xprt *xprt, char *servname,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 struct rpc_program *program, u32 vers,
118 rpc_authflavor_t flavor)
119{
120 struct rpc_version *version;
121 struct rpc_clnt *clnt = NULL;
J. Bruce Fields6a192752005-06-22 17:16:23 +0000122 struct rpc_auth *auth;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 int err;
124 int len;
125
126 dprintk("RPC: creating %s client for %s (xprt %p)\n",
127 program->name, servname, xprt);
128
129 err = -EINVAL;
130 if (!xprt)
131 goto out_err;
132 if (vers >= program->nrvers || !(version = program->version[vers]))
133 goto out_err;
134
135 err = -ENOMEM;
136 clnt = (struct rpc_clnt *) kmalloc(sizeof(*clnt), GFP_KERNEL);
137 if (!clnt)
138 goto out_err;
139 memset(clnt, 0, sizeof(*clnt));
140 atomic_set(&clnt->cl_users, 0);
141 atomic_set(&clnt->cl_count, 1);
142 clnt->cl_parent = clnt;
143
144 clnt->cl_server = clnt->cl_inline_name;
145 len = strlen(servname) + 1;
146 if (len > sizeof(clnt->cl_inline_name)) {
147 char *buf = kmalloc(len, GFP_KERNEL);
148 if (buf != 0)
149 clnt->cl_server = buf;
150 else
151 len = sizeof(clnt->cl_inline_name);
152 }
153 strlcpy(clnt->cl_server, servname, len);
154
155 clnt->cl_xprt = xprt;
156 clnt->cl_procinfo = version->procs;
157 clnt->cl_maxproc = version->nrprocs;
158 clnt->cl_protname = program->name;
159 clnt->cl_pmap = &clnt->cl_pmap_default;
160 clnt->cl_port = xprt->addr.sin_port;
161 clnt->cl_prog = program->number;
162 clnt->cl_vers = version->number;
163 clnt->cl_prot = xprt->prot;
164 clnt->cl_stats = program->stats;
165 rpc_init_wait_queue(&clnt->cl_pmap_default.pm_bindwait, "bindwait");
166
167 if (!clnt->cl_port)
168 clnt->cl_autobind = 1;
169
170 clnt->cl_rtt = &clnt->cl_rtt_default;
171 rpc_init_rtt(&clnt->cl_rtt_default, xprt->timeout.to_initval);
172
173 err = rpc_setup_pipedir(clnt, program->pipe_dir_name);
174 if (err < 0)
175 goto out_no_path;
176
J. Bruce Fields6a192752005-06-22 17:16:23 +0000177 auth = rpcauth_create(flavor, clnt);
178 if (IS_ERR(auth)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 printk(KERN_INFO "RPC: Couldn't create auth handle (flavor %u)\n",
180 flavor);
J. Bruce Fields6a192752005-06-22 17:16:23 +0000181 err = PTR_ERR(auth);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 goto out_no_auth;
183 }
184
185 /* save the nodename */
186 clnt->cl_nodelen = strlen(system_utsname.nodename);
187 if (clnt->cl_nodelen > UNX_MAXNODENAME)
188 clnt->cl_nodelen = UNX_MAXNODENAME;
189 memcpy(clnt->cl_nodename, system_utsname.nodename, clnt->cl_nodelen);
190 return clnt;
191
192out_no_auth:
Christoph Hellwig278c9952005-07-24 23:53:01 +0100193 rpc_rmdir(clnt->cl_dentry);
194 rpc_rmdir(clnt->__cl_parent_dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195out_no_path:
196 if (clnt->cl_server != clnt->cl_inline_name)
197 kfree(clnt->cl_server);
198 kfree(clnt);
199out_err:
Trond Myklebust5b616f52005-06-22 17:16:20 +0000200 xprt_destroy(xprt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 return ERR_PTR(err);
202}
203
Trond Myklebust5ee0ed72005-06-22 17:16:20 +0000204/**
205 * Create an RPC client
206 * @xprt - pointer to xprt struct
207 * @servname - name of server
208 * @info - rpc_program
209 * @version - rpc_program version
210 * @authflavor - rpc_auth flavour to use
211 *
212 * Creates an RPC client structure, then pings the server in order to
213 * determine if it is up, and if it supports this program and version.
214 *
215 * This function should never be called by asynchronous tasks such as
216 * the portmapper.
217 */
218struct rpc_clnt *rpc_create_client(struct rpc_xprt *xprt, char *servname,
219 struct rpc_program *info, u32 version, rpc_authflavor_t authflavor)
220{
221 struct rpc_clnt *clnt;
222 int err;
223
224 clnt = rpc_new_client(xprt, servname, info, version, authflavor);
225 if (IS_ERR(clnt))
226 return clnt;
227 err = rpc_ping(clnt, RPC_TASK_SOFT|RPC_TASK_NOINTR);
228 if (err == 0)
229 return clnt;
230 rpc_shutdown_client(clnt);
231 return ERR_PTR(err);
232}
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234/*
235 * This function clones the RPC client structure. It allows us to share the
236 * same transport while varying parameters such as the authentication
237 * flavour.
238 */
239struct rpc_clnt *
240rpc_clone_client(struct rpc_clnt *clnt)
241{
242 struct rpc_clnt *new;
243
244 new = (struct rpc_clnt *)kmalloc(sizeof(*new), GFP_KERNEL);
245 if (!new)
246 goto out_no_clnt;
247 memcpy(new, clnt, sizeof(*new));
248 atomic_set(&new->cl_count, 1);
249 atomic_set(&new->cl_users, 0);
250 new->cl_parent = clnt;
251 atomic_inc(&clnt->cl_count);
252 /* Duplicate portmapper */
253 rpc_init_wait_queue(&new->cl_pmap_default.pm_bindwait, "bindwait");
254 /* Turn off autobind on clones */
255 new->cl_autobind = 0;
256 new->cl_oneshot = 0;
257 new->cl_dead = 0;
258 rpc_init_rtt(&new->cl_rtt_default, clnt->cl_xprt->timeout.to_initval);
259 if (new->cl_auth)
260 atomic_inc(&new->cl_auth->au_count);
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000261 new->cl_pmap = &new->cl_pmap_default;
262 rpc_init_wait_queue(&new->cl_pmap_default.pm_bindwait, "bindwait");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 return new;
264out_no_clnt:
265 printk(KERN_INFO "RPC: out of memory in %s\n", __FUNCTION__);
266 return ERR_PTR(-ENOMEM);
267}
268
269/*
270 * Properly shut down an RPC client, terminating all outstanding
271 * requests. Note that we must be certain that cl_oneshot and
272 * cl_dead are cleared, or else the client would be destroyed
273 * when the last task releases it.
274 */
275int
276rpc_shutdown_client(struct rpc_clnt *clnt)
277{
278 dprintk("RPC: shutting down %s client for %s, tasks=%d\n",
279 clnt->cl_protname, clnt->cl_server,
280 atomic_read(&clnt->cl_users));
281
282 while (atomic_read(&clnt->cl_users) > 0) {
283 /* Don't let rpc_release_client destroy us */
284 clnt->cl_oneshot = 0;
285 clnt->cl_dead = 0;
286 rpc_killall_tasks(clnt);
287 sleep_on_timeout(&destroy_wait, 1*HZ);
288 }
289
290 if (atomic_read(&clnt->cl_users) < 0) {
291 printk(KERN_ERR "RPC: rpc_shutdown_client clnt %p tasks=%d\n",
292 clnt, atomic_read(&clnt->cl_users));
293#ifdef RPC_DEBUG
294 rpc_show_tasks();
295#endif
296 BUG();
297 }
298
299 return rpc_destroy_client(clnt);
300}
301
302/*
303 * Delete an RPC client
304 */
305int
306rpc_destroy_client(struct rpc_clnt *clnt)
307{
308 if (!atomic_dec_and_test(&clnt->cl_count))
309 return 1;
310 BUG_ON(atomic_read(&clnt->cl_users) != 0);
311
312 dprintk("RPC: destroying %s client for %s\n",
313 clnt->cl_protname, clnt->cl_server);
314 if (clnt->cl_auth) {
315 rpcauth_destroy(clnt->cl_auth);
316 clnt->cl_auth = NULL;
317 }
318 if (clnt->cl_parent != clnt) {
319 rpc_destroy_client(clnt->cl_parent);
320 goto out_free;
321 }
Christoph Hellwig278c9952005-07-24 23:53:01 +0100322 if (clnt->cl_dentry)
323 rpc_rmdir(clnt->cl_dentry);
324 if (clnt->__cl_parent_dentry)
325 rpc_rmdir(clnt->__cl_parent_dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 if (clnt->cl_xprt) {
327 xprt_destroy(clnt->cl_xprt);
328 clnt->cl_xprt = NULL;
329 }
330 if (clnt->cl_server != clnt->cl_inline_name)
331 kfree(clnt->cl_server);
332out_free:
333 kfree(clnt);
334 return 0;
335}
336
337/*
338 * Release an RPC client
339 */
340void
341rpc_release_client(struct rpc_clnt *clnt)
342{
343 dprintk("RPC: rpc_release_client(%p, %d)\n",
344 clnt, atomic_read(&clnt->cl_users));
345
346 if (!atomic_dec_and_test(&clnt->cl_users))
347 return;
348 wake_up(&destroy_wait);
349 if (clnt->cl_oneshot || clnt->cl_dead)
350 rpc_destroy_client(clnt);
351}
352
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000353/**
354 * rpc_bind_new_program - bind a new RPC program to an existing client
355 * @old - old rpc_client
356 * @program - rpc program to set
357 * @vers - rpc program version
358 *
359 * Clones the rpc client and sets up a new RPC program. This is mainly
360 * of use for enabling different RPC programs to share the same transport.
361 * The Sun NFSv2/v3 ACL protocol can do this.
362 */
363struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *old,
364 struct rpc_program *program,
365 int vers)
366{
367 struct rpc_clnt *clnt;
368 struct rpc_version *version;
369 int err;
370
371 BUG_ON(vers >= program->nrvers || !program->version[vers]);
372 version = program->version[vers];
373 clnt = rpc_clone_client(old);
374 if (IS_ERR(clnt))
375 goto out;
376 clnt->cl_procinfo = version->procs;
377 clnt->cl_maxproc = version->nrprocs;
378 clnt->cl_protname = program->name;
379 clnt->cl_prog = program->number;
380 clnt->cl_vers = version->number;
381 clnt->cl_stats = program->stats;
382 err = rpc_ping(clnt, RPC_TASK_SOFT|RPC_TASK_NOINTR);
383 if (err != 0) {
384 rpc_shutdown_client(clnt);
385 clnt = ERR_PTR(err);
386 }
387out:
388 return clnt;
389}
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391/*
392 * Default callback for async RPC calls
393 */
394static void
395rpc_default_callback(struct rpc_task *task)
396{
397}
398
399/*
Trond Myklebust14b218a2005-06-22 17:16:28 +0000400 * Export the signal mask handling for synchronous code that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 * sleeps on RPC calls
402 */
Trond Myklebust14b218a2005-06-22 17:16:28 +0000403#define RPC_INTR_SIGNALS (sigmask(SIGINT) | sigmask(SIGQUIT) | sigmask(SIGKILL))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Trond Myklebust14b218a2005-06-22 17:16:28 +0000405static void rpc_save_sigmask(sigset_t *oldset, int intr)
406{
407 unsigned long sigallow = 0;
408 sigset_t sigmask;
409
410 /* Block all signals except those listed in sigallow */
411 if (intr)
412 sigallow |= RPC_INTR_SIGNALS;
413 siginitsetinv(&sigmask, sigallow);
414 sigprocmask(SIG_BLOCK, &sigmask, oldset);
415}
416
417static inline void rpc_task_sigmask(struct rpc_task *task, sigset_t *oldset)
418{
419 rpc_save_sigmask(oldset, !RPC_TASK_UNINTERRUPTIBLE(task));
420}
421
422static inline void rpc_restore_sigmask(sigset_t *oldset)
423{
424 sigprocmask(SIG_SETMASK, oldset, NULL);
425}
426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427void rpc_clnt_sigmask(struct rpc_clnt *clnt, sigset_t *oldset)
428{
Trond Myklebust14b218a2005-06-22 17:16:28 +0000429 rpc_save_sigmask(oldset, clnt->cl_intr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431
432void rpc_clnt_sigunmask(struct rpc_clnt *clnt, sigset_t *oldset)
433{
Trond Myklebust14b218a2005-06-22 17:16:28 +0000434 rpc_restore_sigmask(oldset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435}
436
437/*
438 * New rpc_call implementation
439 */
440int rpc_call_sync(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
441{
442 struct rpc_task *task;
443 sigset_t oldset;
444 int status;
445
446 /* If this client is slain all further I/O fails */
447 if (clnt->cl_dead)
448 return -EIO;
449
450 BUG_ON(flags & RPC_TASK_ASYNC);
451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 status = -ENOMEM;
453 task = rpc_new_task(clnt, NULL, flags);
454 if (task == NULL)
455 goto out;
456
Trond Myklebust14b218a2005-06-22 17:16:28 +0000457 /* Mask signals on RPC calls _and_ GSS_AUTH upcalls */
458 rpc_task_sigmask(task, &oldset);
459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 rpc_call_setup(task, msg, 0);
461
462 /* Set up the call info struct and execute the task */
Trond Myklebust14b218a2005-06-22 17:16:28 +0000463 if (task->tk_status == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 status = rpc_execute(task);
Trond Myklebust14b218a2005-06-22 17:16:28 +0000465 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 status = task->tk_status;
467 rpc_release_task(task);
468 }
469
Trond Myklebust14b218a2005-06-22 17:16:28 +0000470 rpc_restore_sigmask(&oldset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 return status;
473}
474
475/*
476 * New rpc_call implementation
477 */
478int
479rpc_call_async(struct rpc_clnt *clnt, struct rpc_message *msg, int flags,
480 rpc_action callback, void *data)
481{
482 struct rpc_task *task;
483 sigset_t oldset;
484 int status;
485
486 /* If this client is slain all further I/O fails */
487 if (clnt->cl_dead)
488 return -EIO;
489
490 flags |= RPC_TASK_ASYNC;
491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 /* Create/initialize a new RPC task */
493 if (!callback)
494 callback = rpc_default_callback;
495 status = -ENOMEM;
496 if (!(task = rpc_new_task(clnt, callback, flags)))
497 goto out;
498 task->tk_calldata = data;
499
Trond Myklebust14b218a2005-06-22 17:16:28 +0000500 /* Mask signals on GSS_AUTH upcalls */
501 rpc_task_sigmask(task, &oldset);
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 rpc_call_setup(task, msg, 0);
504
505 /* Set up the call info struct and execute the task */
506 status = task->tk_status;
507 if (status == 0)
508 rpc_execute(task);
509 else
510 rpc_release_task(task);
511
Trond Myklebust14b218a2005-06-22 17:16:28 +0000512 rpc_restore_sigmask(&oldset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 return status;
515}
516
517
518void
519rpc_call_setup(struct rpc_task *task, struct rpc_message *msg, int flags)
520{
521 task->tk_msg = *msg;
522 task->tk_flags |= flags;
523 /* Bind the user cred */
524 if (task->tk_msg.rpc_cred != NULL)
525 rpcauth_holdcred(task);
526 else
527 rpcauth_bindcred(task);
528
529 if (task->tk_status == 0)
530 task->tk_action = call_start;
531 else
532 task->tk_action = NULL;
533}
534
535void
536rpc_setbufsize(struct rpc_clnt *clnt, unsigned int sndsize, unsigned int rcvsize)
537{
538 struct rpc_xprt *xprt = clnt->cl_xprt;
Chuck Lever470056c2005-08-25 16:25:56 -0700539 if (xprt->ops->set_buffer_size)
540 xprt->ops->set_buffer_size(xprt, sndsize, rcvsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541}
542
543/*
544 * Return size of largest payload RPC client can support, in bytes
545 *
546 * For stream transports, this is one RPC record fragment (see RFC
547 * 1831), as we don't support multi-record requests yet. For datagram
548 * transports, this is the size of an IP packet minus the IP, UDP, and
549 * RPC header sizes.
550 */
551size_t rpc_max_payload(struct rpc_clnt *clnt)
552{
553 return clnt->cl_xprt->max_payload;
554}
555EXPORT_SYMBOL(rpc_max_payload);
556
557/*
558 * Restart an (async) RPC call. Usually called from within the
559 * exit handler.
560 */
561void
562rpc_restart_call(struct rpc_task *task)
563{
564 if (RPC_ASSASSINATED(task))
565 return;
566
567 task->tk_action = call_start;
568}
569
570/*
571 * 0. Initial state
572 *
573 * Other FSM states can be visited zero or more times, but
574 * this state is visited exactly once for each RPC.
575 */
576static void
577call_start(struct rpc_task *task)
578{
579 struct rpc_clnt *clnt = task->tk_client;
580
581 dprintk("RPC: %4d call_start %s%d proc %d (%s)\n", task->tk_pid,
582 clnt->cl_protname, clnt->cl_vers, task->tk_msg.rpc_proc->p_proc,
583 (RPC_IS_ASYNC(task) ? "async" : "sync"));
584
585 /* Increment call count */
586 task->tk_msg.rpc_proc->p_count++;
587 clnt->cl_stats->rpccnt++;
588 task->tk_action = call_reserve;
589}
590
591/*
592 * 1. Reserve an RPC call slot
593 */
594static void
595call_reserve(struct rpc_task *task)
596{
597 dprintk("RPC: %4d call_reserve\n", task->tk_pid);
598
599 if (!rpcauth_uptodatecred(task)) {
600 task->tk_action = call_refresh;
601 return;
602 }
603
604 task->tk_status = 0;
605 task->tk_action = call_reserveresult;
606 xprt_reserve(task);
607}
608
609/*
610 * 1b. Grok the result of xprt_reserve()
611 */
612static void
613call_reserveresult(struct rpc_task *task)
614{
615 int status = task->tk_status;
616
617 dprintk("RPC: %4d call_reserveresult (status %d)\n",
618 task->tk_pid, task->tk_status);
619
620 /*
621 * After a call to xprt_reserve(), we must have either
622 * a request slot or else an error status.
623 */
624 task->tk_status = 0;
625 if (status >= 0) {
626 if (task->tk_rqstp) {
627 task->tk_action = call_allocate;
628 return;
629 }
630
631 printk(KERN_ERR "%s: status=%d, but no request slot, exiting\n",
632 __FUNCTION__, status);
633 rpc_exit(task, -EIO);
634 return;
635 }
636
637 /*
638 * Even though there was an error, we may have acquired
639 * a request slot somehow. Make sure not to leak it.
640 */
641 if (task->tk_rqstp) {
642 printk(KERN_ERR "%s: status=%d, request allocated anyway\n",
643 __FUNCTION__, status);
644 xprt_release(task);
645 }
646
647 switch (status) {
648 case -EAGAIN: /* woken up; retry */
649 task->tk_action = call_reserve;
650 return;
651 case -EIO: /* probably a shutdown */
652 break;
653 default:
654 printk(KERN_ERR "%s: unrecognized error %d, exiting\n",
655 __FUNCTION__, status);
656 break;
657 }
658 rpc_exit(task, status);
659}
660
661/*
662 * 2. Allocate the buffer. For details, see sched.c:rpc_malloc.
663 * (Note: buffer memory is freed in rpc_task_release).
664 */
665static void
666call_allocate(struct rpc_task *task)
667{
668 unsigned int bufsiz;
669
670 dprintk("RPC: %4d call_allocate (status %d)\n",
671 task->tk_pid, task->tk_status);
672 task->tk_action = call_bind;
673 if (task->tk_buffer)
674 return;
675
676 /* FIXME: compute buffer requirements more exactly using
677 * auth->au_wslack */
678 bufsiz = task->tk_msg.rpc_proc->p_bufsiz + RPC_SLACK_SPACE;
679
680 if (rpc_malloc(task, bufsiz << 1) != NULL)
681 return;
682 printk(KERN_INFO "RPC: buffer allocation failed for task %p\n", task);
683
Trond Myklebust14b218a2005-06-22 17:16:28 +0000684 if (RPC_IS_ASYNC(task) || !signalled()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 xprt_release(task);
686 task->tk_action = call_reserve;
687 rpc_delay(task, HZ>>4);
688 return;
689 }
690
691 rpc_exit(task, -ERESTARTSYS);
692}
693
694/*
695 * 3. Encode arguments of an RPC call
696 */
697static void
698call_encode(struct rpc_task *task)
699{
700 struct rpc_clnt *clnt = task->tk_client;
701 struct rpc_rqst *req = task->tk_rqstp;
702 struct xdr_buf *sndbuf = &req->rq_snd_buf;
703 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
704 unsigned int bufsiz;
705 kxdrproc_t encode;
706 int status;
707 u32 *p;
708
709 dprintk("RPC: %4d call_encode (status %d)\n",
710 task->tk_pid, task->tk_status);
711
712 /* Default buffer setup */
713 bufsiz = task->tk_bufsize >> 1;
714 sndbuf->head[0].iov_base = (void *)task->tk_buffer;
715 sndbuf->head[0].iov_len = bufsiz;
716 sndbuf->tail[0].iov_len = 0;
717 sndbuf->page_len = 0;
718 sndbuf->len = 0;
719 sndbuf->buflen = bufsiz;
720 rcvbuf->head[0].iov_base = (void *)((char *)task->tk_buffer + bufsiz);
721 rcvbuf->head[0].iov_len = bufsiz;
722 rcvbuf->tail[0].iov_len = 0;
723 rcvbuf->page_len = 0;
724 rcvbuf->len = 0;
725 rcvbuf->buflen = bufsiz;
726
727 /* Encode header and provided arguments */
728 encode = task->tk_msg.rpc_proc->p_encode;
729 if (!(p = call_header(task))) {
730 printk(KERN_INFO "RPC: call_header failed, exit EIO\n");
731 rpc_exit(task, -EIO);
732 return;
733 }
734 if (encode && (status = rpcauth_wrap_req(task, encode, req, p,
735 task->tk_msg.rpc_argp)) < 0) {
736 printk(KERN_WARNING "%s: can't encode arguments: %d\n",
737 clnt->cl_protname, -status);
738 rpc_exit(task, status);
739 }
740}
741
742/*
743 * 4. Get the server port number if not yet set
744 */
745static void
746call_bind(struct rpc_task *task)
747{
748 struct rpc_clnt *clnt = task->tk_client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
Chuck Leverda351872005-08-11 16:25:11 -0400750 dprintk("RPC: %4d call_bind (status %d)\n",
751 task->tk_pid, task->tk_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Chuck Leverda351872005-08-11 16:25:11 -0400753 task->tk_action = call_connect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 if (!clnt->cl_port) {
Chuck Leverda351872005-08-11 16:25:11 -0400755 task->tk_action = call_bind_status;
Chuck Lever03bf4b72005-08-25 16:25:55 -0700756 task->tk_timeout = task->tk_xprt->bind_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 rpc_getport(task, clnt);
758 }
759}
760
761/*
Chuck Leverda351872005-08-11 16:25:11 -0400762 * 4a. Sort out bind result
763 */
764static void
765call_bind_status(struct rpc_task *task)
766{
767 int status = -EACCES;
768
769 if (task->tk_status >= 0) {
770 dprintk("RPC: %4d call_bind_status (status %d)\n",
771 task->tk_pid, task->tk_status);
772 task->tk_status = 0;
773 task->tk_action = call_connect;
774 return;
775 }
776
777 switch (task->tk_status) {
778 case -EACCES:
779 dprintk("RPC: %4d remote rpcbind: RPC program/version unavailable\n",
780 task->tk_pid);
781 break;
782 case -ETIMEDOUT:
783 dprintk("RPC: %4d rpcbind request timed out\n",
784 task->tk_pid);
785 if (RPC_IS_SOFT(task)) {
786 status = -EIO;
787 break;
788 }
789 goto retry_bind;
790 case -EPFNOSUPPORT:
791 dprintk("RPC: %4d remote rpcbind service unavailable\n",
792 task->tk_pid);
793 break;
794 case -EPROTONOSUPPORT:
795 dprintk("RPC: %4d remote rpcbind version 2 unavailable\n",
796 task->tk_pid);
797 break;
798 default:
799 dprintk("RPC: %4d unrecognized rpcbind error (%d)\n",
800 task->tk_pid, -task->tk_status);
801 status = -EIO;
802 break;
803 }
804
805 rpc_exit(task, status);
806 return;
807
808retry_bind:
809 task->tk_status = 0;
810 task->tk_action = call_bind;
811 return;
812}
813
814/*
815 * 4b. Connect to the RPC server
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 */
817static void
818call_connect(struct rpc_task *task)
819{
Chuck Leverda351872005-08-11 16:25:11 -0400820 struct rpc_xprt *xprt = task->tk_xprt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Chuck Leverda351872005-08-11 16:25:11 -0400822 dprintk("RPC: %4d call_connect xprt %p %s connected\n",
823 task->tk_pid, xprt,
824 (xprt_connected(xprt) ? "is" : "is not"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
Chuck Leverda351872005-08-11 16:25:11 -0400826 task->tk_action = call_transmit;
827 if (!xprt_connected(xprt)) {
828 task->tk_action = call_connect_status;
829 if (task->tk_status < 0)
830 return;
831 xprt_connect(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833}
834
835/*
Chuck Leverda351872005-08-11 16:25:11 -0400836 * 4c. Sort out connect result
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 */
838static void
839call_connect_status(struct rpc_task *task)
840{
841 struct rpc_clnt *clnt = task->tk_client;
842 int status = task->tk_status;
843
Chuck Leverda351872005-08-11 16:25:11 -0400844 dprintk("RPC: %5u call_connect_status (status %d)\n",
845 task->tk_pid, task->tk_status);
846
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 task->tk_status = 0;
848 if (status >= 0) {
849 clnt->cl_stats->netreconn++;
850 task->tk_action = call_transmit;
851 return;
852 }
853
Chuck Leverda351872005-08-11 16:25:11 -0400854 /* Something failed: remote service port may have changed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 if (clnt->cl_autobind)
856 clnt->cl_port = 0;
Chuck Leverda351872005-08-11 16:25:11 -0400857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 switch (status) {
859 case -ENOTCONN:
860 case -ETIMEDOUT:
861 case -EAGAIN:
Chuck Leverda351872005-08-11 16:25:11 -0400862 task->tk_action = call_bind;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 break;
864 default:
865 rpc_exit(task, -EIO);
Chuck Leverda351872005-08-11 16:25:11 -0400866 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 }
868}
869
870/*
871 * 5. Transmit the RPC request, and wait for reply
872 */
873static void
874call_transmit(struct rpc_task *task)
875{
876 dprintk("RPC: %4d call_transmit (status %d)\n",
877 task->tk_pid, task->tk_status);
878
879 task->tk_action = call_status;
880 if (task->tk_status < 0)
881 return;
882 task->tk_status = xprt_prepare_transmit(task);
883 if (task->tk_status != 0)
884 return;
885 /* Encode here so that rpcsec_gss can use correct sequence number. */
886 if (!task->tk_rqstp->rq_bytes_sent)
887 call_encode(task);
888 if (task->tk_status < 0)
889 return;
890 xprt_transmit(task);
891 if (task->tk_status < 0)
892 return;
893 if (!task->tk_msg.rpc_proc->p_decode) {
894 task->tk_action = NULL;
895 rpc_wake_up_task(task);
896 }
897}
898
899/*
900 * 6. Sort out the RPC call status
901 */
902static void
903call_status(struct rpc_task *task)
904{
905 struct rpc_clnt *clnt = task->tk_client;
906 struct rpc_rqst *req = task->tk_rqstp;
907 int status;
908
909 if (req->rq_received > 0 && !req->rq_bytes_sent)
910 task->tk_status = req->rq_received;
911
912 dprintk("RPC: %4d call_status (status %d)\n",
913 task->tk_pid, task->tk_status);
914
915 status = task->tk_status;
916 if (status >= 0) {
917 task->tk_action = call_decode;
918 return;
919 }
920
921 task->tk_status = 0;
922 switch(status) {
923 case -ETIMEDOUT:
924 task->tk_action = call_timeout;
925 break;
926 case -ECONNREFUSED:
927 case -ENOTCONN:
928 req->rq_bytes_sent = 0;
929 if (clnt->cl_autobind)
930 clnt->cl_port = 0;
931 task->tk_action = call_bind;
932 break;
933 case -EAGAIN:
934 task->tk_action = call_transmit;
935 break;
936 case -EIO:
937 /* shutdown or soft timeout */
938 rpc_exit(task, status);
939 break;
940 default:
941 if (clnt->cl_chatty)
942 printk("%s: RPC call returned error %d\n",
943 clnt->cl_protname, -status);
944 rpc_exit(task, status);
945 break;
946 }
947}
948
949/*
950 * 6a. Handle RPC timeout
951 * We do not release the request slot, so we keep using the
952 * same XID for all retransmits.
953 */
954static void
955call_timeout(struct rpc_task *task)
956{
957 struct rpc_clnt *clnt = task->tk_client;
958
959 if (xprt_adjust_timeout(task->tk_rqstp) == 0) {
960 dprintk("RPC: %4d call_timeout (minor)\n", task->tk_pid);
961 goto retry;
962 }
963
964 dprintk("RPC: %4d call_timeout (major)\n", task->tk_pid);
965 if (RPC_IS_SOFT(task)) {
966 if (clnt->cl_chatty)
967 printk(KERN_NOTICE "%s: server %s not responding, timed out\n",
968 clnt->cl_protname, clnt->cl_server);
969 rpc_exit(task, -EIO);
970 return;
971 }
972
973 if (clnt->cl_chatty && !(task->tk_flags & RPC_CALL_MAJORSEEN)) {
974 task->tk_flags |= RPC_CALL_MAJORSEEN;
975 printk(KERN_NOTICE "%s: server %s not responding, still trying\n",
976 clnt->cl_protname, clnt->cl_server);
977 }
978 if (clnt->cl_autobind)
979 clnt->cl_port = 0;
980
981retry:
982 clnt->cl_stats->rpcretrans++;
983 task->tk_action = call_bind;
984 task->tk_status = 0;
985}
986
987/*
988 * 7. Decode the RPC reply
989 */
990static void
991call_decode(struct rpc_task *task)
992{
993 struct rpc_clnt *clnt = task->tk_client;
994 struct rpc_rqst *req = task->tk_rqstp;
995 kxdrproc_t decode = task->tk_msg.rpc_proc->p_decode;
996 u32 *p;
997
998 dprintk("RPC: %4d call_decode (status %d)\n",
999 task->tk_pid, task->tk_status);
1000
1001 if (clnt->cl_chatty && (task->tk_flags & RPC_CALL_MAJORSEEN)) {
1002 printk(KERN_NOTICE "%s: server %s OK\n",
1003 clnt->cl_protname, clnt->cl_server);
1004 task->tk_flags &= ~RPC_CALL_MAJORSEEN;
1005 }
1006
1007 if (task->tk_status < 12) {
1008 if (!RPC_IS_SOFT(task)) {
1009 task->tk_action = call_bind;
1010 clnt->cl_stats->rpcretrans++;
1011 goto out_retry;
1012 }
1013 printk(KERN_WARNING "%s: too small RPC reply size (%d bytes)\n",
1014 clnt->cl_protname, task->tk_status);
1015 rpc_exit(task, -EIO);
1016 return;
1017 }
1018
1019 req->rq_rcv_buf.len = req->rq_private_buf.len;
1020
1021 /* Check that the softirq receive buffer is valid */
1022 WARN_ON(memcmp(&req->rq_rcv_buf, &req->rq_private_buf,
1023 sizeof(req->rq_rcv_buf)) != 0);
1024
1025 /* Verify the RPC header */
1026 if (!(p = call_verify(task))) {
1027 if (task->tk_action == NULL)
1028 return;
1029 goto out_retry;
1030 }
1031
1032 task->tk_action = NULL;
1033
1034 if (decode)
1035 task->tk_status = rpcauth_unwrap_resp(task, decode, req, p,
1036 task->tk_msg.rpc_resp);
1037 dprintk("RPC: %4d call_decode result %d\n", task->tk_pid,
1038 task->tk_status);
1039 return;
1040out_retry:
1041 req->rq_received = req->rq_private_buf.len = 0;
1042 task->tk_status = 0;
1043}
1044
1045/*
1046 * 8. Refresh the credentials if rejected by the server
1047 */
1048static void
1049call_refresh(struct rpc_task *task)
1050{
1051 dprintk("RPC: %4d call_refresh\n", task->tk_pid);
1052
1053 xprt_release(task); /* Must do to obtain new XID */
1054 task->tk_action = call_refreshresult;
1055 task->tk_status = 0;
1056 task->tk_client->cl_stats->rpcauthrefresh++;
1057 rpcauth_refreshcred(task);
1058}
1059
1060/*
1061 * 8a. Process the results of a credential refresh
1062 */
1063static void
1064call_refreshresult(struct rpc_task *task)
1065{
1066 int status = task->tk_status;
1067 dprintk("RPC: %4d call_refreshresult (status %d)\n",
1068 task->tk_pid, task->tk_status);
1069
1070 task->tk_status = 0;
1071 task->tk_action = call_reserve;
1072 if (status >= 0 && rpcauth_uptodatecred(task))
1073 return;
1074 if (status == -EACCES) {
1075 rpc_exit(task, -EACCES);
1076 return;
1077 }
1078 task->tk_action = call_refresh;
1079 if (status != -ETIMEDOUT)
1080 rpc_delay(task, 3*HZ);
1081 return;
1082}
1083
1084/*
1085 * Call header serialization
1086 */
1087static u32 *
1088call_header(struct rpc_task *task)
1089{
1090 struct rpc_clnt *clnt = task->tk_client;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 struct rpc_rqst *req = task->tk_rqstp;
1092 u32 *p = req->rq_svec[0].iov_base;
1093
1094 /* FIXME: check buffer size? */
Chuck Lever808012f2005-08-25 16:25:49 -07001095
1096 p = xprt_skip_transport_header(task->tk_xprt, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 *p++ = req->rq_xid; /* XID */
1098 *p++ = htonl(RPC_CALL); /* CALL */
1099 *p++ = htonl(RPC_VERSION); /* RPC version */
1100 *p++ = htonl(clnt->cl_prog); /* program number */
1101 *p++ = htonl(clnt->cl_vers); /* program version */
1102 *p++ = htonl(task->tk_msg.rpc_proc->p_proc); /* procedure */
Trond Myklebust334ccfd2005-06-22 17:16:19 +00001103 p = rpcauth_marshcred(task, p);
1104 req->rq_slen = xdr_adjust_iovec(&req->rq_svec[0], p);
1105 return p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106}
1107
1108/*
1109 * Reply header verification
1110 */
1111static u32 *
1112call_verify(struct rpc_task *task)
1113{
1114 struct kvec *iov = &task->tk_rqstp->rq_rcv_buf.head[0];
1115 int len = task->tk_rqstp->rq_rcv_buf.len >> 2;
1116 u32 *p = iov->iov_base, n;
1117 int error = -EACCES;
1118
1119 if ((len -= 3) < 0)
1120 goto out_overflow;
1121 p += 1; /* skip XID */
1122
1123 if ((n = ntohl(*p++)) != RPC_REPLY) {
1124 printk(KERN_WARNING "call_verify: not an RPC reply: %x\n", n);
1125 goto out_retry;
1126 }
1127 if ((n = ntohl(*p++)) != RPC_MSG_ACCEPTED) {
1128 if (--len < 0)
1129 goto out_overflow;
1130 switch ((n = ntohl(*p++))) {
1131 case RPC_AUTH_ERROR:
1132 break;
1133 case RPC_MISMATCH:
Andreas Gruenbachercdf47702005-06-22 17:16:23 +00001134 dprintk("%s: RPC call version mismatch!\n", __FUNCTION__);
1135 error = -EPROTONOSUPPORT;
1136 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 default:
Andreas Gruenbachercdf47702005-06-22 17:16:23 +00001138 dprintk("%s: RPC call rejected, unknown error: %x\n", __FUNCTION__, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 goto out_eio;
1140 }
1141 if (--len < 0)
1142 goto out_overflow;
1143 switch ((n = ntohl(*p++))) {
1144 case RPC_AUTH_REJECTEDCRED:
1145 case RPC_AUTH_REJECTEDVERF:
1146 case RPCSEC_GSS_CREDPROBLEM:
1147 case RPCSEC_GSS_CTXPROBLEM:
1148 if (!task->tk_cred_retry)
1149 break;
1150 task->tk_cred_retry--;
1151 dprintk("RPC: %4d call_verify: retry stale creds\n",
1152 task->tk_pid);
1153 rpcauth_invalcred(task);
1154 task->tk_action = call_refresh;
1155 return NULL;
1156 case RPC_AUTH_BADCRED:
1157 case RPC_AUTH_BADVERF:
1158 /* possibly garbled cred/verf? */
1159 if (!task->tk_garb_retry)
1160 break;
1161 task->tk_garb_retry--;
1162 dprintk("RPC: %4d call_verify: retry garbled creds\n",
1163 task->tk_pid);
1164 task->tk_action = call_bind;
1165 return NULL;
1166 case RPC_AUTH_TOOWEAK:
1167 printk(KERN_NOTICE "call_verify: server requires stronger "
1168 "authentication.\n");
1169 break;
1170 default:
1171 printk(KERN_WARNING "call_verify: unknown auth error: %x\n", n);
1172 error = -EIO;
1173 }
1174 dprintk("RPC: %4d call_verify: call rejected %d\n",
1175 task->tk_pid, n);
1176 goto out_err;
1177 }
1178 if (!(p = rpcauth_checkverf(task, p))) {
1179 printk(KERN_WARNING "call_verify: auth check failed\n");
1180 goto out_retry; /* bad verifier, retry */
1181 }
1182 len = p - (u32 *)iov->iov_base - 1;
1183 if (len < 0)
1184 goto out_overflow;
1185 switch ((n = ntohl(*p++))) {
1186 case RPC_SUCCESS:
1187 return p;
1188 case RPC_PROG_UNAVAIL:
Andreas Gruenbachercdf47702005-06-22 17:16:23 +00001189 dprintk("RPC: call_verify: program %u is unsupported by server %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 (unsigned int)task->tk_client->cl_prog,
1191 task->tk_client->cl_server);
Andreas Gruenbachercdf47702005-06-22 17:16:23 +00001192 error = -EPFNOSUPPORT;
1193 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 case RPC_PROG_MISMATCH:
Andreas Gruenbachercdf47702005-06-22 17:16:23 +00001195 dprintk("RPC: call_verify: program %u, version %u unsupported by server %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 (unsigned int)task->tk_client->cl_prog,
1197 (unsigned int)task->tk_client->cl_vers,
1198 task->tk_client->cl_server);
Andreas Gruenbachercdf47702005-06-22 17:16:23 +00001199 error = -EPROTONOSUPPORT;
1200 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 case RPC_PROC_UNAVAIL:
Andreas Gruenbachercdf47702005-06-22 17:16:23 +00001202 dprintk("RPC: call_verify: proc %p unsupported by program %u, version %u on server %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 task->tk_msg.rpc_proc,
1204 task->tk_client->cl_prog,
1205 task->tk_client->cl_vers,
1206 task->tk_client->cl_server);
Andreas Gruenbachercdf47702005-06-22 17:16:23 +00001207 error = -EOPNOTSUPP;
1208 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 case RPC_GARBAGE_ARGS:
1210 dprintk("RPC: %4d %s: server saw garbage\n", task->tk_pid, __FUNCTION__);
1211 break; /* retry */
1212 default:
1213 printk(KERN_WARNING "call_verify: server accept status: %x\n", n);
1214 /* Also retry */
1215 }
1216
1217out_retry:
1218 task->tk_client->cl_stats->rpcgarbage++;
1219 if (task->tk_garb_retry) {
1220 task->tk_garb_retry--;
Andreas Gruenbachercdf47702005-06-22 17:16:23 +00001221 dprintk("RPC %s: retrying %4d\n", __FUNCTION__, task->tk_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 task->tk_action = call_bind;
1223 return NULL;
1224 }
1225 printk(KERN_WARNING "RPC %s: retry failed, exit EIO\n", __FUNCTION__);
1226out_eio:
1227 error = -EIO;
1228out_err:
1229 rpc_exit(task, error);
1230 return NULL;
1231out_overflow:
1232 printk(KERN_WARNING "RPC %s: server reply was truncated.\n", __FUNCTION__);
1233 goto out_retry;
1234}
Trond Myklebust5ee0ed72005-06-22 17:16:20 +00001235
1236static int rpcproc_encode_null(void *rqstp, u32 *data, void *obj)
1237{
1238 return 0;
1239}
1240
1241static int rpcproc_decode_null(void *rqstp, u32 *data, void *obj)
1242{
1243 return 0;
1244}
1245
1246static struct rpc_procinfo rpcproc_null = {
1247 .p_encode = rpcproc_encode_null,
1248 .p_decode = rpcproc_decode_null,
1249};
1250
1251int rpc_ping(struct rpc_clnt *clnt, int flags)
1252{
1253 struct rpc_message msg = {
1254 .rpc_proc = &rpcproc_null,
1255 };
1256 int err;
1257 msg.rpc_cred = authnull_ops.lookup_cred(NULL, NULL, 0);
1258 err = rpc_call_sync(clnt, &msg, flags);
1259 put_rpccred(msg.rpc_cred);
1260 return err;
1261}