Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1 | /* |
| 2 | * linux/net/sunrpc/xprtsock.c |
| 3 | * |
| 4 | * Client-side transport implementation for sockets. |
| 5 | * |
Alan Cox | 113aa83 | 2008-10-13 19:01:08 -0700 | [diff] [blame] | 6 | * TCP callback races fixes (C) 1998 Red Hat |
| 7 | * TCP send fixes (C) 1998 Red Hat |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 8 | * TCP NFS related read + write fixes |
| 9 | * (C) 1999 Dave Airlie, University of Limerick, Ireland <airlied@linux.ie> |
| 10 | * |
| 11 | * Rewrite of larges part of the code in order to stabilize TCP stuff. |
| 12 | * Fix behaviour when socket buffer is full. |
| 13 | * (C) 1999 Trond Myklebust <trond.myklebust@fys.uio.no> |
Chuck Lever | 55aa4f5 | 2005-08-11 16:25:47 -0400 | [diff] [blame] | 14 | * |
| 15 | * IP socket transport implementation, (C) 2005 Chuck Lever <cel@netapp.com> |
Chuck Lever | 8f9d5b1 | 2007-08-06 11:57:53 -0400 | [diff] [blame] | 16 | * |
| 17 | * IPv6 support contributed by Gilles Quillard, Bull Open Source, 2005. |
| 18 | * <gilles.quillard@bull.net> |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <linux/types.h> |
| 22 | #include <linux/slab.h> |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 23 | #include <linux/module.h> |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 24 | #include <linux/capability.h> |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 25 | #include <linux/pagemap.h> |
| 26 | #include <linux/errno.h> |
| 27 | #include <linux/socket.h> |
| 28 | #include <linux/in.h> |
| 29 | #include <linux/net.h> |
| 30 | #include <linux/mm.h> |
| 31 | #include <linux/udp.h> |
| 32 | #include <linux/tcp.h> |
| 33 | #include <linux/sunrpc/clnt.h> |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 34 | #include <linux/sunrpc/sched.h> |
Rahul Iyer | 4cfc7e6 | 2009-09-10 17:32:28 +0300 | [diff] [blame] | 35 | #include <linux/sunrpc/svcsock.h> |
\"Talpey, Thomas\ | 49c36fc | 2007-09-10 13:47:31 -0400 | [diff] [blame] | 36 | #include <linux/sunrpc/xprtsock.h> |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 37 | #include <linux/file.h> |
Ricardo Labiaga | 44b98ef | 2009-04-01 09:23:02 -0400 | [diff] [blame] | 38 | #ifdef CONFIG_NFS_V4_1 |
| 39 | #include <linux/sunrpc/bc_xprt.h> |
| 40 | #endif |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 41 | |
| 42 | #include <net/sock.h> |
| 43 | #include <net/checksum.h> |
| 44 | #include <net/udp.h> |
| 45 | #include <net/tcp.h> |
| 46 | |
Rahul Iyer | 4cfc7e6 | 2009-09-10 17:32:28 +0300 | [diff] [blame] | 47 | #include "sunrpc.h" |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 48 | /* |
Chuck Lever | c556b75 | 2005-11-01 12:24:48 -0500 | [diff] [blame] | 49 | * xprtsock tunables |
| 50 | */ |
| 51 | unsigned int xprt_udp_slot_table_entries = RPC_DEF_SLOT_TABLE; |
| 52 | unsigned int xprt_tcp_slot_table_entries = RPC_DEF_SLOT_TABLE; |
| 53 | |
| 54 | unsigned int xprt_min_resvport = RPC_DEF_MIN_RESVPORT; |
| 55 | unsigned int xprt_max_resvport = RPC_DEF_MAX_RESVPORT; |
| 56 | |
Trond Myklebust | 7d1e825 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 57 | #define XS_TCP_LINGER_TO (15U * HZ) |
Trond Myklebust | 25fe614 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 58 | static unsigned int xs_tcp_fin_timeout __read_mostly = XS_TCP_LINGER_TO; |
Trond Myklebust | 7d1e825 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 59 | |
Chuck Lever | c556b75 | 2005-11-01 12:24:48 -0500 | [diff] [blame] | 60 | /* |
Chuck Lever | fbf7668 | 2006-12-05 16:35:54 -0500 | [diff] [blame] | 61 | * We can register our own files under /proc/sys/sunrpc by |
| 62 | * calling register_sysctl_table() again. The files in that |
| 63 | * directory become the union of all files registered there. |
| 64 | * |
| 65 | * We simply need to make sure that we don't collide with |
| 66 | * someone else's file names! |
| 67 | */ |
| 68 | |
| 69 | #ifdef RPC_DEBUG |
| 70 | |
| 71 | static unsigned int min_slot_table_size = RPC_MIN_SLOT_TABLE; |
| 72 | static unsigned int max_slot_table_size = RPC_MAX_SLOT_TABLE; |
| 73 | static unsigned int xprt_min_resvport_limit = RPC_MIN_RESVPORT; |
| 74 | static unsigned int xprt_max_resvport_limit = RPC_MAX_RESVPORT; |
| 75 | |
| 76 | static struct ctl_table_header *sunrpc_table_header; |
| 77 | |
| 78 | /* |
| 79 | * FIXME: changing the UDP slot table size should also resize the UDP |
| 80 | * socket buffers for existing UDP transports |
| 81 | */ |
| 82 | static ctl_table xs_tunables_table[] = { |
| 83 | { |
Chuck Lever | fbf7668 | 2006-12-05 16:35:54 -0500 | [diff] [blame] | 84 | .procname = "udp_slot_table_entries", |
| 85 | .data = &xprt_udp_slot_table_entries, |
| 86 | .maxlen = sizeof(unsigned int), |
| 87 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 88 | .proc_handler = proc_dointvec_minmax, |
Chuck Lever | fbf7668 | 2006-12-05 16:35:54 -0500 | [diff] [blame] | 89 | .extra1 = &min_slot_table_size, |
| 90 | .extra2 = &max_slot_table_size |
| 91 | }, |
| 92 | { |
Chuck Lever | fbf7668 | 2006-12-05 16:35:54 -0500 | [diff] [blame] | 93 | .procname = "tcp_slot_table_entries", |
| 94 | .data = &xprt_tcp_slot_table_entries, |
| 95 | .maxlen = sizeof(unsigned int), |
| 96 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 97 | .proc_handler = proc_dointvec_minmax, |
Chuck Lever | fbf7668 | 2006-12-05 16:35:54 -0500 | [diff] [blame] | 98 | .extra1 = &min_slot_table_size, |
| 99 | .extra2 = &max_slot_table_size |
| 100 | }, |
| 101 | { |
Chuck Lever | fbf7668 | 2006-12-05 16:35:54 -0500 | [diff] [blame] | 102 | .procname = "min_resvport", |
| 103 | .data = &xprt_min_resvport, |
| 104 | .maxlen = sizeof(unsigned int), |
| 105 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 106 | .proc_handler = proc_dointvec_minmax, |
Chuck Lever | fbf7668 | 2006-12-05 16:35:54 -0500 | [diff] [blame] | 107 | .extra1 = &xprt_min_resvport_limit, |
| 108 | .extra2 = &xprt_max_resvport_limit |
| 109 | }, |
| 110 | { |
Chuck Lever | fbf7668 | 2006-12-05 16:35:54 -0500 | [diff] [blame] | 111 | .procname = "max_resvport", |
| 112 | .data = &xprt_max_resvport, |
| 113 | .maxlen = sizeof(unsigned int), |
| 114 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 115 | .proc_handler = proc_dointvec_minmax, |
Chuck Lever | fbf7668 | 2006-12-05 16:35:54 -0500 | [diff] [blame] | 116 | .extra1 = &xprt_min_resvport_limit, |
| 117 | .extra2 = &xprt_max_resvport_limit |
| 118 | }, |
| 119 | { |
Trond Myklebust | 25fe614 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 120 | .procname = "tcp_fin_timeout", |
| 121 | .data = &xs_tcp_fin_timeout, |
| 122 | .maxlen = sizeof(xs_tcp_fin_timeout), |
| 123 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 124 | .proc_handler = proc_dointvec_jiffies, |
Trond Myklebust | 25fe614 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 125 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 126 | { }, |
Chuck Lever | fbf7668 | 2006-12-05 16:35:54 -0500 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | static ctl_table sunrpc_table[] = { |
| 130 | { |
Chuck Lever | fbf7668 | 2006-12-05 16:35:54 -0500 | [diff] [blame] | 131 | .procname = "sunrpc", |
| 132 | .mode = 0555, |
| 133 | .child = xs_tunables_table |
| 134 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 135 | { }, |
Chuck Lever | fbf7668 | 2006-12-05 16:35:54 -0500 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | #endif |
| 139 | |
| 140 | /* |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 141 | * Wait duration for a reply from the RPC portmapper. |
| 142 | */ |
| 143 | #define XS_BIND_TO (60U * HZ) |
| 144 | |
| 145 | /* |
| 146 | * Delay if a UDP socket connect error occurs. This is most likely some |
| 147 | * kind of resource problem on the local host. |
| 148 | */ |
| 149 | #define XS_UDP_REEST_TO (2U * HZ) |
| 150 | |
| 151 | /* |
| 152 | * The reestablish timeout allows clients to delay for a bit before attempting |
| 153 | * to reconnect to a server that just dropped our connection. |
| 154 | * |
| 155 | * We implement an exponential backoff when trying to reestablish a TCP |
| 156 | * transport connection with the server. Some servers like to drop a TCP |
| 157 | * connection when they are overworked, so we start with a short timeout and |
| 158 | * increase over time if the server is down or not responding. |
| 159 | */ |
| 160 | #define XS_TCP_INIT_REEST_TO (3U * HZ) |
| 161 | #define XS_TCP_MAX_REEST_TO (5U * 60 * HZ) |
| 162 | |
| 163 | /* |
| 164 | * TCP idle timeout; client drops the transport socket if it is idle |
| 165 | * for this long. Note that we also timeout UDP sockets to prevent |
| 166 | * holding port numbers when there is no RPC traffic. |
| 167 | */ |
| 168 | #define XS_IDLE_DISC_TO (5U * 60 * HZ) |
| 169 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 170 | #ifdef RPC_DEBUG |
| 171 | # undef RPC_DEBUG_DATA |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 172 | # define RPCDBG_FACILITY RPCDBG_TRANS |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 173 | #endif |
| 174 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 175 | #ifdef RPC_DEBUG_DATA |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 176 | static void xs_pktdump(char *msg, u32 *packet, unsigned int count) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 177 | { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 178 | u8 *buf = (u8 *) packet; |
| 179 | int j; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 180 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 181 | dprintk("RPC: %s\n", msg); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 182 | for (j = 0; j < count && j < 128; j += 4) { |
| 183 | if (!(j & 31)) { |
| 184 | if (j) |
| 185 | dprintk("\n"); |
| 186 | dprintk("0x%04x ", j); |
| 187 | } |
| 188 | dprintk("%02x%02x%02x%02x ", |
| 189 | buf[j], buf[j+1], buf[j+2], buf[j+3]); |
| 190 | } |
| 191 | dprintk("\n"); |
| 192 | } |
| 193 | #else |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 194 | static inline void xs_pktdump(char *msg, u32 *packet, unsigned int count) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 195 | { |
| 196 | /* NOP */ |
| 197 | } |
| 198 | #endif |
| 199 | |
Chuck Lever | ffc2e51 | 2006-12-05 16:35:11 -0500 | [diff] [blame] | 200 | struct sock_xprt { |
| 201 | struct rpc_xprt xprt; |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 202 | |
| 203 | /* |
| 204 | * Network layer |
| 205 | */ |
| 206 | struct socket * sock; |
| 207 | struct sock * inet; |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 208 | |
| 209 | /* |
| 210 | * State of TCP reply receive |
| 211 | */ |
| 212 | __be32 tcp_fraghdr, |
| 213 | tcp_xid; |
| 214 | |
| 215 | u32 tcp_offset, |
| 216 | tcp_reclen; |
| 217 | |
| 218 | unsigned long tcp_copied, |
| 219 | tcp_flags; |
Chuck Lever | c847546 | 2006-12-05 16:35:26 -0500 | [diff] [blame] | 220 | |
| 221 | /* |
| 222 | * Connection of transports |
| 223 | */ |
Trond Myklebust | 34161db | 2006-12-07 15:48:15 -0500 | [diff] [blame] | 224 | struct delayed_work connect_worker; |
Chuck Lever | fbfffbd | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 225 | struct sockaddr_storage srcaddr; |
| 226 | unsigned short srcport; |
Chuck Lever | 7c6e066 | 2006-12-05 16:35:30 -0500 | [diff] [blame] | 227 | |
| 228 | /* |
| 229 | * UDP socket buffer size parameters |
| 230 | */ |
| 231 | size_t rcvsize, |
| 232 | sndsize; |
Chuck Lever | 314dfd7 | 2006-12-05 16:35:34 -0500 | [diff] [blame] | 233 | |
| 234 | /* |
| 235 | * Saved socket callback addresses |
| 236 | */ |
| 237 | void (*old_data_ready)(struct sock *, int); |
| 238 | void (*old_state_change)(struct sock *); |
| 239 | void (*old_write_space)(struct sock *); |
Trond Myklebust | 2a9e1cf | 2008-10-28 15:21:39 -0400 | [diff] [blame] | 240 | void (*old_error_report)(struct sock *); |
Chuck Lever | ffc2e51 | 2006-12-05 16:35:11 -0500 | [diff] [blame] | 241 | }; |
| 242 | |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 243 | /* |
| 244 | * TCP receive state flags |
| 245 | */ |
| 246 | #define TCP_RCV_LAST_FRAG (1UL << 0) |
| 247 | #define TCP_RCV_COPY_FRAGHDR (1UL << 1) |
| 248 | #define TCP_RCV_COPY_XID (1UL << 2) |
| 249 | #define TCP_RCV_COPY_DATA (1UL << 3) |
Ricardo Labiaga | f4a2e41 | 2009-04-01 09:22:54 -0400 | [diff] [blame] | 250 | #define TCP_RCV_READ_CALLDIR (1UL << 4) |
| 251 | #define TCP_RCV_COPY_CALLDIR (1UL << 5) |
Ricardo Labiaga | 18dca02 | 2009-04-01 09:22:53 -0400 | [diff] [blame] | 252 | |
| 253 | /* |
| 254 | * TCP RPC flags |
| 255 | */ |
Ricardo Labiaga | f4a2e41 | 2009-04-01 09:22:54 -0400 | [diff] [blame] | 256 | #define TCP_RPC_REPLY (1UL << 6) |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 257 | |
Chuck Lever | 95392c5 | 2007-08-06 11:57:58 -0400 | [diff] [blame] | 258 | static inline struct sockaddr *xs_addr(struct rpc_xprt *xprt) |
Chuck Lever | edb267a | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 259 | { |
Chuck Lever | 95392c5 | 2007-08-06 11:57:58 -0400 | [diff] [blame] | 260 | return (struct sockaddr *) &xprt->addr; |
| 261 | } |
| 262 | |
| 263 | static inline struct sockaddr_in *xs_addr_in(struct rpc_xprt *xprt) |
| 264 | { |
| 265 | return (struct sockaddr_in *) &xprt->addr; |
| 266 | } |
| 267 | |
| 268 | static inline struct sockaddr_in6 *xs_addr_in6(struct rpc_xprt *xprt) |
| 269 | { |
| 270 | return (struct sockaddr_in6 *) &xprt->addr; |
| 271 | } |
| 272 | |
Chuck Lever | c877b84 | 2009-08-09 15:09:36 -0400 | [diff] [blame] | 273 | static void xs_format_common_peer_addresses(struct rpc_xprt *xprt) |
Chuck Lever | edb267a | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 274 | { |
Chuck Lever | c877b84 | 2009-08-09 15:09:36 -0400 | [diff] [blame] | 275 | struct sockaddr *sap = xs_addr(xprt); |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 276 | struct sockaddr_in6 *sin6; |
| 277 | struct sockaddr_in *sin; |
Chuck Lever | c877b84 | 2009-08-09 15:09:36 -0400 | [diff] [blame] | 278 | char buf[128]; |
Chuck Lever | edb267a | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 279 | |
Chuck Lever | c877b84 | 2009-08-09 15:09:36 -0400 | [diff] [blame] | 280 | (void)rpc_ntop(sap, buf, sizeof(buf)); |
| 281 | xprt->address_strings[RPC_DISPLAY_ADDR] = kstrdup(buf, GFP_KERNEL); |
| 282 | |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 283 | switch (sap->sa_family) { |
| 284 | case AF_INET: |
| 285 | sin = xs_addr_in(xprt); |
Joe Perches | fc0b5791 | 2010-03-08 12:15:28 -0800 | [diff] [blame] | 286 | snprintf(buf, sizeof(buf), "%08x", ntohl(sin->sin_addr.s_addr)); |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 287 | break; |
| 288 | case AF_INET6: |
| 289 | sin6 = xs_addr_in6(xprt); |
Joe Perches | fc0b5791 | 2010-03-08 12:15:28 -0800 | [diff] [blame] | 290 | snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr); |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 291 | break; |
| 292 | default: |
| 293 | BUG(); |
Chuck Lever | edb267a | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 294 | } |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 295 | xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL); |
Chuck Lever | edb267a | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 296 | } |
| 297 | |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 298 | static void xs_format_common_peer_ports(struct rpc_xprt *xprt) |
Chuck Lever | 4b6473f | 2007-08-06 11:57:12 -0400 | [diff] [blame] | 299 | { |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 300 | struct sockaddr *sap = xs_addr(xprt); |
| 301 | char buf[128]; |
Chuck Lever | 4b6473f | 2007-08-06 11:57:12 -0400 | [diff] [blame] | 302 | |
Joe Perches | 81160e66 | 2010-03-08 12:15:59 -0800 | [diff] [blame] | 303 | snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap)); |
Chuck Lever | c877b84 | 2009-08-09 15:09:36 -0400 | [diff] [blame] | 304 | xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL); |
Chuck Lever | 4b6473f | 2007-08-06 11:57:12 -0400 | [diff] [blame] | 305 | |
Joe Perches | 81160e66 | 2010-03-08 12:15:59 -0800 | [diff] [blame] | 306 | snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap)); |
Chuck Lever | c877b84 | 2009-08-09 15:09:36 -0400 | [diff] [blame] | 307 | xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL); |
| 308 | } |
Chuck Lever | 4b6473f | 2007-08-06 11:57:12 -0400 | [diff] [blame] | 309 | |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 310 | static void xs_format_peer_addresses(struct rpc_xprt *xprt, |
| 311 | const char *protocol, |
| 312 | const char *netid) |
Chuck Lever | edb267a | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 313 | { |
Chuck Lever | b454ae9 | 2008-01-07 18:34:48 -0500 | [diff] [blame] | 314 | xprt->address_strings[RPC_DISPLAY_PROTO] = protocol; |
Chuck Lever | b454ae9 | 2008-01-07 18:34:48 -0500 | [diff] [blame] | 315 | xprt->address_strings[RPC_DISPLAY_NETID] = netid; |
Chuck Lever | c877b84 | 2009-08-09 15:09:36 -0400 | [diff] [blame] | 316 | xs_format_common_peer_addresses(xprt); |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 317 | xs_format_common_peer_ports(xprt); |
Chuck Lever | 4b6473f | 2007-08-06 11:57:12 -0400 | [diff] [blame] | 318 | } |
| 319 | |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 320 | static void xs_update_peer_port(struct rpc_xprt *xprt) |
Chuck Lever | 4b6473f | 2007-08-06 11:57:12 -0400 | [diff] [blame] | 321 | { |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 322 | kfree(xprt->address_strings[RPC_DISPLAY_HEX_PORT]); |
| 323 | kfree(xprt->address_strings[RPC_DISPLAY_PORT]); |
Chuck Lever | 4b6473f | 2007-08-06 11:57:12 -0400 | [diff] [blame] | 324 | |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 325 | xs_format_common_peer_ports(xprt); |
Chuck Lever | edb267a | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static void xs_free_peer_addresses(struct rpc_xprt *xprt) |
| 329 | { |
Chuck Lever | 33e01dc | 2008-01-14 12:32:20 -0500 | [diff] [blame] | 330 | unsigned int i; |
| 331 | |
| 332 | for (i = 0; i < RPC_DISPLAY_MAX; i++) |
| 333 | switch (i) { |
| 334 | case RPC_DISPLAY_PROTO: |
| 335 | case RPC_DISPLAY_NETID: |
| 336 | continue; |
| 337 | default: |
| 338 | kfree(xprt->address_strings[i]); |
| 339 | } |
Chuck Lever | edb267a | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 340 | } |
| 341 | |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 342 | #define XS_SENDMSG_FLAGS (MSG_DONTWAIT | MSG_NOSIGNAL) |
| 343 | |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 344 | static int xs_send_kvec(struct socket *sock, struct sockaddr *addr, int addrlen, struct kvec *vec, unsigned int base, int more) |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 345 | { |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 346 | struct msghdr msg = { |
| 347 | .msg_name = addr, |
| 348 | .msg_namelen = addrlen, |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 349 | .msg_flags = XS_SENDMSG_FLAGS | (more ? MSG_MORE : 0), |
| 350 | }; |
| 351 | struct kvec iov = { |
| 352 | .iov_base = vec->iov_base + base, |
| 353 | .iov_len = vec->iov_len - base, |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 354 | }; |
| 355 | |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 356 | if (iov.iov_len != 0) |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 357 | return kernel_sendmsg(sock, &msg, &iov, 1, iov.iov_len); |
| 358 | return kernel_sendmsg(sock, &msg, NULL, 0, 0); |
| 359 | } |
| 360 | |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 361 | static int xs_send_pagedata(struct socket *sock, struct xdr_buf *xdr, unsigned int base, int more) |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 362 | { |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 363 | struct page **ppage; |
| 364 | unsigned int remainder; |
| 365 | int err, sent = 0; |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 366 | |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 367 | remainder = xdr->page_len - base; |
| 368 | base += xdr->page_base; |
| 369 | ppage = xdr->pages + (base >> PAGE_SHIFT); |
| 370 | base &= ~PAGE_MASK; |
| 371 | for(;;) { |
| 372 | unsigned int len = min_t(unsigned int, PAGE_SIZE - base, remainder); |
| 373 | int flags = XS_SENDMSG_FLAGS; |
| 374 | |
| 375 | remainder -= len; |
| 376 | if (remainder != 0 || more) |
| 377 | flags |= MSG_MORE; |
| 378 | err = sock->ops->sendpage(sock, *ppage, base, len, flags); |
| 379 | if (remainder == 0 || err != len) |
| 380 | break; |
| 381 | sent += err; |
| 382 | ppage++; |
| 383 | base = 0; |
| 384 | } |
| 385 | if (sent == 0) |
| 386 | return err; |
| 387 | if (err > 0) |
| 388 | sent += err; |
| 389 | return sent; |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 390 | } |
| 391 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 392 | /** |
| 393 | * xs_sendpages - write pages directly to a socket |
| 394 | * @sock: socket to send on |
| 395 | * @addr: UDP only -- address of destination |
| 396 | * @addrlen: UDP only -- length of destination address |
| 397 | * @xdr: buffer containing this request |
| 398 | * @base: starting position in the buffer |
| 399 | * |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 400 | */ |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 401 | static int xs_sendpages(struct socket *sock, struct sockaddr *addr, int addrlen, struct xdr_buf *xdr, unsigned int base) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 402 | { |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 403 | unsigned int remainder = xdr->len - base; |
| 404 | int err, sent = 0; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 405 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 406 | if (unlikely(!sock)) |
Trond Myklebust | fba91af | 2009-03-11 14:06:41 -0400 | [diff] [blame] | 407 | return -ENOTSOCK; |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 408 | |
| 409 | clear_bit(SOCK_ASYNC_NOSPACE, &sock->flags); |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 410 | if (base != 0) { |
| 411 | addr = NULL; |
| 412 | addrlen = 0; |
| 413 | } |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 414 | |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 415 | if (base < xdr->head[0].iov_len || addr != NULL) { |
| 416 | unsigned int len = xdr->head[0].iov_len - base; |
| 417 | remainder -= len; |
| 418 | err = xs_send_kvec(sock, addr, addrlen, &xdr->head[0], base, remainder != 0); |
| 419 | if (remainder == 0 || err != len) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 420 | goto out; |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 421 | sent += err; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 422 | base = 0; |
| 423 | } else |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 424 | base -= xdr->head[0].iov_len; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 425 | |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 426 | if (base < xdr->page_len) { |
| 427 | unsigned int len = xdr->page_len - base; |
| 428 | remainder -= len; |
| 429 | err = xs_send_pagedata(sock, xdr, base, remainder != 0); |
| 430 | if (remainder == 0 || err != len) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 431 | goto out; |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 432 | sent += err; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 433 | base = 0; |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 434 | } else |
| 435 | base -= xdr->page_len; |
| 436 | |
| 437 | if (base >= xdr->tail[0].iov_len) |
| 438 | return sent; |
| 439 | err = xs_send_kvec(sock, NULL, 0, &xdr->tail[0], base, 0); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 440 | out: |
Trond Myklebust | 24c5684 | 2006-10-17 15:06:22 -0400 | [diff] [blame] | 441 | if (sent == 0) |
| 442 | return err; |
| 443 | if (err > 0) |
| 444 | sent += err; |
| 445 | return sent; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 446 | } |
| 447 | |
Trond Myklebust | b6ddf64 | 2008-04-17 18:52:19 -0400 | [diff] [blame] | 448 | static void xs_nospace_callback(struct rpc_task *task) |
| 449 | { |
| 450 | struct sock_xprt *transport = container_of(task->tk_rqstp->rq_xprt, struct sock_xprt, xprt); |
| 451 | |
| 452 | transport->inet->sk_write_pending--; |
| 453 | clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags); |
| 454 | } |
| 455 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 456 | /** |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 457 | * xs_nospace - place task on wait queue if transmit was incomplete |
| 458 | * @task: task to put to sleep |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 459 | * |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 460 | */ |
Trond Myklebust | 5e3771c | 2009-03-11 14:38:01 -0400 | [diff] [blame] | 461 | static int xs_nospace(struct rpc_task *task) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 462 | { |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 463 | struct rpc_rqst *req = task->tk_rqstp; |
| 464 | struct rpc_xprt *xprt = req->rq_xprt; |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 465 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
Trond Myklebust | 5e3771c | 2009-03-11 14:38:01 -0400 | [diff] [blame] | 466 | int ret = 0; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 467 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 468 | dprintk("RPC: %5u xmit incomplete (%u left of %u)\n", |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 469 | task->tk_pid, req->rq_slen - req->rq_bytes_sent, |
| 470 | req->rq_slen); |
| 471 | |
Trond Myklebust | b6ddf64 | 2008-04-17 18:52:19 -0400 | [diff] [blame] | 472 | /* Protect against races with write_space */ |
| 473 | spin_lock_bh(&xprt->transport_lock); |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 474 | |
Trond Myklebust | b6ddf64 | 2008-04-17 18:52:19 -0400 | [diff] [blame] | 475 | /* Don't race with disconnect */ |
| 476 | if (xprt_connected(xprt)) { |
| 477 | if (test_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags)) { |
Trond Myklebust | 5e3771c | 2009-03-11 14:38:01 -0400 | [diff] [blame] | 478 | ret = -EAGAIN; |
Trond Myklebust | b6ddf64 | 2008-04-17 18:52:19 -0400 | [diff] [blame] | 479 | /* |
| 480 | * Notify TCP that we're limited by the application |
| 481 | * window size |
| 482 | */ |
| 483 | set_bit(SOCK_NOSPACE, &transport->sock->flags); |
| 484 | transport->inet->sk_write_pending++; |
| 485 | /* ...and wait for more buffer space */ |
| 486 | xprt_wait_for_buffer_space(task, xs_nospace_callback); |
| 487 | } |
| 488 | } else { |
| 489 | clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags); |
Trond Myklebust | 5e3771c | 2009-03-11 14:38:01 -0400 | [diff] [blame] | 490 | ret = -ENOTCONN; |
Trond Myklebust | b6ddf64 | 2008-04-17 18:52:19 -0400 | [diff] [blame] | 491 | } |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 492 | |
Trond Myklebust | b6ddf64 | 2008-04-17 18:52:19 -0400 | [diff] [blame] | 493 | spin_unlock_bh(&xprt->transport_lock); |
Trond Myklebust | 5e3771c | 2009-03-11 14:38:01 -0400 | [diff] [blame] | 494 | return ret; |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | /** |
| 498 | * xs_udp_send_request - write an RPC request to a UDP socket |
| 499 | * @task: address of RPC task that manages the state of an RPC request |
| 500 | * |
| 501 | * Return values: |
| 502 | * 0: The request has been sent |
| 503 | * EAGAIN: The socket was blocked, please call again later to |
| 504 | * complete the request |
| 505 | * ENOTCONN: Caller needs to invoke connect logic then call again |
| 506 | * other: Some other error occured, the request was not sent |
| 507 | */ |
| 508 | static int xs_udp_send_request(struct rpc_task *task) |
| 509 | { |
| 510 | struct rpc_rqst *req = task->tk_rqstp; |
| 511 | struct rpc_xprt *xprt = req->rq_xprt; |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 512 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 513 | struct xdr_buf *xdr = &req->rq_snd_buf; |
| 514 | int status; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 515 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 516 | xs_pktdump("packet data:", |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 517 | req->rq_svec->iov_base, |
| 518 | req->rq_svec->iov_len); |
| 519 | |
Trond Myklebust | 01d37c4 | 2009-03-11 14:09:39 -0400 | [diff] [blame] | 520 | if (!xprt_bound(xprt)) |
| 521 | return -ENOTCONN; |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 522 | status = xs_sendpages(transport->sock, |
Chuck Lever | 95392c5 | 2007-08-06 11:57:58 -0400 | [diff] [blame] | 523 | xs_addr(xprt), |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 524 | xprt->addrlen, xdr, |
| 525 | req->rq_bytes_sent); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 526 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 527 | dprintk("RPC: xs_udp_send_request(%u) = %d\n", |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 528 | xdr->len - req->rq_bytes_sent, status); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 529 | |
Trond Myklebust | 2199700 | 2007-10-01 11:43:37 -0400 | [diff] [blame] | 530 | if (status >= 0) { |
Trond Myklebust | d60dbb2 | 2010-05-13 12:51:49 -0400 | [diff] [blame] | 531 | req->rq_xmit_bytes_sent += status; |
Trond Myklebust | 2199700 | 2007-10-01 11:43:37 -0400 | [diff] [blame] | 532 | if (status >= req->rq_slen) |
| 533 | return 0; |
| 534 | /* Still some bytes left; set up for a retry later. */ |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 535 | status = -EAGAIN; |
Trond Myklebust | 2199700 | 2007-10-01 11:43:37 -0400 | [diff] [blame] | 536 | } |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 537 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 538 | switch (status) { |
Trond Myklebust | fba91af | 2009-03-11 14:06:41 -0400 | [diff] [blame] | 539 | case -ENOTSOCK: |
| 540 | status = -ENOTCONN; |
| 541 | /* Should we call xs_close() here? */ |
| 542 | break; |
Trond Myklebust | b6ddf64 | 2008-04-17 18:52:19 -0400 | [diff] [blame] | 543 | case -EAGAIN: |
Trond Myklebust | 5e3771c | 2009-03-11 14:38:01 -0400 | [diff] [blame] | 544 | status = xs_nospace(task); |
Trond Myklebust | b6ddf64 | 2008-04-17 18:52:19 -0400 | [diff] [blame] | 545 | break; |
Trond Myklebust | c8485e4 | 2009-03-11 14:37:59 -0400 | [diff] [blame] | 546 | default: |
| 547 | dprintk("RPC: sendmsg returned unrecognized error %d\n", |
| 548 | -status); |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 549 | case -ENETUNREACH: |
| 550 | case -EPIPE: |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 551 | case -ECONNREFUSED: |
| 552 | /* When the server has died, an ICMP port unreachable message |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 553 | * prompts ECONNREFUSED. */ |
Trond Myklebust | b6ddf64 | 2008-04-17 18:52:19 -0400 | [diff] [blame] | 554 | clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 555 | } |
Bian Naimeng | 5fe46e9 | 2010-03-08 14:49:01 +0800 | [diff] [blame] | 556 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 557 | return status; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 558 | } |
| 559 | |
Trond Myklebust | e06799f | 2007-11-05 15:44:12 -0500 | [diff] [blame] | 560 | /** |
| 561 | * xs_tcp_shutdown - gracefully shut down a TCP socket |
| 562 | * @xprt: transport |
| 563 | * |
| 564 | * Initiates a graceful shutdown of the TCP socket by calling the |
| 565 | * equivalent of shutdown(SHUT_WR); |
| 566 | */ |
| 567 | static void xs_tcp_shutdown(struct rpc_xprt *xprt) |
| 568 | { |
| 569 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
| 570 | struct socket *sock = transport->sock; |
| 571 | |
| 572 | if (sock != NULL) |
| 573 | kernel_sock_shutdown(sock, SHUT_WR); |
| 574 | } |
| 575 | |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 576 | static inline void xs_encode_tcp_record_marker(struct xdr_buf *buf) |
| 577 | { |
| 578 | u32 reclen = buf->len - sizeof(rpc_fraghdr); |
| 579 | rpc_fraghdr *base = buf->head[0].iov_base; |
| 580 | *base = htonl(RPC_LAST_STREAM_FRAGMENT | reclen); |
| 581 | } |
| 582 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 583 | /** |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 584 | * xs_tcp_send_request - write an RPC request to a TCP socket |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 585 | * @task: address of RPC task that manages the state of an RPC request |
| 586 | * |
| 587 | * Return values: |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 588 | * 0: The request has been sent |
| 589 | * EAGAIN: The socket was blocked, please call again later to |
| 590 | * complete the request |
| 591 | * ENOTCONN: Caller needs to invoke connect logic then call again |
| 592 | * other: Some other error occured, the request was not sent |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 593 | * |
| 594 | * XXX: In the case of soft timeouts, should we eventually give up |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 595 | * if sendmsg is not able to make progress? |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 596 | */ |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 597 | static int xs_tcp_send_request(struct rpc_task *task) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 598 | { |
| 599 | struct rpc_rqst *req = task->tk_rqstp; |
| 600 | struct rpc_xprt *xprt = req->rq_xprt; |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 601 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 602 | struct xdr_buf *xdr = &req->rq_snd_buf; |
Chuck Lever | b595bb1 | 2007-08-06 11:56:42 -0400 | [diff] [blame] | 603 | int status; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 604 | |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 605 | xs_encode_tcp_record_marker(&req->rq_snd_buf); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 606 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 607 | xs_pktdump("packet data:", |
| 608 | req->rq_svec->iov_base, |
| 609 | req->rq_svec->iov_len); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 610 | |
| 611 | /* Continue transmitting the packet/record. We must be careful |
| 612 | * to cope with writespace callbacks arriving _after_ we have |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 613 | * called sendmsg(). */ |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 614 | while (1) { |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 615 | status = xs_sendpages(transport->sock, |
| 616 | NULL, 0, xdr, req->rq_bytes_sent); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 617 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 618 | dprintk("RPC: xs_tcp_send_request(%u) = %d\n", |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 619 | xdr->len - req->rq_bytes_sent, status); |
| 620 | |
| 621 | if (unlikely(status < 0)) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 622 | break; |
| 623 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 624 | /* If we've sent the entire packet, immediately |
| 625 | * reset the count of bytes sent. */ |
| 626 | req->rq_bytes_sent += status; |
Trond Myklebust | d60dbb2 | 2010-05-13 12:51:49 -0400 | [diff] [blame] | 627 | req->rq_xmit_bytes_sent += status; |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 628 | if (likely(req->rq_bytes_sent >= req->rq_slen)) { |
| 629 | req->rq_bytes_sent = 0; |
| 630 | return 0; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 631 | } |
| 632 | |
Trond Myklebust | 06b4b68 | 2008-04-16 16:51:38 -0400 | [diff] [blame] | 633 | if (status != 0) |
| 634 | continue; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 635 | status = -EAGAIN; |
Trond Myklebust | 06b4b68 | 2008-04-16 16:51:38 -0400 | [diff] [blame] | 636 | break; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 637 | } |
| 638 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 639 | switch (status) { |
Trond Myklebust | fba91af | 2009-03-11 14:06:41 -0400 | [diff] [blame] | 640 | case -ENOTSOCK: |
| 641 | status = -ENOTCONN; |
| 642 | /* Should we call xs_close() here? */ |
| 643 | break; |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 644 | case -EAGAIN: |
Trond Myklebust | 5e3771c | 2009-03-11 14:38:01 -0400 | [diff] [blame] | 645 | status = xs_nospace(task); |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 646 | break; |
| 647 | default: |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 648 | dprintk("RPC: sendmsg returned unrecognized error %d\n", |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 649 | -status); |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 650 | case -ECONNRESET: |
Trond Myklebust | 55420c2 | 2009-03-11 15:29:24 -0400 | [diff] [blame] | 651 | case -EPIPE: |
Trond Myklebust | e06799f | 2007-11-05 15:44:12 -0500 | [diff] [blame] | 652 | xs_tcp_shutdown(xprt); |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 653 | case -ECONNREFUSED: |
| 654 | case -ENOTCONN: |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 655 | clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 656 | } |
Bian Naimeng | 5fe46e9 | 2010-03-08 14:49:01 +0800 | [diff] [blame] | 657 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 658 | return status; |
| 659 | } |
| 660 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 661 | /** |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 662 | * xs_tcp_release_xprt - clean up after a tcp transmission |
| 663 | * @xprt: transport |
| 664 | * @task: rpc task |
| 665 | * |
| 666 | * This cleans up if an error causes us to abort the transmission of a request. |
| 667 | * In this case, the socket may need to be reset in order to avoid confusing |
| 668 | * the server. |
| 669 | */ |
| 670 | static void xs_tcp_release_xprt(struct rpc_xprt *xprt, struct rpc_task *task) |
| 671 | { |
| 672 | struct rpc_rqst *req; |
| 673 | |
| 674 | if (task != xprt->snd_task) |
| 675 | return; |
| 676 | if (task == NULL) |
| 677 | goto out_release; |
| 678 | req = task->tk_rqstp; |
| 679 | if (req->rq_bytes_sent == 0) |
| 680 | goto out_release; |
| 681 | if (req->rq_bytes_sent == req->rq_snd_buf.len) |
| 682 | goto out_release; |
| 683 | set_bit(XPRT_CLOSE_WAIT, &task->tk_xprt->state); |
| 684 | out_release: |
| 685 | xprt_release_xprt(xprt, task); |
| 686 | } |
| 687 | |
Trond Myklebust | 2a9e1cf | 2008-10-28 15:21:39 -0400 | [diff] [blame] | 688 | static void xs_save_old_callbacks(struct sock_xprt *transport, struct sock *sk) |
| 689 | { |
| 690 | transport->old_data_ready = sk->sk_data_ready; |
| 691 | transport->old_state_change = sk->sk_state_change; |
| 692 | transport->old_write_space = sk->sk_write_space; |
| 693 | transport->old_error_report = sk->sk_error_report; |
| 694 | } |
| 695 | |
| 696 | static void xs_restore_old_callbacks(struct sock_xprt *transport, struct sock *sk) |
| 697 | { |
| 698 | sk->sk_data_ready = transport->old_data_ready; |
| 699 | sk->sk_state_change = transport->old_state_change; |
| 700 | sk->sk_write_space = transport->old_write_space; |
| 701 | sk->sk_error_report = transport->old_error_report; |
| 702 | } |
| 703 | |
Chuck Lever | fe315e7 | 2009-03-11 14:10:21 -0400 | [diff] [blame] | 704 | static void xs_reset_transport(struct sock_xprt *transport) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 705 | { |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 706 | struct socket *sock = transport->sock; |
| 707 | struct sock *sk = transport->inet; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 708 | |
Chuck Lever | fe315e7 | 2009-03-11 14:10:21 -0400 | [diff] [blame] | 709 | if (sk == NULL) |
| 710 | return; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 711 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 712 | write_lock_bh(&sk->sk_callback_lock); |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 713 | transport->inet = NULL; |
| 714 | transport->sock = NULL; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 715 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 716 | sk->sk_user_data = NULL; |
Trond Myklebust | 2a9e1cf | 2008-10-28 15:21:39 -0400 | [diff] [blame] | 717 | |
| 718 | xs_restore_old_callbacks(transport, sk); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 719 | write_unlock_bh(&sk->sk_callback_lock); |
| 720 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 721 | sk->sk_no_check = 0; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 722 | |
| 723 | sock_release(sock); |
Chuck Lever | fe315e7 | 2009-03-11 14:10:21 -0400 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | /** |
| 727 | * xs_close - close a socket |
| 728 | * @xprt: transport |
| 729 | * |
| 730 | * This is used when all requests are complete; ie, no DRC state remains |
| 731 | * on the server we want to save. |
Trond Myklebust | f75e674 | 2009-04-21 17:18:20 -0400 | [diff] [blame] | 732 | * |
| 733 | * The caller _must_ be holding XPRT_LOCKED in order to avoid issues with |
| 734 | * xs_reset_transport() zeroing the socket from underneath a writer. |
Chuck Lever | fe315e7 | 2009-03-11 14:10:21 -0400 | [diff] [blame] | 735 | */ |
| 736 | static void xs_close(struct rpc_xprt *xprt) |
| 737 | { |
| 738 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
| 739 | |
| 740 | dprintk("RPC: xs_close xprt %p\n", xprt); |
| 741 | |
| 742 | xs_reset_transport(transport); |
Neil Brown | 61d0a8e | 2009-09-23 14:36:37 -0400 | [diff] [blame] | 743 | xprt->reestablish_timeout = 0; |
Chuck Lever | fe315e7 | 2009-03-11 14:10:21 -0400 | [diff] [blame] | 744 | |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 745 | smp_mb__before_clear_bit(); |
Trond Myklebust | 7d1e825 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 746 | clear_bit(XPRT_CONNECTION_ABORT, &xprt->state); |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 747 | clear_bit(XPRT_CLOSE_WAIT, &xprt->state); |
Trond Myklebust | 3b948ae | 2007-11-05 17:42:39 -0500 | [diff] [blame] | 748 | clear_bit(XPRT_CLOSING, &xprt->state); |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 749 | smp_mb__after_clear_bit(); |
Trond Myklebust | 62da3b2 | 2007-11-06 18:44:20 -0500 | [diff] [blame] | 750 | xprt_disconnect_done(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 751 | } |
| 752 | |
Trond Myklebust | f75e674 | 2009-04-21 17:18:20 -0400 | [diff] [blame] | 753 | static void xs_tcp_close(struct rpc_xprt *xprt) |
| 754 | { |
| 755 | if (test_and_clear_bit(XPRT_CONNECTION_CLOSE, &xprt->state)) |
| 756 | xs_close(xprt); |
| 757 | else |
| 758 | xs_tcp_shutdown(xprt); |
| 759 | } |
| 760 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 761 | /** |
| 762 | * xs_destroy - prepare to shutdown a transport |
| 763 | * @xprt: doomed transport |
| 764 | * |
| 765 | */ |
| 766 | static void xs_destroy(struct rpc_xprt *xprt) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 767 | { |
Chuck Lever | c847546 | 2006-12-05 16:35:26 -0500 | [diff] [blame] | 768 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
| 769 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 770 | dprintk("RPC: xs_destroy xprt %p\n", xprt); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 771 | |
Trond Myklebust | c1384c9 | 2007-06-14 18:00:42 -0400 | [diff] [blame] | 772 | cancel_rearming_delayed_work(&transport->connect_worker); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 773 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 774 | xs_close(xprt); |
Chuck Lever | edb267a | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 775 | xs_free_peer_addresses(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 776 | kfree(xprt->slot); |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 777 | kfree(xprt); |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 778 | module_put(THIS_MODULE); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 779 | } |
| 780 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 781 | static inline struct rpc_xprt *xprt_from_sock(struct sock *sk) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 782 | { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 783 | return (struct rpc_xprt *) sk->sk_user_data; |
| 784 | } |
| 785 | |
| 786 | /** |
| 787 | * xs_udp_data_ready - "data ready" callback for UDP sockets |
| 788 | * @sk: socket with data to read |
| 789 | * @len: how much data to read |
| 790 | * |
| 791 | */ |
| 792 | static void xs_udp_data_ready(struct sock *sk, int len) |
| 793 | { |
| 794 | struct rpc_task *task; |
| 795 | struct rpc_xprt *xprt; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 796 | struct rpc_rqst *rovr; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 797 | struct sk_buff *skb; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 798 | int err, repsize, copied; |
Alexey Dobriyan | d8ed029 | 2006-09-26 22:29:38 -0700 | [diff] [blame] | 799 | u32 _xid; |
| 800 | __be32 *xp; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 801 | |
| 802 | read_lock(&sk->sk_callback_lock); |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 803 | dprintk("RPC: xs_udp_data_ready...\n"); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 804 | if (!(xprt = xprt_from_sock(sk))) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 805 | goto out; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 806 | |
| 807 | if ((skb = skb_recv_datagram(sk, 0, 1, &err)) == NULL) |
| 808 | goto out; |
| 809 | |
| 810 | if (xprt->shutdown) |
| 811 | goto dropit; |
| 812 | |
| 813 | repsize = skb->len - sizeof(struct udphdr); |
| 814 | if (repsize < 4) { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 815 | dprintk("RPC: impossible RPC reply size %d!\n", repsize); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 816 | goto dropit; |
| 817 | } |
| 818 | |
| 819 | /* Copy the XID from the skb... */ |
| 820 | xp = skb_header_pointer(skb, sizeof(struct udphdr), |
| 821 | sizeof(_xid), &_xid); |
| 822 | if (xp == NULL) |
| 823 | goto dropit; |
| 824 | |
| 825 | /* Look up and lock the request corresponding to the given XID */ |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 826 | spin_lock(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 827 | rovr = xprt_lookup_rqst(xprt, *xp); |
| 828 | if (!rovr) |
| 829 | goto out_unlock; |
| 830 | task = rovr->rq_task; |
| 831 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 832 | if ((copied = rovr->rq_private_buf.buflen) > repsize) |
| 833 | copied = repsize; |
| 834 | |
| 835 | /* Suck it into the iovec, verify checksum if not done by hw. */ |
Herbert Xu | 1781f7f | 2007-12-11 11:30:32 -0800 | [diff] [blame] | 836 | if (csum_partial_copy_to_xdr(&rovr->rq_private_buf, skb)) { |
| 837 | UDPX_INC_STATS_BH(sk, UDP_MIB_INERRORS); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 838 | goto out_unlock; |
Herbert Xu | 1781f7f | 2007-12-11 11:30:32 -0800 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | UDPX_INC_STATS_BH(sk, UDP_MIB_INDATAGRAMS); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 842 | |
| 843 | /* Something worked... */ |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 844 | dst_confirm(skb_dst(skb)); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 845 | |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 846 | xprt_adjust_cwnd(task, copied); |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 847 | xprt_complete_rqst(task, copied); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 848 | |
| 849 | out_unlock: |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 850 | spin_unlock(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 851 | dropit: |
| 852 | skb_free_datagram(sk, skb); |
| 853 | out: |
| 854 | read_unlock(&sk->sk_callback_lock); |
| 855 | } |
| 856 | |
Chuck Lever | dd45647 | 2006-12-05 16:35:44 -0500 | [diff] [blame] | 857 | static inline void xs_tcp_read_fraghdr(struct rpc_xprt *xprt, struct xdr_skb_reader *desc) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 858 | { |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 859 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 860 | size_t len, used; |
| 861 | char *p; |
| 862 | |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 863 | p = ((char *) &transport->tcp_fraghdr) + transport->tcp_offset; |
| 864 | len = sizeof(transport->tcp_fraghdr) - transport->tcp_offset; |
Chuck Lever | 9d29231 | 2006-12-05 16:35:41 -0500 | [diff] [blame] | 865 | used = xdr_skb_read_bits(desc, p, len); |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 866 | transport->tcp_offset += used; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 867 | if (used != len) |
| 868 | return; |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 869 | |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 870 | transport->tcp_reclen = ntohl(transport->tcp_fraghdr); |
| 871 | if (transport->tcp_reclen & RPC_LAST_STREAM_FRAGMENT) |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 872 | transport->tcp_flags |= TCP_RCV_LAST_FRAG; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 873 | else |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 874 | transport->tcp_flags &= ~TCP_RCV_LAST_FRAG; |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 875 | transport->tcp_reclen &= RPC_FRAGMENT_SIZE_MASK; |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 876 | |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 877 | transport->tcp_flags &= ~TCP_RCV_COPY_FRAGHDR; |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 878 | transport->tcp_offset = 0; |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 879 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 880 | /* Sanity check of the record length */ |
Ricardo Labiaga | 18dca02 | 2009-04-01 09:22:53 -0400 | [diff] [blame] | 881 | if (unlikely(transport->tcp_reclen < 8)) { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 882 | dprintk("RPC: invalid TCP record fragment length\n"); |
Trond Myklebust | 3ebb067 | 2007-11-06 18:40:12 -0500 | [diff] [blame] | 883 | xprt_force_disconnect(xprt); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 884 | return; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 885 | } |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 886 | dprintk("RPC: reading TCP record fragment of length %d\n", |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 887 | transport->tcp_reclen); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 888 | } |
| 889 | |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 890 | static void xs_tcp_check_fraghdr(struct sock_xprt *transport) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 891 | { |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 892 | if (transport->tcp_offset == transport->tcp_reclen) { |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 893 | transport->tcp_flags |= TCP_RCV_COPY_FRAGHDR; |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 894 | transport->tcp_offset = 0; |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 895 | if (transport->tcp_flags & TCP_RCV_LAST_FRAG) { |
| 896 | transport->tcp_flags &= ~TCP_RCV_COPY_DATA; |
| 897 | transport->tcp_flags |= TCP_RCV_COPY_XID; |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 898 | transport->tcp_copied = 0; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 899 | } |
| 900 | } |
| 901 | } |
| 902 | |
Chuck Lever | dd45647 | 2006-12-05 16:35:44 -0500 | [diff] [blame] | 903 | static inline void xs_tcp_read_xid(struct sock_xprt *transport, struct xdr_skb_reader *desc) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 904 | { |
| 905 | size_t len, used; |
| 906 | char *p; |
| 907 | |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 908 | len = sizeof(transport->tcp_xid) - transport->tcp_offset; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 909 | dprintk("RPC: reading XID (%Zu bytes)\n", len); |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 910 | p = ((char *) &transport->tcp_xid) + transport->tcp_offset; |
Chuck Lever | 9d29231 | 2006-12-05 16:35:41 -0500 | [diff] [blame] | 911 | used = xdr_skb_read_bits(desc, p, len); |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 912 | transport->tcp_offset += used; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 913 | if (used != len) |
| 914 | return; |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 915 | transport->tcp_flags &= ~TCP_RCV_COPY_XID; |
Ricardo Labiaga | f4a2e41 | 2009-04-01 09:22:54 -0400 | [diff] [blame] | 916 | transport->tcp_flags |= TCP_RCV_READ_CALLDIR; |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 917 | transport->tcp_copied = 4; |
Ricardo Labiaga | 18dca02 | 2009-04-01 09:22:53 -0400 | [diff] [blame] | 918 | dprintk("RPC: reading %s XID %08x\n", |
| 919 | (transport->tcp_flags & TCP_RPC_REPLY) ? "reply for" |
| 920 | : "request with", |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 921 | ntohl(transport->tcp_xid)); |
| 922 | xs_tcp_check_fraghdr(transport); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 923 | } |
| 924 | |
Ricardo Labiaga | 18dca02 | 2009-04-01 09:22:53 -0400 | [diff] [blame] | 925 | static inline void xs_tcp_read_calldir(struct sock_xprt *transport, |
| 926 | struct xdr_skb_reader *desc) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 927 | { |
Ricardo Labiaga | 18dca02 | 2009-04-01 09:22:53 -0400 | [diff] [blame] | 928 | size_t len, used; |
| 929 | u32 offset; |
| 930 | __be32 calldir; |
| 931 | |
| 932 | /* |
| 933 | * We want transport->tcp_offset to be 8 at the end of this routine |
| 934 | * (4 bytes for the xid and 4 bytes for the call/reply flag). |
| 935 | * When this function is called for the first time, |
| 936 | * transport->tcp_offset is 4 (after having already read the xid). |
| 937 | */ |
| 938 | offset = transport->tcp_offset - sizeof(transport->tcp_xid); |
| 939 | len = sizeof(calldir) - offset; |
| 940 | dprintk("RPC: reading CALL/REPLY flag (%Zu bytes)\n", len); |
| 941 | used = xdr_skb_read_bits(desc, &calldir, len); |
| 942 | transport->tcp_offset += used; |
| 943 | if (used != len) |
| 944 | return; |
Ricardo Labiaga | f4a2e41 | 2009-04-01 09:22:54 -0400 | [diff] [blame] | 945 | transport->tcp_flags &= ~TCP_RCV_READ_CALLDIR; |
| 946 | transport->tcp_flags |= TCP_RCV_COPY_CALLDIR; |
Ricardo Labiaga | 18dca02 | 2009-04-01 09:22:53 -0400 | [diff] [blame] | 947 | transport->tcp_flags |= TCP_RCV_COPY_DATA; |
Ricardo Labiaga | f4a2e41 | 2009-04-01 09:22:54 -0400 | [diff] [blame] | 948 | /* |
| 949 | * We don't yet have the XDR buffer, so we will write the calldir |
| 950 | * out after we get the buffer from the 'struct rpc_rqst' |
| 951 | */ |
Ricardo Labiaga | 18dca02 | 2009-04-01 09:22:53 -0400 | [diff] [blame] | 952 | if (ntohl(calldir) == RPC_REPLY) |
| 953 | transport->tcp_flags |= TCP_RPC_REPLY; |
| 954 | else |
| 955 | transport->tcp_flags &= ~TCP_RPC_REPLY; |
| 956 | dprintk("RPC: reading %s CALL/REPLY flag %08x\n", |
| 957 | (transport->tcp_flags & TCP_RPC_REPLY) ? |
| 958 | "reply for" : "request with", calldir); |
| 959 | xs_tcp_check_fraghdr(transport); |
| 960 | } |
| 961 | |
Ricardo Labiaga | 44b98ef | 2009-04-01 09:23:02 -0400 | [diff] [blame] | 962 | static inline void xs_tcp_read_common(struct rpc_xprt *xprt, |
| 963 | struct xdr_skb_reader *desc, |
| 964 | struct rpc_rqst *req) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 965 | { |
Ricardo Labiaga | 44b98ef | 2009-04-01 09:23:02 -0400 | [diff] [blame] | 966 | struct sock_xprt *transport = |
| 967 | container_of(xprt, struct sock_xprt, xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 968 | struct xdr_buf *rcvbuf; |
| 969 | size_t len; |
| 970 | ssize_t r; |
| 971 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 972 | rcvbuf = &req->rq_private_buf; |
Ricardo Labiaga | f4a2e41 | 2009-04-01 09:22:54 -0400 | [diff] [blame] | 973 | |
| 974 | if (transport->tcp_flags & TCP_RCV_COPY_CALLDIR) { |
| 975 | /* |
| 976 | * Save the RPC direction in the XDR buffer |
| 977 | */ |
| 978 | __be32 calldir = transport->tcp_flags & TCP_RPC_REPLY ? |
| 979 | htonl(RPC_REPLY) : 0; |
| 980 | |
| 981 | memcpy(rcvbuf->head[0].iov_base + transport->tcp_copied, |
| 982 | &calldir, sizeof(calldir)); |
| 983 | transport->tcp_copied += sizeof(calldir); |
| 984 | transport->tcp_flags &= ~TCP_RCV_COPY_CALLDIR; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 985 | } |
| 986 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 987 | len = desc->count; |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 988 | if (len > transport->tcp_reclen - transport->tcp_offset) { |
Chuck Lever | dd45647 | 2006-12-05 16:35:44 -0500 | [diff] [blame] | 989 | struct xdr_skb_reader my_desc; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 990 | |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 991 | len = transport->tcp_reclen - transport->tcp_offset; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 992 | memcpy(&my_desc, desc, sizeof(my_desc)); |
| 993 | my_desc.count = len; |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 994 | r = xdr_partial_copy_from_skb(rcvbuf, transport->tcp_copied, |
Chuck Lever | 9d29231 | 2006-12-05 16:35:41 -0500 | [diff] [blame] | 995 | &my_desc, xdr_skb_read_bits); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 996 | desc->count -= r; |
| 997 | desc->offset += r; |
| 998 | } else |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 999 | r = xdr_partial_copy_from_skb(rcvbuf, transport->tcp_copied, |
Chuck Lever | 9d29231 | 2006-12-05 16:35:41 -0500 | [diff] [blame] | 1000 | desc, xdr_skb_read_bits); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1001 | |
| 1002 | if (r > 0) { |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 1003 | transport->tcp_copied += r; |
| 1004 | transport->tcp_offset += r; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1005 | } |
| 1006 | if (r != len) { |
| 1007 | /* Error when copying to the receive buffer, |
| 1008 | * usually because we weren't able to allocate |
| 1009 | * additional buffer pages. All we can do now |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 1010 | * is turn off TCP_RCV_COPY_DATA, so the request |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1011 | * will not receive any additional updates, |
| 1012 | * and time out. |
| 1013 | * Any remaining data from this record will |
| 1014 | * be discarded. |
| 1015 | */ |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 1016 | transport->tcp_flags &= ~TCP_RCV_COPY_DATA; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1017 | dprintk("RPC: XID %08x truncated request\n", |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 1018 | ntohl(transport->tcp_xid)); |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1019 | dprintk("RPC: xprt = %p, tcp_copied = %lu, " |
| 1020 | "tcp_offset = %u, tcp_reclen = %u\n", |
| 1021 | xprt, transport->tcp_copied, |
| 1022 | transport->tcp_offset, transport->tcp_reclen); |
Ricardo Labiaga | 44b98ef | 2009-04-01 09:23:02 -0400 | [diff] [blame] | 1023 | return; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1024 | } |
| 1025 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1026 | dprintk("RPC: XID %08x read %Zd bytes\n", |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 1027 | ntohl(transport->tcp_xid), r); |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1028 | dprintk("RPC: xprt = %p, tcp_copied = %lu, tcp_offset = %u, " |
| 1029 | "tcp_reclen = %u\n", xprt, transport->tcp_copied, |
| 1030 | transport->tcp_offset, transport->tcp_reclen); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1031 | |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 1032 | if (transport->tcp_copied == req->rq_private_buf.buflen) |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 1033 | transport->tcp_flags &= ~TCP_RCV_COPY_DATA; |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 1034 | else if (transport->tcp_offset == transport->tcp_reclen) { |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 1035 | if (transport->tcp_flags & TCP_RCV_LAST_FRAG) |
| 1036 | transport->tcp_flags &= ~TCP_RCV_COPY_DATA; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1037 | } |
Ricardo Labiaga | 44b98ef | 2009-04-01 09:23:02 -0400 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | /* |
| 1041 | * Finds the request corresponding to the RPC xid and invokes the common |
| 1042 | * tcp read code to read the data. |
| 1043 | */ |
| 1044 | static inline int xs_tcp_read_reply(struct rpc_xprt *xprt, |
| 1045 | struct xdr_skb_reader *desc) |
| 1046 | { |
| 1047 | struct sock_xprt *transport = |
| 1048 | container_of(xprt, struct sock_xprt, xprt); |
| 1049 | struct rpc_rqst *req; |
| 1050 | |
| 1051 | dprintk("RPC: read reply XID %08x\n", ntohl(transport->tcp_xid)); |
| 1052 | |
| 1053 | /* Find and lock the request corresponding to this xid */ |
| 1054 | spin_lock(&xprt->transport_lock); |
| 1055 | req = xprt_lookup_rqst(xprt, transport->tcp_xid); |
| 1056 | if (!req) { |
| 1057 | dprintk("RPC: XID %08x request not found!\n", |
| 1058 | ntohl(transport->tcp_xid)); |
| 1059 | spin_unlock(&xprt->transport_lock); |
| 1060 | return -1; |
| 1061 | } |
| 1062 | |
| 1063 | xs_tcp_read_common(xprt, desc, req); |
| 1064 | |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 1065 | if (!(transport->tcp_flags & TCP_RCV_COPY_DATA)) |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 1066 | xprt_complete_rqst(req->rq_task, transport->tcp_copied); |
Ricardo Labiaga | 44b98ef | 2009-04-01 09:23:02 -0400 | [diff] [blame] | 1067 | |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 1068 | spin_unlock(&xprt->transport_lock); |
Ricardo Labiaga | 44b98ef | 2009-04-01 09:23:02 -0400 | [diff] [blame] | 1069 | return 0; |
| 1070 | } |
| 1071 | |
| 1072 | #if defined(CONFIG_NFS_V4_1) |
| 1073 | /* |
| 1074 | * Obtains an rpc_rqst previously allocated and invokes the common |
| 1075 | * tcp read code to read the data. The result is placed in the callback |
| 1076 | * queue. |
| 1077 | * If we're unable to obtain the rpc_rqst we schedule the closing of the |
| 1078 | * connection and return -1. |
| 1079 | */ |
| 1080 | static inline int xs_tcp_read_callback(struct rpc_xprt *xprt, |
| 1081 | struct xdr_skb_reader *desc) |
| 1082 | { |
| 1083 | struct sock_xprt *transport = |
| 1084 | container_of(xprt, struct sock_xprt, xprt); |
| 1085 | struct rpc_rqst *req; |
| 1086 | |
| 1087 | req = xprt_alloc_bc_request(xprt); |
| 1088 | if (req == NULL) { |
| 1089 | printk(KERN_WARNING "Callback slot table overflowed\n"); |
| 1090 | xprt_force_disconnect(xprt); |
| 1091 | return -1; |
| 1092 | } |
| 1093 | |
| 1094 | req->rq_xid = transport->tcp_xid; |
| 1095 | dprintk("RPC: read callback XID %08x\n", ntohl(req->rq_xid)); |
| 1096 | xs_tcp_read_common(xprt, desc, req); |
| 1097 | |
| 1098 | if (!(transport->tcp_flags & TCP_RCV_COPY_DATA)) { |
| 1099 | struct svc_serv *bc_serv = xprt->bc_serv; |
| 1100 | |
| 1101 | /* |
| 1102 | * Add callback request to callback list. The callback |
| 1103 | * service sleeps on the sv_cb_waitq waiting for new |
| 1104 | * requests. Wake it up after adding enqueing the |
| 1105 | * request. |
| 1106 | */ |
| 1107 | dprintk("RPC: add callback request to list\n"); |
| 1108 | spin_lock(&bc_serv->sv_cb_lock); |
| 1109 | list_add(&req->rq_bc_list, &bc_serv->sv_cb_list); |
| 1110 | spin_unlock(&bc_serv->sv_cb_lock); |
| 1111 | wake_up(&bc_serv->sv_cb_waitq); |
| 1112 | } |
| 1113 | |
| 1114 | req->rq_private_buf.len = transport->tcp_copied; |
| 1115 | |
| 1116 | return 0; |
| 1117 | } |
| 1118 | |
| 1119 | static inline int _xs_tcp_read_data(struct rpc_xprt *xprt, |
| 1120 | struct xdr_skb_reader *desc) |
| 1121 | { |
| 1122 | struct sock_xprt *transport = |
| 1123 | container_of(xprt, struct sock_xprt, xprt); |
| 1124 | |
| 1125 | return (transport->tcp_flags & TCP_RPC_REPLY) ? |
| 1126 | xs_tcp_read_reply(xprt, desc) : |
| 1127 | xs_tcp_read_callback(xprt, desc); |
| 1128 | } |
| 1129 | #else |
| 1130 | static inline int _xs_tcp_read_data(struct rpc_xprt *xprt, |
| 1131 | struct xdr_skb_reader *desc) |
| 1132 | { |
| 1133 | return xs_tcp_read_reply(xprt, desc); |
| 1134 | } |
| 1135 | #endif /* CONFIG_NFS_V4_1 */ |
| 1136 | |
| 1137 | /* |
| 1138 | * Read data off the transport. This can be either an RPC_CALL or an |
| 1139 | * RPC_REPLY. Relay the processing to helper functions. |
| 1140 | */ |
| 1141 | static void xs_tcp_read_data(struct rpc_xprt *xprt, |
| 1142 | struct xdr_skb_reader *desc) |
| 1143 | { |
| 1144 | struct sock_xprt *transport = |
| 1145 | container_of(xprt, struct sock_xprt, xprt); |
| 1146 | |
| 1147 | if (_xs_tcp_read_data(xprt, desc) == 0) |
| 1148 | xs_tcp_check_fraghdr(transport); |
| 1149 | else { |
| 1150 | /* |
| 1151 | * The transport_lock protects the request handling. |
| 1152 | * There's no need to hold it to update the tcp_flags. |
| 1153 | */ |
| 1154 | transport->tcp_flags &= ~TCP_RCV_COPY_DATA; |
| 1155 | } |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1156 | } |
| 1157 | |
Chuck Lever | dd45647 | 2006-12-05 16:35:44 -0500 | [diff] [blame] | 1158 | static inline void xs_tcp_read_discard(struct sock_xprt *transport, struct xdr_skb_reader *desc) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1159 | { |
| 1160 | size_t len; |
| 1161 | |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 1162 | len = transport->tcp_reclen - transport->tcp_offset; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1163 | if (len > desc->count) |
| 1164 | len = desc->count; |
| 1165 | desc->count -= len; |
| 1166 | desc->offset += len; |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 1167 | transport->tcp_offset += len; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1168 | dprintk("RPC: discarded %Zu bytes\n", len); |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 1169 | xs_tcp_check_fraghdr(transport); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1170 | } |
| 1171 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1172 | static int xs_tcp_data_recv(read_descriptor_t *rd_desc, struct sk_buff *skb, unsigned int offset, size_t len) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1173 | { |
| 1174 | struct rpc_xprt *xprt = rd_desc->arg.data; |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 1175 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
Chuck Lever | dd45647 | 2006-12-05 16:35:44 -0500 | [diff] [blame] | 1176 | struct xdr_skb_reader desc = { |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1177 | .skb = skb, |
| 1178 | .offset = offset, |
| 1179 | .count = len, |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1180 | }; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1181 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1182 | dprintk("RPC: xs_tcp_data_recv started\n"); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1183 | do { |
| 1184 | /* Read in a new fragment marker if necessary */ |
| 1185 | /* Can we ever really expect to get completely empty fragments? */ |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 1186 | if (transport->tcp_flags & TCP_RCV_COPY_FRAGHDR) { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1187 | xs_tcp_read_fraghdr(xprt, &desc); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1188 | continue; |
| 1189 | } |
| 1190 | /* Read in the xid if necessary */ |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 1191 | if (transport->tcp_flags & TCP_RCV_COPY_XID) { |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 1192 | xs_tcp_read_xid(transport, &desc); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1193 | continue; |
| 1194 | } |
Ricardo Labiaga | 18dca02 | 2009-04-01 09:22:53 -0400 | [diff] [blame] | 1195 | /* Read in the call/reply flag */ |
Ricardo Labiaga | f4a2e41 | 2009-04-01 09:22:54 -0400 | [diff] [blame] | 1196 | if (transport->tcp_flags & TCP_RCV_READ_CALLDIR) { |
Ricardo Labiaga | 18dca02 | 2009-04-01 09:22:53 -0400 | [diff] [blame] | 1197 | xs_tcp_read_calldir(transport, &desc); |
| 1198 | continue; |
| 1199 | } |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1200 | /* Read in the request data */ |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 1201 | if (transport->tcp_flags & TCP_RCV_COPY_DATA) { |
Ricardo Labiaga | 44b98ef | 2009-04-01 09:23:02 -0400 | [diff] [blame] | 1202 | xs_tcp_read_data(xprt, &desc); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1203 | continue; |
| 1204 | } |
| 1205 | /* Skip over any trailing bytes on short reads */ |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 1206 | xs_tcp_read_discard(transport, &desc); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1207 | } while (desc.count); |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1208 | dprintk("RPC: xs_tcp_data_recv done\n"); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1209 | return len - desc.count; |
| 1210 | } |
| 1211 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1212 | /** |
| 1213 | * xs_tcp_data_ready - "data ready" callback for TCP sockets |
| 1214 | * @sk: socket with data to read |
| 1215 | * @bytes: how much data to read |
| 1216 | * |
| 1217 | */ |
| 1218 | static void xs_tcp_data_ready(struct sock *sk, int bytes) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1219 | { |
| 1220 | struct rpc_xprt *xprt; |
| 1221 | read_descriptor_t rd_desc; |
Trond Myklebust | ff2d7db | 2008-02-25 21:40:51 -0800 | [diff] [blame] | 1222 | int read; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1223 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1224 | dprintk("RPC: xs_tcp_data_ready...\n"); |
| 1225 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1226 | read_lock(&sk->sk_callback_lock); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1227 | if (!(xprt = xprt_from_sock(sk))) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1228 | goto out; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1229 | if (xprt->shutdown) |
| 1230 | goto out; |
| 1231 | |
Neil Brown | 61d0a8e | 2009-09-23 14:36:37 -0400 | [diff] [blame] | 1232 | /* Any data means we had a useful conversation, so |
| 1233 | * the we don't need to delay the next reconnect |
| 1234 | */ |
| 1235 | if (xprt->reestablish_timeout) |
| 1236 | xprt->reestablish_timeout = 0; |
| 1237 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1238 | /* We use rd_desc to pass struct xprt to xs_tcp_data_recv */ |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1239 | rd_desc.arg.data = xprt; |
Trond Myklebust | ff2d7db | 2008-02-25 21:40:51 -0800 | [diff] [blame] | 1240 | do { |
| 1241 | rd_desc.count = 65536; |
| 1242 | read = tcp_read_sock(sk, &rd_desc, xs_tcp_data_recv); |
| 1243 | } while (read > 0); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1244 | out: |
| 1245 | read_unlock(&sk->sk_callback_lock); |
| 1246 | } |
| 1247 | |
Trond Myklebust | 7d1e825 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 1248 | /* |
| 1249 | * Do the equivalent of linger/linger2 handling for dealing with |
| 1250 | * broken servers that don't close the socket in a timely |
| 1251 | * fashion |
| 1252 | */ |
| 1253 | static void xs_tcp_schedule_linger_timeout(struct rpc_xprt *xprt, |
| 1254 | unsigned long timeout) |
| 1255 | { |
| 1256 | struct sock_xprt *transport; |
| 1257 | |
| 1258 | if (xprt_test_and_set_connecting(xprt)) |
| 1259 | return; |
| 1260 | set_bit(XPRT_CONNECTION_ABORT, &xprt->state); |
| 1261 | transport = container_of(xprt, struct sock_xprt, xprt); |
| 1262 | queue_delayed_work(rpciod_workqueue, &transport->connect_worker, |
| 1263 | timeout); |
| 1264 | } |
| 1265 | |
| 1266 | static void xs_tcp_cancel_linger_timeout(struct rpc_xprt *xprt) |
| 1267 | { |
| 1268 | struct sock_xprt *transport; |
| 1269 | |
| 1270 | transport = container_of(xprt, struct sock_xprt, xprt); |
| 1271 | |
| 1272 | if (!test_bit(XPRT_CONNECTION_ABORT, &xprt->state) || |
| 1273 | !cancel_delayed_work(&transport->connect_worker)) |
| 1274 | return; |
| 1275 | clear_bit(XPRT_CONNECTION_ABORT, &xprt->state); |
| 1276 | xprt_clear_connecting(xprt); |
| 1277 | } |
| 1278 | |
| 1279 | static void xs_sock_mark_closed(struct rpc_xprt *xprt) |
| 1280 | { |
| 1281 | smp_mb__before_clear_bit(); |
| 1282 | clear_bit(XPRT_CLOSE_WAIT, &xprt->state); |
| 1283 | clear_bit(XPRT_CLOSING, &xprt->state); |
| 1284 | smp_mb__after_clear_bit(); |
| 1285 | /* Mark transport as closed and wake up all pending tasks */ |
| 1286 | xprt_disconnect_done(xprt); |
| 1287 | } |
| 1288 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1289 | /** |
| 1290 | * xs_tcp_state_change - callback to handle TCP socket state changes |
| 1291 | * @sk: socket whose state has changed |
| 1292 | * |
| 1293 | */ |
| 1294 | static void xs_tcp_state_change(struct sock *sk) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1295 | { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1296 | struct rpc_xprt *xprt; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1297 | |
| 1298 | read_lock(&sk->sk_callback_lock); |
| 1299 | if (!(xprt = xprt_from_sock(sk))) |
| 1300 | goto out; |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1301 | dprintk("RPC: xs_tcp_state_change client %p...\n", xprt); |
| 1302 | dprintk("RPC: state %x conn %d dead %d zapped %d\n", |
| 1303 | sk->sk_state, xprt_connected(xprt), |
| 1304 | sock_flag(sk, SOCK_DEAD), |
| 1305 | sock_flag(sk, SOCK_ZAPPED)); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1306 | |
| 1307 | switch (sk->sk_state) { |
| 1308 | case TCP_ESTABLISHED: |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 1309 | spin_lock_bh(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1310 | if (!xprt_test_and_set_connected(xprt)) { |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 1311 | struct sock_xprt *transport = container_of(xprt, |
| 1312 | struct sock_xprt, xprt); |
| 1313 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1314 | /* Reset TCP record info */ |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 1315 | transport->tcp_offset = 0; |
| 1316 | transport->tcp_reclen = 0; |
| 1317 | transport->tcp_copied = 0; |
Chuck Lever | e136d09 | 2006-12-05 16:35:23 -0500 | [diff] [blame] | 1318 | transport->tcp_flags = |
| 1319 | TCP_RCV_COPY_FRAGHDR | TCP_RCV_COPY_XID; |
Chuck Lever | 5197113 | 2006-12-05 16:35:19 -0500 | [diff] [blame] | 1320 | |
Trond Myklebust | 2a49199 | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 1321 | xprt_wake_pending_tasks(xprt, -EAGAIN); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1322 | } |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 1323 | spin_unlock_bh(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1324 | break; |
Trond Myklebust | 3b948ae | 2007-11-05 17:42:39 -0500 | [diff] [blame] | 1325 | case TCP_FIN_WAIT1: |
| 1326 | /* The client initiated a shutdown of the socket */ |
Trond Myklebust | 7c1d71c | 2008-04-17 16:52:57 -0400 | [diff] [blame] | 1327 | xprt->connect_cookie++; |
Trond Myklebust | 663b885 | 2008-01-01 18:42:12 -0500 | [diff] [blame] | 1328 | xprt->reestablish_timeout = 0; |
Trond Myklebust | 3b948ae | 2007-11-05 17:42:39 -0500 | [diff] [blame] | 1329 | set_bit(XPRT_CLOSING, &xprt->state); |
| 1330 | smp_mb__before_clear_bit(); |
| 1331 | clear_bit(XPRT_CONNECTED, &xprt->state); |
Trond Myklebust | ef80367 | 2007-12-31 16:19:17 -0500 | [diff] [blame] | 1332 | clear_bit(XPRT_CLOSE_WAIT, &xprt->state); |
Trond Myklebust | 3b948ae | 2007-11-05 17:42:39 -0500 | [diff] [blame] | 1333 | smp_mb__after_clear_bit(); |
Trond Myklebust | 25fe614 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 1334 | xs_tcp_schedule_linger_timeout(xprt, xs_tcp_fin_timeout); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1335 | break; |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 1336 | case TCP_CLOSE_WAIT: |
Trond Myklebust | 3b948ae | 2007-11-05 17:42:39 -0500 | [diff] [blame] | 1337 | /* The server initiated a shutdown of the socket */ |
Trond Myklebust | 66af1e5 | 2007-11-06 10:18:36 -0500 | [diff] [blame] | 1338 | xprt_force_disconnect(xprt); |
Trond Myklebust | 663b885 | 2008-01-01 18:42:12 -0500 | [diff] [blame] | 1339 | case TCP_SYN_SENT: |
Trond Myklebust | 7c1d71c | 2008-04-17 16:52:57 -0400 | [diff] [blame] | 1340 | xprt->connect_cookie++; |
Trond Myklebust | 663b885 | 2008-01-01 18:42:12 -0500 | [diff] [blame] | 1341 | case TCP_CLOSING: |
| 1342 | /* |
| 1343 | * If the server closed down the connection, make sure that |
| 1344 | * we back off before reconnecting |
| 1345 | */ |
| 1346 | if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO) |
| 1347 | xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO; |
Trond Myklebust | 3b948ae | 2007-11-05 17:42:39 -0500 | [diff] [blame] | 1348 | break; |
| 1349 | case TCP_LAST_ACK: |
Trond Myklebust | 670f945 | 2009-03-11 14:37:58 -0400 | [diff] [blame] | 1350 | set_bit(XPRT_CLOSING, &xprt->state); |
Trond Myklebust | 25fe614 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 1351 | xs_tcp_schedule_linger_timeout(xprt, xs_tcp_fin_timeout); |
Trond Myklebust | 3b948ae | 2007-11-05 17:42:39 -0500 | [diff] [blame] | 1352 | smp_mb__before_clear_bit(); |
| 1353 | clear_bit(XPRT_CONNECTED, &xprt->state); |
| 1354 | smp_mb__after_clear_bit(); |
| 1355 | break; |
| 1356 | case TCP_CLOSE: |
Trond Myklebust | 7d1e825 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 1357 | xs_tcp_cancel_linger_timeout(xprt); |
| 1358 | xs_sock_mark_closed(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1359 | } |
| 1360 | out: |
| 1361 | read_unlock(&sk->sk_callback_lock); |
| 1362 | } |
| 1363 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1364 | /** |
Trond Myklebust | 482f32e | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 1365 | * xs_error_report - callback mainly for catching socket errors |
Trond Myklebust | 2a9e1cf | 2008-10-28 15:21:39 -0400 | [diff] [blame] | 1366 | * @sk: socket |
| 1367 | */ |
Trond Myklebust | 482f32e | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 1368 | static void xs_error_report(struct sock *sk) |
Trond Myklebust | 2a9e1cf | 2008-10-28 15:21:39 -0400 | [diff] [blame] | 1369 | { |
| 1370 | struct rpc_xprt *xprt; |
| 1371 | |
| 1372 | read_lock(&sk->sk_callback_lock); |
Trond Myklebust | 2a9e1cf | 2008-10-28 15:21:39 -0400 | [diff] [blame] | 1373 | if (!(xprt = xprt_from_sock(sk))) |
| 1374 | goto out; |
| 1375 | dprintk("RPC: %s client %p...\n" |
| 1376 | "RPC: error %d\n", |
| 1377 | __func__, xprt, sk->sk_err); |
Trond Myklebust | 482f32e | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 1378 | xprt_wake_pending_tasks(xprt, -EAGAIN); |
Trond Myklebust | 2a9e1cf | 2008-10-28 15:21:39 -0400 | [diff] [blame] | 1379 | out: |
| 1380 | read_unlock(&sk->sk_callback_lock); |
| 1381 | } |
| 1382 | |
Ilpo Järvinen | 1f0fa15 | 2009-02-06 23:48:33 -0800 | [diff] [blame] | 1383 | static void xs_write_space(struct sock *sk) |
| 1384 | { |
| 1385 | struct socket *sock; |
| 1386 | struct rpc_xprt *xprt; |
| 1387 | |
| 1388 | if (unlikely(!(sock = sk->sk_socket))) |
| 1389 | return; |
| 1390 | clear_bit(SOCK_NOSPACE, &sock->flags); |
| 1391 | |
| 1392 | if (unlikely(!(xprt = xprt_from_sock(sk)))) |
| 1393 | return; |
| 1394 | if (test_and_clear_bit(SOCK_ASYNC_NOSPACE, &sock->flags) == 0) |
| 1395 | return; |
| 1396 | |
| 1397 | xprt_write_space(xprt); |
| 1398 | } |
| 1399 | |
Trond Myklebust | 2a9e1cf | 2008-10-28 15:21:39 -0400 | [diff] [blame] | 1400 | /** |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 1401 | * xs_udp_write_space - callback invoked when socket buffer space |
| 1402 | * becomes available |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1403 | * @sk: socket whose state has changed |
| 1404 | * |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1405 | * Called when more output buffer space is available for this socket. |
| 1406 | * We try not to wake our writers until they can make "significant" |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 1407 | * progress, otherwise we'll waste resources thrashing kernel_sendmsg |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1408 | * with a bunch of small requests. |
| 1409 | */ |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 1410 | static void xs_udp_write_space(struct sock *sk) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1411 | { |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1412 | read_lock(&sk->sk_callback_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1413 | |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 1414 | /* from net/core/sock.c:sock_def_write_space */ |
Ilpo Järvinen | 1f0fa15 | 2009-02-06 23:48:33 -0800 | [diff] [blame] | 1415 | if (sock_writeable(sk)) |
| 1416 | xs_write_space(sk); |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 1417 | |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 1418 | read_unlock(&sk->sk_callback_lock); |
| 1419 | } |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1420 | |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 1421 | /** |
| 1422 | * xs_tcp_write_space - callback invoked when socket buffer space |
| 1423 | * becomes available |
| 1424 | * @sk: socket whose state has changed |
| 1425 | * |
| 1426 | * Called when more output buffer space is available for this socket. |
| 1427 | * We try not to wake our writers until they can make "significant" |
| 1428 | * progress, otherwise we'll waste resources thrashing kernel_sendmsg |
| 1429 | * with a bunch of small requests. |
| 1430 | */ |
| 1431 | static void xs_tcp_write_space(struct sock *sk) |
| 1432 | { |
| 1433 | read_lock(&sk->sk_callback_lock); |
| 1434 | |
| 1435 | /* from net/core/stream.c:sk_stream_write_space */ |
Ilpo Järvinen | 1f0fa15 | 2009-02-06 23:48:33 -0800 | [diff] [blame] | 1436 | if (sk_stream_wspace(sk) >= sk_stream_min_wspace(sk)) |
| 1437 | xs_write_space(sk); |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 1438 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1439 | read_unlock(&sk->sk_callback_lock); |
| 1440 | } |
| 1441 | |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 1442 | static void xs_udp_do_set_buffer_size(struct rpc_xprt *xprt) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1443 | { |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 1444 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
| 1445 | struct sock *sk = transport->inet; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1446 | |
Chuck Lever | 7c6e066 | 2006-12-05 16:35:30 -0500 | [diff] [blame] | 1447 | if (transport->rcvsize) { |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1448 | sk->sk_userlocks |= SOCK_RCVBUF_LOCK; |
Chuck Lever | 7c6e066 | 2006-12-05 16:35:30 -0500 | [diff] [blame] | 1449 | sk->sk_rcvbuf = transport->rcvsize * xprt->max_reqs * 2; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1450 | } |
Chuck Lever | 7c6e066 | 2006-12-05 16:35:30 -0500 | [diff] [blame] | 1451 | if (transport->sndsize) { |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1452 | sk->sk_userlocks |= SOCK_SNDBUF_LOCK; |
Chuck Lever | 7c6e066 | 2006-12-05 16:35:30 -0500 | [diff] [blame] | 1453 | sk->sk_sndbuf = transport->sndsize * xprt->max_reqs * 2; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1454 | sk->sk_write_space(sk); |
| 1455 | } |
| 1456 | } |
| 1457 | |
Chuck Lever | 43118c2 | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 1458 | /** |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 1459 | * xs_udp_set_buffer_size - set send and receive limits |
Chuck Lever | 43118c2 | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 1460 | * @xprt: generic transport |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 1461 | * @sndsize: requested size of send buffer, in bytes |
| 1462 | * @rcvsize: requested size of receive buffer, in bytes |
Chuck Lever | 43118c2 | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 1463 | * |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 1464 | * Set socket send and receive buffer size limits. |
Chuck Lever | 43118c2 | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 1465 | */ |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 1466 | static void xs_udp_set_buffer_size(struct rpc_xprt *xprt, size_t sndsize, size_t rcvsize) |
Chuck Lever | 43118c2 | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 1467 | { |
Chuck Lever | 7c6e066 | 2006-12-05 16:35:30 -0500 | [diff] [blame] | 1468 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
| 1469 | |
| 1470 | transport->sndsize = 0; |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 1471 | if (sndsize) |
Chuck Lever | 7c6e066 | 2006-12-05 16:35:30 -0500 | [diff] [blame] | 1472 | transport->sndsize = sndsize + 1024; |
| 1473 | transport->rcvsize = 0; |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 1474 | if (rcvsize) |
Chuck Lever | 7c6e066 | 2006-12-05 16:35:30 -0500 | [diff] [blame] | 1475 | transport->rcvsize = rcvsize + 1024; |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 1476 | |
| 1477 | xs_udp_do_set_buffer_size(xprt); |
Chuck Lever | 43118c2 | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 1478 | } |
| 1479 | |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 1480 | /** |
| 1481 | * xs_udp_timer - called when a retransmit timeout occurs on a UDP transport |
| 1482 | * @task: task that timed out |
| 1483 | * |
| 1484 | * Adjust the congestion window after a retransmit timeout has occurred. |
| 1485 | */ |
| 1486 | static void xs_udp_timer(struct rpc_task *task) |
| 1487 | { |
| 1488 | xprt_adjust_cwnd(task, -ETIMEDOUT); |
| 1489 | } |
| 1490 | |
Chuck Lever | b85d880 | 2006-05-25 01:40:49 -0400 | [diff] [blame] | 1491 | static unsigned short xs_get_random_port(void) |
| 1492 | { |
| 1493 | unsigned short range = xprt_max_resvport - xprt_min_resvport; |
| 1494 | unsigned short rand = (unsigned short) net_random() % range; |
| 1495 | return rand + xprt_min_resvport; |
| 1496 | } |
| 1497 | |
Chuck Lever | 9220041 | 2006-01-03 09:55:51 +0100 | [diff] [blame] | 1498 | /** |
| 1499 | * xs_set_port - reset the port number in the remote endpoint address |
| 1500 | * @xprt: generic transport |
| 1501 | * @port: new port number |
| 1502 | * |
| 1503 | */ |
| 1504 | static void xs_set_port(struct rpc_xprt *xprt, unsigned short port) |
| 1505 | { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1506 | dprintk("RPC: setting port for xprt %p to %u\n", xprt, port); |
Chuck Lever | c4efcb1 | 2006-08-22 20:06:19 -0400 | [diff] [blame] | 1507 | |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 1508 | rpc_set_port(xs_addr(xprt), port); |
| 1509 | xs_update_peer_port(xprt); |
Chuck Lever | 9220041 | 2006-01-03 09:55:51 +0100 | [diff] [blame] | 1510 | } |
| 1511 | |
Trond Myklebust | 67a391d | 2007-11-05 17:40:58 -0500 | [diff] [blame] | 1512 | static unsigned short xs_get_srcport(struct sock_xprt *transport, struct socket *sock) |
| 1513 | { |
Chuck Lever | fbfffbd | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 1514 | unsigned short port = transport->srcport; |
Trond Myklebust | 67a391d | 2007-11-05 17:40:58 -0500 | [diff] [blame] | 1515 | |
| 1516 | if (port == 0 && transport->xprt.resvport) |
| 1517 | port = xs_get_random_port(); |
| 1518 | return port; |
| 1519 | } |
| 1520 | |
| 1521 | static unsigned short xs_next_srcport(struct sock_xprt *transport, struct socket *sock, unsigned short port) |
| 1522 | { |
Chuck Lever | fbfffbd | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 1523 | if (transport->srcport != 0) |
| 1524 | transport->srcport = 0; |
Trond Myklebust | 67a391d | 2007-11-05 17:40:58 -0500 | [diff] [blame] | 1525 | if (!transport->xprt.resvport) |
| 1526 | return 0; |
| 1527 | if (port <= xprt_min_resvport || port > xprt_max_resvport) |
| 1528 | return xprt_max_resvport; |
| 1529 | return --port; |
| 1530 | } |
| 1531 | |
Chuck Lever | 7dc753f | 2007-08-06 11:57:28 -0400 | [diff] [blame] | 1532 | static int xs_bind4(struct sock_xprt *transport, struct socket *sock) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1533 | { |
| 1534 | struct sockaddr_in myaddr = { |
| 1535 | .sin_family = AF_INET, |
| 1536 | }; |
Frank van Maarseveen | d3bc9a1 | 2007-07-09 22:23:35 +0200 | [diff] [blame] | 1537 | struct sockaddr_in *sa; |
Trond Myklebust | 67a391d | 2007-11-05 17:40:58 -0500 | [diff] [blame] | 1538 | int err, nloop = 0; |
| 1539 | unsigned short port = xs_get_srcport(transport, sock); |
| 1540 | unsigned short last; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1541 | |
Chuck Lever | fbfffbd | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 1542 | sa = (struct sockaddr_in *)&transport->srcaddr; |
Frank van Maarseveen | d3bc9a1 | 2007-07-09 22:23:35 +0200 | [diff] [blame] | 1543 | myaddr.sin_addr = sa->sin_addr; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1544 | do { |
| 1545 | myaddr.sin_port = htons(port); |
Sridhar Samudrala | e6242e9 | 2006-08-07 20:58:01 -0700 | [diff] [blame] | 1546 | err = kernel_bind(sock, (struct sockaddr *) &myaddr, |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1547 | sizeof(myaddr)); |
Trond Myklebust | 67a391d | 2007-11-05 17:40:58 -0500 | [diff] [blame] | 1548 | if (port == 0) |
Frank van Maarseveen | d3bc9a1 | 2007-07-09 22:23:35 +0200 | [diff] [blame] | 1549 | break; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1550 | if (err == 0) { |
Chuck Lever | fbfffbd | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 1551 | transport->srcport = port; |
Frank van Maarseveen | d3bc9a1 | 2007-07-09 22:23:35 +0200 | [diff] [blame] | 1552 | break; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1553 | } |
Trond Myklebust | 67a391d | 2007-11-05 17:40:58 -0500 | [diff] [blame] | 1554 | last = port; |
| 1555 | port = xs_next_srcport(transport, sock, port); |
| 1556 | if (port > last) |
| 1557 | nloop++; |
| 1558 | } while (err == -EADDRINUSE && nloop != 2); |
Harvey Harrison | 21454aa | 2008-10-31 00:54:56 -0700 | [diff] [blame] | 1559 | dprintk("RPC: %s %pI4:%u: %s (%d)\n", |
| 1560 | __func__, &myaddr.sin_addr, |
Chuck Lever | 7dc753f | 2007-08-06 11:57:28 -0400 | [diff] [blame] | 1561 | port, err ? "failed" : "ok", err); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1562 | return err; |
| 1563 | } |
| 1564 | |
Chuck Lever | 90058d3 | 2007-08-06 11:57:33 -0400 | [diff] [blame] | 1565 | static int xs_bind6(struct sock_xprt *transport, struct socket *sock) |
| 1566 | { |
| 1567 | struct sockaddr_in6 myaddr = { |
| 1568 | .sin6_family = AF_INET6, |
| 1569 | }; |
| 1570 | struct sockaddr_in6 *sa; |
Trond Myklebust | 67a391d | 2007-11-05 17:40:58 -0500 | [diff] [blame] | 1571 | int err, nloop = 0; |
| 1572 | unsigned short port = xs_get_srcport(transport, sock); |
| 1573 | unsigned short last; |
Chuck Lever | 90058d3 | 2007-08-06 11:57:33 -0400 | [diff] [blame] | 1574 | |
Chuck Lever | fbfffbd | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 1575 | sa = (struct sockaddr_in6 *)&transport->srcaddr; |
Chuck Lever | 90058d3 | 2007-08-06 11:57:33 -0400 | [diff] [blame] | 1576 | myaddr.sin6_addr = sa->sin6_addr; |
| 1577 | do { |
| 1578 | myaddr.sin6_port = htons(port); |
| 1579 | err = kernel_bind(sock, (struct sockaddr *) &myaddr, |
| 1580 | sizeof(myaddr)); |
Trond Myklebust | 67a391d | 2007-11-05 17:40:58 -0500 | [diff] [blame] | 1581 | if (port == 0) |
Chuck Lever | 90058d3 | 2007-08-06 11:57:33 -0400 | [diff] [blame] | 1582 | break; |
| 1583 | if (err == 0) { |
Chuck Lever | fbfffbd | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 1584 | transport->srcport = port; |
Chuck Lever | 90058d3 | 2007-08-06 11:57:33 -0400 | [diff] [blame] | 1585 | break; |
| 1586 | } |
Trond Myklebust | 67a391d | 2007-11-05 17:40:58 -0500 | [diff] [blame] | 1587 | last = port; |
| 1588 | port = xs_next_srcport(transport, sock, port); |
| 1589 | if (port > last) |
| 1590 | nloop++; |
| 1591 | } while (err == -EADDRINUSE && nloop != 2); |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 1592 | dprintk("RPC: xs_bind6 %pI6:%u: %s (%d)\n", |
Harvey Harrison | fdb46ee | 2008-10-28 16:10:17 -0700 | [diff] [blame] | 1593 | &myaddr.sin6_addr, port, err ? "failed" : "ok", err); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1594 | return err; |
| 1595 | } |
| 1596 | |
Peter Zijlstra | ed07536 | 2006-12-06 20:35:24 -0800 | [diff] [blame] | 1597 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 1598 | static struct lock_class_key xs_key[2]; |
| 1599 | static struct lock_class_key xs_slock_key[2]; |
| 1600 | |
Chuck Lever | 8945ee5 | 2007-08-06 11:58:04 -0400 | [diff] [blame] | 1601 | static inline void xs_reclassify_socket4(struct socket *sock) |
Peter Zijlstra | ed07536 | 2006-12-06 20:35:24 -0800 | [diff] [blame] | 1602 | { |
| 1603 | struct sock *sk = sock->sk; |
Chuck Lever | 8945ee5 | 2007-08-06 11:58:04 -0400 | [diff] [blame] | 1604 | |
John Heffner | 02b3d34 | 2007-09-12 10:42:12 +0200 | [diff] [blame] | 1605 | BUG_ON(sock_owned_by_user(sk)); |
Chuck Lever | 8945ee5 | 2007-08-06 11:58:04 -0400 | [diff] [blame] | 1606 | sock_lock_init_class_and_name(sk, "slock-AF_INET-RPC", |
| 1607 | &xs_slock_key[0], "sk_lock-AF_INET-RPC", &xs_key[0]); |
| 1608 | } |
Peter Zijlstra | ed07536 | 2006-12-06 20:35:24 -0800 | [diff] [blame] | 1609 | |
Chuck Lever | 8945ee5 | 2007-08-06 11:58:04 -0400 | [diff] [blame] | 1610 | static inline void xs_reclassify_socket6(struct socket *sock) |
| 1611 | { |
| 1612 | struct sock *sk = sock->sk; |
Peter Zijlstra | ed07536 | 2006-12-06 20:35:24 -0800 | [diff] [blame] | 1613 | |
Linus Torvalds | f4921af | 2007-10-15 10:46:05 -0700 | [diff] [blame] | 1614 | BUG_ON(sock_owned_by_user(sk)); |
Chuck Lever | 8945ee5 | 2007-08-06 11:58:04 -0400 | [diff] [blame] | 1615 | sock_lock_init_class_and_name(sk, "slock-AF_INET6-RPC", |
| 1616 | &xs_slock_key[1], "sk_lock-AF_INET6-RPC", &xs_key[1]); |
Peter Zijlstra | ed07536 | 2006-12-06 20:35:24 -0800 | [diff] [blame] | 1617 | } |
| 1618 | #else |
Chuck Lever | 8945ee5 | 2007-08-06 11:58:04 -0400 | [diff] [blame] | 1619 | static inline void xs_reclassify_socket4(struct socket *sock) |
| 1620 | { |
| 1621 | } |
| 1622 | |
| 1623 | static inline void xs_reclassify_socket6(struct socket *sock) |
Peter Zijlstra | ed07536 | 2006-12-06 20:35:24 -0800 | [diff] [blame] | 1624 | { |
| 1625 | } |
| 1626 | #endif |
| 1627 | |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1628 | static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1629 | { |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1630 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
Chuck Lever | edb267a | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 1631 | |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 1632 | if (!transport->inet) { |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1633 | struct sock *sk = sock->sk; |
| 1634 | |
| 1635 | write_lock_bh(&sk->sk_callback_lock); |
| 1636 | |
Trond Myklebust | 2a9e1cf | 2008-10-28 15:21:39 -0400 | [diff] [blame] | 1637 | xs_save_old_callbacks(transport, sk); |
| 1638 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1639 | sk->sk_user_data = xprt; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1640 | sk->sk_data_ready = xs_udp_data_ready; |
| 1641 | sk->sk_write_space = xs_udp_write_space; |
Trond Myklebust | 482f32e | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 1642 | sk->sk_error_report = xs_error_report; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1643 | sk->sk_no_check = UDP_CSUM_NORCV; |
Trond Myklebust | b079fa7b | 2005-12-13 16:13:52 -0500 | [diff] [blame] | 1644 | sk->sk_allocation = GFP_ATOMIC; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1645 | |
| 1646 | xprt_set_connected(xprt); |
| 1647 | |
| 1648 | /* Reset to new socket */ |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 1649 | transport->sock = sock; |
| 1650 | transport->inet = sk; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1651 | |
| 1652 | write_unlock_bh(&sk->sk_callback_lock); |
| 1653 | } |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 1654 | xs_udp_do_set_buffer_size(xprt); |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1655 | } |
| 1656 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1657 | /** |
Chuck Lever | 9c3d72d | 2007-08-06 11:57:43 -0400 | [diff] [blame] | 1658 | * xs_udp_connect_worker4 - set up a UDP socket |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1659 | * @work: RPC transport to connect |
| 1660 | * |
| 1661 | * Invoked by a work queue tasklet. |
| 1662 | */ |
Chuck Lever | 9c3d72d | 2007-08-06 11:57:43 -0400 | [diff] [blame] | 1663 | static void xs_udp_connect_worker4(struct work_struct *work) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1664 | { |
| 1665 | struct sock_xprt *transport = |
| 1666 | container_of(work, struct sock_xprt, connect_worker.work); |
| 1667 | struct rpc_xprt *xprt = &transport->xprt; |
| 1668 | struct socket *sock = transport->sock; |
| 1669 | int err, status = -EIO; |
| 1670 | |
Trond Myklebust | 01d37c4 | 2009-03-11 14:09:39 -0400 | [diff] [blame] | 1671 | if (xprt->shutdown) |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1672 | goto out; |
| 1673 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1674 | /* Start by resetting any existing state */ |
Chuck Lever | fe315e7 | 2009-03-11 14:10:21 -0400 | [diff] [blame] | 1675 | xs_reset_transport(transport); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1676 | |
Chuck Lever | fe315e7 | 2009-03-11 14:10:21 -0400 | [diff] [blame] | 1677 | err = sock_create_kern(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &sock); |
| 1678 | if (err < 0) { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1679 | dprintk("RPC: can't create UDP transport socket (%d).\n", -err); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1680 | goto out; |
| 1681 | } |
Chuck Lever | 8945ee5 | 2007-08-06 11:58:04 -0400 | [diff] [blame] | 1682 | xs_reclassify_socket4(sock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1683 | |
Chuck Lever | 7dc753f | 2007-08-06 11:57:28 -0400 | [diff] [blame] | 1684 | if (xs_bind4(transport, sock)) { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1685 | sock_release(sock); |
| 1686 | goto out; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1687 | } |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1688 | |
Chuck Lever | c740eff | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 1689 | dprintk("RPC: worker connecting xprt %p via %s to " |
| 1690 | "%s (port %s)\n", xprt, |
| 1691 | xprt->address_strings[RPC_DISPLAY_PROTO], |
| 1692 | xprt->address_strings[RPC_DISPLAY_ADDR], |
| 1693 | xprt->address_strings[RPC_DISPLAY_PORT]); |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1694 | |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1695 | xs_udp_finish_connecting(xprt, sock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1696 | status = 0; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1697 | out: |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1698 | xprt_clear_connecting(xprt); |
Trond Myklebust | 7d1e825 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 1699 | xprt_wake_pending_tasks(xprt, status); |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1700 | } |
| 1701 | |
Chuck Lever | 68e220b | 2007-08-06 11:57:48 -0400 | [diff] [blame] | 1702 | /** |
| 1703 | * xs_udp_connect_worker6 - set up a UDP socket |
| 1704 | * @work: RPC transport to connect |
| 1705 | * |
| 1706 | * Invoked by a work queue tasklet. |
| 1707 | */ |
| 1708 | static void xs_udp_connect_worker6(struct work_struct *work) |
| 1709 | { |
| 1710 | struct sock_xprt *transport = |
| 1711 | container_of(work, struct sock_xprt, connect_worker.work); |
| 1712 | struct rpc_xprt *xprt = &transport->xprt; |
| 1713 | struct socket *sock = transport->sock; |
| 1714 | int err, status = -EIO; |
| 1715 | |
Trond Myklebust | 01d37c4 | 2009-03-11 14:09:39 -0400 | [diff] [blame] | 1716 | if (xprt->shutdown) |
Chuck Lever | 68e220b | 2007-08-06 11:57:48 -0400 | [diff] [blame] | 1717 | goto out; |
| 1718 | |
| 1719 | /* Start by resetting any existing state */ |
Chuck Lever | fe315e7 | 2009-03-11 14:10:21 -0400 | [diff] [blame] | 1720 | xs_reset_transport(transport); |
Chuck Lever | 68e220b | 2007-08-06 11:57:48 -0400 | [diff] [blame] | 1721 | |
Chuck Lever | fe315e7 | 2009-03-11 14:10:21 -0400 | [diff] [blame] | 1722 | err = sock_create_kern(PF_INET6, SOCK_DGRAM, IPPROTO_UDP, &sock); |
| 1723 | if (err < 0) { |
Chuck Lever | 68e220b | 2007-08-06 11:57:48 -0400 | [diff] [blame] | 1724 | dprintk("RPC: can't create UDP transport socket (%d).\n", -err); |
| 1725 | goto out; |
| 1726 | } |
Chuck Lever | 8945ee5 | 2007-08-06 11:58:04 -0400 | [diff] [blame] | 1727 | xs_reclassify_socket6(sock); |
Chuck Lever | 68e220b | 2007-08-06 11:57:48 -0400 | [diff] [blame] | 1728 | |
| 1729 | if (xs_bind6(transport, sock) < 0) { |
| 1730 | sock_release(sock); |
| 1731 | goto out; |
| 1732 | } |
| 1733 | |
Chuck Lever | c740eff | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 1734 | dprintk("RPC: worker connecting xprt %p via %s to " |
| 1735 | "%s (port %s)\n", xprt, |
| 1736 | xprt->address_strings[RPC_DISPLAY_PROTO], |
| 1737 | xprt->address_strings[RPC_DISPLAY_ADDR], |
| 1738 | xprt->address_strings[RPC_DISPLAY_PORT]); |
Chuck Lever | 68e220b | 2007-08-06 11:57:48 -0400 | [diff] [blame] | 1739 | |
| 1740 | xs_udp_finish_connecting(xprt, sock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1741 | status = 0; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1742 | out: |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1743 | xprt_clear_connecting(xprt); |
Trond Myklebust | 7d1e825 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 1744 | xprt_wake_pending_tasks(xprt, status); |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1745 | } |
| 1746 | |
Chuck Lever | 3167e12 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1747 | /* |
| 1748 | * We need to preserve the port number so the reply cache on the server can |
| 1749 | * find our cached RPC replies when we get around to reconnecting. |
| 1750 | */ |
Trond Myklebust | 40d2549 | 2009-03-11 14:37:58 -0400 | [diff] [blame] | 1751 | static void xs_abort_connection(struct rpc_xprt *xprt, struct sock_xprt *transport) |
Chuck Lever | 3167e12 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1752 | { |
| 1753 | int result; |
Chuck Lever | 3167e12 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1754 | struct sockaddr any; |
| 1755 | |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1756 | dprintk("RPC: disconnecting xprt %p to reuse port\n", xprt); |
Chuck Lever | 3167e12 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1757 | |
| 1758 | /* |
| 1759 | * Disconnect the transport socket by doing a connect operation |
| 1760 | * with AF_UNSPEC. This should return immediately... |
| 1761 | */ |
| 1762 | memset(&any, 0, sizeof(any)); |
| 1763 | any.sa_family = AF_UNSPEC; |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 1764 | result = kernel_connect(transport->sock, &any, sizeof(any), 0); |
Trond Myklebust | 7d1e825 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 1765 | if (!result) |
| 1766 | xs_sock_mark_closed(xprt); |
| 1767 | else |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1768 | dprintk("RPC: AF_UNSPEC connect return code %d\n", |
Chuck Lever | 3167e12 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1769 | result); |
| 1770 | } |
| 1771 | |
Trond Myklebust | 40d2549 | 2009-03-11 14:37:58 -0400 | [diff] [blame] | 1772 | static void xs_tcp_reuse_connection(struct rpc_xprt *xprt, struct sock_xprt *transport) |
| 1773 | { |
| 1774 | unsigned int state = transport->inet->sk_state; |
| 1775 | |
| 1776 | if (state == TCP_CLOSE && transport->sock->state == SS_UNCONNECTED) |
| 1777 | return; |
| 1778 | if ((1 << state) & (TCPF_ESTABLISHED|TCPF_SYN_SENT)) |
| 1779 | return; |
| 1780 | xs_abort_connection(xprt, transport); |
| 1781 | } |
| 1782 | |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1783 | static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock) |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1784 | { |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1785 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
Chuck Lever | edb267a | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 1786 | |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 1787 | if (!transport->inet) { |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1788 | struct sock *sk = sock->sk; |
| 1789 | |
| 1790 | write_lock_bh(&sk->sk_callback_lock); |
| 1791 | |
Trond Myklebust | 2a9e1cf | 2008-10-28 15:21:39 -0400 | [diff] [blame] | 1792 | xs_save_old_callbacks(transport, sk); |
| 1793 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1794 | sk->sk_user_data = xprt; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1795 | sk->sk_data_ready = xs_tcp_data_ready; |
| 1796 | sk->sk_state_change = xs_tcp_state_change; |
| 1797 | sk->sk_write_space = xs_tcp_write_space; |
Trond Myklebust | 482f32e | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 1798 | sk->sk_error_report = xs_error_report; |
Trond Myklebust | b079fa7b | 2005-12-13 16:13:52 -0500 | [diff] [blame] | 1799 | sk->sk_allocation = GFP_ATOMIC; |
Chuck Lever | 3167e12 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1800 | |
| 1801 | /* socket options */ |
| 1802 | sk->sk_userlocks |= SOCK_BINDPORT_LOCK; |
| 1803 | sock_reset_flag(sk, SOCK_LINGER); |
| 1804 | tcp_sk(sk)->linger2 = 0; |
| 1805 | tcp_sk(sk)->nonagle |= TCP_NAGLE_OFF; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1806 | |
| 1807 | xprt_clear_connected(xprt); |
| 1808 | |
| 1809 | /* Reset to new socket */ |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 1810 | transport->sock = sock; |
| 1811 | transport->inet = sk; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1812 | |
| 1813 | write_unlock_bh(&sk->sk_callback_lock); |
| 1814 | } |
| 1815 | |
Trond Myklebust | 01d37c4 | 2009-03-11 14:09:39 -0400 | [diff] [blame] | 1816 | if (!xprt_bound(xprt)) |
| 1817 | return -ENOTCONN; |
| 1818 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1819 | /* Tell the socket layer to start connecting... */ |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 1820 | xprt->stat.connect_count++; |
| 1821 | xprt->stat.connect_start = jiffies; |
Chuck Lever | 95392c5 | 2007-08-06 11:57:58 -0400 | [diff] [blame] | 1822 | return kernel_connect(sock, xs_addr(xprt), xprt->addrlen, O_NONBLOCK); |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | /** |
Trond Myklebust | b61d59f | 2009-03-11 14:38:04 -0400 | [diff] [blame] | 1826 | * xs_tcp_setup_socket - create a TCP socket and connect to a remote endpoint |
| 1827 | * @xprt: RPC transport to connect |
| 1828 | * @transport: socket transport to connect |
| 1829 | * @create_sock: function to create a socket of the correct type |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1830 | * |
| 1831 | * Invoked by a work queue tasklet. |
| 1832 | */ |
Trond Myklebust | b61d59f | 2009-03-11 14:38:04 -0400 | [diff] [blame] | 1833 | static void xs_tcp_setup_socket(struct rpc_xprt *xprt, |
| 1834 | struct sock_xprt *transport, |
| 1835 | struct socket *(*create_sock)(struct rpc_xprt *, |
| 1836 | struct sock_xprt *)) |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1837 | { |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1838 | struct socket *sock = transport->sock; |
Trond Myklebust | b61d59f | 2009-03-11 14:38:04 -0400 | [diff] [blame] | 1839 | int status = -EIO; |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1840 | |
Trond Myklebust | 01d37c4 | 2009-03-11 14:09:39 -0400 | [diff] [blame] | 1841 | if (xprt->shutdown) |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1842 | goto out; |
| 1843 | |
| 1844 | if (!sock) { |
Trond Myklebust | 7d1e825 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 1845 | clear_bit(XPRT_CONNECTION_ABORT, &xprt->state); |
Trond Myklebust | b61d59f | 2009-03-11 14:38:04 -0400 | [diff] [blame] | 1846 | sock = create_sock(xprt, transport); |
| 1847 | if (IS_ERR(sock)) { |
| 1848 | status = PTR_ERR(sock); |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1849 | goto out; |
| 1850 | } |
Trond Myklebust | 7d1e825 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 1851 | } else { |
| 1852 | int abort_and_exit; |
| 1853 | |
| 1854 | abort_and_exit = test_and_clear_bit(XPRT_CONNECTION_ABORT, |
| 1855 | &xprt->state); |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1856 | /* "close" the socket, preserving the local port */ |
Trond Myklebust | 40d2549 | 2009-03-11 14:37:58 -0400 | [diff] [blame] | 1857 | xs_tcp_reuse_connection(xprt, transport); |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1858 | |
Trond Myklebust | 7d1e825 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 1859 | if (abort_and_exit) |
| 1860 | goto out_eagain; |
| 1861 | } |
| 1862 | |
Chuck Lever | c740eff | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 1863 | dprintk("RPC: worker connecting xprt %p via %s to " |
| 1864 | "%s (port %s)\n", xprt, |
| 1865 | xprt->address_strings[RPC_DISPLAY_PROTO], |
| 1866 | xprt->address_strings[RPC_DISPLAY_ADDR], |
| 1867 | xprt->address_strings[RPC_DISPLAY_PORT]); |
Chuck Lever | 16be2d2 | 2007-08-06 11:57:38 -0400 | [diff] [blame] | 1868 | |
| 1869 | status = xs_tcp_finish_connecting(xprt, sock); |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 1870 | dprintk("RPC: %p connect status %d connected %d sock state %d\n", |
| 1871 | xprt, -status, xprt_connected(xprt), |
| 1872 | sock->sk->sk_state); |
Trond Myklebust | 2a49199 | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 1873 | switch (status) { |
Trond Myklebust | f75e674 | 2009-04-21 17:18:20 -0400 | [diff] [blame] | 1874 | default: |
| 1875 | printk("%s: connect returned unhandled error %d\n", |
| 1876 | __func__, status); |
| 1877 | case -EADDRNOTAVAIL: |
| 1878 | /* We're probably in TIME_WAIT. Get rid of existing socket, |
| 1879 | * and retry |
| 1880 | */ |
| 1881 | set_bit(XPRT_CONNECTION_CLOSE, &xprt->state); |
| 1882 | xprt_force_disconnect(xprt); |
Trond Myklebust | 88b5ed7 | 2009-06-17 13:22:57 -0700 | [diff] [blame] | 1883 | break; |
Trond Myklebust | 8a2cec2 | 2009-03-11 14:38:01 -0400 | [diff] [blame] | 1884 | case -ECONNREFUSED: |
| 1885 | case -ECONNRESET: |
| 1886 | case -ENETUNREACH: |
| 1887 | /* retry with existing socket, after a delay */ |
Trond Myklebust | 2a49199 | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 1888 | case 0: |
| 1889 | case -EINPROGRESS: |
| 1890 | case -EALREADY: |
Trond Myklebust | 7d1e825 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 1891 | xprt_clear_connecting(xprt); |
| 1892 | return; |
Trond Myklebust | 9fcfe0c | 2010-03-02 13:06:21 -0500 | [diff] [blame] | 1893 | case -EINVAL: |
| 1894 | /* Happens, for instance, if the user specified a link |
| 1895 | * local IPv6 address without a scope-id. |
| 1896 | */ |
| 1897 | goto out; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1898 | } |
Trond Myklebust | 7d1e825 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 1899 | out_eagain: |
Trond Myklebust | 2a49199 | 2009-03-11 14:38:00 -0400 | [diff] [blame] | 1900 | status = -EAGAIN; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1901 | out: |
Chuck Lever | 2226feb | 2005-08-11 16:25:38 -0400 | [diff] [blame] | 1902 | xprt_clear_connecting(xprt); |
Trond Myklebust | 7d1e825 | 2009-03-11 14:38:03 -0400 | [diff] [blame] | 1903 | xprt_wake_pending_tasks(xprt, status); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1904 | } |
| 1905 | |
Trond Myklebust | b61d59f | 2009-03-11 14:38:04 -0400 | [diff] [blame] | 1906 | static struct socket *xs_create_tcp_sock4(struct rpc_xprt *xprt, |
| 1907 | struct sock_xprt *transport) |
| 1908 | { |
| 1909 | struct socket *sock; |
| 1910 | int err; |
| 1911 | |
| 1912 | /* start from scratch */ |
| 1913 | err = sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock); |
| 1914 | if (err < 0) { |
| 1915 | dprintk("RPC: can't create TCP transport socket (%d).\n", |
| 1916 | -err); |
| 1917 | goto out_err; |
| 1918 | } |
| 1919 | xs_reclassify_socket4(sock); |
| 1920 | |
| 1921 | if (xs_bind4(transport, sock) < 0) { |
| 1922 | sock_release(sock); |
| 1923 | goto out_err; |
| 1924 | } |
| 1925 | return sock; |
| 1926 | out_err: |
| 1927 | return ERR_PTR(-EIO); |
| 1928 | } |
| 1929 | |
| 1930 | /** |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1931 | * xs_tcp_connect_worker4 - connect a TCP socket to a remote endpoint |
| 1932 | * @work: RPC transport to connect |
| 1933 | * |
| 1934 | * Invoked by a work queue tasklet. |
| 1935 | */ |
| 1936 | static void xs_tcp_connect_worker4(struct work_struct *work) |
| 1937 | { |
| 1938 | struct sock_xprt *transport = |
| 1939 | container_of(work, struct sock_xprt, connect_worker.work); |
| 1940 | struct rpc_xprt *xprt = &transport->xprt; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1941 | |
Trond Myklebust | b61d59f | 2009-03-11 14:38:04 -0400 | [diff] [blame] | 1942 | xs_tcp_setup_socket(xprt, transport, xs_create_tcp_sock4); |
| 1943 | } |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1944 | |
Trond Myklebust | b61d59f | 2009-03-11 14:38:04 -0400 | [diff] [blame] | 1945 | static struct socket *xs_create_tcp_sock6(struct rpc_xprt *xprt, |
| 1946 | struct sock_xprt *transport) |
| 1947 | { |
| 1948 | struct socket *sock; |
| 1949 | int err; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1950 | |
Trond Myklebust | b61d59f | 2009-03-11 14:38:04 -0400 | [diff] [blame] | 1951 | /* start from scratch */ |
| 1952 | err = sock_create_kern(PF_INET6, SOCK_STREAM, IPPROTO_TCP, &sock); |
| 1953 | if (err < 0) { |
| 1954 | dprintk("RPC: can't create TCP transport socket (%d).\n", |
| 1955 | -err); |
| 1956 | goto out_err; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1957 | } |
Trond Myklebust | b61d59f | 2009-03-11 14:38:04 -0400 | [diff] [blame] | 1958 | xs_reclassify_socket6(sock); |
| 1959 | |
| 1960 | if (xs_bind6(transport, sock) < 0) { |
| 1961 | sock_release(sock); |
| 1962 | goto out_err; |
| 1963 | } |
| 1964 | return sock; |
| 1965 | out_err: |
| 1966 | return ERR_PTR(-EIO); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1967 | } |
| 1968 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1969 | /** |
Chuck Lever | 68e220b | 2007-08-06 11:57:48 -0400 | [diff] [blame] | 1970 | * xs_tcp_connect_worker6 - connect a TCP socket to a remote endpoint |
| 1971 | * @work: RPC transport to connect |
| 1972 | * |
| 1973 | * Invoked by a work queue tasklet. |
| 1974 | */ |
| 1975 | static void xs_tcp_connect_worker6(struct work_struct *work) |
| 1976 | { |
| 1977 | struct sock_xprt *transport = |
| 1978 | container_of(work, struct sock_xprt, connect_worker.work); |
| 1979 | struct rpc_xprt *xprt = &transport->xprt; |
Chuck Lever | 68e220b | 2007-08-06 11:57:48 -0400 | [diff] [blame] | 1980 | |
Trond Myklebust | b61d59f | 2009-03-11 14:38:04 -0400 | [diff] [blame] | 1981 | xs_tcp_setup_socket(xprt, transport, xs_create_tcp_sock6); |
Chuck Lever | 68e220b | 2007-08-06 11:57:48 -0400 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | /** |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1985 | * xs_connect - connect a socket to a remote endpoint |
| 1986 | * @task: address of RPC task that manages state of connect request |
| 1987 | * |
| 1988 | * TCP: If the remote end dropped the connection, delay reconnecting. |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1989 | * |
| 1990 | * UDP socket connects are synchronous, but we use a work queue anyway |
| 1991 | * to guarantee that even unprivileged user processes can set up a |
| 1992 | * socket on a privileged port. |
| 1993 | * |
| 1994 | * If a UDP socket connect fails, the delay behavior here prevents |
| 1995 | * retry floods (hard mounts). |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1996 | */ |
| 1997 | static void xs_connect(struct rpc_task *task) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1998 | { |
| 1999 | struct rpc_xprt *xprt = task->tk_xprt; |
Chuck Lever | ee0ac0c | 2006-12-05 16:35:15 -0500 | [diff] [blame] | 2000 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2001 | |
Chuck Lever | 09a21c4 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 2002 | if (transport->sock != NULL && !RPC_IS_SOFTCONN(task)) { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 2003 | dprintk("RPC: xs_connect delayed xprt %p for %lu " |
| 2004 | "seconds\n", |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 2005 | xprt, xprt->reestablish_timeout / HZ); |
Trond Myklebust | c1384c9 | 2007-06-14 18:00:42 -0400 | [diff] [blame] | 2006 | queue_delayed_work(rpciod_workqueue, |
| 2007 | &transport->connect_worker, |
| 2008 | xprt->reestablish_timeout); |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 2009 | xprt->reestablish_timeout <<= 1; |
Neil Brown | 61d0a8e | 2009-09-23 14:36:37 -0400 | [diff] [blame] | 2010 | if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO) |
| 2011 | xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO; |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 2012 | if (xprt->reestablish_timeout > XS_TCP_MAX_REEST_TO) |
| 2013 | xprt->reestablish_timeout = XS_TCP_MAX_REEST_TO; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 2014 | } else { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 2015 | dprintk("RPC: xs_connect scheduled xprt %p\n", xprt); |
Trond Myklebust | c1384c9 | 2007-06-14 18:00:42 -0400 | [diff] [blame] | 2016 | queue_delayed_work(rpciod_workqueue, |
| 2017 | &transport->connect_worker, 0); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2018 | } |
| 2019 | } |
| 2020 | |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 2021 | /** |
| 2022 | * xs_udp_print_stats - display UDP socket-specifc stats |
| 2023 | * @xprt: rpc_xprt struct containing statistics |
| 2024 | * @seq: output file |
| 2025 | * |
| 2026 | */ |
| 2027 | static void xs_udp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq) |
| 2028 | { |
Chuck Lever | c847546 | 2006-12-05 16:35:26 -0500 | [diff] [blame] | 2029 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
| 2030 | |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 2031 | seq_printf(seq, "\txprt:\tudp %u %lu %lu %lu %lu %Lu %Lu\n", |
Chuck Lever | fbfffbd | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 2032 | transport->srcport, |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 2033 | xprt->stat.bind_count, |
| 2034 | xprt->stat.sends, |
| 2035 | xprt->stat.recvs, |
| 2036 | xprt->stat.bad_xids, |
| 2037 | xprt->stat.req_u, |
| 2038 | xprt->stat.bklog_u); |
| 2039 | } |
| 2040 | |
| 2041 | /** |
| 2042 | * xs_tcp_print_stats - display TCP socket-specifc stats |
| 2043 | * @xprt: rpc_xprt struct containing statistics |
| 2044 | * @seq: output file |
| 2045 | * |
| 2046 | */ |
| 2047 | static void xs_tcp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq) |
| 2048 | { |
Chuck Lever | c847546 | 2006-12-05 16:35:26 -0500 | [diff] [blame] | 2049 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 2050 | long idle_time = 0; |
| 2051 | |
| 2052 | if (xprt_connected(xprt)) |
| 2053 | idle_time = (long)(jiffies - xprt->last_used) / HZ; |
| 2054 | |
| 2055 | seq_printf(seq, "\txprt:\ttcp %u %lu %lu %lu %ld %lu %lu %lu %Lu %Lu\n", |
Chuck Lever | fbfffbd | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 2056 | transport->srcport, |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 2057 | xprt->stat.bind_count, |
| 2058 | xprt->stat.connect_count, |
| 2059 | xprt->stat.connect_time, |
| 2060 | idle_time, |
| 2061 | xprt->stat.sends, |
| 2062 | xprt->stat.recvs, |
| 2063 | xprt->stat.bad_xids, |
| 2064 | xprt->stat.req_u, |
| 2065 | xprt->stat.bklog_u); |
| 2066 | } |
| 2067 | |
Rahul Iyer | 4cfc7e6 | 2009-09-10 17:32:28 +0300 | [diff] [blame] | 2068 | /* |
| 2069 | * Allocate a bunch of pages for a scratch buffer for the rpc code. The reason |
| 2070 | * we allocate pages instead doing a kmalloc like rpc_malloc is because we want |
| 2071 | * to use the server side send routines. |
| 2072 | */ |
H Hartley Sweeten | 5a51f13 | 2010-01-14 15:38:31 -0700 | [diff] [blame] | 2073 | static void *bc_malloc(struct rpc_task *task, size_t size) |
Rahul Iyer | 4cfc7e6 | 2009-09-10 17:32:28 +0300 | [diff] [blame] | 2074 | { |
| 2075 | struct page *page; |
| 2076 | struct rpc_buffer *buf; |
| 2077 | |
| 2078 | BUG_ON(size > PAGE_SIZE - sizeof(struct rpc_buffer)); |
| 2079 | page = alloc_page(GFP_KERNEL); |
| 2080 | |
| 2081 | if (!page) |
| 2082 | return NULL; |
| 2083 | |
| 2084 | buf = page_address(page); |
| 2085 | buf->len = PAGE_SIZE; |
| 2086 | |
| 2087 | return buf->data; |
| 2088 | } |
| 2089 | |
| 2090 | /* |
| 2091 | * Free the space allocated in the bc_alloc routine |
| 2092 | */ |
H Hartley Sweeten | 5a51f13 | 2010-01-14 15:38:31 -0700 | [diff] [blame] | 2093 | static void bc_free(void *buffer) |
Rahul Iyer | 4cfc7e6 | 2009-09-10 17:32:28 +0300 | [diff] [blame] | 2094 | { |
| 2095 | struct rpc_buffer *buf; |
| 2096 | |
| 2097 | if (!buffer) |
| 2098 | return; |
| 2099 | |
| 2100 | buf = container_of(buffer, struct rpc_buffer, data); |
| 2101 | free_page((unsigned long)buf); |
| 2102 | } |
| 2103 | |
| 2104 | /* |
| 2105 | * Use the svc_sock to send the callback. Must be called with svsk->sk_mutex |
| 2106 | * held. Borrows heavily from svc_tcp_sendto and xs_tcp_send_request. |
| 2107 | */ |
| 2108 | static int bc_sendto(struct rpc_rqst *req) |
| 2109 | { |
| 2110 | int len; |
| 2111 | struct xdr_buf *xbufp = &req->rq_snd_buf; |
| 2112 | struct rpc_xprt *xprt = req->rq_xprt; |
| 2113 | struct sock_xprt *transport = |
| 2114 | container_of(xprt, struct sock_xprt, xprt); |
| 2115 | struct socket *sock = transport->sock; |
| 2116 | unsigned long headoff; |
| 2117 | unsigned long tailoff; |
| 2118 | |
| 2119 | /* |
| 2120 | * Set up the rpc header and record marker stuff |
| 2121 | */ |
| 2122 | xs_encode_tcp_record_marker(xbufp); |
| 2123 | |
| 2124 | tailoff = (unsigned long)xbufp->tail[0].iov_base & ~PAGE_MASK; |
| 2125 | headoff = (unsigned long)xbufp->head[0].iov_base & ~PAGE_MASK; |
| 2126 | len = svc_send_common(sock, xbufp, |
| 2127 | virt_to_page(xbufp->head[0].iov_base), headoff, |
| 2128 | xbufp->tail[0].iov_base, tailoff); |
| 2129 | |
| 2130 | if (len != xbufp->len) { |
| 2131 | printk(KERN_NOTICE "Error sending entire callback!\n"); |
| 2132 | len = -EAGAIN; |
| 2133 | } |
| 2134 | |
| 2135 | return len; |
| 2136 | } |
| 2137 | |
| 2138 | /* |
| 2139 | * The send routine. Borrows from svc_send |
| 2140 | */ |
| 2141 | static int bc_send_request(struct rpc_task *task) |
| 2142 | { |
| 2143 | struct rpc_rqst *req = task->tk_rqstp; |
| 2144 | struct svc_xprt *xprt; |
| 2145 | struct svc_sock *svsk; |
| 2146 | u32 len; |
| 2147 | |
| 2148 | dprintk("sending request with xid: %08x\n", ntohl(req->rq_xid)); |
| 2149 | /* |
| 2150 | * Get the server socket associated with this callback xprt |
| 2151 | */ |
| 2152 | xprt = req->rq_xprt->bc_xprt; |
| 2153 | svsk = container_of(xprt, struct svc_sock, sk_xprt); |
| 2154 | |
| 2155 | /* |
| 2156 | * Grab the mutex to serialize data as the connection is shared |
| 2157 | * with the fore channel |
| 2158 | */ |
| 2159 | if (!mutex_trylock(&xprt->xpt_mutex)) { |
| 2160 | rpc_sleep_on(&xprt->xpt_bc_pending, task, NULL); |
| 2161 | if (!mutex_trylock(&xprt->xpt_mutex)) |
| 2162 | return -EAGAIN; |
| 2163 | rpc_wake_up_queued_task(&xprt->xpt_bc_pending, task); |
| 2164 | } |
| 2165 | if (test_bit(XPT_DEAD, &xprt->xpt_flags)) |
| 2166 | len = -ENOTCONN; |
| 2167 | else |
| 2168 | len = bc_sendto(req); |
| 2169 | mutex_unlock(&xprt->xpt_mutex); |
| 2170 | |
| 2171 | if (len > 0) |
| 2172 | len = 0; |
| 2173 | |
| 2174 | return len; |
| 2175 | } |
| 2176 | |
| 2177 | /* |
| 2178 | * The close routine. Since this is client initiated, we do nothing |
| 2179 | */ |
| 2180 | |
| 2181 | static void bc_close(struct rpc_xprt *xprt) |
| 2182 | { |
Rahul Iyer | 4cfc7e6 | 2009-09-10 17:32:28 +0300 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | /* |
| 2186 | * The xprt destroy routine. Again, because this connection is client |
| 2187 | * initiated, we do nothing |
| 2188 | */ |
| 2189 | |
| 2190 | static void bc_destroy(struct rpc_xprt *xprt) |
| 2191 | { |
Rahul Iyer | 4cfc7e6 | 2009-09-10 17:32:28 +0300 | [diff] [blame] | 2192 | } |
| 2193 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 2194 | static struct rpc_xprt_ops xs_udp_ops = { |
Chuck Lever | 43118c2 | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 2195 | .set_buffer_size = xs_udp_set_buffer_size, |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 2196 | .reserve_xprt = xprt_reserve_xprt_cong, |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 2197 | .release_xprt = xprt_release_xprt_cong, |
Chuck Lever | 45160d6 | 2007-07-01 12:13:17 -0400 | [diff] [blame] | 2198 | .rpcbind = rpcb_getport_async, |
Chuck Lever | 9220041 | 2006-01-03 09:55:51 +0100 | [diff] [blame] | 2199 | .set_port = xs_set_port, |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 2200 | .connect = xs_connect, |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 2201 | .buf_alloc = rpc_malloc, |
| 2202 | .buf_free = rpc_free, |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 2203 | .send_request = xs_udp_send_request, |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 2204 | .set_retrans_timeout = xprt_set_retrans_timeout_rtt, |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 2205 | .timer = xs_udp_timer, |
Chuck Lever | a58dd39 | 2005-08-25 16:25:53 -0700 | [diff] [blame] | 2206 | .release_request = xprt_release_rqst_cong, |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 2207 | .close = xs_close, |
| 2208 | .destroy = xs_destroy, |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 2209 | .print_stats = xs_udp_print_stats, |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 2210 | }; |
| 2211 | |
| 2212 | static struct rpc_xprt_ops xs_tcp_ops = { |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 2213 | .reserve_xprt = xprt_reserve_xprt, |
Trond Myklebust | e0ab53d | 2006-07-27 17:22:50 -0400 | [diff] [blame] | 2214 | .release_xprt = xs_tcp_release_xprt, |
Chuck Lever | 45160d6 | 2007-07-01 12:13:17 -0400 | [diff] [blame] | 2215 | .rpcbind = rpcb_getport_async, |
Chuck Lever | 9220041 | 2006-01-03 09:55:51 +0100 | [diff] [blame] | 2216 | .set_port = xs_set_port, |
Trond Myklebust | 0b9e794 | 2010-04-16 16:41:57 -0400 | [diff] [blame] | 2217 | .connect = xs_connect, |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 2218 | .buf_alloc = rpc_malloc, |
| 2219 | .buf_free = rpc_free, |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 2220 | .send_request = xs_tcp_send_request, |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 2221 | .set_retrans_timeout = xprt_set_retrans_timeout_def, |
Trond Myklebust | f75e674 | 2009-04-21 17:18:20 -0400 | [diff] [blame] | 2222 | .close = xs_tcp_close, |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 2223 | .destroy = xs_destroy, |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 2224 | .print_stats = xs_tcp_print_stats, |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2225 | }; |
| 2226 | |
Rahul Iyer | 4cfc7e6 | 2009-09-10 17:32:28 +0300 | [diff] [blame] | 2227 | /* |
| 2228 | * The rpc_xprt_ops for the server backchannel |
| 2229 | */ |
| 2230 | |
| 2231 | static struct rpc_xprt_ops bc_tcp_ops = { |
| 2232 | .reserve_xprt = xprt_reserve_xprt, |
| 2233 | .release_xprt = xprt_release_xprt, |
| 2234 | .buf_alloc = bc_malloc, |
| 2235 | .buf_free = bc_free, |
| 2236 | .send_request = bc_send_request, |
| 2237 | .set_retrans_timeout = xprt_set_retrans_timeout_def, |
| 2238 | .close = bc_close, |
| 2239 | .destroy = bc_destroy, |
| 2240 | .print_stats = xs_tcp_print_stats, |
| 2241 | }; |
| 2242 | |
\"Talpey, Thomas\ | 3c341b0b | 2007-09-10 13:47:07 -0400 | [diff] [blame] | 2243 | static struct rpc_xprt *xs_setup_xprt(struct xprt_create *args, |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 2244 | unsigned int slot_table_size) |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 2245 | { |
| 2246 | struct rpc_xprt *xprt; |
Chuck Lever | ffc2e51 | 2006-12-05 16:35:11 -0500 | [diff] [blame] | 2247 | struct sock_xprt *new; |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 2248 | |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 2249 | if (args->addrlen > sizeof(xprt->addr)) { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 2250 | dprintk("RPC: xs_setup_xprt: address too large\n"); |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 2251 | return ERR_PTR(-EBADF); |
| 2252 | } |
| 2253 | |
Chuck Lever | ffc2e51 | 2006-12-05 16:35:11 -0500 | [diff] [blame] | 2254 | new = kzalloc(sizeof(*new), GFP_KERNEL); |
| 2255 | if (new == NULL) { |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 2256 | dprintk("RPC: xs_setup_xprt: couldn't allocate " |
| 2257 | "rpc_xprt\n"); |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 2258 | return ERR_PTR(-ENOMEM); |
| 2259 | } |
Chuck Lever | ffc2e51 | 2006-12-05 16:35:11 -0500 | [diff] [blame] | 2260 | xprt = &new->xprt; |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 2261 | |
| 2262 | xprt->max_reqs = slot_table_size; |
| 2263 | xprt->slot = kcalloc(xprt->max_reqs, sizeof(struct rpc_rqst), GFP_KERNEL); |
| 2264 | if (xprt->slot == NULL) { |
| 2265 | kfree(xprt); |
Chuck Lever | 46121cf | 2007-01-31 12:14:08 -0500 | [diff] [blame] | 2266 | dprintk("RPC: xs_setup_xprt: couldn't allocate slot " |
| 2267 | "table\n"); |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 2268 | return ERR_PTR(-ENOMEM); |
| 2269 | } |
| 2270 | |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 2271 | memcpy(&xprt->addr, args->dstaddr, args->addrlen); |
| 2272 | xprt->addrlen = args->addrlen; |
Frank van Maarseveen | d3bc9a1 | 2007-07-09 22:23:35 +0200 | [diff] [blame] | 2273 | if (args->srcaddr) |
Chuck Lever | fbfffbd | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 2274 | memcpy(&new->srcaddr, args->srcaddr, args->addrlen); |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 2275 | |
| 2276 | return xprt; |
| 2277 | } |
| 2278 | |
Trond Myklebust | 2881ae7 | 2007-12-20 16:03:54 -0500 | [diff] [blame] | 2279 | static const struct rpc_timeout xs_udp_default_timeout = { |
| 2280 | .to_initval = 5 * HZ, |
| 2281 | .to_maxval = 30 * HZ, |
| 2282 | .to_increment = 5 * HZ, |
| 2283 | .to_retries = 5, |
| 2284 | }; |
| 2285 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 2286 | /** |
| 2287 | * xs_setup_udp - Set up transport to use a UDP socket |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 2288 | * @args: rpc transport creation arguments |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 2289 | * |
| 2290 | */ |
Adrian Bunk | 483066d | 2007-10-24 18:24:02 +0200 | [diff] [blame] | 2291 | static struct rpc_xprt *xs_setup_udp(struct xprt_create *args) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2292 | { |
Chuck Lever | 8f9d5b1 | 2007-08-06 11:57:53 -0400 | [diff] [blame] | 2293 | struct sockaddr *addr = args->dstaddr; |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 2294 | struct rpc_xprt *xprt; |
Chuck Lever | c847546 | 2006-12-05 16:35:26 -0500 | [diff] [blame] | 2295 | struct sock_xprt *transport; |
J. Bruce Fields | 0a68b0b | 2010-05-26 08:42:24 -0400 | [diff] [blame] | 2296 | struct rpc_xprt *ret; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2297 | |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 2298 | xprt = xs_setup_xprt(args, xprt_udp_slot_table_entries); |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 2299 | if (IS_ERR(xprt)) |
| 2300 | return xprt; |
Chuck Lever | c847546 | 2006-12-05 16:35:26 -0500 | [diff] [blame] | 2301 | transport = container_of(xprt, struct sock_xprt, xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2302 | |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 2303 | xprt->prot = IPPROTO_UDP; |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 2304 | xprt->tsh_size = 0; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2305 | /* XXX: header size can vary due to auth type, IPv6, etc. */ |
| 2306 | xprt->max_payload = (1U << 16) - (MAX_HEADER << 3); |
| 2307 | |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 2308 | xprt->bind_timeout = XS_BIND_TO; |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 2309 | xprt->reestablish_timeout = XS_UDP_REEST_TO; |
| 2310 | xprt->idle_timeout = XS_IDLE_DISC_TO; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2311 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 2312 | xprt->ops = &xs_udp_ops; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2313 | |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 2314 | xprt->timeout = &xs_udp_default_timeout; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2315 | |
Chuck Lever | 8f9d5b1 | 2007-08-06 11:57:53 -0400 | [diff] [blame] | 2316 | switch (addr->sa_family) { |
| 2317 | case AF_INET: |
| 2318 | if (((struct sockaddr_in *)addr)->sin_port != htons(0)) |
| 2319 | xprt_set_bound(xprt); |
| 2320 | |
| 2321 | INIT_DELAYED_WORK(&transport->connect_worker, |
| 2322 | xs_udp_connect_worker4); |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 2323 | xs_format_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP); |
Chuck Lever | 8f9d5b1 | 2007-08-06 11:57:53 -0400 | [diff] [blame] | 2324 | break; |
| 2325 | case AF_INET6: |
| 2326 | if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0)) |
| 2327 | xprt_set_bound(xprt); |
| 2328 | |
| 2329 | INIT_DELAYED_WORK(&transport->connect_worker, |
| 2330 | xs_udp_connect_worker6); |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 2331 | xs_format_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP6); |
Chuck Lever | 8f9d5b1 | 2007-08-06 11:57:53 -0400 | [diff] [blame] | 2332 | break; |
| 2333 | default: |
J. Bruce Fields | 0a68b0b | 2010-05-26 08:42:24 -0400 | [diff] [blame] | 2334 | ret = ERR_PTR(-EAFNOSUPPORT); |
| 2335 | goto out_err; |
Chuck Lever | 8f9d5b1 | 2007-08-06 11:57:53 -0400 | [diff] [blame] | 2336 | } |
| 2337 | |
Chuck Lever | c740eff | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 2338 | if (xprt_bound(xprt)) |
| 2339 | dprintk("RPC: set up xprt to %s (port %s) via %s\n", |
| 2340 | xprt->address_strings[RPC_DISPLAY_ADDR], |
| 2341 | xprt->address_strings[RPC_DISPLAY_PORT], |
| 2342 | xprt->address_strings[RPC_DISPLAY_PROTO]); |
| 2343 | else |
| 2344 | dprintk("RPC: set up xprt to %s (autobind) via %s\n", |
| 2345 | xprt->address_strings[RPC_DISPLAY_ADDR], |
| 2346 | xprt->address_strings[RPC_DISPLAY_PROTO]); |
Chuck Lever | edb267a | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 2347 | |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 2348 | if (try_module_get(THIS_MODULE)) |
| 2349 | return xprt; |
J. Bruce Fields | 0a68b0b | 2010-05-26 08:42:24 -0400 | [diff] [blame] | 2350 | ret = ERR_PTR(-EINVAL); |
| 2351 | out_err: |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 2352 | kfree(xprt->slot); |
| 2353 | kfree(xprt); |
J. Bruce Fields | 0a68b0b | 2010-05-26 08:42:24 -0400 | [diff] [blame] | 2354 | return ret; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2355 | } |
| 2356 | |
Trond Myklebust | 2881ae7 | 2007-12-20 16:03:54 -0500 | [diff] [blame] | 2357 | static const struct rpc_timeout xs_tcp_default_timeout = { |
| 2358 | .to_initval = 60 * HZ, |
| 2359 | .to_maxval = 60 * HZ, |
| 2360 | .to_retries = 2, |
| 2361 | }; |
| 2362 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 2363 | /** |
| 2364 | * xs_setup_tcp - Set up transport to use a TCP socket |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 2365 | * @args: rpc transport creation arguments |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 2366 | * |
| 2367 | */ |
Adrian Bunk | 483066d | 2007-10-24 18:24:02 +0200 | [diff] [blame] | 2368 | static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2369 | { |
Chuck Lever | 8f9d5b1 | 2007-08-06 11:57:53 -0400 | [diff] [blame] | 2370 | struct sockaddr *addr = args->dstaddr; |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 2371 | struct rpc_xprt *xprt; |
Chuck Lever | c847546 | 2006-12-05 16:35:26 -0500 | [diff] [blame] | 2372 | struct sock_xprt *transport; |
J. Bruce Fields | 0a68b0b | 2010-05-26 08:42:24 -0400 | [diff] [blame] | 2373 | struct rpc_xprt *ret; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2374 | |
Frank van Maarseveen | 96802a0 | 2007-07-08 13:08:54 +0200 | [diff] [blame] | 2375 | xprt = xs_setup_xprt(args, xprt_tcp_slot_table_entries); |
Chuck Lever | c8541ec | 2006-10-17 14:44:27 -0400 | [diff] [blame] | 2376 | if (IS_ERR(xprt)) |
| 2377 | return xprt; |
Chuck Lever | c847546 | 2006-12-05 16:35:26 -0500 | [diff] [blame] | 2378 | transport = container_of(xprt, struct sock_xprt, xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2379 | |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 2380 | xprt->prot = IPPROTO_TCP; |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 2381 | xprt->tsh_size = sizeof(rpc_fraghdr) / sizeof(u32); |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 2382 | xprt->max_payload = RPC_MAX_FRAGMENT_SIZE; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2383 | |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 2384 | xprt->bind_timeout = XS_BIND_TO; |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 2385 | xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO; |
| 2386 | xprt->idle_timeout = XS_IDLE_DISC_TO; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2387 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 2388 | xprt->ops = &xs_tcp_ops; |
Trond Myklebust | ba7392b | 2007-12-20 16:03:55 -0500 | [diff] [blame] | 2389 | xprt->timeout = &xs_tcp_default_timeout; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2390 | |
Chuck Lever | 8f9d5b1 | 2007-08-06 11:57:53 -0400 | [diff] [blame] | 2391 | switch (addr->sa_family) { |
| 2392 | case AF_INET: |
| 2393 | if (((struct sockaddr_in *)addr)->sin_port != htons(0)) |
| 2394 | xprt_set_bound(xprt); |
| 2395 | |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 2396 | INIT_DELAYED_WORK(&transport->connect_worker, |
| 2397 | xs_tcp_connect_worker4); |
| 2398 | xs_format_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP); |
Chuck Lever | 8f9d5b1 | 2007-08-06 11:57:53 -0400 | [diff] [blame] | 2399 | break; |
| 2400 | case AF_INET6: |
| 2401 | if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0)) |
| 2402 | xprt_set_bound(xprt); |
| 2403 | |
Chuck Lever | 9dc3b09 | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 2404 | INIT_DELAYED_WORK(&transport->connect_worker, |
| 2405 | xs_tcp_connect_worker6); |
| 2406 | xs_format_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP6); |
Chuck Lever | 8f9d5b1 | 2007-08-06 11:57:53 -0400 | [diff] [blame] | 2407 | break; |
| 2408 | default: |
J. Bruce Fields | 0a68b0b | 2010-05-26 08:42:24 -0400 | [diff] [blame] | 2409 | ret = ERR_PTR(-EAFNOSUPPORT); |
| 2410 | goto out_err; |
Chuck Lever | 8f9d5b1 | 2007-08-06 11:57:53 -0400 | [diff] [blame] | 2411 | } |
| 2412 | |
Chuck Lever | c740eff | 2009-08-09 15:09:46 -0400 | [diff] [blame] | 2413 | if (xprt_bound(xprt)) |
| 2414 | dprintk("RPC: set up xprt to %s (port %s) via %s\n", |
| 2415 | xprt->address_strings[RPC_DISPLAY_ADDR], |
| 2416 | xprt->address_strings[RPC_DISPLAY_PORT], |
| 2417 | xprt->address_strings[RPC_DISPLAY_PROTO]); |
| 2418 | else |
| 2419 | dprintk("RPC: set up xprt to %s (autobind) via %s\n", |
| 2420 | xprt->address_strings[RPC_DISPLAY_ADDR], |
| 2421 | xprt->address_strings[RPC_DISPLAY_PROTO]); |
| 2422 | |
Chuck Lever | edb267a | 2006-08-22 20:06:18 -0400 | [diff] [blame] | 2423 | |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 2424 | if (try_module_get(THIS_MODULE)) |
| 2425 | return xprt; |
J. Bruce Fields | 0a68b0b | 2010-05-26 08:42:24 -0400 | [diff] [blame] | 2426 | ret = ERR_PTR(-EINVAL); |
| 2427 | out_err: |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 2428 | kfree(xprt->slot); |
| 2429 | kfree(xprt); |
J. Bruce Fields | 0a68b0b | 2010-05-26 08:42:24 -0400 | [diff] [blame] | 2430 | return ret; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 2431 | } |
Chuck Lever | 282b32e | 2006-12-05 16:35:51 -0500 | [diff] [blame] | 2432 | |
Alexandros Batsakis | f300bab | 2009-09-10 17:33:30 +0300 | [diff] [blame] | 2433 | /** |
| 2434 | * xs_setup_bc_tcp - Set up transport to use a TCP backchannel socket |
| 2435 | * @args: rpc transport creation arguments |
| 2436 | * |
| 2437 | */ |
| 2438 | static struct rpc_xprt *xs_setup_bc_tcp(struct xprt_create *args) |
| 2439 | { |
| 2440 | struct sockaddr *addr = args->dstaddr; |
| 2441 | struct rpc_xprt *xprt; |
| 2442 | struct sock_xprt *transport; |
| 2443 | struct svc_sock *bc_sock; |
J. Bruce Fields | 0a68b0b | 2010-05-26 08:42:24 -0400 | [diff] [blame] | 2444 | struct rpc_xprt *ret; |
Alexandros Batsakis | f300bab | 2009-09-10 17:33:30 +0300 | [diff] [blame] | 2445 | |
Alexandros Batsakis | f300bab | 2009-09-10 17:33:30 +0300 | [diff] [blame] | 2446 | xprt = xs_setup_xprt(args, xprt_tcp_slot_table_entries); |
| 2447 | if (IS_ERR(xprt)) |
| 2448 | return xprt; |
| 2449 | transport = container_of(xprt, struct sock_xprt, xprt); |
| 2450 | |
| 2451 | xprt->prot = IPPROTO_TCP; |
| 2452 | xprt->tsh_size = sizeof(rpc_fraghdr) / sizeof(u32); |
| 2453 | xprt->max_payload = RPC_MAX_FRAGMENT_SIZE; |
| 2454 | xprt->timeout = &xs_tcp_default_timeout; |
| 2455 | |
| 2456 | /* backchannel */ |
| 2457 | xprt_set_bound(xprt); |
| 2458 | xprt->bind_timeout = 0; |
Alexandros Batsakis | f300bab | 2009-09-10 17:33:30 +0300 | [diff] [blame] | 2459 | xprt->reestablish_timeout = 0; |
| 2460 | xprt->idle_timeout = 0; |
| 2461 | |
| 2462 | /* |
| 2463 | * The backchannel uses the same socket connection as the |
| 2464 | * forechannel |
| 2465 | */ |
| 2466 | xprt->bc_xprt = args->bc_xprt; |
| 2467 | bc_sock = container_of(args->bc_xprt, struct svc_sock, sk_xprt); |
| 2468 | bc_sock->sk_bc_xprt = xprt; |
| 2469 | transport->sock = bc_sock->sk_sock; |
| 2470 | transport->inet = bc_sock->sk_sk; |
| 2471 | |
| 2472 | xprt->ops = &bc_tcp_ops; |
| 2473 | |
| 2474 | switch (addr->sa_family) { |
| 2475 | case AF_INET: |
| 2476 | xs_format_peer_addresses(xprt, "tcp", |
| 2477 | RPCBIND_NETID_TCP); |
| 2478 | break; |
| 2479 | case AF_INET6: |
| 2480 | xs_format_peer_addresses(xprt, "tcp", |
| 2481 | RPCBIND_NETID_TCP6); |
| 2482 | break; |
| 2483 | default: |
J. Bruce Fields | 0a68b0b | 2010-05-26 08:42:24 -0400 | [diff] [blame] | 2484 | ret = ERR_PTR(-EAFNOSUPPORT); |
| 2485 | goto out_err; |
Alexandros Batsakis | f300bab | 2009-09-10 17:33:30 +0300 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | if (xprt_bound(xprt)) |
| 2489 | dprintk("RPC: set up xprt to %s (port %s) via %s\n", |
| 2490 | xprt->address_strings[RPC_DISPLAY_ADDR], |
| 2491 | xprt->address_strings[RPC_DISPLAY_PORT], |
| 2492 | xprt->address_strings[RPC_DISPLAY_PROTO]); |
| 2493 | else |
| 2494 | dprintk("RPC: set up xprt to %s (autobind) via %s\n", |
| 2495 | xprt->address_strings[RPC_DISPLAY_ADDR], |
| 2496 | xprt->address_strings[RPC_DISPLAY_PROTO]); |
| 2497 | |
| 2498 | /* |
| 2499 | * Since we don't want connections for the backchannel, we set |
| 2500 | * the xprt status to connected |
| 2501 | */ |
| 2502 | xprt_set_connected(xprt); |
| 2503 | |
| 2504 | |
| 2505 | if (try_module_get(THIS_MODULE)) |
| 2506 | return xprt; |
J. Bruce Fields | 0a68b0b | 2010-05-26 08:42:24 -0400 | [diff] [blame] | 2507 | ret = ERR_PTR(-EINVAL); |
| 2508 | out_err: |
Alexandros Batsakis | f300bab | 2009-09-10 17:33:30 +0300 | [diff] [blame] | 2509 | kfree(xprt->slot); |
| 2510 | kfree(xprt); |
J. Bruce Fields | 0a68b0b | 2010-05-26 08:42:24 -0400 | [diff] [blame] | 2511 | return ret; |
Alexandros Batsakis | f300bab | 2009-09-10 17:33:30 +0300 | [diff] [blame] | 2512 | } |
| 2513 | |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 2514 | static struct xprt_class xs_udp_transport = { |
| 2515 | .list = LIST_HEAD_INIT(xs_udp_transport.list), |
| 2516 | .name = "udp", |
| 2517 | .owner = THIS_MODULE, |
Alexandros Batsakis | f300bab | 2009-09-10 17:33:30 +0300 | [diff] [blame] | 2518 | .ident = XPRT_TRANSPORT_UDP, |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 2519 | .setup = xs_setup_udp, |
| 2520 | }; |
| 2521 | |
| 2522 | static struct xprt_class xs_tcp_transport = { |
| 2523 | .list = LIST_HEAD_INIT(xs_tcp_transport.list), |
| 2524 | .name = "tcp", |
| 2525 | .owner = THIS_MODULE, |
Alexandros Batsakis | f300bab | 2009-09-10 17:33:30 +0300 | [diff] [blame] | 2526 | .ident = XPRT_TRANSPORT_TCP, |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 2527 | .setup = xs_setup_tcp, |
| 2528 | }; |
| 2529 | |
Alexandros Batsakis | f300bab | 2009-09-10 17:33:30 +0300 | [diff] [blame] | 2530 | static struct xprt_class xs_bc_tcp_transport = { |
| 2531 | .list = LIST_HEAD_INIT(xs_bc_tcp_transport.list), |
| 2532 | .name = "tcp NFSv4.1 backchannel", |
| 2533 | .owner = THIS_MODULE, |
| 2534 | .ident = XPRT_TRANSPORT_BC_TCP, |
| 2535 | .setup = xs_setup_bc_tcp, |
| 2536 | }; |
| 2537 | |
Chuck Lever | 282b32e | 2006-12-05 16:35:51 -0500 | [diff] [blame] | 2538 | /** |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 2539 | * init_socket_xprt - set up xprtsock's sysctls, register with RPC client |
Chuck Lever | 282b32e | 2006-12-05 16:35:51 -0500 | [diff] [blame] | 2540 | * |
| 2541 | */ |
| 2542 | int init_socket_xprt(void) |
| 2543 | { |
Chuck Lever | fbf7668 | 2006-12-05 16:35:54 -0500 | [diff] [blame] | 2544 | #ifdef RPC_DEBUG |
Eric W. Biederman | 2b1bec5 | 2007-02-14 00:33:24 -0800 | [diff] [blame] | 2545 | if (!sunrpc_table_header) |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 2546 | sunrpc_table_header = register_sysctl_table(sunrpc_table); |
Chuck Lever | fbf7668 | 2006-12-05 16:35:54 -0500 | [diff] [blame] | 2547 | #endif |
| 2548 | |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 2549 | xprt_register_transport(&xs_udp_transport); |
| 2550 | xprt_register_transport(&xs_tcp_transport); |
Alexandros Batsakis | f300bab | 2009-09-10 17:33:30 +0300 | [diff] [blame] | 2551 | xprt_register_transport(&xs_bc_tcp_transport); |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 2552 | |
Chuck Lever | 282b32e | 2006-12-05 16:35:51 -0500 | [diff] [blame] | 2553 | return 0; |
| 2554 | } |
| 2555 | |
| 2556 | /** |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 2557 | * cleanup_socket_xprt - remove xprtsock's sysctls, unregister |
Chuck Lever | 282b32e | 2006-12-05 16:35:51 -0500 | [diff] [blame] | 2558 | * |
| 2559 | */ |
| 2560 | void cleanup_socket_xprt(void) |
| 2561 | { |
Chuck Lever | fbf7668 | 2006-12-05 16:35:54 -0500 | [diff] [blame] | 2562 | #ifdef RPC_DEBUG |
| 2563 | if (sunrpc_table_header) { |
| 2564 | unregister_sysctl_table(sunrpc_table_header); |
| 2565 | sunrpc_table_header = NULL; |
| 2566 | } |
| 2567 | #endif |
\"Talpey, Thomas\ | bc25571 | 2007-09-10 13:46:39 -0400 | [diff] [blame] | 2568 | |
| 2569 | xprt_unregister_transport(&xs_udp_transport); |
| 2570 | xprt_unregister_transport(&xs_tcp_transport); |
Alexandros Batsakis | f300bab | 2009-09-10 17:33:30 +0300 | [diff] [blame] | 2571 | xprt_unregister_transport(&xs_bc_tcp_transport); |
Chuck Lever | 282b32e | 2006-12-05 16:35:51 -0500 | [diff] [blame] | 2572 | } |
Trond Myklebust | cbf1107 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2573 | |
| 2574 | static int param_set_uint_minmax(const char *val, struct kernel_param *kp, |
| 2575 | unsigned int min, unsigned int max) |
| 2576 | { |
| 2577 | unsigned long num; |
| 2578 | int ret; |
| 2579 | |
| 2580 | if (!val) |
| 2581 | return -EINVAL; |
| 2582 | ret = strict_strtoul(val, 0, &num); |
| 2583 | if (ret == -EINVAL || num < min || num > max) |
| 2584 | return -EINVAL; |
| 2585 | *((unsigned int *)kp->arg) = num; |
| 2586 | return 0; |
| 2587 | } |
| 2588 | |
| 2589 | static int param_set_portnr(const char *val, struct kernel_param *kp) |
| 2590 | { |
| 2591 | return param_set_uint_minmax(val, kp, |
| 2592 | RPC_MIN_RESVPORT, |
| 2593 | RPC_MAX_RESVPORT); |
| 2594 | } |
| 2595 | |
| 2596 | static int param_get_portnr(char *buffer, struct kernel_param *kp) |
| 2597 | { |
| 2598 | return param_get_uint(buffer, kp); |
| 2599 | } |
| 2600 | #define param_check_portnr(name, p) \ |
| 2601 | __param_check(name, p, unsigned int); |
| 2602 | |
| 2603 | module_param_named(min_resvport, xprt_min_resvport, portnr, 0644); |
| 2604 | module_param_named(max_resvport, xprt_max_resvport, portnr, 0644); |
| 2605 | |
| 2606 | static int param_set_slot_table_size(const char *val, struct kernel_param *kp) |
| 2607 | { |
| 2608 | return param_set_uint_minmax(val, kp, |
| 2609 | RPC_MIN_SLOT_TABLE, |
| 2610 | RPC_MAX_SLOT_TABLE); |
| 2611 | } |
| 2612 | |
| 2613 | static int param_get_slot_table_size(char *buffer, struct kernel_param *kp) |
| 2614 | { |
| 2615 | return param_get_uint(buffer, kp); |
| 2616 | } |
| 2617 | #define param_check_slot_table_size(name, p) \ |
| 2618 | __param_check(name, p, unsigned int); |
| 2619 | |
| 2620 | module_param_named(tcp_slot_table_entries, xprt_tcp_slot_table_entries, |
| 2621 | slot_table_size, 0644); |
| 2622 | module_param_named(udp_slot_table_entries, xprt_udp_slot_table_entries, |
| 2623 | slot_table_size, 0644); |
| 2624 | |