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/sunrpc.h>
60 static void xs_close(struct rpc_xprt *xprt);
61 static void xs_set_srcport(struct sock_xprt *transport, struct socket *sock);
62 static void xs_tcp_set_socket_timeouts(struct rpc_xprt *xprt,
68 static unsigned int xprt_udp_slot_table_entries = RPC_DEF_SLOT_TABLE;
69 static unsigned int xprt_tcp_slot_table_entries = RPC_MIN_SLOT_TABLE;
70 static unsigned int xprt_max_tcp_slot_table_entries = RPC_MAX_SLOT_TABLE;
72 static unsigned int xprt_min_resvport = RPC_DEF_MIN_RESVPORT;
73 static unsigned int xprt_max_resvport = RPC_DEF_MAX_RESVPORT;
75 #define XS_TCP_LINGER_TO (15U * HZ)
76 static unsigned int xs_tcp_fin_timeout __read_mostly = XS_TCP_LINGER_TO;
79 * We can register our own files under /proc/sys/sunrpc by
80 * calling register_sysctl_table() again. The files in that
81 * directory become the union of all files registered there.
83 * We simply need to make sure that we don't collide with
84 * someone else's file names!
87 static unsigned int min_slot_table_size = RPC_MIN_SLOT_TABLE;
88 static unsigned int max_slot_table_size = RPC_MAX_SLOT_TABLE;
89 static unsigned int max_tcp_slot_table_limit = RPC_MAX_SLOT_TABLE_LIMIT;
90 static unsigned int xprt_min_resvport_limit = RPC_MIN_RESVPORT;
91 static unsigned int xprt_max_resvport_limit = RPC_MAX_RESVPORT;
93 static struct ctl_table_header *sunrpc_table_header;
95 static struct xprt_class xs_local_transport;
96 static struct xprt_class xs_udp_transport;
97 static struct xprt_class xs_tcp_transport;
98 static struct xprt_class xs_bc_tcp_transport;
101 * FIXME: changing the UDP slot table size should also resize the UDP
102 * socket buffers for existing UDP transports
104 static struct ctl_table xs_tunables_table[] = {
106 .procname = "udp_slot_table_entries",
107 .data = &xprt_udp_slot_table_entries,
108 .maxlen = sizeof(unsigned int),
110 .proc_handler = proc_dointvec_minmax,
111 .extra1 = &min_slot_table_size,
112 .extra2 = &max_slot_table_size
115 .procname = "tcp_slot_table_entries",
116 .data = &xprt_tcp_slot_table_entries,
117 .maxlen = sizeof(unsigned int),
119 .proc_handler = proc_dointvec_minmax,
120 .extra1 = &min_slot_table_size,
121 .extra2 = &max_slot_table_size
124 .procname = "tcp_max_slot_table_entries",
125 .data = &xprt_max_tcp_slot_table_entries,
126 .maxlen = sizeof(unsigned int),
128 .proc_handler = proc_dointvec_minmax,
129 .extra1 = &min_slot_table_size,
130 .extra2 = &max_tcp_slot_table_limit
133 .procname = "min_resvport",
134 .data = &xprt_min_resvport,
135 .maxlen = sizeof(unsigned int),
137 .proc_handler = proc_dointvec_minmax,
138 .extra1 = &xprt_min_resvport_limit,
139 .extra2 = &xprt_max_resvport_limit
142 .procname = "max_resvport",
143 .data = &xprt_max_resvport,
144 .maxlen = sizeof(unsigned int),
146 .proc_handler = proc_dointvec_minmax,
147 .extra1 = &xprt_min_resvport_limit,
148 .extra2 = &xprt_max_resvport_limit
151 .procname = "tcp_fin_timeout",
152 .data = &xs_tcp_fin_timeout,
153 .maxlen = sizeof(xs_tcp_fin_timeout),
155 .proc_handler = proc_dointvec_jiffies,
160 static struct ctl_table sunrpc_table[] = {
162 .procname = "sunrpc",
164 .child = xs_tunables_table
170 * Wait duration for a reply from the RPC portmapper.
172 #define XS_BIND_TO (60U * HZ)
175 * Delay if a UDP socket connect error occurs. This is most likely some
176 * kind of resource problem on the local host.
178 #define XS_UDP_REEST_TO (2U * HZ)
181 * The reestablish timeout allows clients to delay for a bit before attempting
182 * to reconnect to a server that just dropped our connection.
184 * We implement an exponential backoff when trying to reestablish a TCP
185 * transport connection with the server. Some servers like to drop a TCP
186 * connection when they are overworked, so we start with a short timeout and
187 * increase over time if the server is down or not responding.
189 #define XS_TCP_INIT_REEST_TO (3U * HZ)
192 * TCP idle timeout; client drops the transport socket if it is idle
193 * for this long. Note that we also timeout UDP sockets to prevent
194 * holding port numbers when there is no RPC traffic.
196 #define XS_IDLE_DISC_TO (5U * 60 * HZ)
198 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
199 # undef RPC_DEBUG_DATA
200 # define RPCDBG_FACILITY RPCDBG_TRANS
203 #ifdef RPC_DEBUG_DATA
204 static void xs_pktdump(char *msg, u32 *packet, unsigned int count)
206 u8 *buf = (u8 *) packet;
209 dprintk("RPC: %s\n", msg);
210 for (j = 0; j < count && j < 128; j += 4) {
214 dprintk("0x%04x ", j);
216 dprintk("%02x%02x%02x%02x ",
217 buf[j], buf[j+1], buf[j+2], buf[j+3]);
222 static inline void xs_pktdump(char *msg, u32 *packet, unsigned int count)
228 static inline struct rpc_xprt *xprt_from_sock(struct sock *sk)
230 return (struct rpc_xprt *) sk->sk_user_data;
233 static inline struct sockaddr *xs_addr(struct rpc_xprt *xprt)
235 return (struct sockaddr *) &xprt->addr;
238 static inline struct sockaddr_un *xs_addr_un(struct rpc_xprt *xprt)
240 return (struct sockaddr_un *) &xprt->addr;
243 static inline struct sockaddr_in *xs_addr_in(struct rpc_xprt *xprt)
245 return (struct sockaddr_in *) &xprt->addr;
248 static inline struct sockaddr_in6 *xs_addr_in6(struct rpc_xprt *xprt)
250 return (struct sockaddr_in6 *) &xprt->addr;
253 static void xs_format_common_peer_addresses(struct rpc_xprt *xprt)
255 struct sockaddr *sap = xs_addr(xprt);
256 struct sockaddr_in6 *sin6;
257 struct sockaddr_in *sin;
258 struct sockaddr_un *sun;
261 switch (sap->sa_family) {
263 sun = xs_addr_un(xprt);
264 strscpy(buf, sun->sun_path, sizeof(buf));
265 xprt->address_strings[RPC_DISPLAY_ADDR] =
266 kstrdup(buf, GFP_KERNEL);
269 (void)rpc_ntop(sap, buf, sizeof(buf));
270 xprt->address_strings[RPC_DISPLAY_ADDR] =
271 kstrdup(buf, GFP_KERNEL);
272 sin = xs_addr_in(xprt);
273 snprintf(buf, sizeof(buf), "%08x", ntohl(sin->sin_addr.s_addr));
276 (void)rpc_ntop(sap, buf, sizeof(buf));
277 xprt->address_strings[RPC_DISPLAY_ADDR] =
278 kstrdup(buf, GFP_KERNEL);
279 sin6 = xs_addr_in6(xprt);
280 snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr);
286 xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
289 static void xs_format_common_peer_ports(struct rpc_xprt *xprt)
291 struct sockaddr *sap = xs_addr(xprt);
294 snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
295 xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL);
297 snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
298 xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL);
301 static void xs_format_peer_addresses(struct rpc_xprt *xprt,
302 const char *protocol,
305 xprt->address_strings[RPC_DISPLAY_PROTO] = protocol;
306 xprt->address_strings[RPC_DISPLAY_NETID] = netid;
307 xs_format_common_peer_addresses(xprt);
308 xs_format_common_peer_ports(xprt);
311 static void xs_update_peer_port(struct rpc_xprt *xprt)
313 kfree(xprt->address_strings[RPC_DISPLAY_HEX_PORT]);
314 kfree(xprt->address_strings[RPC_DISPLAY_PORT]);
316 xs_format_common_peer_ports(xprt);
319 static void xs_free_peer_addresses(struct rpc_xprt *xprt)
323 for (i = 0; i < RPC_DISPLAY_MAX; i++)
325 case RPC_DISPLAY_PROTO:
326 case RPC_DISPLAY_NETID:
329 kfree(xprt->address_strings[i]);
334 xs_alloc_sparse_pages(struct xdr_buf *buf, size_t want, gfp_t gfp)
338 if (!want || !(buf->flags & XDRBUF_SPARSE_PAGES))
340 n = (buf->page_base + want + PAGE_SIZE - 1) >> PAGE_SHIFT;
341 for (i = 0; i < n; i++) {
344 buf->bvec[i].bv_page = buf->pages[i] = alloc_page(gfp);
345 if (!buf->pages[i]) {
347 return i > buf->page_base ? i - buf->page_base : 0;
354 xs_sock_recvmsg(struct socket *sock, struct msghdr *msg, int flags, size_t seek)
358 iov_iter_advance(&msg->msg_iter, seek);
359 ret = sock_recvmsg(sock, msg, flags);
360 return ret > 0 ? ret + seek : ret;
364 xs_read_kvec(struct socket *sock, struct msghdr *msg, int flags,
365 struct kvec *kvec, size_t count, size_t seek)
367 iov_iter_kvec(&msg->msg_iter, READ, kvec, 1, count);
368 return xs_sock_recvmsg(sock, msg, flags, seek);
372 xs_read_bvec(struct socket *sock, struct msghdr *msg, int flags,
373 struct bio_vec *bvec, unsigned long nr, size_t count,
376 iov_iter_bvec(&msg->msg_iter, READ, bvec, nr, count);
377 return xs_sock_recvmsg(sock, msg, flags, seek);
381 xs_read_discard(struct socket *sock, struct msghdr *msg, int flags,
384 iov_iter_discard(&msg->msg_iter, READ, count);
385 return sock_recvmsg(sock, msg, flags);
388 #if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
390 xs_flush_bvec(const struct bio_vec *bvec, size_t count, size_t seek)
392 struct bvec_iter bi = {
397 bvec_iter_advance(bvec, &bi, seek & PAGE_MASK);
398 for_each_bvec(bv, bvec, bi, bi)
399 flush_dcache_page(bv.bv_page);
403 xs_flush_bvec(const struct bio_vec *bvec, size_t count, size_t seek)
409 xs_read_xdr_buf(struct socket *sock, struct msghdr *msg, int flags,
410 struct xdr_buf *buf, size_t count, size_t seek, size_t *read)
412 size_t want, seek_init = seek, offset = 0;
415 want = min_t(size_t, count, buf->head[0].iov_len);
417 ret = xs_read_kvec(sock, msg, flags, &buf->head[0], want, seek);
421 if (offset == count || msg->msg_flags & (MSG_EOR|MSG_TRUNC))
431 want = xs_alloc_sparse_pages(
432 buf, min_t(size_t, count - offset, buf->page_len),
433 GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
435 ret = xs_read_bvec(sock, msg, flags, buf->bvec,
436 xdr_buf_pagecount(buf),
437 want + buf->page_base,
438 seek + buf->page_base);
441 xs_flush_bvec(buf->bvec, ret, seek + buf->page_base);
442 ret -= buf->page_base;
444 if (offset == count || msg->msg_flags & (MSG_EOR|MSG_TRUNC))
454 want = min_t(size_t, count - offset, buf->tail[0].iov_len);
456 ret = xs_read_kvec(sock, msg, flags, &buf->tail[0], want, seek);
460 if (offset == count || msg->msg_flags & (MSG_EOR|MSG_TRUNC))
464 } else if (offset < seek_init)
468 *read = offset - seek_init;
476 xs_read_header(struct sock_xprt *transport, struct xdr_buf *buf)
478 if (!transport->recv.copied) {
479 if (buf->head[0].iov_len >= transport->recv.offset)
480 memcpy(buf->head[0].iov_base,
481 &transport->recv.xid,
482 transport->recv.offset);
483 transport->recv.copied = transport->recv.offset;
488 xs_read_stream_request_done(struct sock_xprt *transport)
490 return transport->recv.fraghdr & cpu_to_be32(RPC_LAST_STREAM_FRAGMENT);
494 xs_read_stream_check_eor(struct sock_xprt *transport,
497 if (xs_read_stream_request_done(transport))
498 msg->msg_flags |= MSG_EOR;
502 xs_read_stream_request(struct sock_xprt *transport, struct msghdr *msg,
503 int flags, struct rpc_rqst *req)
505 struct xdr_buf *buf = &req->rq_private_buf;
509 xs_read_header(transport, buf);
511 want = transport->recv.len - transport->recv.offset;
513 ret = xs_read_xdr_buf(transport->sock, msg, flags, buf,
514 transport->recv.copied + want,
515 transport->recv.copied,
517 transport->recv.offset += read;
518 transport->recv.copied += read;
521 if (transport->recv.offset == transport->recv.len)
522 xs_read_stream_check_eor(transport, msg);
532 msg->msg_flags |= MSG_TRUNC;
537 return ret < 0 ? ret : read;
541 xs_read_stream_headersize(bool isfrag)
544 return sizeof(__be32);
545 return 3 * sizeof(__be32);
549 xs_read_stream_header(struct sock_xprt *transport, struct msghdr *msg,
550 int flags, size_t want, size_t seek)
553 .iov_base = &transport->recv.fraghdr,
556 return xs_read_kvec(transport->sock, msg, flags, &kvec, want, seek);
559 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
561 xs_read_stream_call(struct sock_xprt *transport, struct msghdr *msg, int flags)
563 struct rpc_xprt *xprt = &transport->xprt;
564 struct rpc_rqst *req;
567 /* Is this transport associated with the backchannel? */
571 /* Look up and lock the request corresponding to the given XID */
572 req = xprt_lookup_bc_request(xprt, transport->recv.xid);
574 printk(KERN_WARNING "Callback slot table overflowed\n");
577 if (transport->recv.copied && !req->rq_private_buf.len)
580 ret = xs_read_stream_request(transport, msg, flags, req);
581 if (msg->msg_flags & (MSG_EOR|MSG_TRUNC))
582 xprt_complete_bc_request(req, transport->recv.copied);
584 req->rq_private_buf.len = transport->recv.copied;
588 #else /* CONFIG_SUNRPC_BACKCHANNEL */
590 xs_read_stream_call(struct sock_xprt *transport, struct msghdr *msg, int flags)
594 #endif /* CONFIG_SUNRPC_BACKCHANNEL */
597 xs_read_stream_reply(struct sock_xprt *transport, struct msghdr *msg, int flags)
599 struct rpc_xprt *xprt = &transport->xprt;
600 struct rpc_rqst *req;
603 /* Look up and lock the request corresponding to the given XID */
604 spin_lock(&xprt->queue_lock);
605 req = xprt_lookup_rqst(xprt, transport->recv.xid);
606 if (!req || (transport->recv.copied && !req->rq_private_buf.len)) {
607 msg->msg_flags |= MSG_TRUNC;
611 spin_unlock(&xprt->queue_lock);
613 ret = xs_read_stream_request(transport, msg, flags, req);
615 spin_lock(&xprt->queue_lock);
616 if (msg->msg_flags & (MSG_EOR|MSG_TRUNC))
617 xprt_complete_rqst(req->rq_task, transport->recv.copied);
619 req->rq_private_buf.len = transport->recv.copied;
620 xprt_unpin_rqst(req);
622 spin_unlock(&xprt->queue_lock);
627 xs_read_stream(struct sock_xprt *transport, int flags)
629 struct msghdr msg = { 0 };
630 size_t want, read = 0;
633 if (transport->recv.len == 0) {
634 want = xs_read_stream_headersize(transport->recv.copied != 0);
635 ret = xs_read_stream_header(transport, &msg, flags, want,
636 transport->recv.offset);
639 transport->recv.offset = ret;
640 if (transport->recv.offset != want)
641 return transport->recv.offset;
642 transport->recv.len = be32_to_cpu(transport->recv.fraghdr) &
643 RPC_FRAGMENT_SIZE_MASK;
644 transport->recv.offset -= sizeof(transport->recv.fraghdr);
648 switch (be32_to_cpu(transport->recv.calldir)) {
650 msg.msg_flags |= MSG_TRUNC;
653 ret = xs_read_stream_call(transport, &msg, flags);
656 ret = xs_read_stream_reply(transport, &msg, flags);
658 if (msg.msg_flags & MSG_TRUNC) {
659 transport->recv.calldir = cpu_to_be32(-1);
660 transport->recv.copied = -1;
665 if (transport->recv.offset < transport->recv.len) {
666 if (!(msg.msg_flags & MSG_TRUNC))
669 ret = xs_read_discard(transport->sock, &msg, flags,
670 transport->recv.len - transport->recv.offset);
673 transport->recv.offset += ret;
675 if (transport->recv.offset != transport->recv.len)
678 if (xs_read_stream_request_done(transport)) {
679 trace_xs_stream_read_request(transport);
680 transport->recv.copied = 0;
682 transport->recv.offset = 0;
683 transport->recv.len = 0;
686 return ret != 0 ? ret : -ESHUTDOWN;
689 static __poll_t xs_poll_socket(struct sock_xprt *transport)
691 return transport->sock->ops->poll(transport->file, transport->sock,
695 static bool xs_poll_socket_readable(struct sock_xprt *transport)
697 __poll_t events = xs_poll_socket(transport);
699 return (events & (EPOLLIN | EPOLLRDNORM)) && !(events & EPOLLRDHUP);
702 static void xs_poll_check_readable(struct sock_xprt *transport)
705 clear_bit(XPRT_SOCK_DATA_READY, &transport->sock_state);
706 if (!xs_poll_socket_readable(transport))
708 if (!test_and_set_bit(XPRT_SOCK_DATA_READY, &transport->sock_state))
709 queue_work(xprtiod_workqueue, &transport->recv_worker);
712 static void xs_stream_data_receive(struct sock_xprt *transport)
717 mutex_lock(&transport->recv_mutex);
718 if (transport->sock == NULL)
721 ret = xs_read_stream(transport, MSG_DONTWAIT);
727 if (ret == -ESHUTDOWN)
728 kernel_sock_shutdown(transport->sock, SHUT_RDWR);
730 xs_poll_check_readable(transport);
732 mutex_unlock(&transport->recv_mutex);
733 trace_xs_stream_read_data(&transport->xprt, ret, read);
736 static void xs_stream_data_receive_workfn(struct work_struct *work)
738 struct sock_xprt *transport =
739 container_of(work, struct sock_xprt, recv_worker);
740 unsigned int pflags = memalloc_nofs_save();
742 xs_stream_data_receive(transport);
743 memalloc_nofs_restore(pflags);
747 xs_stream_reset_connect(struct sock_xprt *transport)
749 transport->recv.offset = 0;
750 transport->recv.len = 0;
751 transport->recv.copied = 0;
752 transport->xmit.offset = 0;
756 xs_stream_start_connect(struct sock_xprt *transport)
758 transport->xprt.stat.connect_count++;
759 transport->xprt.stat.connect_start = jiffies;
762 #define XS_SENDMSG_FLAGS (MSG_DONTWAIT | MSG_NOSIGNAL)
765 * xs_nospace - handle transmit was incomplete
766 * @req: pointer to RPC request
767 * @transport: pointer to struct sock_xprt
770 static int xs_nospace(struct rpc_rqst *req, struct sock_xprt *transport)
772 struct rpc_xprt *xprt = &transport->xprt;
773 struct sock *sk = transport->inet;
776 trace_rpc_socket_nospace(req, transport);
778 /* Protect against races with write_space */
779 spin_lock(&xprt->transport_lock);
781 /* Don't race with disconnect */
782 if (xprt_connected(xprt)) {
783 /* wait for more buffer space */
784 set_bit(XPRT_SOCK_NOSPACE, &transport->sock_state);
785 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
786 sk->sk_write_pending++;
787 xprt_wait_for_buffer_space(xprt);
791 spin_unlock(&xprt->transport_lock);
795 static int xs_sock_nospace(struct rpc_rqst *req)
797 struct sock_xprt *transport =
798 container_of(req->rq_xprt, struct sock_xprt, xprt);
799 struct sock *sk = transport->inet;
803 if (!sock_writeable(sk))
804 ret = xs_nospace(req, transport);
809 static int xs_stream_nospace(struct rpc_rqst *req, bool vm_wait)
811 struct sock_xprt *transport =
812 container_of(req->rq_xprt, struct sock_xprt, xprt);
813 struct sock *sk = transport->inet;
819 if (!sk_stream_memory_free(sk))
820 ret = xs_nospace(req, transport);
825 static int xs_stream_prepare_request(struct rpc_rqst *req, struct xdr_buf *buf)
827 return xdr_alloc_bvec(buf, rpc_task_gfp_mask());
831 * Determine if the previous message in the stream was aborted before it
832 * could complete transmission.
835 xs_send_request_was_aborted(struct sock_xprt *transport, struct rpc_rqst *req)
837 return transport->xmit.offset != 0 && req->rq_bytes_sent == 0;
841 * Return the stream record marker field for a record of length < 2^31-1
844 xs_stream_record_marker(struct xdr_buf *xdr)
848 return cpu_to_be32(RPC_LAST_STREAM_FRAGMENT | (u32)xdr->len);
852 * xs_local_send_request - write an RPC request to an AF_LOCAL socket
853 * @req: pointer to RPC request
856 * 0: The request has been sent
857 * EAGAIN: The socket was blocked, please call again later to
858 * complete the request
859 * ENOTCONN: Caller needs to invoke connect logic then call again
860 * other: Some other error occurred, the request was not sent
862 static int xs_local_send_request(struct rpc_rqst *req)
864 struct rpc_xprt *xprt = req->rq_xprt;
865 struct sock_xprt *transport =
866 container_of(xprt, struct sock_xprt, xprt);
867 struct xdr_buf *xdr = &req->rq_snd_buf;
868 rpc_fraghdr rm = xs_stream_record_marker(xdr);
869 unsigned int msglen = rm ? req->rq_slen + sizeof(rm) : req->rq_slen;
870 struct msghdr msg = {
871 .msg_flags = XS_SENDMSG_FLAGS,
877 /* Close the stream if the previous transmission was incomplete */
878 if (xs_send_request_was_aborted(transport, req)) {
879 xprt_force_disconnect(xprt);
883 xs_pktdump("packet data:",
884 req->rq_svec->iov_base, req->rq_svec->iov_len);
886 vm_wait = sk_stream_is_writeable(transport->inet) ? true : false;
888 req->rq_xtime = ktime_get();
889 status = xprt_sock_sendmsg(transport->sock, &msg, xdr,
890 transport->xmit.offset, rm, &sent);
891 dprintk("RPC: %s(%u) = %d\n",
892 __func__, xdr->len - transport->xmit.offset, status);
894 if (likely(sent > 0) || status == 0) {
895 transport->xmit.offset += sent;
896 req->rq_bytes_sent = transport->xmit.offset;
897 if (likely(req->rq_bytes_sent >= msglen)) {
898 req->rq_xmit_bytes_sent += transport->xmit.offset;
899 transport->xmit.offset = 0;
908 status = xs_stream_nospace(req, vm_wait);
911 dprintk("RPC: sendmsg returned unrecognized error %d\n",
915 xprt_force_disconnect(xprt);
923 * xs_udp_send_request - write an RPC request to a UDP socket
924 * @req: pointer to RPC request
927 * 0: The request has been sent
928 * EAGAIN: The socket was blocked, please call again later to
929 * complete the request
930 * ENOTCONN: Caller needs to invoke connect logic then call again
931 * other: Some other error occurred, the request was not sent
933 static int xs_udp_send_request(struct rpc_rqst *req)
935 struct rpc_xprt *xprt = req->rq_xprt;
936 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
937 struct xdr_buf *xdr = &req->rq_snd_buf;
938 struct msghdr msg = {
939 .msg_name = xs_addr(xprt),
940 .msg_namelen = xprt->addrlen,
941 .msg_flags = XS_SENDMSG_FLAGS,
946 xs_pktdump("packet data:",
947 req->rq_svec->iov_base,
948 req->rq_svec->iov_len);
950 if (!xprt_bound(xprt))
953 if (!xprt_request_get_cong(xprt, req))
956 status = xdr_alloc_bvec(xdr, rpc_task_gfp_mask());
959 req->rq_xtime = ktime_get();
960 status = xprt_sock_sendmsg(transport->sock, &msg, xdr, 0, 0, &sent);
962 dprintk("RPC: xs_udp_send_request(%u) = %d\n",
965 /* firewall is blocking us, don't return -EAGAIN or we end up looping */
966 if (status == -EPERM)
969 if (status == -EAGAIN && sock_writeable(transport->inet))
972 if (sent > 0 || status == 0) {
973 req->rq_xmit_bytes_sent += sent;
974 if (sent >= req->rq_slen)
976 /* Still some bytes left; set up for a retry later. */
984 /* Should we call xs_close() here? */
987 status = xs_sock_nospace(req);
994 /* When the server has died, an ICMP port unreachable message
995 * prompts ECONNREFUSED. */
998 dprintk("RPC: sendmsg returned unrecognized error %d\n",
1006 * xs_tcp_send_request - write an RPC request to a TCP socket
1007 * @req: pointer to RPC request
1010 * 0: The request has been sent
1011 * EAGAIN: The socket was blocked, please call again later to
1012 * complete the request
1013 * ENOTCONN: Caller needs to invoke connect logic then call again
1014 * other: Some other error occurred, the request was not sent
1016 * XXX: In the case of soft timeouts, should we eventually give up
1017 * if sendmsg is not able to make progress?
1019 static int xs_tcp_send_request(struct rpc_rqst *req)
1021 struct rpc_xprt *xprt = req->rq_xprt;
1022 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
1023 struct xdr_buf *xdr = &req->rq_snd_buf;
1024 rpc_fraghdr rm = xs_stream_record_marker(xdr);
1025 unsigned int msglen = rm ? req->rq_slen + sizeof(rm) : req->rq_slen;
1026 struct msghdr msg = {
1027 .msg_flags = XS_SENDMSG_FLAGS,
1033 /* Close the stream if the previous transmission was incomplete */
1034 if (xs_send_request_was_aborted(transport, req)) {
1035 if (transport->sock != NULL)
1036 kernel_sock_shutdown(transport->sock, SHUT_RDWR);
1039 if (!transport->inet)
1042 xs_pktdump("packet data:",
1043 req->rq_svec->iov_base,
1044 req->rq_svec->iov_len);
1046 if (test_bit(XPRT_SOCK_UPD_TIMEOUT, &transport->sock_state))
1047 xs_tcp_set_socket_timeouts(xprt, transport->sock);
1049 xs_set_srcport(transport, transport->sock);
1051 /* Continue transmitting the packet/record. We must be careful
1052 * to cope with writespace callbacks arriving _after_ we have
1053 * called sendmsg(). */
1054 req->rq_xtime = ktime_get();
1055 tcp_sock_set_cork(transport->inet, true);
1057 vm_wait = sk_stream_is_writeable(transport->inet) ? true : false;
1060 status = xprt_sock_sendmsg(transport->sock, &msg, xdr,
1061 transport->xmit.offset, rm, &sent);
1063 dprintk("RPC: xs_tcp_send_request(%u) = %d\n",
1064 xdr->len - transport->xmit.offset, status);
1066 /* If we've sent the entire packet, immediately
1067 * reset the count of bytes sent. */
1068 transport->xmit.offset += sent;
1069 req->rq_bytes_sent = transport->xmit.offset;
1070 if (likely(req->rq_bytes_sent >= msglen)) {
1071 req->rq_xmit_bytes_sent += transport->xmit.offset;
1072 transport->xmit.offset = 0;
1073 if (atomic_long_read(&xprt->xmit_queuelen) == 1)
1074 tcp_sock_set_cork(transport->inet, false);
1078 WARN_ON_ONCE(sent == 0 && status == 0);
1083 } while (status == 0);
1088 /* Should we call xs_close() here? */
1091 status = xs_stream_nospace(req, vm_wait);
1101 dprintk("RPC: sendmsg returned unrecognized error %d\n",
1108 static void xs_save_old_callbacks(struct sock_xprt *transport, struct sock *sk)
1110 transport->old_data_ready = sk->sk_data_ready;
1111 transport->old_state_change = sk->sk_state_change;
1112 transport->old_write_space = sk->sk_write_space;
1113 transport->old_error_report = sk->sk_error_report;
1116 static void xs_restore_old_callbacks(struct sock_xprt *transport, struct sock *sk)
1118 sk->sk_data_ready = transport->old_data_ready;
1119 sk->sk_state_change = transport->old_state_change;
1120 sk->sk_write_space = transport->old_write_space;
1121 sk->sk_error_report = transport->old_error_report;
1124 static void xs_sock_reset_state_flags(struct rpc_xprt *xprt)
1126 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
1128 clear_bit(XPRT_SOCK_DATA_READY, &transport->sock_state);
1129 clear_bit(XPRT_SOCK_WAKE_ERROR, &transport->sock_state);
1130 clear_bit(XPRT_SOCK_WAKE_WRITE, &transport->sock_state);
1131 clear_bit(XPRT_SOCK_WAKE_DISCONNECT, &transport->sock_state);
1132 clear_bit(XPRT_SOCK_NOSPACE, &transport->sock_state);
1135 static void xs_run_error_worker(struct sock_xprt *transport, unsigned int nr)
1137 set_bit(nr, &transport->sock_state);
1138 queue_work(xprtiod_workqueue, &transport->error_worker);
1141 static void xs_sock_reset_connection_flags(struct rpc_xprt *xprt)
1143 xprt->connect_cookie++;
1144 smp_mb__before_atomic();
1145 clear_bit(XPRT_CLOSE_WAIT, &xprt->state);
1146 clear_bit(XPRT_CLOSING, &xprt->state);
1147 xs_sock_reset_state_flags(xprt);
1148 smp_mb__after_atomic();
1152 * xs_error_report - callback to handle TCP socket state errors
1155 * Note: we don't call sock_error() since there may be a rpc_task
1156 * using the socket, and so we don't want to clear sk->sk_err.
1158 static void xs_error_report(struct sock *sk)
1160 struct sock_xprt *transport;
1161 struct rpc_xprt *xprt;
1163 if (!(xprt = xprt_from_sock(sk)))
1166 transport = container_of(xprt, struct sock_xprt, xprt);
1167 transport->xprt_err = -sk->sk_err;
1168 if (transport->xprt_err == 0)
1170 dprintk("RPC: xs_error_report client %p, error=%d...\n",
1171 xprt, -transport->xprt_err);
1172 trace_rpc_socket_error(xprt, sk->sk_socket, transport->xprt_err);
1174 /* barrier ensures xprt_err is set before XPRT_SOCK_WAKE_ERROR */
1175 smp_mb__before_atomic();
1176 xs_run_error_worker(transport, XPRT_SOCK_WAKE_ERROR);
1179 static void xs_reset_transport(struct sock_xprt *transport)
1181 struct socket *sock = transport->sock;
1182 struct sock *sk = transport->inet;
1183 struct rpc_xprt *xprt = &transport->xprt;
1184 struct file *filp = transport->file;
1189 * Make sure we're calling this in a context from which it is safe
1190 * to call __fput_sync(). In practice that means rpciod and the
1193 if (!(current->flags & PF_WQ_WORKER)) {
1195 set_bit(XPRT_CLOSE_WAIT, &xprt->state);
1199 if (atomic_read(&transport->xprt.swapper))
1200 sk_clear_memalloc(sk);
1202 kernel_sock_shutdown(sock, SHUT_RDWR);
1204 mutex_lock(&transport->recv_mutex);
1206 transport->inet = NULL;
1207 transport->sock = NULL;
1208 transport->file = NULL;
1210 sk->sk_user_data = NULL;
1212 xs_restore_old_callbacks(transport, sk);
1213 xprt_clear_connected(xprt);
1214 xs_sock_reset_connection_flags(xprt);
1215 /* Reset stream record info */
1216 xs_stream_reset_connect(transport);
1218 mutex_unlock(&transport->recv_mutex);
1220 trace_rpc_socket_close(xprt, sock);
1223 xprt_disconnect_done(xprt);
1227 * xs_close - close a socket
1230 * This is used when all requests are complete; ie, no DRC state remains
1231 * on the server we want to save.
1233 * The caller _must_ be holding XPRT_LOCKED in order to avoid issues with
1234 * xs_reset_transport() zeroing the socket from underneath a writer.
1236 static void xs_close(struct rpc_xprt *xprt)
1238 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
1240 dprintk("RPC: xs_close xprt %p\n", xprt);
1242 xs_reset_transport(transport);
1243 xprt->reestablish_timeout = 0;
1246 static void xs_inject_disconnect(struct rpc_xprt *xprt)
1248 dprintk("RPC: injecting transport disconnect on xprt=%p\n",
1250 xprt_disconnect_done(xprt);
1253 static void xs_xprt_free(struct rpc_xprt *xprt)
1255 xs_free_peer_addresses(xprt);
1260 * xs_destroy - prepare to shutdown a transport
1261 * @xprt: doomed transport
1264 static void xs_destroy(struct rpc_xprt *xprt)
1266 struct sock_xprt *transport = container_of(xprt,
1267 struct sock_xprt, xprt);
1268 dprintk("RPC: xs_destroy xprt %p\n", xprt);
1270 cancel_delayed_work_sync(&transport->connect_worker);
1272 cancel_work_sync(&transport->recv_worker);
1273 cancel_work_sync(&transport->error_worker);
1275 module_put(THIS_MODULE);
1279 * xs_udp_data_read_skb - receive callback for UDP sockets
1285 static void xs_udp_data_read_skb(struct rpc_xprt *xprt,
1287 struct sk_buff *skb)
1289 struct rpc_task *task;
1290 struct rpc_rqst *rovr;
1291 int repsize, copied;
1297 dprintk("RPC: impossible RPC reply size %d!\n", repsize);
1301 /* Copy the XID from the skb... */
1302 xp = skb_header_pointer(skb, 0, sizeof(_xid), &_xid);
1306 /* Look up and lock the request corresponding to the given XID */
1307 spin_lock(&xprt->queue_lock);
1308 rovr = xprt_lookup_rqst(xprt, *xp);
1311 xprt_pin_rqst(rovr);
1312 xprt_update_rtt(rovr->rq_task);
1313 spin_unlock(&xprt->queue_lock);
1314 task = rovr->rq_task;
1316 if ((copied = rovr->rq_private_buf.buflen) > repsize)
1319 /* Suck it into the iovec, verify checksum if not done by hw. */
1320 if (csum_partial_copy_to_xdr(&rovr->rq_private_buf, skb)) {
1321 spin_lock(&xprt->queue_lock);
1322 __UDPX_INC_STATS(sk, UDP_MIB_INERRORS);
1327 spin_lock(&xprt->transport_lock);
1328 xprt_adjust_cwnd(xprt, task, copied);
1329 spin_unlock(&xprt->transport_lock);
1330 spin_lock(&xprt->queue_lock);
1331 xprt_complete_rqst(task, copied);
1332 __UDPX_INC_STATS(sk, UDP_MIB_INDATAGRAMS);
1334 xprt_unpin_rqst(rovr);
1336 spin_unlock(&xprt->queue_lock);
1339 static void xs_udp_data_receive(struct sock_xprt *transport)
1341 struct sk_buff *skb;
1345 mutex_lock(&transport->recv_mutex);
1346 sk = transport->inet;
1350 skb = skb_recv_udp(sk, MSG_DONTWAIT, &err);
1353 xs_udp_data_read_skb(&transport->xprt, sk, skb);
1357 xs_poll_check_readable(transport);
1359 mutex_unlock(&transport->recv_mutex);
1362 static void xs_udp_data_receive_workfn(struct work_struct *work)
1364 struct sock_xprt *transport =
1365 container_of(work, struct sock_xprt, recv_worker);
1366 unsigned int pflags = memalloc_nofs_save();
1368 xs_udp_data_receive(transport);
1369 memalloc_nofs_restore(pflags);
1373 * xs_data_ready - "data ready" callback for sockets
1374 * @sk: socket with data to read
1377 static void xs_data_ready(struct sock *sk)
1379 struct rpc_xprt *xprt;
1381 xprt = xprt_from_sock(sk);
1383 struct sock_xprt *transport = container_of(xprt,
1384 struct sock_xprt, xprt);
1386 trace_xs_data_ready(xprt);
1388 transport->old_data_ready(sk);
1389 /* Any data means we had a useful conversation, so
1390 * then we don't need to delay the next reconnect
1392 if (xprt->reestablish_timeout)
1393 xprt->reestablish_timeout = 0;
1394 if (!test_and_set_bit(XPRT_SOCK_DATA_READY, &transport->sock_state))
1395 queue_work(xprtiod_workqueue, &transport->recv_worker);
1400 * Helper function to force a TCP close if the server is sending
1401 * junk and/or it has put us in CLOSE_WAIT
1403 static void xs_tcp_force_close(struct rpc_xprt *xprt)
1405 xprt_force_disconnect(xprt);
1408 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
1409 static size_t xs_tcp_bc_maxpayload(struct rpc_xprt *xprt)
1413 #endif /* CONFIG_SUNRPC_BACKCHANNEL */
1416 * xs_local_state_change - callback to handle AF_LOCAL socket state changes
1417 * @sk: socket whose state has changed
1420 static void xs_local_state_change(struct sock *sk)
1422 struct rpc_xprt *xprt;
1423 struct sock_xprt *transport;
1425 if (!(xprt = xprt_from_sock(sk)))
1427 transport = container_of(xprt, struct sock_xprt, xprt);
1428 if (sk->sk_shutdown & SHUTDOWN_MASK) {
1429 clear_bit(XPRT_CONNECTED, &xprt->state);
1430 /* Trigger the socket release */
1431 xs_run_error_worker(transport, XPRT_SOCK_WAKE_DISCONNECT);
1436 * xs_tcp_state_change - callback to handle TCP socket state changes
1437 * @sk: socket whose state has changed
1440 static void xs_tcp_state_change(struct sock *sk)
1442 struct rpc_xprt *xprt;
1443 struct sock_xprt *transport;
1445 if (!(xprt = xprt_from_sock(sk)))
1447 dprintk("RPC: xs_tcp_state_change client %p...\n", xprt);
1448 dprintk("RPC: state %x conn %d dead %d zapped %d sk_shutdown %d\n",
1449 sk->sk_state, xprt_connected(xprt),
1450 sock_flag(sk, SOCK_DEAD),
1451 sock_flag(sk, SOCK_ZAPPED),
1454 transport = container_of(xprt, struct sock_xprt, xprt);
1455 trace_rpc_socket_state_change(xprt, sk->sk_socket);
1456 switch (sk->sk_state) {
1457 case TCP_ESTABLISHED:
1458 if (!xprt_test_and_set_connected(xprt)) {
1459 xprt->connect_cookie++;
1460 clear_bit(XPRT_SOCK_CONNECTING, &transport->sock_state);
1461 xprt_clear_connecting(xprt);
1463 xprt->stat.connect_count++;
1464 xprt->stat.connect_time += (long)jiffies -
1465 xprt->stat.connect_start;
1466 xs_run_error_worker(transport, XPRT_SOCK_WAKE_PENDING);
1470 /* The client initiated a shutdown of the socket */
1471 xprt->connect_cookie++;
1472 xprt->reestablish_timeout = 0;
1473 set_bit(XPRT_CLOSING, &xprt->state);
1474 smp_mb__before_atomic();
1475 clear_bit(XPRT_CONNECTED, &xprt->state);
1476 clear_bit(XPRT_CLOSE_WAIT, &xprt->state);
1477 smp_mb__after_atomic();
1479 case TCP_CLOSE_WAIT:
1480 /* The server initiated a shutdown of the socket */
1481 xprt->connect_cookie++;
1482 clear_bit(XPRT_CONNECTED, &xprt->state);
1483 xs_run_error_worker(transport, XPRT_SOCK_WAKE_DISCONNECT);
1487 * If the server closed down the connection, make sure that
1488 * we back off before reconnecting
1490 if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO)
1491 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
1494 set_bit(XPRT_CLOSING, &xprt->state);
1495 smp_mb__before_atomic();
1496 clear_bit(XPRT_CONNECTED, &xprt->state);
1497 smp_mb__after_atomic();
1500 if (test_and_clear_bit(XPRT_SOCK_CONNECTING,
1501 &transport->sock_state))
1502 xprt_clear_connecting(xprt);
1503 clear_bit(XPRT_CLOSING, &xprt->state);
1504 /* Trigger the socket release */
1505 xs_run_error_worker(transport, XPRT_SOCK_WAKE_DISCONNECT);
1509 static void xs_write_space(struct sock *sk)
1511 struct sock_xprt *transport;
1512 struct rpc_xprt *xprt;
1516 clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
1518 if (unlikely(!(xprt = xprt_from_sock(sk))))
1520 transport = container_of(xprt, struct sock_xprt, xprt);
1521 if (!test_and_clear_bit(XPRT_SOCK_NOSPACE, &transport->sock_state))
1523 xs_run_error_worker(transport, XPRT_SOCK_WAKE_WRITE);
1524 sk->sk_write_pending--;
1528 * xs_udp_write_space - callback invoked when socket buffer space
1530 * @sk: socket whose state has changed
1532 * Called when more output buffer space is available for this socket.
1533 * We try not to wake our writers until they can make "significant"
1534 * progress, otherwise we'll waste resources thrashing kernel_sendmsg
1535 * with a bunch of small requests.
1537 static void xs_udp_write_space(struct sock *sk)
1539 /* from net/core/sock.c:sock_def_write_space */
1540 if (sock_writeable(sk))
1545 * xs_tcp_write_space - callback invoked when socket buffer space
1547 * @sk: socket whose state has changed
1549 * Called when more output buffer space is available for this socket.
1550 * We try not to wake our writers until they can make "significant"
1551 * progress, otherwise we'll waste resources thrashing kernel_sendmsg
1552 * with a bunch of small requests.
1554 static void xs_tcp_write_space(struct sock *sk)
1556 /* from net/core/stream.c:sk_stream_write_space */
1557 if (sk_stream_is_writeable(sk))
1561 static void xs_udp_do_set_buffer_size(struct rpc_xprt *xprt)
1563 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
1564 struct sock *sk = transport->inet;
1566 if (transport->rcvsize) {
1567 sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
1568 sk->sk_rcvbuf = transport->rcvsize * xprt->max_reqs * 2;
1570 if (transport->sndsize) {
1571 sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
1572 sk->sk_sndbuf = transport->sndsize * xprt->max_reqs * 2;
1573 sk->sk_write_space(sk);
1578 * xs_udp_set_buffer_size - set send and receive limits
1579 * @xprt: generic transport
1580 * @sndsize: requested size of send buffer, in bytes
1581 * @rcvsize: requested size of receive buffer, in bytes
1583 * Set socket send and receive buffer size limits.
1585 static void xs_udp_set_buffer_size(struct rpc_xprt *xprt, size_t sndsize, size_t rcvsize)
1587 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
1589 transport->sndsize = 0;
1591 transport->sndsize = sndsize + 1024;
1592 transport->rcvsize = 0;
1594 transport->rcvsize = rcvsize + 1024;
1596 xs_udp_do_set_buffer_size(xprt);
1600 * xs_udp_timer - called when a retransmit timeout occurs on a UDP transport
1601 * @xprt: controlling transport
1602 * @task: task that timed out
1604 * Adjust the congestion window after a retransmit timeout has occurred.
1606 static void xs_udp_timer(struct rpc_xprt *xprt, struct rpc_task *task)
1608 spin_lock(&xprt->transport_lock);
1609 xprt_adjust_cwnd(xprt, task, -ETIMEDOUT);
1610 spin_unlock(&xprt->transport_lock);
1613 static int xs_get_random_port(void)
1615 unsigned short min = xprt_min_resvport, max = xprt_max_resvport;
1616 unsigned short range;
1617 unsigned short rand;
1621 range = max - min + 1;
1622 rand = prandom_u32_max(range);
1626 static unsigned short xs_sock_getport(struct socket *sock)
1628 struct sockaddr_storage buf;
1629 unsigned short port = 0;
1631 if (kernel_getsockname(sock, (struct sockaddr *)&buf) < 0)
1633 switch (buf.ss_family) {
1635 port = ntohs(((struct sockaddr_in6 *)&buf)->sin6_port);
1638 port = ntohs(((struct sockaddr_in *)&buf)->sin_port);
1645 * xs_set_port - reset the port number in the remote endpoint address
1646 * @xprt: generic transport
1647 * @port: new port number
1650 static void xs_set_port(struct rpc_xprt *xprt, unsigned short port)
1652 dprintk("RPC: setting port for xprt %p to %u\n", xprt, port);
1654 rpc_set_port(xs_addr(xprt), port);
1655 xs_update_peer_port(xprt);
1658 static void xs_set_srcport(struct sock_xprt *transport, struct socket *sock)
1660 if (transport->srcport == 0 && transport->xprt.reuseport)
1661 transport->srcport = xs_sock_getport(sock);
1664 static int xs_get_srcport(struct sock_xprt *transport)
1666 int port = transport->srcport;
1668 if (port == 0 && transport->xprt.resvport)
1669 port = xs_get_random_port();
1673 static unsigned short xs_sock_srcport(struct rpc_xprt *xprt)
1675 struct sock_xprt *sock = container_of(xprt, struct sock_xprt, xprt);
1676 unsigned short ret = 0;
1677 mutex_lock(&sock->recv_mutex);
1679 ret = xs_sock_getport(sock->sock);
1680 mutex_unlock(&sock->recv_mutex);
1684 static int xs_sock_srcaddr(struct rpc_xprt *xprt, char *buf, size_t buflen)
1686 struct sock_xprt *sock = container_of(xprt, struct sock_xprt, xprt);
1689 struct sockaddr_storage st;
1691 int ret = -ENOTCONN;
1693 mutex_lock(&sock->recv_mutex);
1695 ret = kernel_getsockname(sock->sock, &saddr.sa);
1697 ret = snprintf(buf, buflen, "%pISc", &saddr.sa);
1699 mutex_unlock(&sock->recv_mutex);
1703 static unsigned short xs_next_srcport(struct sock_xprt *transport, unsigned short port)
1705 if (transport->srcport != 0)
1706 transport->srcport = 0;
1707 if (!transport->xprt.resvport)
1709 if (port <= xprt_min_resvport || port > xprt_max_resvport)
1710 return xprt_max_resvport;
1713 static int xs_bind(struct sock_xprt *transport, struct socket *sock)
1715 struct sockaddr_storage myaddr;
1717 int port = xs_get_srcport(transport);
1718 unsigned short last;
1721 * If we are asking for any ephemeral port (i.e. port == 0 &&
1722 * transport->xprt.resvport == 0), don't bind. Let the local
1723 * port selection happen implicitly when the socket is used
1724 * (for example at connect time).
1726 * This ensures that we can continue to establish TCP
1727 * connections even when all local ephemeral ports are already
1728 * a part of some TCP connection. This makes no difference
1729 * for UDP sockets, but also doesn't harm them.
1731 * If we're asking for any reserved port (i.e. port == 0 &&
1732 * transport->xprt.resvport == 1) xs_get_srcport above will
1733 * ensure that port is non-zero and we will bind as needed.
1738 memcpy(&myaddr, &transport->srcaddr, transport->xprt.addrlen);
1740 rpc_set_port((struct sockaddr *)&myaddr, port);
1741 err = kernel_bind(sock, (struct sockaddr *)&myaddr,
1742 transport->xprt.addrlen);
1744 if (transport->xprt.reuseport)
1745 transport->srcport = port;
1749 port = xs_next_srcport(transport, port);
1752 } while (err == -EADDRINUSE && nloop != 2);
1754 if (myaddr.ss_family == AF_INET)
1755 dprintk("RPC: %s %pI4:%u: %s (%d)\n", __func__,
1756 &((struct sockaddr_in *)&myaddr)->sin_addr,
1757 port, err ? "failed" : "ok", err);
1759 dprintk("RPC: %s %pI6:%u: %s (%d)\n", __func__,
1760 &((struct sockaddr_in6 *)&myaddr)->sin6_addr,
1761 port, err ? "failed" : "ok", err);
1766 * We don't support autobind on AF_LOCAL sockets
1768 static void xs_local_rpcbind(struct rpc_task *task)
1770 xprt_set_bound(task->tk_xprt);
1773 static void xs_local_set_port(struct rpc_xprt *xprt, unsigned short port)
1777 #ifdef CONFIG_DEBUG_LOCK_ALLOC
1778 static struct lock_class_key xs_key[3];
1779 static struct lock_class_key xs_slock_key[3];
1781 static inline void xs_reclassify_socketu(struct socket *sock)
1783 struct sock *sk = sock->sk;
1785 sock_lock_init_class_and_name(sk, "slock-AF_LOCAL-RPC",
1786 &xs_slock_key[0], "sk_lock-AF_LOCAL-RPC", &xs_key[0]);
1789 static inline void xs_reclassify_socket4(struct socket *sock)
1791 struct sock *sk = sock->sk;
1793 sock_lock_init_class_and_name(sk, "slock-AF_INET-RPC",
1794 &xs_slock_key[1], "sk_lock-AF_INET-RPC", &xs_key[1]);
1797 static inline void xs_reclassify_socket6(struct socket *sock)
1799 struct sock *sk = sock->sk;
1801 sock_lock_init_class_and_name(sk, "slock-AF_INET6-RPC",
1802 &xs_slock_key[2], "sk_lock-AF_INET6-RPC", &xs_key[2]);
1805 static inline void xs_reclassify_socket(int family, struct socket *sock)
1807 if (WARN_ON_ONCE(!sock_allow_reclassification(sock->sk)))
1812 xs_reclassify_socketu(sock);
1815 xs_reclassify_socket4(sock);
1818 xs_reclassify_socket6(sock);
1823 static inline void xs_reclassify_socket(int family, struct socket *sock)
1828 static void xs_dummy_setup_socket(struct work_struct *work)
1832 static struct socket *xs_create_sock(struct rpc_xprt *xprt,
1833 struct sock_xprt *transport, int family, int type,
1834 int protocol, bool reuseport)
1837 struct socket *sock;
1840 err = __sock_create(xprt->xprt_net, family, type, protocol, &sock, 1);
1842 dprintk("RPC: can't create %d transport socket (%d).\n",
1846 xs_reclassify_socket(family, sock);
1849 sock_set_reuseport(sock->sk);
1851 err = xs_bind(transport, sock);
1857 filp = sock_alloc_file(sock, O_NONBLOCK, NULL);
1859 return ERR_CAST(filp);
1860 transport->file = filp;
1864 return ERR_PTR(err);
1867 static int xs_local_finish_connecting(struct rpc_xprt *xprt,
1868 struct socket *sock)
1870 struct sock_xprt *transport = container_of(xprt, struct sock_xprt,
1873 if (!transport->inet) {
1874 struct sock *sk = sock->sk;
1878 xs_save_old_callbacks(transport, sk);
1880 sk->sk_user_data = xprt;
1881 sk->sk_data_ready = xs_data_ready;
1882 sk->sk_write_space = xs_udp_write_space;
1883 sk->sk_state_change = xs_local_state_change;
1884 sk->sk_error_report = xs_error_report;
1886 xprt_clear_connected(xprt);
1888 /* Reset to new socket */
1889 transport->sock = sock;
1890 transport->inet = sk;
1895 xs_stream_start_connect(transport);
1897 return kernel_connect(sock, xs_addr(xprt), xprt->addrlen, 0);
1901 * xs_local_setup_socket - create AF_LOCAL socket, connect to a local endpoint
1902 * @transport: socket transport to connect
1904 static int xs_local_setup_socket(struct sock_xprt *transport)
1906 struct rpc_xprt *xprt = &transport->xprt;
1908 struct socket *sock;
1911 status = __sock_create(xprt->xprt_net, AF_LOCAL,
1912 SOCK_STREAM, 0, &sock, 1);
1914 dprintk("RPC: can't create AF_LOCAL "
1915 "transport socket (%d).\n", -status);
1918 xs_reclassify_socket(AF_LOCAL, sock);
1920 filp = sock_alloc_file(sock, O_NONBLOCK, NULL);
1922 status = PTR_ERR(filp);
1925 transport->file = filp;
1927 dprintk("RPC: worker connecting xprt %p via AF_LOCAL to %s\n",
1928 xprt, xprt->address_strings[RPC_DISPLAY_ADDR]);
1930 status = xs_local_finish_connecting(xprt, sock);
1931 trace_rpc_socket_connect(xprt, sock, status);
1934 dprintk("RPC: xprt %p connected to %s\n",
1935 xprt, xprt->address_strings[RPC_DISPLAY_ADDR]);
1936 xprt->stat.connect_count++;
1937 xprt->stat.connect_time += (long)jiffies -
1938 xprt->stat.connect_start;
1939 xprt_set_connected(xprt);
1944 dprintk("RPC: xprt %p: socket %s does not exist\n",
1945 xprt, xprt->address_strings[RPC_DISPLAY_ADDR]);
1948 dprintk("RPC: xprt %p: connection refused for %s\n",
1949 xprt, xprt->address_strings[RPC_DISPLAY_ADDR]);
1952 printk(KERN_ERR "%s: unhandled error (%d) connecting to %s\n",
1954 xprt->address_strings[RPC_DISPLAY_ADDR]);
1958 xprt_clear_connecting(xprt);
1959 xprt_wake_pending_tasks(xprt, status);
1963 static void xs_local_connect(struct rpc_xprt *xprt, struct rpc_task *task)
1965 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
1968 if (transport->file)
1969 goto force_disconnect;
1971 if (RPC_IS_ASYNC(task)) {
1973 * We want the AF_LOCAL connect to be resolved in the
1974 * filesystem namespace of the process making the rpc
1975 * call. Thus we connect synchronously.
1977 * If we want to support asynchronous AF_LOCAL calls,
1978 * we'll need to figure out how to pass a namespace to
1981 rpc_task_set_rpc_status(task, -ENOTCONN);
1984 ret = xs_local_setup_socket(transport);
1985 if (ret && !RPC_IS_SOFTCONN(task))
1986 msleep_interruptible(15000);
1989 xprt_force_disconnect(xprt);
1991 xprt_clear_connecting(xprt);
1992 xprt_wake_pending_tasks(xprt, -ENOTCONN);
1995 #if IS_ENABLED(CONFIG_SUNRPC_SWAP)
1997 * Note that this should be called with XPRT_LOCKED held, or recv_mutex
1998 * held, or when we otherwise know that we have exclusive access to the
1999 * socket, to guard against races with xs_reset_transport.
2001 static void xs_set_memalloc(struct rpc_xprt *xprt)
2003 struct sock_xprt *transport = container_of(xprt, struct sock_xprt,
2007 * If there's no sock, then we have nothing to set. The
2008 * reconnecting process will get it for us.
2010 if (!transport->inet)
2012 if (atomic_read(&xprt->swapper))
2013 sk_set_memalloc(transport->inet);
2017 * xs_enable_swap - Tag this transport as being used for swap.
2018 * @xprt: transport to tag
2020 * Take a reference to this transport on behalf of the rpc_clnt, and
2021 * optionally mark it for swapping if it wasn't already.
2024 xs_enable_swap(struct rpc_xprt *xprt)
2026 struct sock_xprt *xs = container_of(xprt, struct sock_xprt, xprt);
2028 mutex_lock(&xs->recv_mutex);
2029 if (atomic_inc_return(&xprt->swapper) == 1 &&
2031 sk_set_memalloc(xs->inet);
2032 mutex_unlock(&xs->recv_mutex);
2037 * xs_disable_swap - Untag this transport as being used for swap.
2038 * @xprt: transport to tag
2040 * Drop a "swapper" reference to this xprt on behalf of the rpc_clnt. If the
2041 * swapper refcount goes to 0, untag the socket as a memalloc socket.
2044 xs_disable_swap(struct rpc_xprt *xprt)
2046 struct sock_xprt *xs = container_of(xprt, struct sock_xprt, xprt);
2048 mutex_lock(&xs->recv_mutex);
2049 if (atomic_dec_and_test(&xprt->swapper) &&
2051 sk_clear_memalloc(xs->inet);
2052 mutex_unlock(&xs->recv_mutex);
2055 static void xs_set_memalloc(struct rpc_xprt *xprt)
2060 xs_enable_swap(struct rpc_xprt *xprt)
2066 xs_disable_swap(struct rpc_xprt *xprt)
2071 static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
2073 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2075 if (!transport->inet) {
2076 struct sock *sk = sock->sk;
2080 xs_save_old_callbacks(transport, sk);
2082 sk->sk_user_data = xprt;
2083 sk->sk_data_ready = xs_data_ready;
2084 sk->sk_write_space = xs_udp_write_space;
2086 xprt_set_connected(xprt);
2088 /* Reset to new socket */
2089 transport->sock = sock;
2090 transport->inet = sk;
2092 xs_set_memalloc(xprt);
2096 xs_udp_do_set_buffer_size(xprt);
2098 xprt->stat.connect_start = jiffies;
2101 static void xs_udp_setup_socket(struct work_struct *work)
2103 struct sock_xprt *transport =
2104 container_of(work, struct sock_xprt, connect_worker.work);
2105 struct rpc_xprt *xprt = &transport->xprt;
2106 struct socket *sock;
2108 unsigned int pflags = current->flags;
2110 if (atomic_read(&xprt->swapper))
2111 current->flags |= PF_MEMALLOC;
2112 sock = xs_create_sock(xprt, transport,
2113 xs_addr(xprt)->sa_family, SOCK_DGRAM,
2114 IPPROTO_UDP, false);
2118 dprintk("RPC: worker connecting xprt %p via %s to "
2119 "%s (port %s)\n", xprt,
2120 xprt->address_strings[RPC_DISPLAY_PROTO],
2121 xprt->address_strings[RPC_DISPLAY_ADDR],
2122 xprt->address_strings[RPC_DISPLAY_PORT]);
2124 xs_udp_finish_connecting(xprt, sock);
2125 trace_rpc_socket_connect(xprt, sock, 0);
2128 xprt_clear_connecting(xprt);
2129 xprt_unlock_connect(xprt, transport);
2130 xprt_wake_pending_tasks(xprt, status);
2131 current_restore_flags(pflags, PF_MEMALLOC);
2135 * xs_tcp_shutdown - gracefully shut down a TCP socket
2138 * Initiates a graceful shutdown of the TCP socket by calling the
2139 * equivalent of shutdown(SHUT_RDWR);
2141 static void xs_tcp_shutdown(struct rpc_xprt *xprt)
2143 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2144 struct socket *sock = transport->sock;
2145 int skst = transport->inet ? transport->inet->sk_state : TCP_CLOSE;
2149 if (!xprt->reuseport) {
2157 case TCP_ESTABLISHED:
2158 case TCP_CLOSE_WAIT:
2159 kernel_sock_shutdown(sock, SHUT_RDWR);
2160 trace_rpc_socket_shutdown(xprt, sock);
2163 xs_reset_transport(transport);
2167 static void xs_tcp_set_socket_timeouts(struct rpc_xprt *xprt,
2168 struct socket *sock)
2170 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2171 unsigned int keepidle;
2172 unsigned int keepcnt;
2175 spin_lock(&xprt->transport_lock);
2176 keepidle = DIV_ROUND_UP(xprt->timeout->to_initval, HZ);
2177 keepcnt = xprt->timeout->to_retries + 1;
2178 timeo = jiffies_to_msecs(xprt->timeout->to_initval) *
2179 (xprt->timeout->to_retries + 1);
2180 clear_bit(XPRT_SOCK_UPD_TIMEOUT, &transport->sock_state);
2181 spin_unlock(&xprt->transport_lock);
2183 /* TCP Keepalive options */
2184 sock_set_keepalive(sock->sk);
2185 tcp_sock_set_keepidle(sock->sk, keepidle);
2186 tcp_sock_set_keepintvl(sock->sk, keepidle);
2187 tcp_sock_set_keepcnt(sock->sk, keepcnt);
2189 /* TCP user timeout (see RFC5482) */
2190 tcp_sock_set_user_timeout(sock->sk, timeo);
2193 static void xs_tcp_set_connect_timeout(struct rpc_xprt *xprt,
2194 unsigned long connect_timeout,
2195 unsigned long reconnect_timeout)
2197 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2198 struct rpc_timeout to;
2199 unsigned long initval;
2201 spin_lock(&xprt->transport_lock);
2202 if (reconnect_timeout < xprt->max_reconnect_timeout)
2203 xprt->max_reconnect_timeout = reconnect_timeout;
2204 if (connect_timeout < xprt->connect_timeout) {
2205 memcpy(&to, xprt->timeout, sizeof(to));
2206 initval = DIV_ROUND_UP(connect_timeout, to.to_retries + 1);
2207 /* Arbitrary lower limit */
2208 if (initval < XS_TCP_INIT_REEST_TO << 1)
2209 initval = XS_TCP_INIT_REEST_TO << 1;
2210 to.to_initval = initval;
2211 to.to_maxval = initval;
2212 memcpy(&transport->tcp_timeout, &to,
2213 sizeof(transport->tcp_timeout));
2214 xprt->timeout = &transport->tcp_timeout;
2215 xprt->connect_timeout = connect_timeout;
2217 set_bit(XPRT_SOCK_UPD_TIMEOUT, &transport->sock_state);
2218 spin_unlock(&xprt->transport_lock);
2221 static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
2223 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2225 if (!transport->inet) {
2226 struct sock *sk = sock->sk;
2228 /* Avoid temporary address, they are bad for long-lived
2229 * connections such as NFS mounts.
2230 * RFC4941, section 3.6 suggests that:
2231 * Individual applications, which have specific
2232 * knowledge about the normal duration of connections,
2233 * MAY override this as appropriate.
2235 if (xs_addr(xprt)->sa_family == PF_INET6) {
2236 ip6_sock_set_addr_preferences(sk,
2237 IPV6_PREFER_SRC_PUBLIC);
2240 xs_tcp_set_socket_timeouts(xprt, sock);
2241 tcp_sock_set_nodelay(sk);
2245 xs_save_old_callbacks(transport, sk);
2247 sk->sk_user_data = xprt;
2248 sk->sk_data_ready = xs_data_ready;
2249 sk->sk_state_change = xs_tcp_state_change;
2250 sk->sk_write_space = xs_tcp_write_space;
2251 sk->sk_error_report = xs_error_report;
2253 /* socket options */
2254 sock_reset_flag(sk, SOCK_LINGER);
2256 xprt_clear_connected(xprt);
2258 /* Reset to new socket */
2259 transport->sock = sock;
2260 transport->inet = sk;
2265 if (!xprt_bound(xprt))
2268 xs_set_memalloc(xprt);
2270 xs_stream_start_connect(transport);
2272 /* Tell the socket layer to start connecting... */
2273 set_bit(XPRT_SOCK_CONNECTING, &transport->sock_state);
2274 return kernel_connect(sock, xs_addr(xprt), xprt->addrlen, O_NONBLOCK);
2278 * xs_tcp_setup_socket - create a TCP socket and connect to a remote endpoint
2279 * @work: queued work item
2281 * Invoked by a work queue tasklet.
2283 static void xs_tcp_setup_socket(struct work_struct *work)
2285 struct sock_xprt *transport =
2286 container_of(work, struct sock_xprt, connect_worker.work);
2287 struct socket *sock = transport->sock;
2288 struct rpc_xprt *xprt = &transport->xprt;
2290 unsigned int pflags = current->flags;
2292 if (atomic_read(&xprt->swapper))
2293 current->flags |= PF_MEMALLOC;
2295 if (xprt_connected(xprt))
2297 if (test_and_clear_bit(XPRT_SOCK_CONNECT_SENT,
2298 &transport->sock_state) ||
2300 xs_reset_transport(transport);
2301 sock = xs_create_sock(xprt, transport, xs_addr(xprt)->sa_family,
2302 SOCK_STREAM, IPPROTO_TCP, true);
2304 xprt_wake_pending_tasks(xprt, PTR_ERR(sock));
2309 dprintk("RPC: worker connecting xprt %p via %s to "
2310 "%s (port %s)\n", xprt,
2311 xprt->address_strings[RPC_DISPLAY_PROTO],
2312 xprt->address_strings[RPC_DISPLAY_ADDR],
2313 xprt->address_strings[RPC_DISPLAY_PORT]);
2315 status = xs_tcp_finish_connecting(xprt, sock);
2316 trace_rpc_socket_connect(xprt, sock, status);
2317 dprintk("RPC: %p connect status %d connected %d sock state %d\n",
2318 xprt, -status, xprt_connected(xprt),
2319 sock->sk->sk_state);
2324 set_bit(XPRT_SOCK_CONNECT_SENT, &transport->sock_state);
2325 if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO)
2326 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
2330 case -EADDRNOTAVAIL:
2331 /* Source port number is unavailable. Try a new one! */
2332 transport->srcport = 0;
2336 /* Happens, for instance, if the user specified a link
2337 * local IPv6 address without a scope-id.
2348 printk("%s: connect returned unhandled error %d\n",
2353 /* xs_tcp_force_close() wakes tasks with a fixed error code.
2354 * We need to wake them first to ensure the correct error code.
2356 xprt_wake_pending_tasks(xprt, status);
2357 xs_tcp_force_close(xprt);
2359 xprt_clear_connecting(xprt);
2361 xprt_unlock_connect(xprt, transport);
2362 current_restore_flags(pflags, PF_MEMALLOC);
2366 * xs_connect - connect a socket to a remote endpoint
2367 * @xprt: pointer to transport structure
2368 * @task: address of RPC task that manages state of connect request
2370 * TCP: If the remote end dropped the connection, delay reconnecting.
2372 * UDP socket connects are synchronous, but we use a work queue anyway
2373 * to guarantee that even unprivileged user processes can set up a
2374 * socket on a privileged port.
2376 * If a UDP socket connect fails, the delay behavior here prevents
2377 * retry floods (hard mounts).
2379 static void xs_connect(struct rpc_xprt *xprt, struct rpc_task *task)
2381 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2382 unsigned long delay = 0;
2384 WARN_ON_ONCE(!xprt_lock_connect(xprt, task, transport));
2386 if (transport->sock != NULL) {
2387 dprintk("RPC: xs_connect delayed xprt %p for %lu "
2388 "seconds\n", xprt, xprt->reestablish_timeout / HZ);
2390 delay = xprt_reconnect_delay(xprt);
2391 xprt_reconnect_backoff(xprt, XS_TCP_INIT_REEST_TO);
2394 dprintk("RPC: xs_connect scheduled xprt %p\n", xprt);
2396 queue_delayed_work(xprtiod_workqueue,
2397 &transport->connect_worker,
2401 static void xs_wake_disconnect(struct sock_xprt *transport)
2403 if (test_and_clear_bit(XPRT_SOCK_WAKE_DISCONNECT, &transport->sock_state))
2404 xs_tcp_force_close(&transport->xprt);
2407 static void xs_wake_write(struct sock_xprt *transport)
2409 if (test_and_clear_bit(XPRT_SOCK_WAKE_WRITE, &transport->sock_state))
2410 xprt_write_space(&transport->xprt);
2413 static void xs_wake_error(struct sock_xprt *transport)
2417 if (!test_bit(XPRT_SOCK_WAKE_ERROR, &transport->sock_state))
2419 mutex_lock(&transport->recv_mutex);
2420 if (transport->sock == NULL)
2422 if (!test_and_clear_bit(XPRT_SOCK_WAKE_ERROR, &transport->sock_state))
2424 sockerr = xchg(&transport->xprt_err, 0);
2426 xprt_wake_pending_tasks(&transport->xprt, sockerr);
2428 mutex_unlock(&transport->recv_mutex);
2431 static void xs_wake_pending(struct sock_xprt *transport)
2433 if (test_and_clear_bit(XPRT_SOCK_WAKE_PENDING, &transport->sock_state))
2434 xprt_wake_pending_tasks(&transport->xprt, -EAGAIN);
2437 static void xs_error_handle(struct work_struct *work)
2439 struct sock_xprt *transport = container_of(work,
2440 struct sock_xprt, error_worker);
2442 xs_wake_disconnect(transport);
2443 xs_wake_write(transport);
2444 xs_wake_error(transport);
2445 xs_wake_pending(transport);
2449 * xs_local_print_stats - display AF_LOCAL socket-specific stats
2450 * @xprt: rpc_xprt struct containing statistics
2454 static void xs_local_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
2458 if (xprt_connected(xprt))
2459 idle_time = (long)(jiffies - xprt->last_used) / HZ;
2461 seq_printf(seq, "\txprt:\tlocal %lu %lu %lu %ld %lu %lu %lu "
2462 "%llu %llu %lu %llu %llu\n",
2463 xprt->stat.bind_count,
2464 xprt->stat.connect_count,
2465 xprt->stat.connect_time / HZ,
2469 xprt->stat.bad_xids,
2472 xprt->stat.max_slots,
2473 xprt->stat.sending_u,
2474 xprt->stat.pending_u);
2478 * xs_udp_print_stats - display UDP socket-specific stats
2479 * @xprt: rpc_xprt struct containing statistics
2483 static void xs_udp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
2485 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2487 seq_printf(seq, "\txprt:\tudp %u %lu %lu %lu %lu %llu %llu "
2490 xprt->stat.bind_count,
2493 xprt->stat.bad_xids,
2496 xprt->stat.max_slots,
2497 xprt->stat.sending_u,
2498 xprt->stat.pending_u);
2502 * xs_tcp_print_stats - display TCP socket-specific stats
2503 * @xprt: rpc_xprt struct containing statistics
2507 static void xs_tcp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
2509 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2512 if (xprt_connected(xprt))
2513 idle_time = (long)(jiffies - xprt->last_used) / HZ;
2515 seq_printf(seq, "\txprt:\ttcp %u %lu %lu %lu %ld %lu %lu %lu "
2516 "%llu %llu %lu %llu %llu\n",
2518 xprt->stat.bind_count,
2519 xprt->stat.connect_count,
2520 xprt->stat.connect_time / HZ,
2524 xprt->stat.bad_xids,
2527 xprt->stat.max_slots,
2528 xprt->stat.sending_u,
2529 xprt->stat.pending_u);
2533 * Allocate a bunch of pages for a scratch buffer for the rpc code. The reason
2534 * we allocate pages instead doing a kmalloc like rpc_malloc is because we want
2535 * to use the server side send routines.
2537 static int bc_malloc(struct rpc_task *task)
2539 struct rpc_rqst *rqst = task->tk_rqstp;
2540 size_t size = rqst->rq_callsize;
2542 struct rpc_buffer *buf;
2544 if (size > PAGE_SIZE - sizeof(struct rpc_buffer)) {
2545 WARN_ONCE(1, "xprtsock: large bc buffer request (size %zu)\n",
2550 page = alloc_page(GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
2554 buf = page_address(page);
2555 buf->len = PAGE_SIZE;
2557 rqst->rq_buffer = buf->data;
2558 rqst->rq_rbuffer = (char *)rqst->rq_buffer + rqst->rq_callsize;
2563 * Free the space allocated in the bc_alloc routine
2565 static void bc_free(struct rpc_task *task)
2567 void *buffer = task->tk_rqstp->rq_buffer;
2568 struct rpc_buffer *buf;
2570 buf = container_of(buffer, struct rpc_buffer, data);
2571 free_page((unsigned long)buf);
2574 static int bc_sendto(struct rpc_rqst *req)
2576 struct xdr_buf *xdr = &req->rq_snd_buf;
2577 struct sock_xprt *transport =
2578 container_of(req->rq_xprt, struct sock_xprt, xprt);
2579 struct msghdr msg = {
2582 rpc_fraghdr marker = cpu_to_be32(RPC_LAST_STREAM_FRAGMENT |
2584 unsigned int sent = 0;
2587 req->rq_xtime = ktime_get();
2588 err = xdr_alloc_bvec(xdr, rpc_task_gfp_mask());
2591 err = xprt_sock_sendmsg(transport->sock, &msg, xdr, 0, marker, &sent);
2593 if (err < 0 || sent != (xdr->len + sizeof(marker)))
2599 * bc_send_request - Send a backchannel Call on a TCP socket
2600 * @req: rpc_rqst containing Call message to be sent
2602 * xpt_mutex ensures @rqstp's whole message is written to the socket
2603 * without interruption.
2606 * %0 if the message was sent successfully
2607 * %ENOTCONN if the message was not sent
2609 static int bc_send_request(struct rpc_rqst *req)
2611 struct svc_xprt *xprt;
2615 * Get the server socket associated with this callback xprt
2617 xprt = req->rq_xprt->bc_xprt;
2620 * Grab the mutex to serialize data as the connection is shared
2621 * with the fore channel
2623 mutex_lock(&xprt->xpt_mutex);
2624 if (test_bit(XPT_DEAD, &xprt->xpt_flags))
2627 len = bc_sendto(req);
2628 mutex_unlock(&xprt->xpt_mutex);
2637 * The close routine. Since this is client initiated, we do nothing
2640 static void bc_close(struct rpc_xprt *xprt)
2642 xprt_disconnect_done(xprt);
2646 * The xprt destroy routine. Again, because this connection is client
2647 * initiated, we do nothing
2650 static void bc_destroy(struct rpc_xprt *xprt)
2652 dprintk("RPC: bc_destroy xprt %p\n", xprt);
2655 module_put(THIS_MODULE);
2658 static const struct rpc_xprt_ops xs_local_ops = {
2659 .reserve_xprt = xprt_reserve_xprt,
2660 .release_xprt = xprt_release_xprt,
2661 .alloc_slot = xprt_alloc_slot,
2662 .free_slot = xprt_free_slot,
2663 .rpcbind = xs_local_rpcbind,
2664 .set_port = xs_local_set_port,
2665 .connect = xs_local_connect,
2666 .buf_alloc = rpc_malloc,
2667 .buf_free = rpc_free,
2668 .prepare_request = xs_stream_prepare_request,
2669 .send_request = xs_local_send_request,
2670 .wait_for_reply_request = xprt_wait_for_reply_request_def,
2672 .destroy = xs_destroy,
2673 .print_stats = xs_local_print_stats,
2674 .enable_swap = xs_enable_swap,
2675 .disable_swap = xs_disable_swap,
2678 static const struct rpc_xprt_ops xs_udp_ops = {
2679 .set_buffer_size = xs_udp_set_buffer_size,
2680 .reserve_xprt = xprt_reserve_xprt_cong,
2681 .release_xprt = xprt_release_xprt_cong,
2682 .alloc_slot = xprt_alloc_slot,
2683 .free_slot = xprt_free_slot,
2684 .rpcbind = rpcb_getport_async,
2685 .set_port = xs_set_port,
2686 .connect = xs_connect,
2687 .get_srcaddr = xs_sock_srcaddr,
2688 .get_srcport = xs_sock_srcport,
2689 .buf_alloc = rpc_malloc,
2690 .buf_free = rpc_free,
2691 .send_request = xs_udp_send_request,
2692 .wait_for_reply_request = xprt_wait_for_reply_request_rtt,
2693 .timer = xs_udp_timer,
2694 .release_request = xprt_release_rqst_cong,
2696 .destroy = xs_destroy,
2697 .print_stats = xs_udp_print_stats,
2698 .enable_swap = xs_enable_swap,
2699 .disable_swap = xs_disable_swap,
2700 .inject_disconnect = xs_inject_disconnect,
2703 static const struct rpc_xprt_ops xs_tcp_ops = {
2704 .reserve_xprt = xprt_reserve_xprt,
2705 .release_xprt = xprt_release_xprt,
2706 .alloc_slot = xprt_alloc_slot,
2707 .free_slot = xprt_free_slot,
2708 .rpcbind = rpcb_getport_async,
2709 .set_port = xs_set_port,
2710 .connect = xs_connect,
2711 .get_srcaddr = xs_sock_srcaddr,
2712 .get_srcport = xs_sock_srcport,
2713 .buf_alloc = rpc_malloc,
2714 .buf_free = rpc_free,
2715 .prepare_request = xs_stream_prepare_request,
2716 .send_request = xs_tcp_send_request,
2717 .wait_for_reply_request = xprt_wait_for_reply_request_def,
2718 .close = xs_tcp_shutdown,
2719 .destroy = xs_destroy,
2720 .set_connect_timeout = xs_tcp_set_connect_timeout,
2721 .print_stats = xs_tcp_print_stats,
2722 .enable_swap = xs_enable_swap,
2723 .disable_swap = xs_disable_swap,
2724 .inject_disconnect = xs_inject_disconnect,
2725 #ifdef CONFIG_SUNRPC_BACKCHANNEL
2726 .bc_setup = xprt_setup_bc,
2727 .bc_maxpayload = xs_tcp_bc_maxpayload,
2728 .bc_num_slots = xprt_bc_max_slots,
2729 .bc_free_rqst = xprt_free_bc_rqst,
2730 .bc_destroy = xprt_destroy_bc,
2735 * The rpc_xprt_ops for the server backchannel
2738 static const struct rpc_xprt_ops bc_tcp_ops = {
2739 .reserve_xprt = xprt_reserve_xprt,
2740 .release_xprt = xprt_release_xprt,
2741 .alloc_slot = xprt_alloc_slot,
2742 .free_slot = xprt_free_slot,
2743 .buf_alloc = bc_malloc,
2744 .buf_free = bc_free,
2745 .send_request = bc_send_request,
2746 .wait_for_reply_request = xprt_wait_for_reply_request_def,
2748 .destroy = bc_destroy,
2749 .print_stats = xs_tcp_print_stats,
2750 .enable_swap = xs_enable_swap,
2751 .disable_swap = xs_disable_swap,
2752 .inject_disconnect = xs_inject_disconnect,
2755 static int xs_init_anyaddr(const int family, struct sockaddr *sap)
2757 static const struct sockaddr_in sin = {
2758 .sin_family = AF_INET,
2759 .sin_addr.s_addr = htonl(INADDR_ANY),
2761 static const struct sockaddr_in6 sin6 = {
2762 .sin6_family = AF_INET6,
2763 .sin6_addr = IN6ADDR_ANY_INIT,
2770 memcpy(sap, &sin, sizeof(sin));
2773 memcpy(sap, &sin6, sizeof(sin6));
2776 dprintk("RPC: %s: Bad address family\n", __func__);
2777 return -EAFNOSUPPORT;
2782 static struct rpc_xprt *xs_setup_xprt(struct xprt_create *args,
2783 unsigned int slot_table_size,
2784 unsigned int max_slot_table_size)
2786 struct rpc_xprt *xprt;
2787 struct sock_xprt *new;
2789 if (args->addrlen > sizeof(xprt->addr)) {
2790 dprintk("RPC: xs_setup_xprt: address too large\n");
2791 return ERR_PTR(-EBADF);
2794 xprt = xprt_alloc(args->net, sizeof(*new), slot_table_size,
2795 max_slot_table_size);
2797 dprintk("RPC: xs_setup_xprt: couldn't allocate "
2799 return ERR_PTR(-ENOMEM);
2802 new = container_of(xprt, struct sock_xprt, xprt);
2803 mutex_init(&new->recv_mutex);
2804 memcpy(&xprt->addr, args->dstaddr, args->addrlen);
2805 xprt->addrlen = args->addrlen;
2807 memcpy(&new->srcaddr, args->srcaddr, args->addrlen);
2810 err = xs_init_anyaddr(args->dstaddr->sa_family,
2811 (struct sockaddr *)&new->srcaddr);
2814 return ERR_PTR(err);
2821 static const struct rpc_timeout xs_local_default_timeout = {
2822 .to_initval = 10 * HZ,
2823 .to_maxval = 10 * HZ,
2828 * xs_setup_local - Set up transport to use an AF_LOCAL socket
2829 * @args: rpc transport creation arguments
2831 * AF_LOCAL is a "tpi_cots_ord" transport, just like TCP
2833 static struct rpc_xprt *xs_setup_local(struct xprt_create *args)
2835 struct sockaddr_un *sun = (struct sockaddr_un *)args->dstaddr;
2836 struct sock_xprt *transport;
2837 struct rpc_xprt *xprt;
2838 struct rpc_xprt *ret;
2840 xprt = xs_setup_xprt(args, xprt_tcp_slot_table_entries,
2841 xprt_max_tcp_slot_table_entries);
2844 transport = container_of(xprt, struct sock_xprt, xprt);
2847 xprt->xprt_class = &xs_local_transport;
2848 xprt->max_payload = RPC_MAX_FRAGMENT_SIZE;
2850 xprt->bind_timeout = XS_BIND_TO;
2851 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
2852 xprt->idle_timeout = XS_IDLE_DISC_TO;
2854 xprt->ops = &xs_local_ops;
2855 xprt->timeout = &xs_local_default_timeout;
2857 INIT_WORK(&transport->recv_worker, xs_stream_data_receive_workfn);
2858 INIT_WORK(&transport->error_worker, xs_error_handle);
2859 INIT_DELAYED_WORK(&transport->connect_worker, xs_dummy_setup_socket);
2861 switch (sun->sun_family) {
2863 if (sun->sun_path[0] != '/') {
2864 dprintk("RPC: bad AF_LOCAL address: %s\n",
2866 ret = ERR_PTR(-EINVAL);
2869 xprt_set_bound(xprt);
2870 xs_format_peer_addresses(xprt, "local", RPCBIND_NETID_LOCAL);
2873 ret = ERR_PTR(-EAFNOSUPPORT);
2877 dprintk("RPC: set up xprt to %s via AF_LOCAL\n",
2878 xprt->address_strings[RPC_DISPLAY_ADDR]);
2880 if (try_module_get(THIS_MODULE))
2882 ret = ERR_PTR(-EINVAL);
2888 static const struct rpc_timeout xs_udp_default_timeout = {
2889 .to_initval = 5 * HZ,
2890 .to_maxval = 30 * HZ,
2891 .to_increment = 5 * HZ,
2896 * xs_setup_udp - Set up transport to use a UDP socket
2897 * @args: rpc transport creation arguments
2900 static struct rpc_xprt *xs_setup_udp(struct xprt_create *args)
2902 struct sockaddr *addr = args->dstaddr;
2903 struct rpc_xprt *xprt;
2904 struct sock_xprt *transport;
2905 struct rpc_xprt *ret;
2907 xprt = xs_setup_xprt(args, xprt_udp_slot_table_entries,
2908 xprt_udp_slot_table_entries);
2911 transport = container_of(xprt, struct sock_xprt, xprt);
2913 xprt->prot = IPPROTO_UDP;
2914 xprt->xprt_class = &xs_udp_transport;
2915 /* XXX: header size can vary due to auth type, IPv6, etc. */
2916 xprt->max_payload = (1U << 16) - (MAX_HEADER << 3);
2918 xprt->bind_timeout = XS_BIND_TO;
2919 xprt->reestablish_timeout = XS_UDP_REEST_TO;
2920 xprt->idle_timeout = XS_IDLE_DISC_TO;
2922 xprt->ops = &xs_udp_ops;
2924 xprt->timeout = &xs_udp_default_timeout;
2926 INIT_WORK(&transport->recv_worker, xs_udp_data_receive_workfn);
2927 INIT_WORK(&transport->error_worker, xs_error_handle);
2928 INIT_DELAYED_WORK(&transport->connect_worker, xs_udp_setup_socket);
2930 switch (addr->sa_family) {
2932 if (((struct sockaddr_in *)addr)->sin_port != htons(0))
2933 xprt_set_bound(xprt);
2935 xs_format_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP);
2938 if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0))
2939 xprt_set_bound(xprt);
2941 xs_format_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP6);
2944 ret = ERR_PTR(-EAFNOSUPPORT);
2948 if (xprt_bound(xprt))
2949 dprintk("RPC: set up xprt to %s (port %s) via %s\n",
2950 xprt->address_strings[RPC_DISPLAY_ADDR],
2951 xprt->address_strings[RPC_DISPLAY_PORT],
2952 xprt->address_strings[RPC_DISPLAY_PROTO]);
2954 dprintk("RPC: set up xprt to %s (autobind) via %s\n",
2955 xprt->address_strings[RPC_DISPLAY_ADDR],
2956 xprt->address_strings[RPC_DISPLAY_PROTO]);
2958 if (try_module_get(THIS_MODULE))
2960 ret = ERR_PTR(-EINVAL);
2966 static const struct rpc_timeout xs_tcp_default_timeout = {
2967 .to_initval = 60 * HZ,
2968 .to_maxval = 60 * HZ,
2973 * xs_setup_tcp - Set up transport to use a TCP socket
2974 * @args: rpc transport creation arguments
2977 static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args)
2979 struct sockaddr *addr = args->dstaddr;
2980 struct rpc_xprt *xprt;
2981 struct sock_xprt *transport;
2982 struct rpc_xprt *ret;
2983 unsigned int max_slot_table_size = xprt_max_tcp_slot_table_entries;
2985 if (args->flags & XPRT_CREATE_INFINITE_SLOTS)
2986 max_slot_table_size = RPC_MAX_SLOT_TABLE_LIMIT;
2988 xprt = xs_setup_xprt(args, xprt_tcp_slot_table_entries,
2989 max_slot_table_size);
2992 transport = container_of(xprt, struct sock_xprt, xprt);
2994 xprt->prot = IPPROTO_TCP;
2995 xprt->xprt_class = &xs_tcp_transport;
2996 xprt->max_payload = RPC_MAX_FRAGMENT_SIZE;
2998 xprt->bind_timeout = XS_BIND_TO;
2999 xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
3000 xprt->idle_timeout = XS_IDLE_DISC_TO;
3002 xprt->ops = &xs_tcp_ops;
3003 xprt->timeout = &xs_tcp_default_timeout;
3005 xprt->max_reconnect_timeout = xprt->timeout->to_maxval;
3006 xprt->connect_timeout = xprt->timeout->to_initval *
3007 (xprt->timeout->to_retries + 1);
3009 INIT_WORK(&transport->recv_worker, xs_stream_data_receive_workfn);
3010 INIT_WORK(&transport->error_worker, xs_error_handle);
3011 INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_setup_socket);
3013 switch (addr->sa_family) {
3015 if (((struct sockaddr_in *)addr)->sin_port != htons(0))
3016 xprt_set_bound(xprt);
3018 xs_format_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP);
3021 if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0))
3022 xprt_set_bound(xprt);
3024 xs_format_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP6);
3027 ret = ERR_PTR(-EAFNOSUPPORT);
3031 if (xprt_bound(xprt))
3032 dprintk("RPC: set up xprt to %s (port %s) via %s\n",
3033 xprt->address_strings[RPC_DISPLAY_ADDR],
3034 xprt->address_strings[RPC_DISPLAY_PORT],
3035 xprt->address_strings[RPC_DISPLAY_PROTO]);
3037 dprintk("RPC: set up xprt to %s (autobind) via %s\n",
3038 xprt->address_strings[RPC_DISPLAY_ADDR],
3039 xprt->address_strings[RPC_DISPLAY_PROTO]);
3041 if (try_module_get(THIS_MODULE))
3043 ret = ERR_PTR(-EINVAL);
3050 * xs_setup_bc_tcp - Set up transport to use a TCP backchannel socket
3051 * @args: rpc transport creation arguments
3054 static struct rpc_xprt *xs_setup_bc_tcp(struct xprt_create *args)
3056 struct sockaddr *addr = args->dstaddr;
3057 struct rpc_xprt *xprt;
3058 struct sock_xprt *transport;
3059 struct svc_sock *bc_sock;
3060 struct rpc_xprt *ret;
3062 xprt = xs_setup_xprt(args, xprt_tcp_slot_table_entries,
3063 xprt_tcp_slot_table_entries);
3066 transport = container_of(xprt, struct sock_xprt, xprt);
3068 xprt->prot = IPPROTO_TCP;
3069 xprt->xprt_class = &xs_bc_tcp_transport;
3070 xprt->max_payload = RPC_MAX_FRAGMENT_SIZE;
3071 xprt->timeout = &xs_tcp_default_timeout;
3074 xprt_set_bound(xprt);
3075 xprt->bind_timeout = 0;
3076 xprt->reestablish_timeout = 0;
3077 xprt->idle_timeout = 0;
3079 xprt->ops = &bc_tcp_ops;
3081 switch (addr->sa_family) {
3083 xs_format_peer_addresses(xprt, "tcp",
3087 xs_format_peer_addresses(xprt, "tcp",
3088 RPCBIND_NETID_TCP6);
3091 ret = ERR_PTR(-EAFNOSUPPORT);
3095 dprintk("RPC: set up xprt to %s (port %s) via %s\n",
3096 xprt->address_strings[RPC_DISPLAY_ADDR],
3097 xprt->address_strings[RPC_DISPLAY_PORT],
3098 xprt->address_strings[RPC_DISPLAY_PROTO]);
3101 * Once we've associated a backchannel xprt with a connection,
3102 * we want to keep it around as long as the connection lasts,
3103 * in case we need to start using it for a backchannel again;
3104 * this reference won't be dropped until bc_xprt is destroyed.
3107 args->bc_xprt->xpt_bc_xprt = xprt;
3108 xprt->bc_xprt = args->bc_xprt;
3109 bc_sock = container_of(args->bc_xprt, struct svc_sock, sk_xprt);
3110 transport->sock = bc_sock->sk_sock;
3111 transport->inet = bc_sock->sk_sk;
3114 * Since we don't want connections for the backchannel, we set
3115 * the xprt status to connected
3117 xprt_set_connected(xprt);
3119 if (try_module_get(THIS_MODULE))
3122 args->bc_xprt->xpt_bc_xprt = NULL;
3123 args->bc_xprt->xpt_bc_xps = NULL;
3125 ret = ERR_PTR(-EINVAL);
3131 static struct xprt_class xs_local_transport = {
3132 .list = LIST_HEAD_INIT(xs_local_transport.list),
3133 .name = "named UNIX socket",
3134 .owner = THIS_MODULE,
3135 .ident = XPRT_TRANSPORT_LOCAL,
3136 .setup = xs_setup_local,
3140 static struct xprt_class xs_udp_transport = {
3141 .list = LIST_HEAD_INIT(xs_udp_transport.list),
3143 .owner = THIS_MODULE,
3144 .ident = XPRT_TRANSPORT_UDP,
3145 .setup = xs_setup_udp,
3146 .netid = { "udp", "udp6", "" },
3149 static struct xprt_class xs_tcp_transport = {
3150 .list = LIST_HEAD_INIT(xs_tcp_transport.list),
3152 .owner = THIS_MODULE,
3153 .ident = XPRT_TRANSPORT_TCP,
3154 .setup = xs_setup_tcp,
3155 .netid = { "tcp", "tcp6", "" },
3158 static struct xprt_class xs_bc_tcp_transport = {
3159 .list = LIST_HEAD_INIT(xs_bc_tcp_transport.list),
3160 .name = "tcp NFSv4.1 backchannel",
3161 .owner = THIS_MODULE,
3162 .ident = XPRT_TRANSPORT_BC_TCP,
3163 .setup = xs_setup_bc_tcp,
3168 * init_socket_xprt - set up xprtsock's sysctls, register with RPC client
3171 int init_socket_xprt(void)
3173 if (!sunrpc_table_header)
3174 sunrpc_table_header = register_sysctl_table(sunrpc_table);
3176 xprt_register_transport(&xs_local_transport);
3177 xprt_register_transport(&xs_udp_transport);
3178 xprt_register_transport(&xs_tcp_transport);
3179 xprt_register_transport(&xs_bc_tcp_transport);
3185 * cleanup_socket_xprt - remove xprtsock's sysctls, unregister
3188 void cleanup_socket_xprt(void)
3190 if (sunrpc_table_header) {
3191 unregister_sysctl_table(sunrpc_table_header);
3192 sunrpc_table_header = NULL;
3195 xprt_unregister_transport(&xs_local_transport);
3196 xprt_unregister_transport(&xs_udp_transport);
3197 xprt_unregister_transport(&xs_tcp_transport);
3198 xprt_unregister_transport(&xs_bc_tcp_transport);
3201 static int param_set_portnr(const char *val, const struct kernel_param *kp)
3203 return param_set_uint_minmax(val, kp,
3208 static const struct kernel_param_ops param_ops_portnr = {
3209 .set = param_set_portnr,
3210 .get = param_get_uint,
3213 #define param_check_portnr(name, p) \
3214 __param_check(name, p, unsigned int);
3216 module_param_named(min_resvport, xprt_min_resvport, portnr, 0644);
3217 module_param_named(max_resvport, xprt_max_resvport, portnr, 0644);
3219 static int param_set_slot_table_size(const char *val,
3220 const struct kernel_param *kp)
3222 return param_set_uint_minmax(val, kp,
3224 RPC_MAX_SLOT_TABLE);
3227 static const struct kernel_param_ops param_ops_slot_table_size = {
3228 .set = param_set_slot_table_size,
3229 .get = param_get_uint,
3232 #define param_check_slot_table_size(name, p) \
3233 __param_check(name, p, unsigned int);
3235 static int param_set_max_slot_table_size(const char *val,
3236 const struct kernel_param *kp)
3238 return param_set_uint_minmax(val, kp,
3240 RPC_MAX_SLOT_TABLE_LIMIT);
3243 static const struct kernel_param_ops param_ops_max_slot_table_size = {
3244 .set = param_set_max_slot_table_size,
3245 .get = param_get_uint,
3248 #define param_check_max_slot_table_size(name, p) \
3249 __param_check(name, p, unsigned int);
3251 module_param_named(tcp_slot_table_entries, xprt_tcp_slot_table_entries,
3252 slot_table_size, 0644);
3253 module_param_named(tcp_max_slot_table_entries, xprt_max_tcp_slot_table_entries,
3254 max_slot_table_size, 0644);
3255 module_param_named(udp_slot_table_entries, xprt_udp_slot_table_entries,
3256 slot_table_size, 0644);