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