2 * linux/net/sunrpc/clnt.c
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.
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.
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.
20 * Copyright (C) 1992,1993 Rick Sladkey <jrs@world.std.com>
21 * Copyright (C) 1995,1996 Olaf Kirch <okir@monad.swb.de>
24 #include <asm/system.h>
26 #include <linux/module.h>
27 #include <linux/types.h>
29 #include <linux/slab.h>
30 #include <linux/utsname.h>
32 #include <linux/sunrpc/clnt.h>
33 #include <linux/workqueue.h>
34 #include <linux/sunrpc/rpc_pipe_fs.h>
36 #include <linux/nfs.h>
39 #define RPC_SLACK_SPACE (1024) /* total overkill */
42 # define RPCDBG_FACILITY RPCDBG_CALL
45 static DECLARE_WAIT_QUEUE_HEAD(destroy_wait);
48 static void call_start(struct rpc_task *task);
49 static void call_reserve(struct rpc_task *task);
50 static void call_reserveresult(struct rpc_task *task);
51 static void call_allocate(struct rpc_task *task);
52 static void call_encode(struct rpc_task *task);
53 static void call_decode(struct rpc_task *task);
54 static void call_bind(struct rpc_task *task);
55 static void call_bind_status(struct rpc_task *task);
56 static void call_transmit(struct rpc_task *task);
57 static void call_status(struct rpc_task *task);
58 static void call_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);
68 rpc_setup_pipedir(struct rpc_clnt *clnt, char *dir_name)
70 static uint32_t clntid;
76 snprintf(clnt->cl_pathname, sizeof(clnt->cl_pathname),
77 "%s/clnt%x", dir_name,
78 (unsigned int)clntid++);
79 clnt->cl_pathname[sizeof(clnt->cl_pathname) - 1] = '\0';
80 clnt->cl_dentry = rpc_mkdir(clnt->cl_pathname, clnt);
81 if (!IS_ERR(clnt->cl_dentry))
83 error = PTR_ERR(clnt->cl_dentry);
84 if (error != -EEXIST) {
85 printk(KERN_INFO "RPC: Couldn't create pipefs entry %s, error %d\n",
86 clnt->cl_pathname, error);
93 * Create an RPC client
94 * FIXME: This should also take a flags argument (as in task->tk_flags).
95 * It's called (among others) from pmap_create_client, which may in
96 * turn be called by an async task. In this case, rpciod should not be
97 * made to sleep too long.
100 rpc_new_client(struct rpc_xprt *xprt, char *servname,
101 struct rpc_program *program, u32 vers,
102 rpc_authflavor_t flavor)
104 struct rpc_version *version;
105 struct rpc_clnt *clnt = NULL;
106 struct rpc_auth *auth;
110 dprintk("RPC: creating %s client for %s (xprt %p)\n",
111 program->name, servname, xprt);
116 if (vers >= program->nrvers || !(version = program->version[vers]))
120 clnt = (struct rpc_clnt *) kmalloc(sizeof(*clnt), GFP_KERNEL);
123 memset(clnt, 0, sizeof(*clnt));
124 atomic_set(&clnt->cl_users, 0);
125 atomic_set(&clnt->cl_count, 1);
126 clnt->cl_parent = clnt;
128 clnt->cl_server = clnt->cl_inline_name;
129 len = strlen(servname) + 1;
130 if (len > sizeof(clnt->cl_inline_name)) {
131 char *buf = kmalloc(len, GFP_KERNEL);
133 clnt->cl_server = buf;
135 len = sizeof(clnt->cl_inline_name);
137 strlcpy(clnt->cl_server, servname, len);
139 clnt->cl_xprt = xprt;
140 clnt->cl_procinfo = version->procs;
141 clnt->cl_maxproc = version->nrprocs;
142 clnt->cl_protname = program->name;
143 clnt->cl_pmap = &clnt->cl_pmap_default;
144 clnt->cl_port = xprt->addr.sin_port;
145 clnt->cl_prog = program->number;
146 clnt->cl_vers = version->number;
147 clnt->cl_prot = xprt->prot;
148 clnt->cl_stats = program->stats;
149 rpc_init_wait_queue(&clnt->cl_pmap_default.pm_bindwait, "bindwait");
152 clnt->cl_autobind = 1;
154 clnt->cl_rtt = &clnt->cl_rtt_default;
155 rpc_init_rtt(&clnt->cl_rtt_default, xprt->timeout.to_initval);
157 err = rpc_setup_pipedir(clnt, program->pipe_dir_name);
161 auth = rpcauth_create(flavor, clnt);
163 printk(KERN_INFO "RPC: Couldn't create auth handle (flavor %u)\n",
169 /* save the nodename */
170 clnt->cl_nodelen = strlen(system_utsname.nodename);
171 if (clnt->cl_nodelen > UNX_MAXNODENAME)
172 clnt->cl_nodelen = UNX_MAXNODENAME;
173 memcpy(clnt->cl_nodename, system_utsname.nodename, clnt->cl_nodelen);
177 rpc_rmdir(clnt->cl_pathname);
179 if (clnt->cl_server != clnt->cl_inline_name)
180 kfree(clnt->cl_server);
188 * Create an RPC client
189 * @xprt - pointer to xprt struct
190 * @servname - name of server
191 * @info - rpc_program
192 * @version - rpc_program version
193 * @authflavor - rpc_auth flavour to use
195 * Creates an RPC client structure, then pings the server in order to
196 * determine if it is up, and if it supports this program and version.
198 * This function should never be called by asynchronous tasks such as
201 struct rpc_clnt *rpc_create_client(struct rpc_xprt *xprt, char *servname,
202 struct rpc_program *info, u32 version, rpc_authflavor_t authflavor)
204 struct rpc_clnt *clnt;
207 clnt = rpc_new_client(xprt, servname, info, version, authflavor);
210 err = rpc_ping(clnt, RPC_TASK_SOFT|RPC_TASK_NOINTR);
213 rpc_shutdown_client(clnt);
218 * This function clones the RPC client structure. It allows us to share the
219 * same transport while varying parameters such as the authentication
223 rpc_clone_client(struct rpc_clnt *clnt)
225 struct rpc_clnt *new;
227 new = (struct rpc_clnt *)kmalloc(sizeof(*new), GFP_KERNEL);
230 memcpy(new, clnt, sizeof(*new));
231 atomic_set(&new->cl_count, 1);
232 atomic_set(&new->cl_users, 0);
233 new->cl_parent = clnt;
234 atomic_inc(&clnt->cl_count);
235 /* Duplicate portmapper */
236 rpc_init_wait_queue(&new->cl_pmap_default.pm_bindwait, "bindwait");
237 /* Turn off autobind on clones */
238 new->cl_autobind = 0;
241 rpc_init_rtt(&new->cl_rtt_default, clnt->cl_xprt->timeout.to_initval);
243 atomic_inc(&new->cl_auth->au_count);
244 new->cl_pmap = &new->cl_pmap_default;
245 rpc_init_wait_queue(&new->cl_pmap_default.pm_bindwait, "bindwait");
248 printk(KERN_INFO "RPC: out of memory in %s\n", __FUNCTION__);
249 return ERR_PTR(-ENOMEM);
253 * Properly shut down an RPC client, terminating all outstanding
254 * requests. Note that we must be certain that cl_oneshot and
255 * cl_dead are cleared, or else the client would be destroyed
256 * when the last task releases it.
259 rpc_shutdown_client(struct rpc_clnt *clnt)
261 dprintk("RPC: shutting down %s client for %s, tasks=%d\n",
262 clnt->cl_protname, clnt->cl_server,
263 atomic_read(&clnt->cl_users));
265 while (atomic_read(&clnt->cl_users) > 0) {
266 /* Don't let rpc_release_client destroy us */
267 clnt->cl_oneshot = 0;
269 rpc_killall_tasks(clnt);
270 sleep_on_timeout(&destroy_wait, 1*HZ);
273 if (atomic_read(&clnt->cl_users) < 0) {
274 printk(KERN_ERR "RPC: rpc_shutdown_client clnt %p tasks=%d\n",
275 clnt, atomic_read(&clnt->cl_users));
282 return rpc_destroy_client(clnt);
286 * Delete an RPC client
289 rpc_destroy_client(struct rpc_clnt *clnt)
291 if (!atomic_dec_and_test(&clnt->cl_count))
293 BUG_ON(atomic_read(&clnt->cl_users) != 0);
295 dprintk("RPC: destroying %s client for %s\n",
296 clnt->cl_protname, clnt->cl_server);
298 rpcauth_destroy(clnt->cl_auth);
299 clnt->cl_auth = NULL;
301 if (clnt->cl_parent != clnt) {
302 rpc_destroy_client(clnt->cl_parent);
305 if (clnt->cl_pathname[0])
306 rpc_rmdir(clnt->cl_pathname);
308 xprt_destroy(clnt->cl_xprt);
309 clnt->cl_xprt = NULL;
311 if (clnt->cl_server != clnt->cl_inline_name)
312 kfree(clnt->cl_server);
319 * Release an RPC client
322 rpc_release_client(struct rpc_clnt *clnt)
324 dprintk("RPC: rpc_release_client(%p, %d)\n",
325 clnt, atomic_read(&clnt->cl_users));
327 if (!atomic_dec_and_test(&clnt->cl_users))
329 wake_up(&destroy_wait);
330 if (clnt->cl_oneshot || clnt->cl_dead)
331 rpc_destroy_client(clnt);
335 * rpc_bind_new_program - bind a new RPC program to an existing client
336 * @old - old rpc_client
337 * @program - rpc program to set
338 * @vers - rpc program version
340 * Clones the rpc client and sets up a new RPC program. This is mainly
341 * of use for enabling different RPC programs to share the same transport.
342 * The Sun NFSv2/v3 ACL protocol can do this.
344 struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *old,
345 struct rpc_program *program,
348 struct rpc_clnt *clnt;
349 struct rpc_version *version;
352 BUG_ON(vers >= program->nrvers || !program->version[vers]);
353 version = program->version[vers];
354 clnt = rpc_clone_client(old);
357 clnt->cl_procinfo = version->procs;
358 clnt->cl_maxproc = version->nrprocs;
359 clnt->cl_protname = program->name;
360 clnt->cl_prog = program->number;
361 clnt->cl_vers = version->number;
362 clnt->cl_stats = program->stats;
363 err = rpc_ping(clnt, RPC_TASK_SOFT|RPC_TASK_NOINTR);
365 rpc_shutdown_client(clnt);
373 * Default callback for async RPC calls
376 rpc_default_callback(struct rpc_task *task)
381 * Export the signal mask handling for synchronous code that
382 * sleeps on RPC calls
384 #define RPC_INTR_SIGNALS (sigmask(SIGINT) | sigmask(SIGQUIT) | sigmask(SIGKILL))
386 static void rpc_save_sigmask(sigset_t *oldset, int intr)
388 unsigned long sigallow = 0;
391 /* Block all signals except those listed in sigallow */
393 sigallow |= RPC_INTR_SIGNALS;
394 siginitsetinv(&sigmask, sigallow);
395 sigprocmask(SIG_BLOCK, &sigmask, oldset);
398 static inline void rpc_task_sigmask(struct rpc_task *task, sigset_t *oldset)
400 rpc_save_sigmask(oldset, !RPC_TASK_UNINTERRUPTIBLE(task));
403 static inline void rpc_restore_sigmask(sigset_t *oldset)
405 sigprocmask(SIG_SETMASK, oldset, NULL);
408 void rpc_clnt_sigmask(struct rpc_clnt *clnt, sigset_t *oldset)
410 rpc_save_sigmask(oldset, clnt->cl_intr);
413 void rpc_clnt_sigunmask(struct rpc_clnt *clnt, sigset_t *oldset)
415 rpc_restore_sigmask(oldset);
419 * New rpc_call implementation
421 int rpc_call_sync(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
423 struct rpc_task *task;
427 /* If this client is slain all further I/O fails */
431 BUG_ON(flags & RPC_TASK_ASYNC);
434 task = rpc_new_task(clnt, NULL, flags);
438 /* Mask signals on RPC calls _and_ GSS_AUTH upcalls */
439 rpc_task_sigmask(task, &oldset);
441 rpc_call_setup(task, msg, 0);
443 /* Set up the call info struct and execute the task */
444 if (task->tk_status == 0) {
445 status = rpc_execute(task);
447 status = task->tk_status;
448 rpc_release_task(task);
451 rpc_restore_sigmask(&oldset);
457 * New rpc_call implementation
460 rpc_call_async(struct rpc_clnt *clnt, struct rpc_message *msg, int flags,
461 rpc_action callback, void *data)
463 struct rpc_task *task;
467 /* If this client is slain all further I/O fails */
471 flags |= RPC_TASK_ASYNC;
473 /* Create/initialize a new RPC task */
475 callback = rpc_default_callback;
477 if (!(task = rpc_new_task(clnt, callback, flags)))
479 task->tk_calldata = data;
481 /* Mask signals on GSS_AUTH upcalls */
482 rpc_task_sigmask(task, &oldset);
484 rpc_call_setup(task, msg, 0);
486 /* Set up the call info struct and execute the task */
487 status = task->tk_status;
491 rpc_release_task(task);
493 rpc_restore_sigmask(&oldset);
500 rpc_call_setup(struct rpc_task *task, struct rpc_message *msg, int flags)
503 task->tk_flags |= flags;
504 /* Bind the user cred */
505 if (task->tk_msg.rpc_cred != NULL)
506 rpcauth_holdcred(task);
508 rpcauth_bindcred(task);
510 if (task->tk_status == 0)
511 task->tk_action = call_start;
513 task->tk_action = NULL;
517 rpc_setbufsize(struct rpc_clnt *clnt, unsigned int sndsize, unsigned int rcvsize)
519 struct rpc_xprt *xprt = clnt->cl_xprt;
520 if (xprt->ops->set_buffer_size)
521 xprt->ops->set_buffer_size(xprt, sndsize, rcvsize);
525 * Return size of largest payload RPC client can support, in bytes
527 * For stream transports, this is one RPC record fragment (see RFC
528 * 1831), as we don't support multi-record requests yet. For datagram
529 * transports, this is the size of an IP packet minus the IP, UDP, and
532 size_t rpc_max_payload(struct rpc_clnt *clnt)
534 return clnt->cl_xprt->max_payload;
536 EXPORT_SYMBOL(rpc_max_payload);
539 * Restart an (async) RPC call. Usually called from within the
543 rpc_restart_call(struct rpc_task *task)
545 if (RPC_ASSASSINATED(task))
548 task->tk_action = call_start;
554 * Other FSM states can be visited zero or more times, but
555 * this state is visited exactly once for each RPC.
558 call_start(struct rpc_task *task)
560 struct rpc_clnt *clnt = task->tk_client;
562 dprintk("RPC: %4d call_start %s%d proc %d (%s)\n", task->tk_pid,
563 clnt->cl_protname, clnt->cl_vers, task->tk_msg.rpc_proc->p_proc,
564 (RPC_IS_ASYNC(task) ? "async" : "sync"));
566 /* Increment call count */
567 task->tk_msg.rpc_proc->p_count++;
568 clnt->cl_stats->rpccnt++;
569 task->tk_action = call_reserve;
573 * 1. Reserve an RPC call slot
576 call_reserve(struct rpc_task *task)
578 dprintk("RPC: %4d call_reserve\n", task->tk_pid);
580 if (!rpcauth_uptodatecred(task)) {
581 task->tk_action = call_refresh;
586 task->tk_action = call_reserveresult;
591 * 1b. Grok the result of xprt_reserve()
594 call_reserveresult(struct rpc_task *task)
596 int status = task->tk_status;
598 dprintk("RPC: %4d call_reserveresult (status %d)\n",
599 task->tk_pid, task->tk_status);
602 * After a call to xprt_reserve(), we must have either
603 * a request slot or else an error status.
607 if (task->tk_rqstp) {
608 task->tk_action = call_allocate;
612 printk(KERN_ERR "%s: status=%d, but no request slot, exiting\n",
613 __FUNCTION__, status);
614 rpc_exit(task, -EIO);
619 * Even though there was an error, we may have acquired
620 * a request slot somehow. Make sure not to leak it.
622 if (task->tk_rqstp) {
623 printk(KERN_ERR "%s: status=%d, request allocated anyway\n",
624 __FUNCTION__, status);
629 case -EAGAIN: /* woken up; retry */
630 task->tk_action = call_reserve;
632 case -EIO: /* probably a shutdown */
635 printk(KERN_ERR "%s: unrecognized error %d, exiting\n",
636 __FUNCTION__, status);
639 rpc_exit(task, status);
643 * 2. Allocate the buffer. For details, see sched.c:rpc_malloc.
644 * (Note: buffer memory is freed in rpc_task_release).
647 call_allocate(struct rpc_task *task)
651 dprintk("RPC: %4d call_allocate (status %d)\n",
652 task->tk_pid, task->tk_status);
653 task->tk_action = call_bind;
657 /* FIXME: compute buffer requirements more exactly using
659 bufsiz = task->tk_msg.rpc_proc->p_bufsiz + RPC_SLACK_SPACE;
661 if (rpc_malloc(task, bufsiz << 1) != NULL)
663 printk(KERN_INFO "RPC: buffer allocation failed for task %p\n", task);
665 if (RPC_IS_ASYNC(task) || !signalled()) {
667 task->tk_action = call_reserve;
668 rpc_delay(task, HZ>>4);
672 rpc_exit(task, -ERESTARTSYS);
676 * 3. Encode arguments of an RPC call
679 call_encode(struct rpc_task *task)
681 struct rpc_clnt *clnt = task->tk_client;
682 struct rpc_rqst *req = task->tk_rqstp;
683 struct xdr_buf *sndbuf = &req->rq_snd_buf;
684 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
690 dprintk("RPC: %4d call_encode (status %d)\n",
691 task->tk_pid, task->tk_status);
693 /* Default buffer setup */
694 bufsiz = task->tk_bufsize >> 1;
695 sndbuf->head[0].iov_base = (void *)task->tk_buffer;
696 sndbuf->head[0].iov_len = bufsiz;
697 sndbuf->tail[0].iov_len = 0;
698 sndbuf->page_len = 0;
700 sndbuf->buflen = bufsiz;
701 rcvbuf->head[0].iov_base = (void *)((char *)task->tk_buffer + bufsiz);
702 rcvbuf->head[0].iov_len = bufsiz;
703 rcvbuf->tail[0].iov_len = 0;
704 rcvbuf->page_len = 0;
706 rcvbuf->buflen = bufsiz;
708 /* Encode header and provided arguments */
709 encode = task->tk_msg.rpc_proc->p_encode;
710 if (!(p = call_header(task))) {
711 printk(KERN_INFO "RPC: call_header failed, exit EIO\n");
712 rpc_exit(task, -EIO);
715 if (encode && (status = rpcauth_wrap_req(task, encode, req, p,
716 task->tk_msg.rpc_argp)) < 0) {
717 printk(KERN_WARNING "%s: can't encode arguments: %d\n",
718 clnt->cl_protname, -status);
719 rpc_exit(task, status);
724 * 4. Get the server port number if not yet set
727 call_bind(struct rpc_task *task)
729 struct rpc_clnt *clnt = task->tk_client;
731 dprintk("RPC: %4d call_bind (status %d)\n",
732 task->tk_pid, task->tk_status);
734 task->tk_action = call_connect;
735 if (!clnt->cl_port) {
736 task->tk_action = call_bind_status;
737 task->tk_timeout = task->tk_xprt->bind_timeout;
738 rpc_getport(task, clnt);
743 * 4a. Sort out bind result
746 call_bind_status(struct rpc_task *task)
748 int status = -EACCES;
750 if (task->tk_status >= 0) {
751 dprintk("RPC: %4d call_bind_status (status %d)\n",
752 task->tk_pid, task->tk_status);
754 task->tk_action = call_connect;
758 switch (task->tk_status) {
760 dprintk("RPC: %4d remote rpcbind: RPC program/version unavailable\n",
764 dprintk("RPC: %4d rpcbind request timed out\n",
766 if (RPC_IS_SOFT(task)) {
772 dprintk("RPC: %4d remote rpcbind service unavailable\n",
775 case -EPROTONOSUPPORT:
776 dprintk("RPC: %4d remote rpcbind version 2 unavailable\n",
780 dprintk("RPC: %4d unrecognized rpcbind error (%d)\n",
781 task->tk_pid, -task->tk_status);
786 rpc_exit(task, status);
791 task->tk_action = call_bind;
796 * 4b. Connect to the RPC server
799 call_connect(struct rpc_task *task)
801 struct rpc_xprt *xprt = task->tk_xprt;
803 dprintk("RPC: %4d call_connect xprt %p %s connected\n",
805 (xprt_connected(xprt) ? "is" : "is not"));
807 task->tk_action = call_transmit;
808 if (!xprt_connected(xprt)) {
809 task->tk_action = call_connect_status;
810 if (task->tk_status < 0)
817 * 4c. Sort out connect result
820 call_connect_status(struct rpc_task *task)
822 struct rpc_clnt *clnt = task->tk_client;
823 int status = task->tk_status;
825 dprintk("RPC: %5u call_connect_status (status %d)\n",
826 task->tk_pid, task->tk_status);
830 clnt->cl_stats->netreconn++;
831 task->tk_action = call_transmit;
835 /* Something failed: remote service port may have changed */
836 if (clnt->cl_autobind)
843 task->tk_action = call_bind;
846 rpc_exit(task, -EIO);
852 * 5. Transmit the RPC request, and wait for reply
855 call_transmit(struct rpc_task *task)
857 dprintk("RPC: %4d call_transmit (status %d)\n",
858 task->tk_pid, task->tk_status);
860 task->tk_action = call_status;
861 if (task->tk_status < 0)
863 task->tk_status = xprt_prepare_transmit(task);
864 if (task->tk_status != 0)
866 /* Encode here so that rpcsec_gss can use correct sequence number. */
867 if (!task->tk_rqstp->rq_bytes_sent)
869 if (task->tk_status < 0)
872 if (task->tk_status < 0)
874 if (!task->tk_msg.rpc_proc->p_decode) {
875 task->tk_action = NULL;
876 rpc_wake_up_task(task);
881 * 6. Sort out the RPC call status
884 call_status(struct rpc_task *task)
886 struct rpc_clnt *clnt = task->tk_client;
887 struct rpc_rqst *req = task->tk_rqstp;
890 if (req->rq_received > 0 && !req->rq_bytes_sent)
891 task->tk_status = req->rq_received;
893 dprintk("RPC: %4d call_status (status %d)\n",
894 task->tk_pid, task->tk_status);
896 status = task->tk_status;
898 task->tk_action = call_decode;
905 task->tk_action = call_timeout;
909 req->rq_bytes_sent = 0;
910 if (clnt->cl_autobind)
912 task->tk_action = call_bind;
915 task->tk_action = call_transmit;
918 /* shutdown or soft timeout */
919 rpc_exit(task, status);
923 printk("%s: RPC call returned error %d\n",
924 clnt->cl_protname, -status);
925 rpc_exit(task, status);
931 * 6a. Handle RPC timeout
932 * We do not release the request slot, so we keep using the
933 * same XID for all retransmits.
936 call_timeout(struct rpc_task *task)
938 struct rpc_clnt *clnt = task->tk_client;
940 if (xprt_adjust_timeout(task->tk_rqstp) == 0) {
941 dprintk("RPC: %4d call_timeout (minor)\n", task->tk_pid);
945 dprintk("RPC: %4d call_timeout (major)\n", task->tk_pid);
946 if (RPC_IS_SOFT(task)) {
948 printk(KERN_NOTICE "%s: server %s not responding, timed out\n",
949 clnt->cl_protname, clnt->cl_server);
950 rpc_exit(task, -EIO);
954 if (clnt->cl_chatty && !(task->tk_flags & RPC_CALL_MAJORSEEN)) {
955 task->tk_flags |= RPC_CALL_MAJORSEEN;
956 printk(KERN_NOTICE "%s: server %s not responding, still trying\n",
957 clnt->cl_protname, clnt->cl_server);
959 if (clnt->cl_autobind)
963 clnt->cl_stats->rpcretrans++;
964 task->tk_action = call_bind;
969 * 7. Decode the RPC reply
972 call_decode(struct rpc_task *task)
974 struct rpc_clnt *clnt = task->tk_client;
975 struct rpc_rqst *req = task->tk_rqstp;
976 kxdrproc_t decode = task->tk_msg.rpc_proc->p_decode;
979 dprintk("RPC: %4d call_decode (status %d)\n",
980 task->tk_pid, task->tk_status);
982 if (clnt->cl_chatty && (task->tk_flags & RPC_CALL_MAJORSEEN)) {
983 printk(KERN_NOTICE "%s: server %s OK\n",
984 clnt->cl_protname, clnt->cl_server);
985 task->tk_flags &= ~RPC_CALL_MAJORSEEN;
988 if (task->tk_status < 12) {
989 if (!RPC_IS_SOFT(task)) {
990 task->tk_action = call_bind;
991 clnt->cl_stats->rpcretrans++;
994 printk(KERN_WARNING "%s: too small RPC reply size (%d bytes)\n",
995 clnt->cl_protname, task->tk_status);
996 rpc_exit(task, -EIO);
1000 req->rq_rcv_buf.len = req->rq_private_buf.len;
1002 /* Check that the softirq receive buffer is valid */
1003 WARN_ON(memcmp(&req->rq_rcv_buf, &req->rq_private_buf,
1004 sizeof(req->rq_rcv_buf)) != 0);
1006 /* Verify the RPC header */
1007 if (!(p = call_verify(task))) {
1008 if (task->tk_action == NULL)
1013 task->tk_action = NULL;
1016 task->tk_status = rpcauth_unwrap_resp(task, decode, req, p,
1017 task->tk_msg.rpc_resp);
1018 dprintk("RPC: %4d call_decode result %d\n", task->tk_pid,
1022 req->rq_received = req->rq_private_buf.len = 0;
1023 task->tk_status = 0;
1027 * 8. Refresh the credentials if rejected by the server
1030 call_refresh(struct rpc_task *task)
1032 dprintk("RPC: %4d call_refresh\n", task->tk_pid);
1034 xprt_release(task); /* Must do to obtain new XID */
1035 task->tk_action = call_refreshresult;
1036 task->tk_status = 0;
1037 task->tk_client->cl_stats->rpcauthrefresh++;
1038 rpcauth_refreshcred(task);
1042 * 8a. Process the results of a credential refresh
1045 call_refreshresult(struct rpc_task *task)
1047 int status = task->tk_status;
1048 dprintk("RPC: %4d call_refreshresult (status %d)\n",
1049 task->tk_pid, task->tk_status);
1051 task->tk_status = 0;
1052 task->tk_action = call_reserve;
1053 if (status >= 0 && rpcauth_uptodatecred(task))
1055 if (status == -EACCES) {
1056 rpc_exit(task, -EACCES);
1059 task->tk_action = call_refresh;
1060 if (status != -ETIMEDOUT)
1061 rpc_delay(task, 3*HZ);
1066 * Call header serialization
1069 call_header(struct rpc_task *task)
1071 struct rpc_clnt *clnt = task->tk_client;
1072 struct rpc_rqst *req = task->tk_rqstp;
1073 u32 *p = req->rq_svec[0].iov_base;
1075 /* FIXME: check buffer size? */
1077 p = xprt_skip_transport_header(task->tk_xprt, p);
1078 *p++ = req->rq_xid; /* XID */
1079 *p++ = htonl(RPC_CALL); /* CALL */
1080 *p++ = htonl(RPC_VERSION); /* RPC version */
1081 *p++ = htonl(clnt->cl_prog); /* program number */
1082 *p++ = htonl(clnt->cl_vers); /* program version */
1083 *p++ = htonl(task->tk_msg.rpc_proc->p_proc); /* procedure */
1084 p = rpcauth_marshcred(task, p);
1085 req->rq_slen = xdr_adjust_iovec(&req->rq_svec[0], p);
1090 * Reply header verification
1093 call_verify(struct rpc_task *task)
1095 struct kvec *iov = &task->tk_rqstp->rq_rcv_buf.head[0];
1096 int len = task->tk_rqstp->rq_rcv_buf.len >> 2;
1097 u32 *p = iov->iov_base, n;
1098 int error = -EACCES;
1102 p += 1; /* skip XID */
1104 if ((n = ntohl(*p++)) != RPC_REPLY) {
1105 printk(KERN_WARNING "call_verify: not an RPC reply: %x\n", n);
1108 if ((n = ntohl(*p++)) != RPC_MSG_ACCEPTED) {
1111 switch ((n = ntohl(*p++))) {
1112 case RPC_AUTH_ERROR:
1115 dprintk("%s: RPC call version mismatch!\n", __FUNCTION__);
1116 error = -EPROTONOSUPPORT;
1119 dprintk("%s: RPC call rejected, unknown error: %x\n", __FUNCTION__, n);
1124 switch ((n = ntohl(*p++))) {
1125 case RPC_AUTH_REJECTEDCRED:
1126 case RPC_AUTH_REJECTEDVERF:
1127 case RPCSEC_GSS_CREDPROBLEM:
1128 case RPCSEC_GSS_CTXPROBLEM:
1129 if (!task->tk_cred_retry)
1131 task->tk_cred_retry--;
1132 dprintk("RPC: %4d call_verify: retry stale creds\n",
1134 rpcauth_invalcred(task);
1135 task->tk_action = call_refresh;
1137 case RPC_AUTH_BADCRED:
1138 case RPC_AUTH_BADVERF:
1139 /* possibly garbled cred/verf? */
1140 if (!task->tk_garb_retry)
1142 task->tk_garb_retry--;
1143 dprintk("RPC: %4d call_verify: retry garbled creds\n",
1145 task->tk_action = call_bind;
1147 case RPC_AUTH_TOOWEAK:
1148 printk(KERN_NOTICE "call_verify: server requires stronger "
1149 "authentication.\n");
1152 printk(KERN_WARNING "call_verify: unknown auth error: %x\n", n);
1155 dprintk("RPC: %4d call_verify: call rejected %d\n",
1159 if (!(p = rpcauth_checkverf(task, p))) {
1160 printk(KERN_WARNING "call_verify: auth check failed\n");
1161 goto out_retry; /* bad verifier, retry */
1163 len = p - (u32 *)iov->iov_base - 1;
1166 switch ((n = ntohl(*p++))) {
1169 case RPC_PROG_UNAVAIL:
1170 dprintk("RPC: call_verify: program %u is unsupported by server %s\n",
1171 (unsigned int)task->tk_client->cl_prog,
1172 task->tk_client->cl_server);
1173 error = -EPFNOSUPPORT;
1175 case RPC_PROG_MISMATCH:
1176 dprintk("RPC: call_verify: program %u, version %u unsupported by server %s\n",
1177 (unsigned int)task->tk_client->cl_prog,
1178 (unsigned int)task->tk_client->cl_vers,
1179 task->tk_client->cl_server);
1180 error = -EPROTONOSUPPORT;
1182 case RPC_PROC_UNAVAIL:
1183 dprintk("RPC: call_verify: proc %p unsupported by program %u, version %u on server %s\n",
1184 task->tk_msg.rpc_proc,
1185 task->tk_client->cl_prog,
1186 task->tk_client->cl_vers,
1187 task->tk_client->cl_server);
1188 error = -EOPNOTSUPP;
1190 case RPC_GARBAGE_ARGS:
1191 dprintk("RPC: %4d %s: server saw garbage\n", task->tk_pid, __FUNCTION__);
1194 printk(KERN_WARNING "call_verify: server accept status: %x\n", n);
1199 task->tk_client->cl_stats->rpcgarbage++;
1200 if (task->tk_garb_retry) {
1201 task->tk_garb_retry--;
1202 dprintk("RPC %s: retrying %4d\n", __FUNCTION__, task->tk_pid);
1203 task->tk_action = call_bind;
1206 printk(KERN_WARNING "RPC %s: retry failed, exit EIO\n", __FUNCTION__);
1210 rpc_exit(task, error);
1213 printk(KERN_WARNING "RPC %s: server reply was truncated.\n", __FUNCTION__);
1217 static int rpcproc_encode_null(void *rqstp, u32 *data, void *obj)
1222 static int rpcproc_decode_null(void *rqstp, u32 *data, void *obj)
1227 static struct rpc_procinfo rpcproc_null = {
1228 .p_encode = rpcproc_encode_null,
1229 .p_decode = rpcproc_decode_null,
1232 int rpc_ping(struct rpc_clnt *clnt, int flags)
1234 struct rpc_message msg = {
1235 .rpc_proc = &rpcproc_null,
1238 msg.rpc_cred = authnull_ops.lookup_cred(NULL, NULL, 0);
1239 err = rpc_call_sync(clnt, &msg, flags);
1240 put_rpccred(msg.rpc_cred);