1 // SPDX-License-Identifier: GPL-2.0
3 * linux/net/sunrpc/xprtsock.c
5 * Client-side transport implementation for sockets.
7 * TCP callback races fixes (C) 1998 Red Hat
8 * TCP send fixes (C) 1998 Red Hat
9 * TCP NFS related read + write fixes
10 * (C) 1999 Dave Airlie, University of Limerick, Ireland <airlied@linux.ie>
12 * Rewrite of larges part of the code in order to stabilize TCP stuff.
13 * Fix behaviour when socket buffer is full.
14 * (C) 1999 Trond Myklebust <trond.myklebust@fys.uio.no>
16 * IP socket transport implementation, (C) 2005 Chuck Lever <cel@netapp.com>
18 * IPv6 support contributed by Gilles Quillard, Bull Open Source, 2005.
19 * <gilles.quillard@bull.net>
22 #include <linux/types.h>
23 #include <linux/string.h>
24 #include <linux/slab.h>
25 #include <linux/module.h>
26 #include <linux/capability.h>
27 #include <linux/pagemap.h>
28 #include <linux/errno.h>
29 #include <linux/socket.h>
31 #include <linux/net.h>
34 #include <linux/udp.h>
35 #include <linux/tcp.h>
36 #include <linux/sunrpc/clnt.h>
37 #include <linux/sunrpc/addr.h>
38 #include <linux/sunrpc/sched.h>
39 #include <linux/sunrpc/svcsock.h>
40 #include <linux/sunrpc/xprtsock.h>
41 #include <linux/file.h>
42 #ifdef CONFIG_SUNRPC_BACKCHANNEL
43 #include <linux/sunrpc/bc_xprt.h>
47 #include <net/checksum.h>
50 #include <linux/bvec.h>
51 #include <linux/highmem.h>
52 #include <linux/uio.h>
53 #include <linux/sched/mm.h>
55 #include <trace/events/sock.h>
56 #include <trace/events/sunrpc.h>
61 static void xs_close(struct rpc_xprt *xprt);
62 static void xs_set_srcport(struct sock_xprt *transport, struct socket *sock);
63 static void xs_tcp_set_socket_timeouts(struct rpc_xprt *xprt,
69 static unsigned int xprt_udp_slot_table_entries = RPC_DEF_SLOT_TABLE;
70 static unsigned int xprt_tcp_slot_table_entries = RPC_MIN_SLOT_TABLE;
71 static unsigned int xprt_max_tcp_slot_table_entries = RPC_MAX_SLOT_TABLE;
73 static unsigned int xprt_min_resvport = RPC_DEF_MIN_RESVPORT;
74 static unsigned int xprt_max_resvport = RPC_DEF_MAX_RESVPORT;
76 #define XS_TCP_LINGER_TO (15U * HZ)
77 static unsigned int xs_tcp_fin_timeout __read_mostly = XS_TCP_LINGER_TO;
80 * We can register our own files under /proc/sys/sunrpc by
81 * calling register_sysctl() again. The files in that
82 * directory become the union of all files registered there.
84 * We simply need to make sure that we don't collide with
85 * someone else's file names!
88 static unsigned int min_slot_table_size = RPC_MIN_SLOT_TABLE;
89 static unsigned int max_slot_table_size = RPC_MAX_SLOT_TABLE;
90 static unsigned int max_tcp_slot_table_limit = RPC_MAX_SLOT_TABLE_LIMIT;
91 static unsigned int xprt_min_resvport_limit = RPC_MIN_RESVPORT;
92 static unsigned int xprt_max_resvport_limit = RPC_MAX_RESVPORT;
94 static struct ctl_table_header *sunrpc_table_header;
96 static struct xprt_class xs_local_transport;
97 static struct xprt_class xs_udp_transport;
98 static struct xprt_class xs_tcp_transport;
99 static struct xprt_class xs_bc_tcp_transport;
102 * FIXME: changing the UDP slot table size should also resize the UDP
103 * socket buffers for existing UDP transports
105 static struct ctl_table xs_tunables_table[] = {
107 .procname = "udp_slot_table_entries",
108 .data = &xprt_udp_slot_table_entries,
109 .maxlen = sizeof(unsigned int),
111 .proc_handler = proc_dointvec_minmax,
112 .extra1 = &min_slot_table_size,
113 .extra2 = &max_slot_table_size
116 .procname = "tcp_slot_table_entries",
117 .data = &xprt_tcp_slot_table_entries,
118 .maxlen = sizeof(unsigned int),
120 .proc_handler = proc_dointvec_minmax,
121 .extra1 = &min_slot_table_size,
122 .extra2 = &max_slot_table_size
125 .procname = "tcp_max_slot_table_entries",
126 .data = &xprt_max_tcp_slot_table_entries,
127 .maxlen = sizeof(unsigned int),
129 .proc_handler = proc_dointvec_minmax,
130 .extra1 = &min_slot_table_size,
131 .extra2 = &max_tcp_slot_table_limit
134 .procname = "min_resvport",
135 .data = &xprt_min_resvport,
136 .maxlen = sizeof(unsigned int),
138 .proc_handler = proc_dointvec_minmax,
139 .extra1 = &xprt_min_resvport_limit,
140 .extra2 = &xprt_max_resvport_limit
143 .procname = "max_resvport",
144 .data = &xprt_max_resvport,
145 .maxlen = sizeof(unsigned int),
147 .proc_handler = proc_dointvec_minmax,
148 .extra1 = &xprt_min_resvport_limit,
149 .extra2 = &xprt_max_resvport_limit
152 .procname = "tcp_fin_timeout",
153 .data = &xs_tcp_fin_timeout,
154 .maxlen = sizeof(xs_tcp_fin_timeout),
156 .proc_handler = proc_dointvec_jiffies,
162 * Wait duration for a reply from the RPC portmapper.
164 #define XS_BIND_TO (60U * HZ)
167 * Delay if a UDP socket connect error occurs. This is most likely some
168 * kind of resource problem on the local host.
170 #define XS_UDP_REEST_TO (2U * HZ)
173 * The reestablish timeout allows clients to delay for a bit before attempting
174 * to reconnect to a server that just dropped our connection.
176 * We implement an exponential backoff when trying to reestablish a TCP
177 * transport connection with the server. Some servers like to drop a TCP
178 * connection when they are overworked, so we start with a short timeout and
179 * increase over time if the server is down or not responding.
181 #define XS_TCP_INIT_REEST_TO (3U * HZ)
184 * TCP idle timeout; client drops the transport socket if it is idle
185 * for this long. Note that we also timeout UDP sockets to prevent
186 * holding port numbers when there is no RPC traffic.
188 #define XS_IDLE_DISC_TO (5U * 60 * HZ)
190 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
191 # undef RPC_DEBUG_DATA
192 # define RPCDBG_FACILITY RPCDBG_TRANS
195 #ifdef RPC_DEBUG_DATA
196 static void xs_pktdump(char *msg, u32 *packet, unsigned int count)
198 u8 *buf = (u8 *) packet;
201 dprintk("RPC: %s\n", msg);
202 for (j = 0; j < count && j < 128; j += 4) {
206 dprintk("0x%04x ", j);
208 dprintk("%02x%02x%02x%02x ",
209 buf[j], buf[j+1], buf[j+2], buf[j+3]);
214 static inline void xs_pktdump(char *msg, u32 *packet, unsigned int count)
220 static inline struct rpc_xprt *xprt_from_sock(struct sock *sk)
222 return (struct rpc_xprt *) sk->sk_user_data;
225 static inline struct sockaddr *xs_addr(struct rpc_xprt *xprt)
227 return (struct sockaddr *) &xprt->addr;
230 static inline struct sockaddr_un *xs_addr_un(struct rpc_xprt *xprt)
232 return (struct sockaddr_un *) &xprt->addr;
235 static inline struct sockaddr_in *xs_addr_in(struct rpc_xprt *xprt)
237 return (struct sockaddr_in *) &xprt->addr;
240 static inline struct sockaddr_in6 *xs_addr_in6(struct rpc_xprt *xprt)
242 return (struct sockaddr_in6 *) &xprt->addr;
245 static void xs_format_common_peer_addresses(struct rpc_xprt *xprt)
247 struct sockaddr *sap = xs_addr(xprt);
248 struct sockaddr_in6 *sin6;
249 struct sockaddr_in *sin;
250 struct sockaddr_un *sun;
253 switch (sap->sa_family) {
255 sun = xs_addr_un(xprt);
256 strscpy(buf, sun->sun_path, sizeof(buf));
257 xprt->address_strings[RPC_DISPLAY_ADDR] =
258 kstrdup(buf, GFP_KERNEL);
261 (void)rpc_ntop(sap, buf, sizeof(buf));
262 xprt->address_strings[RPC_DISPLAY_ADDR] =
263 kstrdup(buf, GFP_KERNEL);
264 sin = xs_addr_in(xprt);
265 snprintf(buf, sizeof(buf), "%08x", ntohl(sin->sin_addr.s_addr));
268 (void)rpc_ntop(sap, buf, sizeof(buf));
269 xprt->address_strings[RPC_DISPLAY_ADDR] =
270 kstrdup(buf, GFP_KERNEL);
271 sin6 = xs_addr_in6(xprt);
272 snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr);
278 xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
281 static void xs_format_common_peer_ports(struct rpc_xprt *xprt)
283 struct sockaddr *sap = xs_addr(xprt);
286 snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
287 xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL);
289 snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
290 xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL);
293 static void xs_format_peer_addresses(struct rpc_xprt *xprt,
294 const char *protocol,
297 xprt->address_strings[RPC_DISPLAY_PROTO] = protocol;
298 xprt->address_strings[RPC_DISPLAY_NETID] = netid;
299 xs_format_common_peer_addresses(xprt);
300 xs_format_common_peer_ports(xprt);
303 static void xs_update_peer_port(struct rpc_xprt *xprt)
305 kfree(xprt->address_strings[RPC_DISPLAY_HEX_PORT]);
306 kfree(xprt->address_strings[RPC_DISPLAY_PORT]);
308 xs_format_common_peer_ports(xprt);
311 static void xs_free_peer_addresses(struct rpc_xprt *xprt)
315 for (i = 0; i < RPC_DISPLAY_MAX; i++)
317 case RPC_DISPLAY_PROTO:
318 case RPC_DISPLAY_NETID:
321 kfree(xprt->address_strings[i]);
326 xs_alloc_sparse_pages(struct xdr_buf *buf, size_t want, gfp_t gfp)
330 if (!want || !(buf->flags & XDRBUF_SPARSE_PAGES))
332 n = (buf->page_base + want + PAGE_SIZE - 1) >> PAGE_SHIFT;
333 for (i = 0; i < n; i++) {
336 buf->bvec[i].bv_page = buf->pages[i] = alloc_page(gfp);
337 if (!buf->pages[i]) {
339 return i > buf->page_base ? i - buf->page_base : 0;
346 xs_sock_recvmsg(struct socket *sock, struct msghdr *msg, int flags, size_t seek)
350 iov_iter_advance(&msg->msg_iter, seek);
351 ret = sock_recvmsg(sock, msg, flags);
352 return ret > 0 ? ret + seek : ret;
356 xs_read_kvec(struct socket *sock, struct msghdr *msg, int flags,
357 struct kvec *kvec, size_t count, size_t seek)
359 iov_iter_kvec(&msg->msg_iter, ITER_DEST, kvec, 1, count);
360 return xs_sock_recvmsg(sock, msg, flags, seek);
364 xs_read_bvec(struct socket *sock, struct msghdr *msg, int flags,
365 struct bio_vec *bvec, unsigned long nr, size_t count,
368 iov_iter_bvec(&msg->msg_iter, ITER_DEST, bvec, nr, count);
369 return xs_sock_recvmsg(sock, msg, flags, seek);
373 xs_read_discard(struct socket *sock, struct msghdr *msg, int flags,
376 iov_iter_discard(&msg->msg_iter, ITER_DEST, count);
377 return sock_recvmsg(sock, msg, flags);
380 #if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
382 xs_flush_bvec(const struct bio_vec *bvec, size_t count, size_t seek)
384 struct bvec_iter bi = {
389 bvec_iter_advance(bvec, &bi, seek & PAGE_MASK);
390 for_each_bvec(bv, bvec, bi, bi)
391 flush_dcache_page(bv.bv_page);
395 xs_flush_bvec(const struct bio_vec *bvec, size_t count, size_t seek)
401 xs_read_xdr_buf(struct socket *sock, struct msghdr *msg, int flags,
402 struct xdr_buf *buf, size_t count, size_t seek, size_t *read)
404 size_t want, seek_init = seek, offset = 0;
407 want = min_t(size_t, count, buf->head[0].iov_len);
409 ret = xs_read_kvec(sock, msg, flags, &buf->head[0], want, seek);
413 if (offset == count || msg->msg_flags & (MSG_EOR|MSG_TRUNC))
423 want = xs_alloc_sparse_pages(
424 buf, min_t(size_t, count - offset, buf->page_len),
425 GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
427 ret = xs_read_bvec(sock, msg, flags, buf->bvec,
428 xdr_buf_pagecount(buf),
429 want + buf->page_base,
430 seek + buf->page_base);
433 xs_flush_bvec(buf->bvec, ret, seek + buf->page_base);
434 ret -= buf->page_base;
436 if (offset == count || msg->msg_flags & (MSG_EOR|MSG_TRUNC))
446 want = min_t(size_t, count - offset, buf->tail[0].iov_len);
448 ret = xs_read_kvec(sock, msg, flags, &buf->tail[0], want, seek);
452 if (offset == count || msg->msg_flags & (MSG_EOR|MSG_TRUNC))
456 } else if (offset < seek_init)
460 *read = offset - seek_init;
468 xs_read_header(struct sock_xprt *transport, struct xdr_buf *buf)
470 if (!transport->recv.copied) {
471 if (buf->head[0].iov_len >= transport->recv.offset)
472 memcpy(buf->head[0].iov_base,
473 &transport->recv.xid,
474 transport->recv.offset);
475 transport->recv.copied = transport->recv.offset;
480 xs_read_stream_request_done(struct sock_xprt *transport)
482 return transport->recv.fraghdr & cpu_to_be32(RPC_LAST_STREAM_FRAGMENT);
486 xs_read_stream_check_eor(struct sock_xprt *transport,
489 if (xs_read_stream_request_done(transport))
490 msg->msg_flags |= MSG_EOR;
494 xs_read_stream_request(struct sock_xprt *transport, struct msghdr *msg,
495 int flags, struct rpc_rqst *req)
497 struct xdr_buf *buf = &req->rq_private_buf;
501 xs_read_header(transport, buf);
503 want = transport->recv.len - transport->recv.offset;
505 ret = xs_read_xdr_buf(transport->sock, msg, flags, buf,
506 transport->recv.copied + want,
507 transport->recv.copied,
509 transport->recv.offset += read;
510 transport->recv.copied += read;
513 if (transport->recv.offset == transport->recv.len)
514 xs_read_stream_check_eor(transport, msg);
524 msg->msg_flags |= MSG_TRUNC;
529 return ret < 0 ? ret : read;
533 xs_read_stream_headersize(bool isfrag)
536 return sizeof(__be32);
537 return 3 * sizeof(__be32);
541 xs_read_stream_header(struct sock_xprt *transport, struct msghdr *msg,
542 int flags, size_t want, size_t seek)
545 .iov_base = &transport->recv.fraghdr,
548 return xs_read_kvec(transport->sock, msg, flags, &kvec, want, seek);
551 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
553 xs_read_stream_call(struct sock_xprt *transport, struct msghdr *msg, int flags)
555 struct rpc_xprt *xprt = &transport->xprt;
556 struct rpc_rqst *req;
559 /* Is this transport associated with the backchannel? */
563 /* Look up and lock the request corresponding to the given XID */
564 req = xprt_lookup_bc_request(xprt, transport->recv.xid);
566 printk(KERN_WARNING "Callback slot table overflowed\n");
569 if (transport->recv.copied && !req->rq_private_buf.len)
572 ret = xs_read_stream_request(transport, msg, flags, req);
573 if (msg->msg_flags & (MSG_EOR|MSG_TRUNC))
574 xprt_complete_bc_request(req, transport->recv.copied);
576 req->rq_private_buf.len = transport->recv.copied;
580 #else /* CONFIG_SUNRPC_BACKCHANNEL */
582 xs_read_stream_call(struct sock_xprt *transport, struct msghdr *msg, int flags)
586 #endif /* CONFIG_SUNRPC_BACKCHANNEL */
589 xs_read_stream_reply(struct sock_xprt *transport, struct msghdr *msg, int flags)
591 struct rpc_xprt *xprt = &transport->xprt;
592 struct rpc_rqst *req;
595 /* Look up and lock the request corresponding to the given XID */
596 spin_lock(&xprt->queue_lock);
597 req = xprt_lookup_rqst(xprt, transport->recv.xid);
598 if (!req || (transport->recv.copied && !req->rq_private_buf.len)) {
599 msg->msg_flags |= MSG_TRUNC;
603 spin_unlock(&xprt->queue_lock);
605 ret = xs_read_stream_request(transport, msg, flags, req);
607 spin_lock(&xprt->queue_lock);
608 if (msg->msg_flags & (MSG_EOR|MSG_TRUNC))
609 xprt_complete_rqst(req->rq_task, transport->recv.copied);
611 req->rq_private_buf.len = transport->recv.copied;
612 xprt_unpin_rqst(req);
614 spin_unlock(&xprt->queue_lock);
619 xs_read_stream(struct sock_xprt *transport, int flags)
621 struct msghdr msg = { 0 };
622 size_t want, read = 0;
625 if (transport->recv.len == 0) {
626 want = xs_read_stream_headersize(transport->recv.copied != 0);
627 ret = xs_read_stream_header(transport, &msg, flags, want,
628 transport->recv.offset);
631 transport->recv.offset = ret;
632 if (transport->recv.offset != want)
633 return transport->recv.offset;
634 transport->recv.len = be32_to_cpu(transport->recv.fraghdr) &
635 RPC_FRAGMENT_SIZE_MASK;
636 transport->recv.offset -= sizeof(transport->recv.fraghdr);
640 switch (be32_to_cpu(transport->recv.calldir)) {
642 msg.msg_flags |= MSG_TRUNC;
645 ret = xs_read_stream_call(transport, &msg, flags);
648 ret = xs_read_stream_reply(transport, &msg, flags);
650 if (msg.msg_flags & MSG_TRUNC) {
651 transport->recv.calldir = cpu_to_be32(-1);
652 transport->recv.copied = -1;
657 if (transport->recv.offset < transport->recv.len) {
658 if (!(msg.msg_flags & MSG_TRUNC))
661 ret = xs_read_discard(transport->sock, &msg, flags,
662 transport->recv.len - transport->recv.offset);
665 transport->recv.offset += ret;
667 if (transport->recv.offset != transport->recv.len)
670 if (xs_read_stream_request_done(transport)) {
671 trace_xs_stream_read_request(transport);
672 transport->recv.copied = 0;
674 transport->recv.offset = 0;
675 transport->recv.len = 0;
678 return ret != 0 ? ret : -ESHUTDOWN;
681 static __poll_t xs_poll_socket(struct sock_xprt *transport)
683 return transport->sock->ops->poll(transport->file, transport->sock,
687 static bool xs_poll_socket_readable(struct sock_xprt *transport)
689 __poll_t events = xs_poll_socket(transport);
691 return (events & (EPOLLIN | EPOLLRDNORM)) && !(events & EPOLLRDHUP);
694 static void xs_poll_check_readable(struct sock_xprt *transport)
697 clear_bit(XPRT_SOCK_DATA_READY, &transport->sock_state);
698 if (!xs_poll_socket_readable(transport))
700 if (!test_and_set_bit(XPRT_SOCK_DATA_READY, &transport->sock_state))
701 queue_work(xprtiod_workqueue, &transport->recv_worker);
704 static void xs_stream_data_receive(struct sock_xprt *transport)
709 mutex_lock(&transport->recv_mutex);
710 if (transport->sock == NULL)
713 ret = xs_read_stream(transport, MSG_DONTWAIT);
719 if (ret == -ESHUTDOWN)
720 kernel_sock_shutdown(transport->sock, SHUT_RDWR);
722 xs_poll_check_readable(transport);
724 mutex_unlock(&transport->recv_mutex);
725 trace_xs_stream_read_data(&transport->xprt, ret, read);
728 static void xs_stream_data_receive_workfn(struct work_struct *work)
730 struct sock_xprt *transport =
731 container_of(work, struct sock_xprt, recv_worker);
732 unsigned int pflags = memalloc_nofs_save();
734 xs_stream_data_receive(transport);
735 memalloc_nofs_restore(pflags);
739 xs_stream_reset_connect(struct sock_xprt *transport)
741 transport->recv.offset = 0;
742 transport->recv.len = 0;
743 transport->recv.copied = 0;
744 transport->xmit.offset = 0;
748 xs_stream_start_connect(struct sock_xprt *transport)
750 transport->xprt.stat.connect_count++;
751 transport->xprt.stat.connect_start = jiffies;
754 #define XS_SENDMSG_FLAGS (MSG_DONTWAIT | MSG_NOSIGNAL)
757 * xs_nospace - handle transmit was incomplete
758 * @req: pointer to RPC request
759 * @transport: pointer to struct sock_xprt
762 static int xs_nospace(struct rpc_rqst *req, struct sock_xprt *transport)
764 struct rpc_xprt *xprt = &transport->xprt;
765 struct sock *sk = transport->inet;
768 trace_rpc_socket_nospace(req, transport);
770 /* Protect against races with write_space */
771 spin_lock(&xprt->transport_lock);
773 /* Don't race with disconnect */
774 if (xprt_connected(xprt)) {
775 /* wait for more buffer space */
776 set_bit(XPRT_SOCK_NOSPACE, &transport->sock_state);
777 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
778 sk->sk_write_pending++;
779 xprt_wait_for_buffer_space(xprt);
783 spin_unlock(&xprt->transport_lock);
787 static int xs_sock_nospace(struct rpc_rqst *req)
789 struct sock_xprt *transport =
790 container_of(req->rq_xprt, struct sock_xprt, xprt);
791 struct sock *sk = transport->inet;
795 if (!sock_writeable(sk))
796 ret = xs_nospace(req, transport);
801 static int xs_stream_nospace(struct rpc_rqst *req, bool vm_wait)
803 struct sock_xprt *transport =
804 container_of(req->rq_xprt, struct sock_xprt, xprt);
805 struct sock *sk = transport->inet;
811 if (!sk_stream_memory_free(sk))
812 ret = xs_nospace(req, transport);
817 static int xs_stream_prepare_request(struct rpc_rqst *req, struct xdr_buf *buf)
819 return xdr_alloc_bvec(buf, rpc_task_gfp_mask());
823 * Determine if the previous message in the stream was aborted before it
824 * could complete transmission.
827 xs_send_request_was_aborted(struct sock_xprt *transport, struct rpc_rqst *req)
829 return transport->xmit.offset != 0 && req->rq_bytes_sent == 0;
833 * Return the stream record marker field for a record of length < 2^31-1
836 xs_stream_record_marker(struct xdr_buf *xdr)
840 return cpu_to_be32(RPC_LAST_STREAM_FRAGMENT | (u32)xdr->len);
844 * xs_local_send_request - write an RPC request to an AF_LOCAL socket
845 * @req: pointer to RPC request
848 * 0: The request has been sent
849 * EAGAIN: The socket was blocked, please call again later to
850 * complete the request
851 * ENOTCONN: Caller needs to invoke connect logic then call again
852 * other: Some other error occurred, the request was not sent
854 static int xs_local_send_request(struct rpc_rqst *req)
856 struct rpc_xprt *xprt = req->rq_xprt;
857 struct sock_xprt *transport =
858 container_of(xprt, struct sock_xprt, xprt);
859 struct xdr_buf *xdr = &req->rq_snd_buf;
860 rpc_fraghdr rm = xs_stream_record_marker(xdr);
861 unsigned int msglen = rm ? req->rq_slen + sizeof(rm) : req->rq_slen;
862 struct msghdr msg = {
863 .msg_flags = XS_SENDMSG_FLAGS,
869 /* Close the stream if the previous transmission was incomplete */
870 if (xs_send_request_was_aborted(transport, req)) {
871 xprt_force_disconnect(xprt);
875 xs_pktdump("packet data:",
876 req->rq_svec->iov_base, req->rq_svec->iov_len);
878 vm_wait = sk_stream_is_writeable(transport->inet) ? true : false;
880 req->rq_xtime = ktime_get();
881 status = xprt_sock_sendmsg(transport->sock, &msg, xdr,
882 transport->xmit.offset, rm, &sent);
883 dprintk("RPC: %s(%u) = %d\n",
884 __func__, xdr->len - transport->xmit.offset, status);
886 if (likely(sent > 0) || status == 0) {
887 transport->xmit.offset += sent;
888 req->rq_bytes_sent = transport->xmit.offset;
889 if (likely(req->rq_bytes_sent >= msglen)) {
890 req->rq_xmit_bytes_sent += transport->xmit.offset;
891 transport->xmit.offset = 0;
900 status = xs_stream_nospace(req, vm_wait);
903 dprintk("RPC: sendmsg returned unrecognized error %d\n",
907 xprt_force_disconnect(xprt);
915 * xs_udp_send_request - write an RPC request to a UDP socket
916 * @req: pointer to RPC request
919 * 0: The request has been sent
920 * EAGAIN: The socket was blocked, please call again later to
921 * complete the request
922 * ENOTCONN: Caller needs to invoke connect logic then call again
923 * other: Some other error occurred, the request was not sent
925 static int xs_udp_send_request(struct rpc_rqst *req)
927 struct rpc_xprt *xprt = req->rq_xprt;
928 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
929 struct xdr_buf *xdr = &req->rq_snd_buf;
930 struct msghdr msg = {
931 .msg_name = xs_addr(xprt),
932 .msg_namelen = xprt->addrlen,
933 .msg_flags = XS_SENDMSG_FLAGS,
938 xs_pktdump("packet data:",
939 req->rq_svec->iov_base,
940 req->rq_svec->iov_len);
942 if (!xprt_bound(xprt))
945 if (!xprt_request_get_cong(xprt, req))
948 status = xdr_alloc_bvec(xdr, rpc_task_gfp_mask());
951 req->rq_xtime = ktime_get();
952 status = xprt_sock_sendmsg(transport->sock, &msg, xdr, 0, 0, &sent);
954 dprintk("RPC: xs_udp_send_request(%u) = %d\n",
957 /* firewall is blocking us, don't return -EAGAIN or we end up looping */
958 if (status == -EPERM)
961 if (status == -EAGAIN && sock_writeable(transport->inet))
964 if (sent > 0 || status == 0) {
965 req->rq_xmit_bytes_sent += sent;
966 if (sent >= req->rq_slen)
968 /* Still some bytes left; set up for a retry later. */
976 /* Should we call xs_close() here? */
979 status = xs_sock_nospace(req);
986 /* When the server has died, an ICMP port unreachable message
987 * prompts ECONNREFUSED. */
990 dprintk("RPC: sendmsg returned unrecognized error %d\n",
998 * xs_tcp_send_request - write an RPC request to a TCP socket
999 * @req: pointer to RPC request
1002 * 0: The request has been sent
1003 * EAGAIN: The socket was blocked, please call again later to
1004 * complete the request
1005 * ENOTCONN: Caller needs to invoke connect logic then call again
1006 * other: Some other error occurred, the request was not sent
1008 * XXX: In the case of soft timeouts, should we eventually give up
1009 * if sendmsg is not able to make progress?
1011 static int xs_tcp_send_request(struct rpc_rqst *req)
1013 struct rpc_xprt *xprt = req->rq_xprt;
1014 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
1015 struct xdr_buf *xdr = &req->rq_snd_buf;
1016 rpc_fraghdr rm = xs_stream_record_marker(xdr);
1017 unsigned int msglen = rm ? req->rq_slen + sizeof(rm) : req->rq_slen;
1018 struct msghdr msg = {
1019 .msg_flags = XS_SENDMSG_FLAGS,
1025 /* Close the stream if the previous transmission was incomplete */
1026 if (xs_send_request_was_aborted(transport, req)) {
1027 if (transport->sock != NULL)
1028 kernel_sock_shutdown(transport->sock, SHUT_RDWR);
1031 if (!transport->inet)
1034 xs_pktdump("packet data:",
1035 req->rq_svec->iov_base,
1036 req->rq_svec->iov_len);
1038 if (test_bit(XPRT_SOCK_UPD_TIMEOUT, &transport->sock_state))
1039 xs_tcp_set_socket_timeouts(xprt, transport->sock);
1041 xs_set_srcport(transport, transport->sock);
1043 /* Continue transmitting the packet/record. We must be careful
1044 * to cope with writespace callbacks arriving _after_ we have
1045 * called sendmsg(). */
1046 req->rq_xtime = ktime_get();
1047 tcp_sock_set_cork(transport->inet, true);
1049 vm_wait = sk_stream_is_writeable(transport->inet) ? true : false;
1052 status = xprt_sock_sendmsg(transport->sock, &msg, xdr,
1053 transport->xmit.offset, rm, &sent);
1055 dprintk("RPC: xs_tcp_send_request(%u) = %d\n",
1056 xdr->len - transport->xmit.offset, status);
1058 /* If we've sent the entire packet, immediately
1059 * reset the count of bytes sent. */
1060 transport->xmit.offset += sent;
1061 req->rq_bytes_sent = transport->xmit.offset;
1062 if (likely(req->rq_bytes_sent >= msglen)) {
1063 req->rq_xmit_bytes_sent += transport->xmit.offset;
1064 transport->xmit.offset = 0;
1065 if (atomic_long_read(&xprt->xmit_queuelen) == 1)
1066 tcp_sock_set_cork(transport->inet, false);
1070 WARN_ON_ONCE(sent == 0 && status == 0);
1075 } while (status == 0);
1080 /* Should we call xs_close() here? */
1083 status = xs_stream_nospace(req, vm_wait);
1093 dprintk("RPC: sendmsg returned unrecognized error %d\n",
1100 static void xs_save_old_callbacks(struct sock_xprt *transport, struct sock *sk)
1102 transport->old_data_ready = sk->sk_data_ready;
1103 transport->old_state_change = sk->sk_state_change;
1104 transport->old_write_space = sk->sk_write_space;
1105 transport->old_error_report = sk->sk_error_report;
1108 static void xs_restore_old_callbacks(struct sock_xprt *transport, struct sock *sk)
1110 sk->sk_data_ready = transport->old_data_ready;
1111 sk->sk_state_change = transport->old_state_change;
1112 sk->sk_write_space = transport->old_write_space;
1113 sk->sk_error_report = transport->old_error_report;
1116 static void xs_sock_reset_state_flags(struct rpc_xprt *xprt)
1118 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
1120 clear_bit(XPRT_SOCK_DATA_READY, &transport->sock_state);
1121 clear_bit(XPRT_SOCK_WAKE_ERROR, &transport->sock_state);
1122 clear_bit(XPRT_SOCK_WAKE_WRITE, &transport->sock_state);
1123 clear_bit(XPRT_SOCK_WAKE_DISCONNECT, &transport->sock_state);
1124 clear_bit(XPRT_SOCK_NOSPACE, &transport->sock_state);
1127 static void xs_run_error_worker(struct sock_xprt *transport, unsigned int nr)
1129 set_bit(nr, &transport->sock_state);
1130 queue_work(xprtiod_workqueue, &transport->error_worker);
1133 static void xs_sock_reset_connection_flags(struct rpc_xprt *xprt)
1135 xprt->connect_cookie++;
1136 smp_mb__before_atomic();
1137 clear_bit(XPRT_CLOSE_WAIT, &xprt->state);
1138 clear_bit(XPRT_CLOSING, &xprt->state);
1139 xs_sock_reset_state_flags(xprt);
1140 smp_mb__after_atomic();
1144 * xs_error_report - callback to handle TCP socket state errors
1147 * Note: we don't call sock_error() since there may be a rpc_task
1148 * using the socket, and so we don't want to clear sk->sk_err.
1150 static void xs_error_report(struct sock *sk)
1152 struct sock_xprt *transport;
1153 struct rpc_xprt *xprt;
1155 if (!(xprt = xprt_from_sock(sk)))
1158 transport = container_of(xprt, struct sock_xprt, xprt);
1159 transport->xprt_err = -sk->sk_err;
1160 if (transport->xprt_err == 0)
1162 dprintk("RPC: xs_error_report client %p, error=%d...\n",
1163 xprt, -transport->xprt_err);
1164 trace_rpc_socket_error(xprt, sk->sk_socket, transport->xprt_err);
1166 /* barrier ensures xprt_err is set before XPRT_SOCK_WAKE_ERROR */
1167 smp_mb__before_atomic();
1168 xs_run_error_worker(transport, XPRT_SOCK_WAKE_ERROR);
1171 static void xs_reset_transport(struct sock_xprt *transport)
1173 struct socket *sock = transport->sock;
1174 struct sock *sk = transport->inet;
1175 struct rpc_xprt *xprt = &transport->xprt;
1176 struct file *filp = transport->file;
1181 * Make sure we're calling this in a context from which it is safe
1182 * to call __fput_sync(). In practice that means rpciod and the
1185 if (!(current->flags & PF_WQ_WORKER)) {
1187 set_bit(XPRT_CLOSE_WAIT, &xprt->state);
1191 if (atomic_read(&transport->xprt.swapper))
1192 sk_clear_memalloc(sk);
1194 kernel_sock_shutdown(sock, SHUT_RDWR);
1196 mutex_lock(&transport->recv_mutex);
1198 transport->inet = NULL;
1199 transport->sock = NULL;
1200 transport->file = NULL;
1202 sk->sk_user_data = NULL;
1204 xs_restore_old_callbacks(transport, sk);
1205 xprt_clear_connected(xprt);
1206 xs_sock_reset_connection_flags(xprt);
1207 /* Reset stream record info */
1208 xs_stream_reset_connect(transport);
1210 mutex_unlock(&transport->recv_mutex);
1212 trace_rpc_socket_close(xprt, sock);
1215 xprt_disconnect_done(xprt);
1219 * xs_close - close a socket
1222 * This is used when all requests are complete; ie, no DRC state remains
1223 * on the server we want to save.
1225 * The caller _must_ be holding XPRT_LOCKED in order to avoid issues with
1226 * xs_reset_transport() zeroing the socket from underneath a writer.
1228 static void xs_close(struct rpc_xprt *xprt)
1230 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
1232 dprintk("RPC: xs_close xprt %p\n", xprt);
1234 xs_reset_transport(transport);
1235 xprt->reestablish_timeout = 0;
1238 static void xs_inject_disconnect(struct rpc_xprt *xprt)
1240 dprintk("RPC: injecting transport disconnect on xprt=%p\n",
1242 xprt_disconnect_done(xprt);
1245 static void xs_xprt_free(struct rpc_xprt *xprt)
1247 xs_free_peer_addresses(xprt);
1252 * xs_destroy - prepare to shutdown a transport
1253 * @xprt: doomed transport
1256 static void xs_destroy(struct rpc_xprt *xprt)
1258 struct sock_xprt *transport = container_of(xprt,
1259 struct sock_xprt, xprt);
1260 dprintk("RPC: xs_destroy xprt %p\n", xprt);
1262 cancel_delayed_work_sync(&transport->connect_worker);
1264 cancel_work_sync(&transport->recv_worker);
1265 cancel_work_sync(&transport->error_worker);
1267 module_put(THIS_MODULE);
1271 * xs_udp_data_read_skb - receive callback for UDP sockets
1277 static void xs_udp_data_read_skb(struct rpc_xprt *xprt,
1279 struct sk_buff *skb)
1281 struct rpc_task *task;
1282 struct rpc_rqst *rovr;
1283 int repsize, copied;
1289 dprintk("RPC: impossible RPC reply size %d!\n", repsize);
1293 /* Copy the XID from the skb... */
1294 xp = skb_header_pointer(skb, 0, sizeof(_xid), &_xid);
1298 /* Look up and lock the request corresponding to the given XID */
1299 spin_lock(&xprt->queue_lock);
1300 rovr = xprt_lookup_rqst(xprt, *xp);
1303 xprt_pin_rqst(rovr);
1304 xprt_update_rtt(rovr->rq_task);
1305 spin_unlock(&xprt->queue_lock);
1306 task = rovr->rq_task;
1308 if ((copied = rovr->rq_private_buf.buflen) > repsize)
1311 /* Suck it into the iovec, verify checksum if not done by hw. */
1312 if (csum_partial_copy_to_xdr(&rovr->rq_private_buf, skb)) {
1313 spin_lock(&xprt->queue_lock);
1314 __UDPX_INC_STATS(sk, UDP_MIB_INERRORS);
1319 spin_lock(&xprt->transport_lock);
1320 xprt_adjust_cwnd(xprt, task, copied);
1321 spin_unlock(&xprt->transport_lock);
1322 spin_lock(&xprt->queue_lock);
1323 xprt_complete_rqst(task, copied);
1324 __UDPX_INC_STATS(sk, UDP_MIB_INDATAGRAMS);
1326 xprt_unpin_rqst(rovr);
1328 spin_unlock(&xprt->queue_lock);
1331 static void xs_udp_data_receive(struct sock_xprt *transport)
1333 struct sk_buff *skb;
1337 mutex_lock(&transport->recv_mutex);
1338 sk = transport->inet;
1342 skb = skb_recv_udp(sk, MSG_DONTWAIT, &err);
1345 xs_udp_data_read_skb(&transport->xprt, sk, skb);
1349 xs_poll_check_readable(transport);
1351 mutex_unlock(&transport->recv_mutex);
1354 static void xs_udp_data_receive_workfn(struct work_struct *work)
1356 struct sock_xprt *transport =
1357 container_of(work, struct sock_xprt, recv_worker);
1358 unsigned int pflags = memalloc_nofs_save();
1360 xs_udp_data_receive(transport);
1361 memalloc_nofs_restore(pflags);
1365 * xs_data_ready - "data ready" callback for sockets
1366 * @sk: socket with data to read
1369 static void xs_data_ready(struct sock *sk)
1371 struct rpc_xprt *xprt;
1373 trace_sk_data_ready(sk);
1375 xprt = xprt_from_sock(sk);
1377 struct sock_xprt *transport = container_of(xprt,
1378 struct sock_xprt, xprt);
1380 trace_xs_data_ready(xprt);
1382 transport->old_data_ready(sk);
1383 /* Any data means we had a useful conversation, so
1384 * then we don't need to delay the next reconnect
1386 if (xprt->reestablish_timeout)
1387 xprt->reestablish_timeout = 0;
1388 if (!test_and_set_bit(XPRT_SOCK_DATA_READY, &transport->sock_state))
1389 queue_work(xprtiod_workqueue, &transport->recv_worker);
1394 * Helper function to force a TCP close if the server is sending
1395 * junk and/or it has put us in CLOSE_WAIT
1397 static void xs_tcp_force_close(struct rpc_xprt *xprt)
1399 xprt_force_disconnect(xprt);
1402 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
1403 static size_t xs_tcp_bc_maxpayload(struct rpc_xprt *xprt)
1407 #endif /* CONFIG_SUNRPC_BACKCHANNEL */
1410 * xs_local_state_change - callback to handle AF_LOCAL socket state changes
1411 * @sk: socket whose state has changed
1414 static void xs_local_state_change(struct sock *sk)
1416 struct rpc_xprt *xprt;
1417 struct sock_xprt *transport;
1419 if (!(xprt = xprt_from_sock(sk)))
1421 transport = container_of(xprt, struct sock_xprt, xprt);
1422 if (sk->sk_shutdown & SHUTDOWN_MASK) {
1423 clear_bit(XPRT_CONNECTED, &xprt->state);
1424 /* Trigger the socket release */
1425 xs_run_error_worker(transport, XPRT_SOCK_WAKE_DISCONNECT);
1430 * xs_tcp_state_change - callback to handle TCP socket state changes
1431 * @sk: socket whose state has changed
1434 static void xs_tcp_state_change(struct sock *sk)
1436 struct rpc_xprt *xprt;
1437 struct sock_xprt *transport;
1439 if (!(xprt = xprt_from_sock(sk)))
1441 dprintk("RPC: xs_tcp_state_change client %p...\n", xprt);
1442 dprintk("RPC: state %x conn %d dead %d zapped %d sk_shutdown %d\n",
1443 sk->sk_state, xprt_connected(xprt),
1444 sock_flag(sk, SOCK_DEAD),
1445 sock_flag(sk, SOCK_ZAPPED),
1448 transport = container_of(xprt, struct sock_xprt, xprt);
1449 trace_rpc_socket_state_change(xprt, sk->sk_socket);
1450 switch (sk->sk_state) {
1451 case TCP_ESTABLISHED:
1452 if (!xprt_test_and_set_connected(xprt)) {
1453 xprt->connect_cookie++;
1454 clear_bit(XPRT_SOCK_CONNECTING, &transport->sock_state);
1455 xprt_clear_connecting(xprt);
1457 xprt->stat.connect_count++;
1458 xprt->stat.connect_time += (long)jiffies -
1459 xprt->stat.connect_start;
1460 xs_run_error_worker(transport, XPRT_SOCK_WAKE_PENDING);
1464 /* The client initiated a shutdown of the socket */
1465 xprt->connect_cookie++;
1466 xprt->reestablish_timeout = 0;
1467 set_bit(XPRT_CLOSING, &xprt->state);
1468 smp_mb__before_atomic();
1469 clear_bit(XPRT_CONNECTED, &xprt->state);
1470 clear_bit(XPRT_CLOSE_WAIT, &xprt->state);
1471 smp_mb__after_atomic();
1473 case TCP_CLOSE_WAIT:
1474 /* The server initiated a shutdown of the socket */
1475 xprt->connect_cookie++;
1476 clear_bit(XPRT_CONNECTED, &xprt->state);
1477 xs_run_error_worker(transport, XPRT_SOCK_WAKE_DISCONNECT);
1481 * If the server closed down the connection, make sure that
1482 * we back off before reconnecting
1484 if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO)
1485 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
1488 set_bit(XPRT_CLOSING, &xprt->state);
1489 smp_mb__before_atomic();
1490 clear_bit(XPRT_CONNECTED, &xprt->state);
1491 smp_mb__after_atomic();
1494 if (test_and_clear_bit(XPRT_SOCK_CONNECTING,
1495 &transport->sock_state))
1496 xprt_clear_connecting(xprt);
1497 clear_bit(XPRT_CLOSING, &xprt->state);
1498 /* Trigger the socket release */
1499 xs_run_error_worker(transport, XPRT_SOCK_WAKE_DISCONNECT);
1503 static void xs_write_space(struct sock *sk)
1505 struct sock_xprt *transport;
1506 struct rpc_xprt *xprt;
1510 clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
1512 if (unlikely(!(xprt = xprt_from_sock(sk))))
1514 transport = container_of(xprt, struct sock_xprt, xprt);
1515 if (!test_and_clear_bit(XPRT_SOCK_NOSPACE, &transport->sock_state))
1517 xs_run_error_worker(transport, XPRT_SOCK_WAKE_WRITE);
1518 sk->sk_write_pending--;
1522 * xs_udp_write_space - callback invoked when socket buffer space
1524 * @sk: socket whose state has changed
1526 * Called when more output buffer space is available for this socket.
1527 * We try not to wake our writers until they can make "significant"
1528 * progress, otherwise we'll waste resources thrashing kernel_sendmsg
1529 * with a bunch of small requests.
1531 static void xs_udp_write_space(struct sock *sk)
1533 /* from net/core/sock.c:sock_def_write_space */
1534 if (sock_writeable(sk))
1539 * xs_tcp_write_space - callback invoked when socket buffer space
1541 * @sk: socket whose state has changed
1543 * Called when more output buffer space is available for this socket.
1544 * We try not to wake our writers until they can make "significant"
1545 * progress, otherwise we'll waste resources thrashing kernel_sendmsg
1546 * with a bunch of small requests.
1548 static void xs_tcp_write_space(struct sock *sk)
1550 /* from net/core/stream.c:sk_stream_write_space */
1551 if (sk_stream_is_writeable(sk))
1555 static void xs_udp_do_set_buffer_size(struct rpc_xprt *xprt)
1557 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
1558 struct sock *sk = transport->inet;
1560 if (transport->rcvsize) {
1561 sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
1562 sk->sk_rcvbuf = transport->rcvsize * xprt->max_reqs * 2;
1564 if (transport->sndsize) {
1565 sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
1566 sk->sk_sndbuf = transport->sndsize * xprt->max_reqs * 2;
1567 sk->sk_write_space(sk);
1572 * xs_udp_set_buffer_size - set send and receive limits
1573 * @xprt: generic transport
1574 * @sndsize: requested size of send buffer, in bytes
1575 * @rcvsize: requested size of receive buffer, in bytes
1577 * Set socket send and receive buffer size limits.
1579 static void xs_udp_set_buffer_size(struct rpc_xprt *xprt, size_t sndsize, size_t rcvsize)
1581 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
1583 transport->sndsize = 0;
1585 transport->sndsize = sndsize + 1024;
1586 transport->rcvsize = 0;
1588 transport->rcvsize = rcvsize + 1024;
1590 xs_udp_do_set_buffer_size(xprt);
1594 * xs_udp_timer - called when a retransmit timeout occurs on a UDP transport
1595 * @xprt: controlling transport
1596 * @task: task that timed out
1598 * Adjust the congestion window after a retransmit timeout has occurred.
1600 static void xs_udp_timer(struct rpc_xprt *xprt, struct rpc_task *task)
1602 spin_lock(&xprt->transport_lock);
1603 xprt_adjust_cwnd(xprt, task, -ETIMEDOUT);
1604 spin_unlock(&xprt->transport_lock);
1607 static int xs_get_random_port(void)
1609 unsigned short min = xprt_min_resvport, max = xprt_max_resvport;
1610 unsigned short range;
1611 unsigned short rand;
1615 range = max - min + 1;
1616 rand = get_random_u32_below(range);
1620 static unsigned short xs_sock_getport(struct socket *sock)
1622 struct sockaddr_storage buf;
1623 unsigned short port = 0;
1625 if (kernel_getsockname(sock, (struct sockaddr *)&buf) < 0)
1627 switch (buf.ss_family) {
1629 port = ntohs(((struct sockaddr_in6 *)&buf)->sin6_port);
1632 port = ntohs(((struct sockaddr_in *)&buf)->sin_port);
1639 * xs_set_port - reset the port number in the remote endpoint address
1640 * @xprt: generic transport
1641 * @port: new port number
1644 static void xs_set_port(struct rpc_xprt *xprt, unsigned short port)
1646 dprintk("RPC: setting port for xprt %p to %u\n", xprt, port);
1648 rpc_set_port(xs_addr(xprt), port);
1649 xs_update_peer_port(xprt);
1652 static void xs_set_srcport(struct sock_xprt *transport, struct socket *sock)
1654 if (transport->srcport == 0 && transport->xprt.reuseport)
1655 transport->srcport = xs_sock_getport(sock);
1658 static int xs_get_srcport(struct sock_xprt *transport)
1660 int port = transport->srcport;
1662 if (port == 0 && transport->xprt.resvport)
1663 port = xs_get_random_port();
1667 static unsigned short xs_sock_srcport(struct rpc_xprt *xprt)
1669 struct sock_xprt *sock = container_of(xprt, struct sock_xprt, xprt);
1670 unsigned short ret = 0;
1671 mutex_lock(&sock->recv_mutex);
1673 ret = xs_sock_getport(sock->sock);
1674 mutex_unlock(&sock->recv_mutex);
1678 static int xs_sock_srcaddr(struct rpc_xprt *xprt, char *buf, size_t buflen)
1680 struct sock_xprt *sock = container_of(xprt, struct sock_xprt, xprt);
1683 struct sockaddr_storage st;
1685 int ret = -ENOTCONN;
1687 mutex_lock(&sock->recv_mutex);
1689 ret = kernel_getsockname(sock->sock, &saddr.sa);
1691 ret = snprintf(buf, buflen, "%pISc", &saddr.sa);
1693 mutex_unlock(&sock->recv_mutex);
1697 static unsigned short xs_next_srcport(struct sock_xprt *transport, unsigned short port)
1699 if (transport->srcport != 0)
1700 transport->srcport = 0;
1701 if (!transport->xprt.resvport)
1703 if (port <= xprt_min_resvport || port > xprt_max_resvport)
1704 return xprt_max_resvport;
1707 static int xs_bind(struct sock_xprt *transport, struct socket *sock)
1709 struct sockaddr_storage myaddr;
1711 int port = xs_get_srcport(transport);
1712 unsigned short last;
1715 * If we are asking for any ephemeral port (i.e. port == 0 &&
1716 * transport->xprt.resvport == 0), don't bind. Let the local
1717 * port selection happen implicitly when the socket is used
1718 * (for example at connect time).
1720 * This ensures that we can continue to establish TCP
1721 * connections even when all local ephemeral ports are already
1722 * a part of some TCP connection. This makes no difference
1723 * for UDP sockets, but also doesn't harm them.
1725 * If we're asking for any reserved port (i.e. port == 0 &&
1726 * transport->xprt.resvport == 1) xs_get_srcport above will
1727 * ensure that port is non-zero and we will bind as needed.
1732 memcpy(&myaddr, &transport->srcaddr, transport->xprt.addrlen);
1734 rpc_set_port((struct sockaddr *)&myaddr, port);
1735 err = kernel_bind(sock, (struct sockaddr *)&myaddr,
1736 transport->xprt.addrlen);
1738 if (transport->xprt.reuseport)
1739 transport->srcport = port;
1743 port = xs_next_srcport(transport, port);
1746 } while (err == -EADDRINUSE && nloop != 2);
1748 if (myaddr.ss_family == AF_INET)
1749 dprintk("RPC: %s %pI4:%u: %s (%d)\n", __func__,
1750 &((struct sockaddr_in *)&myaddr)->sin_addr,
1751 port, err ? "failed" : "ok", err);
1753 dprintk("RPC: %s %pI6:%u: %s (%d)\n", __func__,
1754 &((struct sockaddr_in6 *)&myaddr)->sin6_addr,
1755 port, err ? "failed" : "ok", err);
1760 * We don't support autobind on AF_LOCAL sockets
1762 static void xs_local_rpcbind(struct rpc_task *task)
1764 xprt_set_bound(task->tk_xprt);
1767 static void xs_local_set_port(struct rpc_xprt *xprt, unsigned short port)
1771 #ifdef CONFIG_DEBUG_LOCK_ALLOC
1772 static struct lock_class_key xs_key[3];
1773 static struct lock_class_key xs_slock_key[3];
1775 static inline void xs_reclassify_socketu(struct socket *sock)
1777 struct sock *sk = sock->sk;
1779 sock_lock_init_class_and_name(sk, "slock-AF_LOCAL-RPC",
1780 &xs_slock_key[0], "sk_lock-AF_LOCAL-RPC", &xs_key[0]);
1783 static inline void xs_reclassify_socket4(struct socket *sock)
1785 struct sock *sk = sock->sk;
1787 sock_lock_init_class_and_name(sk, "slock-AF_INET-RPC",
1788 &xs_slock_key[1], "sk_lock-AF_INET-RPC", &xs_key[1]);
1791 static inline void xs_reclassify_socket6(struct socket *sock)
1793 struct sock *sk = sock->sk;
1795 sock_lock_init_class_and_name(sk, "slock-AF_INET6-RPC",
1796 &xs_slock_key[2], "sk_lock-AF_INET6-RPC", &xs_key[2]);
1799 static inline void xs_reclassify_socket(int family, struct socket *sock)
1801 if (WARN_ON_ONCE(!sock_allow_reclassification(sock->sk)))
1806 xs_reclassify_socketu(sock);
1809 xs_reclassify_socket4(sock);
1812 xs_reclassify_socket6(sock);
1817 static inline void xs_reclassify_socket(int family, struct socket *sock)
1822 static void xs_dummy_setup_socket(struct work_struct *work)
1826 static struct socket *xs_create_sock(struct rpc_xprt *xprt,
1827 struct sock_xprt *transport, int family, int type,
1828 int protocol, bool reuseport)
1831 struct socket *sock;
1834 err = __sock_create(xprt->xprt_net, family, type, protocol, &sock, 1);
1836 dprintk("RPC: can't create %d transport socket (%d).\n",
1840 xs_reclassify_socket(family, sock);
1843 sock_set_reuseport(sock->sk);
1845 err = xs_bind(transport, sock);
1851 filp = sock_alloc_file(sock, O_NONBLOCK, NULL);
1853 return ERR_CAST(filp);
1854 transport->file = filp;
1858 return ERR_PTR(err);
1861 static int xs_local_finish_connecting(struct rpc_xprt *xprt,
1862 struct socket *sock)
1864 struct sock_xprt *transport = container_of(xprt, struct sock_xprt,
1867 if (!transport->inet) {
1868 struct sock *sk = sock->sk;
1872 xs_save_old_callbacks(transport, sk);
1874 sk->sk_user_data = xprt;
1875 sk->sk_data_ready = xs_data_ready;
1876 sk->sk_write_space = xs_udp_write_space;
1877 sk->sk_state_change = xs_local_state_change;
1878 sk->sk_error_report = xs_error_report;
1879 sk->sk_use_task_frag = false;
1881 xprt_clear_connected(xprt);
1883 /* Reset to new socket */
1884 transport->sock = sock;
1885 transport->inet = sk;
1890 xs_stream_start_connect(transport);
1892 return kernel_connect(sock, xs_addr(xprt), xprt->addrlen, 0);
1896 * xs_local_setup_socket - create AF_LOCAL socket, connect to a local endpoint
1897 * @transport: socket transport to connect
1899 static int xs_local_setup_socket(struct sock_xprt *transport)
1901 struct rpc_xprt *xprt = &transport->xprt;
1903 struct socket *sock;
1906 status = __sock_create(xprt->xprt_net, AF_LOCAL,
1907 SOCK_STREAM, 0, &sock, 1);
1909 dprintk("RPC: can't create AF_LOCAL "
1910 "transport socket (%d).\n", -status);
1913 xs_reclassify_socket(AF_LOCAL, sock);
1915 filp = sock_alloc_file(sock, O_NONBLOCK, NULL);
1917 status = PTR_ERR(filp);
1920 transport->file = filp;
1922 dprintk("RPC: worker connecting xprt %p via AF_LOCAL to %s\n",
1923 xprt, xprt->address_strings[RPC_DISPLAY_ADDR]);
1925 status = xs_local_finish_connecting(xprt, sock);
1926 trace_rpc_socket_connect(xprt, sock, status);
1929 dprintk("RPC: xprt %p connected to %s\n",
1930 xprt, xprt->address_strings[RPC_DISPLAY_ADDR]);
1931 xprt->stat.connect_count++;
1932 xprt->stat.connect_time += (long)jiffies -
1933 xprt->stat.connect_start;
1934 xprt_set_connected(xprt);
1939 dprintk("RPC: xprt %p: socket %s does not exist\n",
1940 xprt, xprt->address_strings[RPC_DISPLAY_ADDR]);
1943 dprintk("RPC: xprt %p: connection refused for %s\n",
1944 xprt, xprt->address_strings[RPC_DISPLAY_ADDR]);
1947 printk(KERN_ERR "%s: unhandled error (%d) connecting to %s\n",
1949 xprt->address_strings[RPC_DISPLAY_ADDR]);
1953 xprt_clear_connecting(xprt);
1954 xprt_wake_pending_tasks(xprt, status);
1958 static void xs_local_connect(struct rpc_xprt *xprt, struct rpc_task *task)
1960 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
1963 if (transport->file)
1964 goto force_disconnect;
1966 if (RPC_IS_ASYNC(task)) {
1968 * We want the AF_LOCAL connect to be resolved in the
1969 * filesystem namespace of the process making the rpc
1970 * call. Thus we connect synchronously.
1972 * If we want to support asynchronous AF_LOCAL calls,
1973 * we'll need to figure out how to pass a namespace to
1976 rpc_task_set_rpc_status(task, -ENOTCONN);
1979 ret = xs_local_setup_socket(transport);
1980 if (ret && !RPC_IS_SOFTCONN(task))
1981 msleep_interruptible(15000);
1984 xprt_force_disconnect(xprt);
1986 xprt_clear_connecting(xprt);
1987 xprt_wake_pending_tasks(xprt, -ENOTCONN);
1990 #if IS_ENABLED(CONFIG_SUNRPC_SWAP)
1992 * Note that this should be called with XPRT_LOCKED held, or recv_mutex
1993 * held, or when we otherwise know that we have exclusive access to the
1994 * socket, to guard against races with xs_reset_transport.
1996 static void xs_set_memalloc(struct rpc_xprt *xprt)
1998 struct sock_xprt *transport = container_of(xprt, struct sock_xprt,
2002 * If there's no sock, then we have nothing to set. The
2003 * reconnecting process will get it for us.
2005 if (!transport->inet)
2007 if (atomic_read(&xprt->swapper))
2008 sk_set_memalloc(transport->inet);
2012 * xs_enable_swap - Tag this transport as being used for swap.
2013 * @xprt: transport to tag
2015 * Take a reference to this transport on behalf of the rpc_clnt, and
2016 * optionally mark it for swapping if it wasn't already.
2019 xs_enable_swap(struct rpc_xprt *xprt)
2021 struct sock_xprt *xs = container_of(xprt, struct sock_xprt, xprt);
2023 mutex_lock(&xs->recv_mutex);
2024 if (atomic_inc_return(&xprt->swapper) == 1 &&
2026 sk_set_memalloc(xs->inet);
2027 mutex_unlock(&xs->recv_mutex);
2032 * xs_disable_swap - Untag this transport as being used for swap.
2033 * @xprt: transport to tag
2035 * Drop a "swapper" reference to this xprt on behalf of the rpc_clnt. If the
2036 * swapper refcount goes to 0, untag the socket as a memalloc socket.
2039 xs_disable_swap(struct rpc_xprt *xprt)
2041 struct sock_xprt *xs = container_of(xprt, struct sock_xprt, xprt);
2043 mutex_lock(&xs->recv_mutex);
2044 if (atomic_dec_and_test(&xprt->swapper) &&
2046 sk_clear_memalloc(xs->inet);
2047 mutex_unlock(&xs->recv_mutex);
2050 static void xs_set_memalloc(struct rpc_xprt *xprt)
2055 xs_enable_swap(struct rpc_xprt *xprt)
2061 xs_disable_swap(struct rpc_xprt *xprt)
2066 static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
2068 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2070 if (!transport->inet) {
2071 struct sock *sk = sock->sk;
2075 xs_save_old_callbacks(transport, sk);
2077 sk->sk_user_data = xprt;
2078 sk->sk_data_ready = xs_data_ready;
2079 sk->sk_write_space = xs_udp_write_space;
2080 sk->sk_use_task_frag = false;
2082 xprt_set_connected(xprt);
2084 /* Reset to new socket */
2085 transport->sock = sock;
2086 transport->inet = sk;
2088 xs_set_memalloc(xprt);
2092 xs_udp_do_set_buffer_size(xprt);
2094 xprt->stat.connect_start = jiffies;
2097 static void xs_udp_setup_socket(struct work_struct *work)
2099 struct sock_xprt *transport =
2100 container_of(work, struct sock_xprt, connect_worker.work);
2101 struct rpc_xprt *xprt = &transport->xprt;
2102 struct socket *sock;
2104 unsigned int pflags = current->flags;
2106 if (atomic_read(&xprt->swapper))
2107 current->flags |= PF_MEMALLOC;
2108 sock = xs_create_sock(xprt, transport,
2109 xs_addr(xprt)->sa_family, SOCK_DGRAM,
2110 IPPROTO_UDP, false);
2114 dprintk("RPC: worker connecting xprt %p via %s to "
2115 "%s (port %s)\n", xprt,
2116 xprt->address_strings[RPC_DISPLAY_PROTO],
2117 xprt->address_strings[RPC_DISPLAY_ADDR],
2118 xprt->address_strings[RPC_DISPLAY_PORT]);
2120 xs_udp_finish_connecting(xprt, sock);
2121 trace_rpc_socket_connect(xprt, sock, 0);
2124 xprt_clear_connecting(xprt);
2125 xprt_unlock_connect(xprt, transport);
2126 xprt_wake_pending_tasks(xprt, status);
2127 current_restore_flags(pflags, PF_MEMALLOC);
2131 * xs_tcp_shutdown - gracefully shut down a TCP socket
2134 * Initiates a graceful shutdown of the TCP socket by calling the
2135 * equivalent of shutdown(SHUT_RDWR);
2137 static void xs_tcp_shutdown(struct rpc_xprt *xprt)
2139 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2140 struct socket *sock = transport->sock;
2141 int skst = transport->inet ? transport->inet->sk_state : TCP_CLOSE;
2145 if (!xprt->reuseport) {
2154 case TCP_ESTABLISHED:
2155 case TCP_CLOSE_WAIT:
2156 kernel_sock_shutdown(sock, SHUT_RDWR);
2157 trace_rpc_socket_shutdown(xprt, sock);
2160 xs_reset_transport(transport);
2164 static void xs_tcp_set_socket_timeouts(struct rpc_xprt *xprt,
2165 struct socket *sock)
2167 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2168 unsigned int keepidle;
2169 unsigned int keepcnt;
2172 spin_lock(&xprt->transport_lock);
2173 keepidle = DIV_ROUND_UP(xprt->timeout->to_initval, HZ);
2174 keepcnt = xprt->timeout->to_retries + 1;
2175 timeo = jiffies_to_msecs(xprt->timeout->to_initval) *
2176 (xprt->timeout->to_retries + 1);
2177 clear_bit(XPRT_SOCK_UPD_TIMEOUT, &transport->sock_state);
2178 spin_unlock(&xprt->transport_lock);
2180 /* TCP Keepalive options */
2181 sock_set_keepalive(sock->sk);
2182 tcp_sock_set_keepidle(sock->sk, keepidle);
2183 tcp_sock_set_keepintvl(sock->sk, keepidle);
2184 tcp_sock_set_keepcnt(sock->sk, keepcnt);
2186 /* TCP user timeout (see RFC5482) */
2187 tcp_sock_set_user_timeout(sock->sk, timeo);
2190 static void xs_tcp_set_connect_timeout(struct rpc_xprt *xprt,
2191 unsigned long connect_timeout,
2192 unsigned long reconnect_timeout)
2194 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2195 struct rpc_timeout to;
2196 unsigned long initval;
2198 spin_lock(&xprt->transport_lock);
2199 if (reconnect_timeout < xprt->max_reconnect_timeout)
2200 xprt->max_reconnect_timeout = reconnect_timeout;
2201 if (connect_timeout < xprt->connect_timeout) {
2202 memcpy(&to, xprt->timeout, sizeof(to));
2203 initval = DIV_ROUND_UP(connect_timeout, to.to_retries + 1);
2204 /* Arbitrary lower limit */
2205 if (initval < XS_TCP_INIT_REEST_TO << 1)
2206 initval = XS_TCP_INIT_REEST_TO << 1;
2207 to.to_initval = initval;
2208 to.to_maxval = initval;
2209 memcpy(&transport->tcp_timeout, &to,
2210 sizeof(transport->tcp_timeout));
2211 xprt->timeout = &transport->tcp_timeout;
2212 xprt->connect_timeout = connect_timeout;
2214 set_bit(XPRT_SOCK_UPD_TIMEOUT, &transport->sock_state);
2215 spin_unlock(&xprt->transport_lock);
2218 static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
2220 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2222 if (!transport->inet) {
2223 struct sock *sk = sock->sk;
2225 /* Avoid temporary address, they are bad for long-lived
2226 * connections such as NFS mounts.
2227 * RFC4941, section 3.6 suggests that:
2228 * Individual applications, which have specific
2229 * knowledge about the normal duration of connections,
2230 * MAY override this as appropriate.
2232 if (xs_addr(xprt)->sa_family == PF_INET6) {
2233 ip6_sock_set_addr_preferences(sk,
2234 IPV6_PREFER_SRC_PUBLIC);
2237 xs_tcp_set_socket_timeouts(xprt, sock);
2238 tcp_sock_set_nodelay(sk);
2242 xs_save_old_callbacks(transport, sk);
2244 sk->sk_user_data = xprt;
2245 sk->sk_data_ready = xs_data_ready;
2246 sk->sk_state_change = xs_tcp_state_change;
2247 sk->sk_write_space = xs_tcp_write_space;
2248 sk->sk_error_report = xs_error_report;
2249 sk->sk_use_task_frag = false;
2251 /* socket options */
2252 sock_reset_flag(sk, SOCK_LINGER);
2254 xprt_clear_connected(xprt);
2256 /* Reset to new socket */
2257 transport->sock = sock;
2258 transport->inet = sk;
2263 if (!xprt_bound(xprt))
2266 xs_set_memalloc(xprt);
2268 xs_stream_start_connect(transport);
2270 /* Tell the socket layer to start connecting... */
2271 set_bit(XPRT_SOCK_CONNECTING, &transport->sock_state);
2272 return kernel_connect(sock, xs_addr(xprt), xprt->addrlen, O_NONBLOCK);
2276 * xs_tcp_setup_socket - create a TCP socket and connect to a remote endpoint
2277 * @work: queued work item
2279 * Invoked by a work queue tasklet.
2281 static void xs_tcp_setup_socket(struct work_struct *work)
2283 struct sock_xprt *transport =
2284 container_of(work, struct sock_xprt, connect_worker.work);
2285 struct socket *sock = transport->sock;
2286 struct rpc_xprt *xprt = &transport->xprt;
2288 unsigned int pflags = current->flags;
2290 if (atomic_read(&xprt->swapper))
2291 current->flags |= PF_MEMALLOC;
2293 if (xprt_connected(xprt))
2295 if (test_and_clear_bit(XPRT_SOCK_CONNECT_SENT,
2296 &transport->sock_state) ||
2298 xs_reset_transport(transport);
2299 sock = xs_create_sock(xprt, transport, xs_addr(xprt)->sa_family,
2300 SOCK_STREAM, IPPROTO_TCP, true);
2302 xprt_wake_pending_tasks(xprt, PTR_ERR(sock));
2307 dprintk("RPC: worker connecting xprt %p via %s to "
2308 "%s (port %s)\n", xprt,
2309 xprt->address_strings[RPC_DISPLAY_PROTO],
2310 xprt->address_strings[RPC_DISPLAY_ADDR],
2311 xprt->address_strings[RPC_DISPLAY_PORT]);
2313 status = xs_tcp_finish_connecting(xprt, sock);
2314 trace_rpc_socket_connect(xprt, sock, status);
2315 dprintk("RPC: %p connect status %d connected %d sock state %d\n",
2316 xprt, -status, xprt_connected(xprt),
2317 sock->sk->sk_state);
2322 set_bit(XPRT_SOCK_CONNECT_SENT, &transport->sock_state);
2323 if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO)
2324 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
2328 case -EADDRNOTAVAIL:
2329 /* Source port number is unavailable. Try a new one! */
2330 transport->srcport = 0;
2334 /* Happens, for instance, if the user specified a link
2335 * local IPv6 address without a scope-id.
2346 printk("%s: connect returned unhandled error %d\n",
2351 /* xs_tcp_force_close() wakes tasks with a fixed error code.
2352 * We need to wake them first to ensure the correct error code.
2354 xprt_wake_pending_tasks(xprt, status);
2355 xs_tcp_force_close(xprt);
2357 xprt_clear_connecting(xprt);
2359 xprt_unlock_connect(xprt, transport);
2360 current_restore_flags(pflags, PF_MEMALLOC);
2364 * xs_connect - connect a socket to a remote endpoint
2365 * @xprt: pointer to transport structure
2366 * @task: address of RPC task that manages state of connect request
2368 * TCP: If the remote end dropped the connection, delay reconnecting.
2370 * UDP socket connects are synchronous, but we use a work queue anyway
2371 * to guarantee that even unprivileged user processes can set up a
2372 * socket on a privileged port.
2374 * If a UDP socket connect fails, the delay behavior here prevents
2375 * retry floods (hard mounts).
2377 static void xs_connect(struct rpc_xprt *xprt, struct rpc_task *task)
2379 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2380 unsigned long delay = 0;
2382 WARN_ON_ONCE(!xprt_lock_connect(xprt, task, transport));
2384 if (transport->sock != NULL) {
2385 dprintk("RPC: xs_connect delayed xprt %p for %lu "
2386 "seconds\n", xprt, xprt->reestablish_timeout / HZ);
2388 delay = xprt_reconnect_delay(xprt);
2389 xprt_reconnect_backoff(xprt, XS_TCP_INIT_REEST_TO);
2392 dprintk("RPC: xs_connect scheduled xprt %p\n", xprt);
2394 queue_delayed_work(xprtiod_workqueue,
2395 &transport->connect_worker,
2399 static void xs_wake_disconnect(struct sock_xprt *transport)
2401 if (test_and_clear_bit(XPRT_SOCK_WAKE_DISCONNECT, &transport->sock_state))
2402 xs_tcp_force_close(&transport->xprt);
2405 static void xs_wake_write(struct sock_xprt *transport)
2407 if (test_and_clear_bit(XPRT_SOCK_WAKE_WRITE, &transport->sock_state))
2408 xprt_write_space(&transport->xprt);
2411 static void xs_wake_error(struct sock_xprt *transport)
2415 if (!test_bit(XPRT_SOCK_WAKE_ERROR, &transport->sock_state))
2417 mutex_lock(&transport->recv_mutex);
2418 if (transport->sock == NULL)
2420 if (!test_and_clear_bit(XPRT_SOCK_WAKE_ERROR, &transport->sock_state))
2422 sockerr = xchg(&transport->xprt_err, 0);
2424 xprt_wake_pending_tasks(&transport->xprt, sockerr);
2426 mutex_unlock(&transport->recv_mutex);
2429 static void xs_wake_pending(struct sock_xprt *transport)
2431 if (test_and_clear_bit(XPRT_SOCK_WAKE_PENDING, &transport->sock_state))
2432 xprt_wake_pending_tasks(&transport->xprt, -EAGAIN);
2435 static void xs_error_handle(struct work_struct *work)
2437 struct sock_xprt *transport = container_of(work,
2438 struct sock_xprt, error_worker);
2440 xs_wake_disconnect(transport);
2441 xs_wake_write(transport);
2442 xs_wake_error(transport);
2443 xs_wake_pending(transport);
2447 * xs_local_print_stats - display AF_LOCAL socket-specific stats
2448 * @xprt: rpc_xprt struct containing statistics
2452 static void xs_local_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
2456 if (xprt_connected(xprt))
2457 idle_time = (long)(jiffies - xprt->last_used) / HZ;
2459 seq_printf(seq, "\txprt:\tlocal %lu %lu %lu %ld %lu %lu %lu "
2460 "%llu %llu %lu %llu %llu\n",
2461 xprt->stat.bind_count,
2462 xprt->stat.connect_count,
2463 xprt->stat.connect_time / HZ,
2467 xprt->stat.bad_xids,
2470 xprt->stat.max_slots,
2471 xprt->stat.sending_u,
2472 xprt->stat.pending_u);
2476 * xs_udp_print_stats - display UDP socket-specific stats
2477 * @xprt: rpc_xprt struct containing statistics
2481 static void xs_udp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
2483 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2485 seq_printf(seq, "\txprt:\tudp %u %lu %lu %lu %lu %llu %llu "
2488 xprt->stat.bind_count,
2491 xprt->stat.bad_xids,
2494 xprt->stat.max_slots,
2495 xprt->stat.sending_u,
2496 xprt->stat.pending_u);
2500 * xs_tcp_print_stats - display TCP socket-specific stats
2501 * @xprt: rpc_xprt struct containing statistics
2505 static void xs_tcp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
2507 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2510 if (xprt_connected(xprt))
2511 idle_time = (long)(jiffies - xprt->last_used) / HZ;
2513 seq_printf(seq, "\txprt:\ttcp %u %lu %lu %lu %ld %lu %lu %lu "
2514 "%llu %llu %lu %llu %llu\n",
2516 xprt->stat.bind_count,
2517 xprt->stat.connect_count,
2518 xprt->stat.connect_time / HZ,
2522 xprt->stat.bad_xids,
2525 xprt->stat.max_slots,
2526 xprt->stat.sending_u,
2527 xprt->stat.pending_u);
2531 * Allocate a bunch of pages for a scratch buffer for the rpc code. The reason
2532 * we allocate pages instead doing a kmalloc like rpc_malloc is because we want
2533 * to use the server side send routines.
2535 static int bc_malloc(struct rpc_task *task)
2537 struct rpc_rqst *rqst = task->tk_rqstp;
2538 size_t size = rqst->rq_callsize;
2540 struct rpc_buffer *buf;
2542 if (size > PAGE_SIZE - sizeof(struct rpc_buffer)) {
2543 WARN_ONCE(1, "xprtsock: large bc buffer request (size %zu)\n",
2548 page = alloc_page(GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
2552 buf = page_address(page);
2553 buf->len = PAGE_SIZE;
2555 rqst->rq_buffer = buf->data;
2556 rqst->rq_rbuffer = (char *)rqst->rq_buffer + rqst->rq_callsize;
2561 * Free the space allocated in the bc_alloc routine
2563 static void bc_free(struct rpc_task *task)
2565 void *buffer = task->tk_rqstp->rq_buffer;
2566 struct rpc_buffer *buf;
2568 buf = container_of(buffer, struct rpc_buffer, data);
2569 free_page((unsigned long)buf);
2572 static int bc_sendto(struct rpc_rqst *req)
2574 struct xdr_buf *xdr = &req->rq_snd_buf;
2575 struct sock_xprt *transport =
2576 container_of(req->rq_xprt, struct sock_xprt, xprt);
2577 struct msghdr msg = {
2580 rpc_fraghdr marker = cpu_to_be32(RPC_LAST_STREAM_FRAGMENT |
2582 unsigned int sent = 0;
2585 req->rq_xtime = ktime_get();
2586 err = xdr_alloc_bvec(xdr, rpc_task_gfp_mask());
2589 err = xprt_sock_sendmsg(transport->sock, &msg, xdr, 0, marker, &sent);
2591 if (err < 0 || sent != (xdr->len + sizeof(marker)))
2597 * bc_send_request - Send a backchannel Call on a TCP socket
2598 * @req: rpc_rqst containing Call message to be sent
2600 * xpt_mutex ensures @rqstp's whole message is written to the socket
2601 * without interruption.
2604 * %0 if the message was sent successfully
2605 * %ENOTCONN if the message was not sent
2607 static int bc_send_request(struct rpc_rqst *req)
2609 struct svc_xprt *xprt;
2613 * Get the server socket associated with this callback xprt
2615 xprt = req->rq_xprt->bc_xprt;
2618 * Grab the mutex to serialize data as the connection is shared
2619 * with the fore channel
2621 mutex_lock(&xprt->xpt_mutex);
2622 if (test_bit(XPT_DEAD, &xprt->xpt_flags))
2625 len = bc_sendto(req);
2626 mutex_unlock(&xprt->xpt_mutex);
2635 * The close routine. Since this is client initiated, we do nothing
2638 static void bc_close(struct rpc_xprt *xprt)
2640 xprt_disconnect_done(xprt);
2644 * The xprt destroy routine. Again, because this connection is client
2645 * initiated, we do nothing
2648 static void bc_destroy(struct rpc_xprt *xprt)
2650 dprintk("RPC: bc_destroy xprt %p\n", xprt);
2653 module_put(THIS_MODULE);
2656 static const struct rpc_xprt_ops xs_local_ops = {
2657 .reserve_xprt = xprt_reserve_xprt,
2658 .release_xprt = xprt_release_xprt,
2659 .alloc_slot = xprt_alloc_slot,
2660 .free_slot = xprt_free_slot,
2661 .rpcbind = xs_local_rpcbind,
2662 .set_port = xs_local_set_port,
2663 .connect = xs_local_connect,
2664 .buf_alloc = rpc_malloc,
2665 .buf_free = rpc_free,
2666 .prepare_request = xs_stream_prepare_request,
2667 .send_request = xs_local_send_request,
2668 .wait_for_reply_request = xprt_wait_for_reply_request_def,
2670 .destroy = xs_destroy,
2671 .print_stats = xs_local_print_stats,
2672 .enable_swap = xs_enable_swap,
2673 .disable_swap = xs_disable_swap,
2676 static const struct rpc_xprt_ops xs_udp_ops = {
2677 .set_buffer_size = xs_udp_set_buffer_size,
2678 .reserve_xprt = xprt_reserve_xprt_cong,
2679 .release_xprt = xprt_release_xprt_cong,
2680 .alloc_slot = xprt_alloc_slot,
2681 .free_slot = xprt_free_slot,
2682 .rpcbind = rpcb_getport_async,
2683 .set_port = xs_set_port,
2684 .connect = xs_connect,
2685 .get_srcaddr = xs_sock_srcaddr,
2686 .get_srcport = xs_sock_srcport,
2687 .buf_alloc = rpc_malloc,
2688 .buf_free = rpc_free,
2689 .send_request = xs_udp_send_request,
2690 .wait_for_reply_request = xprt_wait_for_reply_request_rtt,
2691 .timer = xs_udp_timer,
2692 .release_request = xprt_release_rqst_cong,
2694 .destroy = xs_destroy,
2695 .print_stats = xs_udp_print_stats,
2696 .enable_swap = xs_enable_swap,
2697 .disable_swap = xs_disable_swap,
2698 .inject_disconnect = xs_inject_disconnect,
2701 static const struct rpc_xprt_ops xs_tcp_ops = {
2702 .reserve_xprt = xprt_reserve_xprt,
2703 .release_xprt = xprt_release_xprt,
2704 .alloc_slot = xprt_alloc_slot,
2705 .free_slot = xprt_free_slot,
2706 .rpcbind = rpcb_getport_async,
2707 .set_port = xs_set_port,
2708 .connect = xs_connect,
2709 .get_srcaddr = xs_sock_srcaddr,
2710 .get_srcport = xs_sock_srcport,
2711 .buf_alloc = rpc_malloc,
2712 .buf_free = rpc_free,
2713 .prepare_request = xs_stream_prepare_request,
2714 .send_request = xs_tcp_send_request,
2715 .wait_for_reply_request = xprt_wait_for_reply_request_def,
2716 .close = xs_tcp_shutdown,
2717 .destroy = xs_destroy,
2718 .set_connect_timeout = xs_tcp_set_connect_timeout,
2719 .print_stats = xs_tcp_print_stats,
2720 .enable_swap = xs_enable_swap,
2721 .disable_swap = xs_disable_swap,
2722 .inject_disconnect = xs_inject_disconnect,
2723 #ifdef CONFIG_SUNRPC_BACKCHANNEL
2724 .bc_setup = xprt_setup_bc,
2725 .bc_maxpayload = xs_tcp_bc_maxpayload,
2726 .bc_num_slots = xprt_bc_max_slots,
2727 .bc_free_rqst = xprt_free_bc_rqst,
2728 .bc_destroy = xprt_destroy_bc,
2733 * The rpc_xprt_ops for the server backchannel
2736 static const struct rpc_xprt_ops bc_tcp_ops = {
2737 .reserve_xprt = xprt_reserve_xprt,
2738 .release_xprt = xprt_release_xprt,
2739 .alloc_slot = xprt_alloc_slot,
2740 .free_slot = xprt_free_slot,
2741 .buf_alloc = bc_malloc,
2742 .buf_free = bc_free,
2743 .send_request = bc_send_request,
2744 .wait_for_reply_request = xprt_wait_for_reply_request_def,
2746 .destroy = bc_destroy,
2747 .print_stats = xs_tcp_print_stats,
2748 .enable_swap = xs_enable_swap,
2749 .disable_swap = xs_disable_swap,
2750 .inject_disconnect = xs_inject_disconnect,
2753 static int xs_init_anyaddr(const int family, struct sockaddr *sap)
2755 static const struct sockaddr_in sin = {
2756 .sin_family = AF_INET,
2757 .sin_addr.s_addr = htonl(INADDR_ANY),
2759 static const struct sockaddr_in6 sin6 = {
2760 .sin6_family = AF_INET6,
2761 .sin6_addr = IN6ADDR_ANY_INIT,
2768 memcpy(sap, &sin, sizeof(sin));
2771 memcpy(sap, &sin6, sizeof(sin6));
2774 dprintk("RPC: %s: Bad address family\n", __func__);
2775 return -EAFNOSUPPORT;
2780 static struct rpc_xprt *xs_setup_xprt(struct xprt_create *args,
2781 unsigned int slot_table_size,
2782 unsigned int max_slot_table_size)
2784 struct rpc_xprt *xprt;
2785 struct sock_xprt *new;
2787 if (args->addrlen > sizeof(xprt->addr)) {
2788 dprintk("RPC: xs_setup_xprt: address too large\n");
2789 return ERR_PTR(-EBADF);
2792 xprt = xprt_alloc(args->net, sizeof(*new), slot_table_size,
2793 max_slot_table_size);
2795 dprintk("RPC: xs_setup_xprt: couldn't allocate "
2797 return ERR_PTR(-ENOMEM);
2800 new = container_of(xprt, struct sock_xprt, xprt);
2801 mutex_init(&new->recv_mutex);
2802 memcpy(&xprt->addr, args->dstaddr, args->addrlen);
2803 xprt->addrlen = args->addrlen;
2805 memcpy(&new->srcaddr, args->srcaddr, args->addrlen);
2808 err = xs_init_anyaddr(args->dstaddr->sa_family,
2809 (struct sockaddr *)&new->srcaddr);
2812 return ERR_PTR(err);
2819 static const struct rpc_timeout xs_local_default_timeout = {
2820 .to_initval = 10 * HZ,
2821 .to_maxval = 10 * HZ,
2826 * xs_setup_local - Set up transport to use an AF_LOCAL socket
2827 * @args: rpc transport creation arguments
2829 * AF_LOCAL is a "tpi_cots_ord" transport, just like TCP
2831 static struct rpc_xprt *xs_setup_local(struct xprt_create *args)
2833 struct sockaddr_un *sun = (struct sockaddr_un *)args->dstaddr;
2834 struct sock_xprt *transport;
2835 struct rpc_xprt *xprt;
2836 struct rpc_xprt *ret;
2838 xprt = xs_setup_xprt(args, xprt_tcp_slot_table_entries,
2839 xprt_max_tcp_slot_table_entries);
2842 transport = container_of(xprt, struct sock_xprt, xprt);
2845 xprt->xprt_class = &xs_local_transport;
2846 xprt->max_payload = RPC_MAX_FRAGMENT_SIZE;
2848 xprt->bind_timeout = XS_BIND_TO;
2849 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
2850 xprt->idle_timeout = XS_IDLE_DISC_TO;
2852 xprt->ops = &xs_local_ops;
2853 xprt->timeout = &xs_local_default_timeout;
2855 INIT_WORK(&transport->recv_worker, xs_stream_data_receive_workfn);
2856 INIT_WORK(&transport->error_worker, xs_error_handle);
2857 INIT_DELAYED_WORK(&transport->connect_worker, xs_dummy_setup_socket);
2859 switch (sun->sun_family) {
2861 if (sun->sun_path[0] != '/') {
2862 dprintk("RPC: bad AF_LOCAL address: %s\n",
2864 ret = ERR_PTR(-EINVAL);
2867 xprt_set_bound(xprt);
2868 xs_format_peer_addresses(xprt, "local", RPCBIND_NETID_LOCAL);
2871 ret = ERR_PTR(-EAFNOSUPPORT);
2875 dprintk("RPC: set up xprt to %s via AF_LOCAL\n",
2876 xprt->address_strings[RPC_DISPLAY_ADDR]);
2878 if (try_module_get(THIS_MODULE))
2880 ret = ERR_PTR(-EINVAL);
2886 static const struct rpc_timeout xs_udp_default_timeout = {
2887 .to_initval = 5 * HZ,
2888 .to_maxval = 30 * HZ,
2889 .to_increment = 5 * HZ,
2894 * xs_setup_udp - Set up transport to use a UDP socket
2895 * @args: rpc transport creation arguments
2898 static struct rpc_xprt *xs_setup_udp(struct xprt_create *args)
2900 struct sockaddr *addr = args->dstaddr;
2901 struct rpc_xprt *xprt;
2902 struct sock_xprt *transport;
2903 struct rpc_xprt *ret;
2905 xprt = xs_setup_xprt(args, xprt_udp_slot_table_entries,
2906 xprt_udp_slot_table_entries);
2909 transport = container_of(xprt, struct sock_xprt, xprt);
2911 xprt->prot = IPPROTO_UDP;
2912 xprt->xprt_class = &xs_udp_transport;
2913 /* XXX: header size can vary due to auth type, IPv6, etc. */
2914 xprt->max_payload = (1U << 16) - (MAX_HEADER << 3);
2916 xprt->bind_timeout = XS_BIND_TO;
2917 xprt->reestablish_timeout = XS_UDP_REEST_TO;
2918 xprt->idle_timeout = XS_IDLE_DISC_TO;
2920 xprt->ops = &xs_udp_ops;
2922 xprt->timeout = &xs_udp_default_timeout;
2924 INIT_WORK(&transport->recv_worker, xs_udp_data_receive_workfn);
2925 INIT_WORK(&transport->error_worker, xs_error_handle);
2926 INIT_DELAYED_WORK(&transport->connect_worker, xs_udp_setup_socket);
2928 switch (addr->sa_family) {
2930 if (((struct sockaddr_in *)addr)->sin_port != htons(0))
2931 xprt_set_bound(xprt);
2933 xs_format_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP);
2936 if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0))
2937 xprt_set_bound(xprt);
2939 xs_format_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP6);
2942 ret = ERR_PTR(-EAFNOSUPPORT);
2946 if (xprt_bound(xprt))
2947 dprintk("RPC: set up xprt to %s (port %s) via %s\n",
2948 xprt->address_strings[RPC_DISPLAY_ADDR],
2949 xprt->address_strings[RPC_DISPLAY_PORT],
2950 xprt->address_strings[RPC_DISPLAY_PROTO]);
2952 dprintk("RPC: set up xprt to %s (autobind) via %s\n",
2953 xprt->address_strings[RPC_DISPLAY_ADDR],
2954 xprt->address_strings[RPC_DISPLAY_PROTO]);
2956 if (try_module_get(THIS_MODULE))
2958 ret = ERR_PTR(-EINVAL);
2964 static const struct rpc_timeout xs_tcp_default_timeout = {
2965 .to_initval = 60 * HZ,
2966 .to_maxval = 60 * HZ,
2971 * xs_setup_tcp - Set up transport to use a TCP socket
2972 * @args: rpc transport creation arguments
2975 static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args)
2977 struct sockaddr *addr = args->dstaddr;
2978 struct rpc_xprt *xprt;
2979 struct sock_xprt *transport;
2980 struct rpc_xprt *ret;
2981 unsigned int max_slot_table_size = xprt_max_tcp_slot_table_entries;
2983 if (args->flags & XPRT_CREATE_INFINITE_SLOTS)
2984 max_slot_table_size = RPC_MAX_SLOT_TABLE_LIMIT;
2986 xprt = xs_setup_xprt(args, xprt_tcp_slot_table_entries,
2987 max_slot_table_size);
2990 transport = container_of(xprt, struct sock_xprt, xprt);
2992 xprt->prot = IPPROTO_TCP;
2993 xprt->xprt_class = &xs_tcp_transport;
2994 xprt->max_payload = RPC_MAX_FRAGMENT_SIZE;
2996 xprt->bind_timeout = XS_BIND_TO;
2997 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
2998 xprt->idle_timeout = XS_IDLE_DISC_TO;
3000 xprt->ops = &xs_tcp_ops;
3001 xprt->timeout = &xs_tcp_default_timeout;
3003 xprt->max_reconnect_timeout = xprt->timeout->to_maxval;
3004 xprt->connect_timeout = xprt->timeout->to_initval *
3005 (xprt->timeout->to_retries + 1);
3007 INIT_WORK(&transport->recv_worker, xs_stream_data_receive_workfn);
3008 INIT_WORK(&transport->error_worker, xs_error_handle);
3009 INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_setup_socket);
3011 switch (addr->sa_family) {
3013 if (((struct sockaddr_in *)addr)->sin_port != htons(0))
3014 xprt_set_bound(xprt);
3016 xs_format_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP);
3019 if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0))
3020 xprt_set_bound(xprt);
3022 xs_format_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP6);
3025 ret = ERR_PTR(-EAFNOSUPPORT);
3029 if (xprt_bound(xprt))
3030 dprintk("RPC: set up xprt to %s (port %s) via %s\n",
3031 xprt->address_strings[RPC_DISPLAY_ADDR],
3032 xprt->address_strings[RPC_DISPLAY_PORT],
3033 xprt->address_strings[RPC_DISPLAY_PROTO]);
3035 dprintk("RPC: set up xprt to %s (autobind) via %s\n",
3036 xprt->address_strings[RPC_DISPLAY_ADDR],
3037 xprt->address_strings[RPC_DISPLAY_PROTO]);
3039 if (try_module_get(THIS_MODULE))
3041 ret = ERR_PTR(-EINVAL);
3048 * xs_setup_bc_tcp - Set up transport to use a TCP backchannel socket
3049 * @args: rpc transport creation arguments
3052 static struct rpc_xprt *xs_setup_bc_tcp(struct xprt_create *args)
3054 struct sockaddr *addr = args->dstaddr;
3055 struct rpc_xprt *xprt;
3056 struct sock_xprt *transport;
3057 struct svc_sock *bc_sock;
3058 struct rpc_xprt *ret;
3060 xprt = xs_setup_xprt(args, xprt_tcp_slot_table_entries,
3061 xprt_tcp_slot_table_entries);
3064 transport = container_of(xprt, struct sock_xprt, xprt);
3066 xprt->prot = IPPROTO_TCP;
3067 xprt->xprt_class = &xs_bc_tcp_transport;
3068 xprt->max_payload = RPC_MAX_FRAGMENT_SIZE;
3069 xprt->timeout = &xs_tcp_default_timeout;
3072 xprt_set_bound(xprt);
3073 xprt->bind_timeout = 0;
3074 xprt->reestablish_timeout = 0;
3075 xprt->idle_timeout = 0;
3077 xprt->ops = &bc_tcp_ops;
3079 switch (addr->sa_family) {
3081 xs_format_peer_addresses(xprt, "tcp",
3085 xs_format_peer_addresses(xprt, "tcp",
3086 RPCBIND_NETID_TCP6);
3089 ret = ERR_PTR(-EAFNOSUPPORT);
3093 dprintk("RPC: set up xprt to %s (port %s) via %s\n",
3094 xprt->address_strings[RPC_DISPLAY_ADDR],
3095 xprt->address_strings[RPC_DISPLAY_PORT],
3096 xprt->address_strings[RPC_DISPLAY_PROTO]);
3099 * Once we've associated a backchannel xprt with a connection,
3100 * we want to keep it around as long as the connection lasts,
3101 * in case we need to start using it for a backchannel again;
3102 * this reference won't be dropped until bc_xprt is destroyed.
3105 args->bc_xprt->xpt_bc_xprt = xprt;
3106 xprt->bc_xprt = args->bc_xprt;
3107 bc_sock = container_of(args->bc_xprt, struct svc_sock, sk_xprt);
3108 transport->sock = bc_sock->sk_sock;
3109 transport->inet = bc_sock->sk_sk;
3112 * Since we don't want connections for the backchannel, we set
3113 * the xprt status to connected
3115 xprt_set_connected(xprt);
3117 if (try_module_get(THIS_MODULE))
3120 args->bc_xprt->xpt_bc_xprt = NULL;
3121 args->bc_xprt->xpt_bc_xps = NULL;
3123 ret = ERR_PTR(-EINVAL);
3129 static struct xprt_class xs_local_transport = {
3130 .list = LIST_HEAD_INIT(xs_local_transport.list),
3131 .name = "named UNIX socket",
3132 .owner = THIS_MODULE,
3133 .ident = XPRT_TRANSPORT_LOCAL,
3134 .setup = xs_setup_local,
3138 static struct xprt_class xs_udp_transport = {
3139 .list = LIST_HEAD_INIT(xs_udp_transport.list),
3141 .owner = THIS_MODULE,
3142 .ident = XPRT_TRANSPORT_UDP,
3143 .setup = xs_setup_udp,
3144 .netid = { "udp", "udp6", "" },
3147 static struct xprt_class xs_tcp_transport = {
3148 .list = LIST_HEAD_INIT(xs_tcp_transport.list),
3150 .owner = THIS_MODULE,
3151 .ident = XPRT_TRANSPORT_TCP,
3152 .setup = xs_setup_tcp,
3153 .netid = { "tcp", "tcp6", "" },
3156 static struct xprt_class xs_bc_tcp_transport = {
3157 .list = LIST_HEAD_INIT(xs_bc_tcp_transport.list),
3158 .name = "tcp NFSv4.1 backchannel",
3159 .owner = THIS_MODULE,
3160 .ident = XPRT_TRANSPORT_BC_TCP,
3161 .setup = xs_setup_bc_tcp,
3166 * init_socket_xprt - set up xprtsock's sysctls, register with RPC client
3169 int init_socket_xprt(void)
3171 if (!sunrpc_table_header)
3172 sunrpc_table_header = register_sysctl("sunrpc", xs_tunables_table);
3174 xprt_register_transport(&xs_local_transport);
3175 xprt_register_transport(&xs_udp_transport);
3176 xprt_register_transport(&xs_tcp_transport);
3177 xprt_register_transport(&xs_bc_tcp_transport);
3183 * cleanup_socket_xprt - remove xprtsock's sysctls, unregister
3186 void cleanup_socket_xprt(void)
3188 if (sunrpc_table_header) {
3189 unregister_sysctl_table(sunrpc_table_header);
3190 sunrpc_table_header = NULL;
3193 xprt_unregister_transport(&xs_local_transport);
3194 xprt_unregister_transport(&xs_udp_transport);
3195 xprt_unregister_transport(&xs_tcp_transport);
3196 xprt_unregister_transport(&xs_bc_tcp_transport);
3199 static int param_set_portnr(const char *val, const struct kernel_param *kp)
3201 return param_set_uint_minmax(val, kp,
3206 static const struct kernel_param_ops param_ops_portnr = {
3207 .set = param_set_portnr,
3208 .get = param_get_uint,
3211 #define param_check_portnr(name, p) \
3212 __param_check(name, p, unsigned int);
3214 module_param_named(min_resvport, xprt_min_resvport, portnr, 0644);
3215 module_param_named(max_resvport, xprt_max_resvport, portnr, 0644);
3217 static int param_set_slot_table_size(const char *val,
3218 const struct kernel_param *kp)
3220 return param_set_uint_minmax(val, kp,
3222 RPC_MAX_SLOT_TABLE);
3225 static const struct kernel_param_ops param_ops_slot_table_size = {
3226 .set = param_set_slot_table_size,
3227 .get = param_get_uint,
3230 #define param_check_slot_table_size(name, p) \
3231 __param_check(name, p, unsigned int);
3233 static int param_set_max_slot_table_size(const char *val,
3234 const struct kernel_param *kp)
3236 return param_set_uint_minmax(val, kp,
3238 RPC_MAX_SLOT_TABLE_LIMIT);
3241 static const struct kernel_param_ops param_ops_max_slot_table_size = {
3242 .set = param_set_max_slot_table_size,
3243 .get = param_get_uint,
3246 #define param_check_max_slot_table_size(name, p) \
3247 __param_check(name, p, unsigned int);
3249 module_param_named(tcp_slot_table_entries, xprt_tcp_slot_table_entries,
3250 slot_table_size, 0644);
3251 module_param_named(tcp_max_slot_table_entries, xprt_max_tcp_slot_table_entries,
3252 max_slot_table_size, 0644);
3253 module_param_named(udp_slot_table_entries, xprt_udp_slot_table_entries,
3254 slot_table_size, 0644);