21 #include <linux/module.h>
22 #include <linux/types.h>
27 #include <linux/slab.h>
28 #include <linux/utsname.h>
31 #include <linux/in6.h>
45 # define RPCDBG_FACILITY RPCDBG_CALL
48 #define dprint_status(t) \
49 dprintk("RPC: %5u %s (status %d)\n", t->tk_pid, \
50 __func__, t->tk_status)
67 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
80 static int rpc_ping(
struct rpc_clnt *clnt);
82 static void rpc_register_client(
struct rpc_clnt *clnt)
92 static void rpc_unregister_client(
struct rpc_clnt *clnt)
102 static void __rpc_clnt_remove_pipedir(
struct rpc_clnt *clnt)
112 static void rpc_clnt_remove_pipedir(
struct rpc_clnt *clnt)
119 __rpc_clnt_remove_pipedir(clnt);
126 const char *dir_name)
130 struct qstr q = { .name = name };
138 q.len =
snprintf(name,
sizeof(name),
"clnt%x", (
unsigned int)clntid++);
139 name[
sizeof(
name) - 1] =
'\0';
144 error = PTR_ERR(dentry);
147 " %s/%s, error %d\n",
148 dir_name, name, error);
157 rpc_setup_pipedir(
struct rpc_clnt *clnt,
const char *dir_name)
161 struct dentry *dentry;
164 if (dir_name ==
NULL)
169 dentry = rpc_setup_pipedir_sb(pipefs_sb, clnt, dir_name);
172 return PTR_ERR(dentry);
177 static inline int rpc_clnt_skip_event(
struct rpc_clnt *clnt,
unsigned long event)
179 if (((event == RPC_PIPEFS_MOUNT) && clnt->
cl_dentry) ||
180 ((event == RPC_PIPEFS_UMOUNT) && !clnt->
cl_dentry))
185 static int __rpc_clnt_handle_event(
struct rpc_clnt *clnt,
unsigned long event,
188 struct dentry *dentry;
192 case RPC_PIPEFS_MOUNT:
193 dentry = rpc_setup_pipedir_sb(sb, clnt,
197 return PTR_ERR(dentry);
199 if (clnt->
cl_auth->au_ops->pipes_create) {
202 __rpc_clnt_remove_pipedir(clnt);
205 case RPC_PIPEFS_UMOUNT:
206 __rpc_clnt_remove_pipedir(clnt);
215 static int __rpc_pipefs_event(
struct rpc_clnt *clnt,
unsigned long event,
221 if (!rpc_clnt_skip_event(clnt, event))
222 error = __rpc_clnt_handle_event(clnt, event, sb);
229 static struct rpc_clnt *rpc_get_client_for_event(
struct net *net,
int event)
238 if (rpc_clnt_skip_event(clnt, event))
249 static int rpc_pipefs_event(
struct notifier_block *nb,
unsigned long event,
256 while ((clnt = rpc_get_client_for_event(sb->
s_fs_info, event))) {
257 error = __rpc_pipefs_event(clnt, event, sb);
266 .notifier_call = rpc_pipefs_event,
267 .priority = SUNRPC_PIPEFS_RPC_PRIO,
280 static void rpc_clnt_set_nodename(
struct rpc_clnt *clnt,
const char *nodename)
288 static struct rpc_clnt * rpc_new_client(
const struct rpc_create_args *args,
struct rpc_xprt *xprt)
293 struct rpc_auth *
auth;
297 dprintk(
"RPC: creating %s client for %s (xprt %p)\n",
298 program->
name, args->servername, xprt);
307 if (args->version >= program->
nrvers)
309 version = program->
version[args->version];
334 if (!xprt_bound(xprt))
338 if (args->timeout !=
NULL) {
347 if (args->client_name) {
350 goto out_no_principal;
368 rpc_clnt_set_nodename(clnt, utsname()->nodename);
369 rpc_register_client(clnt);
373 rpc_clnt_remove_pipedir(clnt);
400 struct rpc_xprt *xprt;
402 struct xprt_create xprtargs = {
404 .ident = args->protocol,
405 .srcaddr = args->saddress,
406 .dstaddr = args->address,
407 .addrlen = args->addrsize,
408 .servername = args->servername,
409 .bc_xprt = args->bc_xprt,
417 if (xprtargs.servername ==
NULL) {
425 servername[0] =
'\0';
426 switch (args->address->sa_family) {
428 snprintf(servername,
sizeof(servername),
"%s",
432 snprintf(servername,
sizeof(servername),
"%pI4",
433 &sin->sin_addr.s_addr);
436 snprintf(servername,
sizeof(servername),
"%pI6",
444 xprtargs.servername = servername;
458 if (args->flags & RPC_CLNT_CREATE_NONPRIVPORT)
461 clnt = rpc_new_client(args, xprt);
465 if (!(args->flags & RPC_CLNT_CREATE_NOPING)) {
466 int err = rpc_ping(clnt);
474 if (args->flags & RPC_CLNT_CREATE_HARDRTRY)
477 if (args->flags & RPC_CLNT_CREATE_AUTOBIND)
479 if (args->flags & RPC_CLNT_CREATE_DISCRTRY)
481 if (!(args->flags & RPC_CLNT_CREATE_QUIET))
493 static struct rpc_clnt *__rpc_clone_client(
struct rpc_create_args *args,
496 struct rpc_xprt *xprt;
506 args->servername = xprt->servername;
508 new = rpc_new_client(args, xprt);
515 new->cl_parent = clnt;
527 dprintk(
"RPC: %s: returned error %d\n", __func__, err);
540 struct rpc_create_args args = {
544 .authflavor = clnt->
cl_auth->au_flavor,
547 return __rpc_clone_client(&args, clnt);
562 struct rpc_create_args args = {
566 .authflavor = flavor,
569 return __rpc_clone_client(&args, clnt);
584 dprintk(
"RPC: killing all tasks for client %p\n", clnt);
610 dprintk_rcu(
"RPC: shutting down %s client for %s\n",
614 while (!list_empty(&clnt->
cl_tasks)) {
628 rpc_free_client(
struct rpc_clnt *clnt)
635 rpc_unregister_client(clnt);
636 rpc_clnt_remove_pipedir(clnt);
649 rpc_free_auth(
struct rpc_clnt *clnt)
652 rpc_free_client(clnt);
665 rpc_free_client(clnt);
674 dprintk(
"RPC: rpc_release_client(%p)\n", clnt);
701 version = program->
version[vers];
711 err = rpc_ping(clnt);
745 if (sk_memalloc_socks()) {
746 struct rpc_xprt *xprt;
764 rpc_task_set_client(task, clnt);
790 .rpc_call_done = rpc_default_callback,
805 rpc_task_set_client(task, task_setup_data->
rpc_client);
806 rpc_task_set_rpc_message(task, task_setup_data->
rpc_message);
830 .callback_ops = &rpc_default_ops,
839 return PTR_ERR(task);
862 .callback_ops = tk_ops,
863 .callback_data =
data,
869 return PTR_ERR(task);
875 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
886 struct xdr_buf *xbufp = &req->rq_snd_buf;
891 dprintk(
"RPC: rpc_run_bc_task req= %p\n", req);
906 xbufp->len = xbufp->head[0].iov_len + xbufp->page_len +
907 xbufp->tail[0].iov_len;
915 dprintk(
"RPC: rpc_run_bc_task: task= %p\n", task);
938 struct rpc_xprt *xprt;
943 bytes = xprt->addrlen;
946 memcpy(buf, &xprt->addr, bytes);
963 enum rpc_display_format_t
format)
965 struct rpc_xprt *xprt;
969 if (xprt->address_strings[format] !=
NULL)
970 return xprt->address_strings[
format];
972 return "unprintable";
976 static const struct sockaddr_in rpc_inaddr_loopback = {
981 static const struct sockaddr_in6 rpc_in6addr_loopback = {
994 static int rpc_sockname(
struct net *net,
struct sockaddr *sap,
size_t salen,
1003 dprintk(
"RPC: can't create UDP socket (%d)\n", err);
1010 (
struct sockaddr *)&rpc_inaddr_loopback,
1011 sizeof(rpc_inaddr_loopback));
1015 (
struct sockaddr *)&rpc_in6addr_loopback,
1016 sizeof(rpc_in6addr_loopback));
1023 dprintk(
"RPC: can't bind UDP socket (%d)\n", err);
1029 dprintk(
"RPC: can't connect UDP socket (%d)\n", err);
1035 dprintk(
"RPC: getsockname failed (%d)\n", err);
1044 dprintk(
"RPC: %s succeeded\n", __func__);
1060 static int rpc_anyaddr(
int family,
struct sockaddr *buf,
size_t buflen)
1064 if (buflen <
sizeof(rpc_inaddr_loopback))
1066 memcpy(buf, &rpc_inaddr_loopback,
1067 sizeof(rpc_inaddr_loopback));
1070 if (buflen <
sizeof(rpc_in6addr_loopback))
1072 memcpy(buf, &rpc_in6addr_loopback,
1073 sizeof(rpc_in6addr_loopback));
1075 dprintk(
"RPC: %s: address family not supported\n",
1079 dprintk(
"RPC: %s: succeeded\n", __func__);
1103 struct rpc_xprt *xprt;
1110 salen = xprt->addrlen;
1111 memcpy(sap, &xprt->addr, salen);
1112 net = get_net(xprt->xprt_net);
1115 rpc_set_port(sap, 0);
1116 err = rpc_sockname(net, sap, salen, buf, buflen);
1120 return rpc_anyaddr(sap->
sa_family, buf, buflen);
1128 struct rpc_xprt *xprt;
1132 if (xprt->ops->set_buffer_size)
1133 xprt->ops->set_buffer_size(xprt, sndsize, rcvsize);
1236 static const char *rpc_proc_name(
const struct rpc_task *task)
1261 dprintk(
"RPC: %5u call_start %s%d proc %s (%s)\n", task->tk_pid,
1263 rpc_proc_name(task),
1267 task->
tk_msg.rpc_proc->p_count++;
1276 call_reserve(
struct rpc_task *task)
1289 call_reserveresult(
struct rpc_task *task)
1342 call_refresh(
struct rpc_task *task)
1348 task->
tk_client->cl_stats->rpcauthrefresh++;
1356 call_refreshresult(
struct rpc_task *task)
1376 dprintk(
"RPC: %5u %s: retry refresh creds\n",
1377 task->tk_pid, __func__);
1380 dprintk(
"RPC: %5u %s: refresh creds failed with error %d\n",
1381 task->tk_pid, __func__, status);
1390 call_allocate(
struct rpc_task *task)
1392 unsigned int slack = task->
tk_rqstp->rq_cred->cr_auth->au_cslack;
1393 struct rpc_rqst *req = task->
tk_rqstp;
1394 struct rpc_xprt *xprt = task->tk_xprt;
1416 req->rq_callsize = RPC_CALLHDRSIZE + (slack << 1) + proc->
p_arglen;
1417 req->rq_callsize <<= 2;
1418 req->rq_rcvsize = RPC_REPHDRSIZE + slack + proc->
p_replen;
1419 req->rq_rcvsize <<= 2;
1421 req->rq_buffer = xprt->ops->buf_alloc(task,
1422 req->rq_callsize + req->rq_rcvsize);
1423 if (req->rq_buffer !=
NULL)
1426 dprintk(
"RPC: %5u rpc_buffer allocation failed\n", task->tk_pid);
1438 rpc_task_need_encode(
struct rpc_task *task)
1440 return task->
tk_rqstp->rq_snd_buf.len == 0;
1444 rpc_task_force_reencode(
struct rpc_task *task)
1446 task->
tk_rqstp->rq_snd_buf.len = 0;
1451 rpc_xdr_buf_init(
struct xdr_buf *buf,
void *
start,
size_t len)
1453 buf->head[0].iov_base =
start;
1454 buf->head[0].iov_len = len;
1455 buf->tail[0].iov_len = 0;
1466 rpc_xdr_encode(
struct rpc_task *task)
1468 struct rpc_rqst *req = task->
tk_rqstp;
1474 rpc_xdr_buf_init(&req->rq_snd_buf,
1477 rpc_xdr_buf_init(&req->rq_rcv_buf,
1478 (
char *)req->rq_buffer + req->rq_callsize,
1481 p = rpc_encode_header(task);
1488 encode = task->
tk_msg.rpc_proc->p_encode;
1502 struct rpc_xprt *xprt = task->tk_xprt;
1507 if (!xprt_bound(xprt)) {
1510 xprt->ops->rpcbind(task);
1518 call_bind_status(
struct rpc_task *task)
1529 trace_rpc_bind_status(task);
1532 dprintk(
"RPC: %5u rpcbind out of memory\n", task->tk_pid);
1536 dprintk(
"RPC: %5u remote rpcbind: RPC program/version "
1537 "unavailable\n", task->tk_pid);
1539 if (task->
tk_msg.rpc_proc->p_proc == 0) {
1549 dprintk(
"RPC: %5u rpcbind request timed out\n",
1554 dprintk(
"RPC: %5u unrecognized remote rpcbind service\n",
1558 dprintk(
"RPC: %5u remote rpcbind version unavailable, retrying\n",
1570 dprintk(
"RPC: %5u remote rpcbind unreachable: %d\n",
1579 dprintk(
"RPC: %5u unrecognized rpcbind error (%d)\n",
1594 call_connect(
struct rpc_task *task)
1596 struct rpc_xprt *xprt = task->tk_xprt;
1598 dprintk(
"RPC: %5u call_connect xprt %p %s connected\n",
1600 (xprt_connected(xprt) ?
"is" :
"is not"));
1603 if (!xprt_connected(xprt)) {
1615 call_connect_status(
struct rpc_task *task)
1623 if (status >= 0 || status == -
EAGAIN) {
1629 trace_rpc_connect_status(task, status);
1644 call_transmit(
struct rpc_task *task)
1656 if (rpc_task_need_encode(task)) {
1658 rpc_xdr_encode(task);
1676 call_transmit_status(task);
1677 if (rpc_reply_expected(task))
1687 call_transmit_status(
struct rpc_task *task)
1697 rpc_task_force_reencode(task);
1707 rpc_task_force_reencode(task);
1727 rpc_task_force_reencode(task);
1731 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
1737 call_bc_transmit(
struct rpc_task *task)
1739 struct rpc_rqst *req = task->
tk_rqstp;
1781 req->rq_connect_cookie);
1804 struct rpc_rqst *req = task->
tk_rqstp;
1807 if (req->rq_reply_bytes_recvd > 0 && !req->rq_bytes_sent)
1808 task->
tk_status = req->rq_reply_bytes_recvd;
1818 trace_rpc_call_status(task);
1833 req->rq_connect_cookie);
1852 printk(
"%s: RPC call returned error %d\n",
1864 call_timeout(
struct rpc_task *task)
1869 dprintk(
"RPC: %5u call_timeout (minor)\n", task->tk_pid);
1873 dprintk(
"RPC: %5u call_timeout (major)\n", task->tk_pid);
1925 struct rpc_rqst *req = task->
tk_rqstp;
1926 kxdrdproc_t decode = task->
tk_msg.rpc_proc->p_decode;
1947 req->rq_rcv_buf.len = req->rq_private_buf.len;
1951 sizeof(req->rq_rcv_buf)) != 0);
1953 if (req->rq_rcv_buf.len < 12) {
1959 dprintk(
"RPC: %s: too small RPC reply size (%d bytes)\n",
1965 p = rpc_verify_header(task);
1967 if (p == ERR_PTR(-
EAGAIN))
1978 dprintk(
"RPC: %5u call_decode result %d\n", task->tk_pid,
1985 req->rq_reply_bytes_recvd = req->rq_rcv_buf.len = 0;
1988 req->rq_connect_cookie);
1993 rpc_encode_header(
struct rpc_task *task)
1996 struct rpc_rqst *req = task->
tk_rqstp;
1997 __be32 *p = req->rq_svec[0].iov_base;
2001 p = xprt_skip_transport_header(task->tk_xprt, p);
2003 *p++ =
htonl(RPC_CALL);
2004 *p++ =
htonl(RPC_VERSION);
2009 req->rq_slen = xdr_adjust_iovec(&req->rq_svec[0], p);
2014 rpc_verify_header(
struct rpc_task *task)
2017 struct kvec *iov = &task->
tk_rqstp->rq_rcv_buf.head[0];
2023 if ((task->
tk_rqstp->rq_rcv_buf.len & 3) != 0) {
2029 dprintk(
"RPC: %5u %s: XDR representation not a multiple of"
2030 " 4 bytes: 0x%x\n", task->tk_pid, __func__,
2038 if ((n =
ntohl(*p++)) != RPC_REPLY) {
2039 dprintk(
"RPC: %5u %s: not an RPC reply: %x\n",
2040 task->tk_pid, __func__, n);
2044 if ((n =
ntohl(*p++)) != RPC_MSG_ACCEPTED) {
2047 switch ((n =
ntohl(*p++))) {
2048 case RPC_AUTH_ERROR:
2051 dprintk(
"RPC: %5u %s: RPC call version mismatch!\n",
2052 task->tk_pid, __func__);
2056 dprintk(
"RPC: %5u %s: RPC call rejected, "
2057 "unknown error: %x\n",
2058 task->tk_pid, __func__, n);
2063 switch ((n =
ntohl(*p++))) {
2064 case RPC_AUTH_REJECTEDCRED:
2065 case RPC_AUTH_REJECTEDVERF:
2066 case RPCSEC_GSS_CREDPROBLEM:
2067 case RPCSEC_GSS_CTXPROBLEM:
2071 dprintk(
"RPC: %5u %s: retry stale creds\n",
2072 task->tk_pid, __func__);
2078 case RPC_AUTH_BADCRED:
2079 case RPC_AUTH_BADVERF:
2084 dprintk(
"RPC: %5u %s: retry garbled creds\n",
2085 task->tk_pid, __func__);
2088 case RPC_AUTH_TOOWEAK:
2091 "authentication.\n",
2096 dprintk(
"RPC: %5u %s: unknown auth error: %x\n",
2097 task->tk_pid, __func__, n);
2100 dprintk(
"RPC: %5u %s: call rejected %d\n",
2101 task->tk_pid, __func__, n);
2105 dprintk(
"RPC: %5u %s: auth check failed\n",
2106 task->tk_pid, __func__);
2112 switch ((n =
ntohl(*p++))) {
2115 case RPC_PROG_UNAVAIL:
2116 dprintk_rcu(
"RPC: %5u %s: program %u is unsupported "
2117 "by server %s\n", task->tk_pid, __func__,
2122 case RPC_PROG_MISMATCH:
2123 dprintk_rcu(
"RPC: %5u %s: program %u, version %u unsupported "
2124 "by server %s\n", task->tk_pid, __func__,
2130 case RPC_PROC_UNAVAIL:
2131 dprintk_rcu(
"RPC: %5u %s: proc %s unsupported by program %u, "
2132 "version %u on server %s\n",
2133 task->tk_pid, __func__,
2134 rpc_proc_name(task),
2139 case RPC_GARBAGE_ARGS:
2140 dprintk(
"RPC: %5u %s: server saw garbage\n",
2141 task->tk_pid, __func__);
2144 dprintk(
"RPC: %5u %s: server accept status: %x\n",
2145 task->tk_pid, __func__, n);
2153 dprintk(
"RPC: %5u %s: retrying\n",
2154 task->tk_pid, __func__);
2163 dprintk(
"RPC: %5u %s: call failed with error %d\n", task->tk_pid,
2165 return ERR_PTR(error);
2167 dprintk(
"RPC: %5u %s: server reply was truncated.\n", task->tk_pid,
2172 static void rpcproc_encode_null(
void *rqstp,
struct xdr_stream *xdr,
void *obj)
2176 static int rpcproc_decode_null(
void *rqstp,
struct xdr_stream *xdr,
void *obj)
2182 .p_encode = rpcproc_encode_null,
2183 .p_decode = rpcproc_decode_null,
2186 static int rpc_ping(
struct rpc_clnt *clnt)
2206 .rpc_message = &
msg,
2207 .callback_ops = &rpc_default_ops,
2215 static void rpc_show_header(
void)
2218 "-timeout ---ops--\n");
2221 static void rpc_show_task(
const struct rpc_clnt *clnt,
2224 const char *rpc_waitq =
"none";
2229 printk(
KERN_INFO "%5u %04x %6d %8p %8p %8ld %8p %sv%u %s a:%ps q:%s\n",
2236 void rpc_show_tasks(
struct net *net)
2251 rpc_show_task(clnt, task);