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 | * |
| 6 | * TCP callback races fixes (C) 1998 Red Hat Software <alan@redhat.com> |
| 7 | * TCP send fixes (C) 1998 Red Hat Software <alan@redhat.com> |
| 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 | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/capability.h> |
| 21 | #include <linux/sched.h> |
| 22 | #include <linux/pagemap.h> |
| 23 | #include <linux/errno.h> |
| 24 | #include <linux/socket.h> |
| 25 | #include <linux/in.h> |
| 26 | #include <linux/net.h> |
| 27 | #include <linux/mm.h> |
| 28 | #include <linux/udp.h> |
| 29 | #include <linux/tcp.h> |
| 30 | #include <linux/sunrpc/clnt.h> |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 31 | #include <linux/sunrpc/sched.h> |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 32 | #include <linux/file.h> |
| 33 | |
| 34 | #include <net/sock.h> |
| 35 | #include <net/checksum.h> |
| 36 | #include <net/udp.h> |
| 37 | #include <net/tcp.h> |
| 38 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 39 | /* |
Chuck Lever | c556b75 | 2005-11-01 12:24:48 -0500 | [diff] [blame] | 40 | * xprtsock tunables |
| 41 | */ |
| 42 | unsigned int xprt_udp_slot_table_entries = RPC_DEF_SLOT_TABLE; |
| 43 | unsigned int xprt_tcp_slot_table_entries = RPC_DEF_SLOT_TABLE; |
| 44 | |
| 45 | unsigned int xprt_min_resvport = RPC_DEF_MIN_RESVPORT; |
| 46 | unsigned int xprt_max_resvport = RPC_DEF_MAX_RESVPORT; |
| 47 | |
| 48 | /* |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 49 | * How many times to try sending a request on a socket before waiting |
| 50 | * for the socket buffer to clear. |
| 51 | */ |
| 52 | #define XS_SENDMSG_RETRY (10U) |
| 53 | |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 54 | /* |
| 55 | * Time out for an RPC UDP socket connect. UDP socket connects are |
| 56 | * synchronous, but we set a timeout anyway in case of resource |
| 57 | * exhaustion on the local host. |
| 58 | */ |
| 59 | #define XS_UDP_CONN_TO (5U * HZ) |
| 60 | |
| 61 | /* |
| 62 | * Wait duration for an RPC TCP connection to be established. Solaris |
| 63 | * NFS over TCP uses 60 seconds, for example, which is in line with how |
| 64 | * long a server takes to reboot. |
| 65 | */ |
| 66 | #define XS_TCP_CONN_TO (60U * HZ) |
| 67 | |
| 68 | /* |
| 69 | * Wait duration for a reply from the RPC portmapper. |
| 70 | */ |
| 71 | #define XS_BIND_TO (60U * HZ) |
| 72 | |
| 73 | /* |
| 74 | * Delay if a UDP socket connect error occurs. This is most likely some |
| 75 | * kind of resource problem on the local host. |
| 76 | */ |
| 77 | #define XS_UDP_REEST_TO (2U * HZ) |
| 78 | |
| 79 | /* |
| 80 | * The reestablish timeout allows clients to delay for a bit before attempting |
| 81 | * to reconnect to a server that just dropped our connection. |
| 82 | * |
| 83 | * We implement an exponential backoff when trying to reestablish a TCP |
| 84 | * transport connection with the server. Some servers like to drop a TCP |
| 85 | * connection when they are overworked, so we start with a short timeout and |
| 86 | * increase over time if the server is down or not responding. |
| 87 | */ |
| 88 | #define XS_TCP_INIT_REEST_TO (3U * HZ) |
| 89 | #define XS_TCP_MAX_REEST_TO (5U * 60 * HZ) |
| 90 | |
| 91 | /* |
| 92 | * TCP idle timeout; client drops the transport socket if it is idle |
| 93 | * for this long. Note that we also timeout UDP sockets to prevent |
| 94 | * holding port numbers when there is no RPC traffic. |
| 95 | */ |
| 96 | #define XS_IDLE_DISC_TO (5U * 60 * HZ) |
| 97 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 98 | #ifdef RPC_DEBUG |
| 99 | # undef RPC_DEBUG_DATA |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 100 | # define RPCDBG_FACILITY RPCDBG_TRANS |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 101 | #endif |
| 102 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 103 | #ifdef RPC_DEBUG_DATA |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 104 | static void xs_pktdump(char *msg, u32 *packet, unsigned int count) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 105 | { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 106 | u8 *buf = (u8 *) packet; |
| 107 | int j; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 108 | |
| 109 | dprintk("RPC: %s\n", msg); |
| 110 | for (j = 0; j < count && j < 128; j += 4) { |
| 111 | if (!(j & 31)) { |
| 112 | if (j) |
| 113 | dprintk("\n"); |
| 114 | dprintk("0x%04x ", j); |
| 115 | } |
| 116 | dprintk("%02x%02x%02x%02x ", |
| 117 | buf[j], buf[j+1], buf[j+2], buf[j+3]); |
| 118 | } |
| 119 | dprintk("\n"); |
| 120 | } |
| 121 | #else |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 122 | static inline void xs_pktdump(char *msg, u32 *packet, unsigned int count) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 123 | { |
| 124 | /* NOP */ |
| 125 | } |
| 126 | #endif |
| 127 | |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 128 | #define XS_SENDMSG_FLAGS (MSG_DONTWAIT | MSG_NOSIGNAL) |
| 129 | |
| 130 | static inline int xs_send_head(struct socket *sock, struct sockaddr *addr, int addrlen, struct xdr_buf *xdr, unsigned int base, unsigned int len) |
| 131 | { |
| 132 | struct kvec iov = { |
| 133 | .iov_base = xdr->head[0].iov_base + base, |
| 134 | .iov_len = len - base, |
| 135 | }; |
| 136 | struct msghdr msg = { |
| 137 | .msg_name = addr, |
| 138 | .msg_namelen = addrlen, |
| 139 | .msg_flags = XS_SENDMSG_FLAGS, |
| 140 | }; |
| 141 | |
| 142 | if (xdr->len > len) |
| 143 | msg.msg_flags |= MSG_MORE; |
| 144 | |
| 145 | if (likely(iov.iov_len)) |
| 146 | return kernel_sendmsg(sock, &msg, &iov, 1, iov.iov_len); |
| 147 | return kernel_sendmsg(sock, &msg, NULL, 0, 0); |
| 148 | } |
| 149 | |
| 150 | static int xs_send_tail(struct socket *sock, struct xdr_buf *xdr, unsigned int base, unsigned int len) |
| 151 | { |
| 152 | struct kvec iov = { |
| 153 | .iov_base = xdr->tail[0].iov_base + base, |
| 154 | .iov_len = len - base, |
| 155 | }; |
| 156 | struct msghdr msg = { |
| 157 | .msg_flags = XS_SENDMSG_FLAGS, |
| 158 | }; |
| 159 | |
| 160 | return kernel_sendmsg(sock, &msg, &iov, 1, iov.iov_len); |
| 161 | } |
| 162 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 163 | /** |
| 164 | * xs_sendpages - write pages directly to a socket |
| 165 | * @sock: socket to send on |
| 166 | * @addr: UDP only -- address of destination |
| 167 | * @addrlen: UDP only -- length of destination address |
| 168 | * @xdr: buffer containing this request |
| 169 | * @base: starting position in the buffer |
| 170 | * |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 171 | */ |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 172 | static inline 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] | 173 | { |
| 174 | struct page **ppage = xdr->pages; |
| 175 | unsigned int len, pglen = xdr->page_len; |
| 176 | int err, ret = 0; |
| 177 | ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int); |
| 178 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 179 | if (unlikely(!sock)) |
| 180 | return -ENOTCONN; |
| 181 | |
| 182 | clear_bit(SOCK_ASYNC_NOSPACE, &sock->flags); |
| 183 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 184 | len = xdr->head[0].iov_len; |
| 185 | if (base < len || (addr != NULL && base == 0)) { |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 186 | err = xs_send_head(sock, addr, addrlen, xdr, base, len); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 187 | if (ret == 0) |
| 188 | ret = err; |
| 189 | else if (err > 0) |
| 190 | ret += err; |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 191 | if (err != (len - base)) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 192 | goto out; |
| 193 | base = 0; |
| 194 | } else |
| 195 | base -= len; |
| 196 | |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 197 | if (unlikely(pglen == 0)) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 198 | goto copy_tail; |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 199 | if (unlikely(base >= pglen)) { |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 200 | base -= pglen; |
| 201 | goto copy_tail; |
| 202 | } |
| 203 | if (base || xdr->page_base) { |
| 204 | pglen -= base; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 205 | base += xdr->page_base; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 206 | ppage += base >> PAGE_CACHE_SHIFT; |
| 207 | base &= ~PAGE_CACHE_MASK; |
| 208 | } |
| 209 | |
| 210 | sendpage = sock->ops->sendpage ? : sock_no_sendpage; |
| 211 | do { |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 212 | int flags = XS_SENDMSG_FLAGS; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 213 | |
| 214 | len = PAGE_CACHE_SIZE; |
| 215 | if (base) |
| 216 | len -= base; |
| 217 | if (pglen < len) |
| 218 | len = pglen; |
| 219 | |
| 220 | if (pglen != len || xdr->tail[0].iov_len != 0) |
| 221 | flags |= MSG_MORE; |
| 222 | |
| 223 | /* Hmm... We might be dealing with highmem pages */ |
| 224 | if (PageHighMem(*ppage)) |
| 225 | sendpage = sock_no_sendpage; |
| 226 | err = sendpage(sock, *ppage, base, len, flags); |
| 227 | if (ret == 0) |
| 228 | ret = err; |
| 229 | else if (err > 0) |
| 230 | ret += err; |
| 231 | if (err != len) |
| 232 | goto out; |
| 233 | base = 0; |
| 234 | ppage++; |
| 235 | } while ((pglen -= len) != 0); |
| 236 | copy_tail: |
| 237 | len = xdr->tail[0].iov_len; |
| 238 | if (base < len) { |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 239 | err = xs_send_tail(sock, xdr, base, len); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 240 | if (ret == 0) |
| 241 | ret = err; |
| 242 | else if (err > 0) |
| 243 | ret += err; |
| 244 | } |
| 245 | out: |
| 246 | return ret; |
| 247 | } |
| 248 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 249 | /** |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 250 | * xs_nospace - place task on wait queue if transmit was incomplete |
| 251 | * @task: task to put to sleep |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 252 | * |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 253 | */ |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 254 | static void xs_nospace(struct rpc_task *task) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 255 | { |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 256 | struct rpc_rqst *req = task->tk_rqstp; |
| 257 | struct rpc_xprt *xprt = req->rq_xprt; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 258 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 259 | dprintk("RPC: %4d xmit incomplete (%u left of %u)\n", |
| 260 | task->tk_pid, req->rq_slen - req->rq_bytes_sent, |
| 261 | req->rq_slen); |
| 262 | |
| 263 | if (test_bit(SOCK_ASYNC_NOSPACE, &xprt->sock->flags)) { |
| 264 | /* Protect against races with write_space */ |
| 265 | spin_lock_bh(&xprt->transport_lock); |
| 266 | |
| 267 | /* Don't race with disconnect */ |
| 268 | if (!xprt_connected(xprt)) |
| 269 | task->tk_status = -ENOTCONN; |
| 270 | else if (test_bit(SOCK_NOSPACE, &xprt->sock->flags)) |
| 271 | xprt_wait_for_buffer_space(task); |
| 272 | |
| 273 | spin_unlock_bh(&xprt->transport_lock); |
| 274 | } else |
| 275 | /* Keep holding the socket if it is blocked */ |
| 276 | rpc_delay(task, HZ>>4); |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * xs_udp_send_request - write an RPC request to a UDP socket |
| 281 | * @task: address of RPC task that manages the state of an RPC request |
| 282 | * |
| 283 | * Return values: |
| 284 | * 0: The request has been sent |
| 285 | * EAGAIN: The socket was blocked, please call again later to |
| 286 | * complete the request |
| 287 | * ENOTCONN: Caller needs to invoke connect logic then call again |
| 288 | * other: Some other error occured, the request was not sent |
| 289 | */ |
| 290 | static int xs_udp_send_request(struct rpc_task *task) |
| 291 | { |
| 292 | struct rpc_rqst *req = task->tk_rqstp; |
| 293 | struct rpc_xprt *xprt = req->rq_xprt; |
| 294 | struct xdr_buf *xdr = &req->rq_snd_buf; |
| 295 | int status; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 296 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 297 | xs_pktdump("packet data:", |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 298 | req->rq_svec->iov_base, |
| 299 | req->rq_svec->iov_len); |
| 300 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 301 | req->rq_xtime = jiffies; |
| 302 | status = xs_sendpages(xprt->sock, (struct sockaddr *) &xprt->addr, |
| 303 | sizeof(xprt->addr), xdr, req->rq_bytes_sent); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 304 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 305 | dprintk("RPC: xs_udp_send_request(%u) = %d\n", |
| 306 | xdr->len - req->rq_bytes_sent, status); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 307 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 308 | if (likely(status >= (int) req->rq_slen)) |
| 309 | return 0; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 310 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 311 | /* Still some bytes left; set up for a retry later. */ |
| 312 | if (status > 0) |
| 313 | status = -EAGAIN; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 314 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 315 | switch (status) { |
| 316 | case -ENETUNREACH: |
| 317 | case -EPIPE: |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 318 | case -ECONNREFUSED: |
| 319 | /* When the server has died, an ICMP port unreachable message |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 320 | * prompts ECONNREFUSED. */ |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 321 | break; |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 322 | case -EAGAIN: |
| 323 | xs_nospace(task); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 324 | break; |
| 325 | default: |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 326 | dprintk("RPC: sendmsg returned unrecognized error %d\n", |
| 327 | -status); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 328 | break; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 329 | } |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 330 | |
| 331 | return status; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 332 | } |
| 333 | |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 334 | static inline void xs_encode_tcp_record_marker(struct xdr_buf *buf) |
| 335 | { |
| 336 | u32 reclen = buf->len - sizeof(rpc_fraghdr); |
| 337 | rpc_fraghdr *base = buf->head[0].iov_base; |
| 338 | *base = htonl(RPC_LAST_STREAM_FRAGMENT | reclen); |
| 339 | } |
| 340 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 341 | /** |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 342 | * xs_tcp_send_request - write an RPC request to a TCP socket |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 343 | * @task: address of RPC task that manages the state of an RPC request |
| 344 | * |
| 345 | * Return values: |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 346 | * 0: The request has been sent |
| 347 | * EAGAIN: The socket was blocked, please call again later to |
| 348 | * complete the request |
| 349 | * ENOTCONN: Caller needs to invoke connect logic then call again |
| 350 | * other: Some other error occured, the request was not sent |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 351 | * |
| 352 | * XXX: In the case of soft timeouts, should we eventually give up |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 353 | * if sendmsg is not able to make progress? |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 354 | */ |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 355 | static int xs_tcp_send_request(struct rpc_task *task) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 356 | { |
| 357 | struct rpc_rqst *req = task->tk_rqstp; |
| 358 | struct rpc_xprt *xprt = req->rq_xprt; |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 359 | struct xdr_buf *xdr = &req->rq_snd_buf; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 360 | int status, retry = 0; |
| 361 | |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 362 | xs_encode_tcp_record_marker(&req->rq_snd_buf); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 363 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 364 | xs_pktdump("packet data:", |
| 365 | req->rq_svec->iov_base, |
| 366 | req->rq_svec->iov_len); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 367 | |
| 368 | /* Continue transmitting the packet/record. We must be careful |
| 369 | * to cope with writespace callbacks arriving _after_ we have |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 370 | * called sendmsg(). */ |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 371 | while (1) { |
| 372 | req->rq_xtime = jiffies; |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 373 | status = xs_sendpages(xprt->sock, NULL, 0, xdr, |
| 374 | req->rq_bytes_sent); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 375 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 376 | dprintk("RPC: xs_tcp_send_request(%u) = %d\n", |
| 377 | xdr->len - req->rq_bytes_sent, status); |
| 378 | |
| 379 | if (unlikely(status < 0)) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 380 | break; |
| 381 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 382 | /* If we've sent the entire packet, immediately |
| 383 | * reset the count of bytes sent. */ |
| 384 | req->rq_bytes_sent += status; |
| 385 | if (likely(req->rq_bytes_sent >= req->rq_slen)) { |
| 386 | req->rq_bytes_sent = 0; |
| 387 | return 0; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 388 | } |
| 389 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 390 | status = -EAGAIN; |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 391 | if (retry++ > XS_SENDMSG_RETRY) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 392 | break; |
| 393 | } |
| 394 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 395 | switch (status) { |
| 396 | case -EAGAIN: |
| 397 | xs_nospace(task); |
| 398 | break; |
| 399 | case -ECONNREFUSED: |
| 400 | case -ECONNRESET: |
| 401 | case -ENOTCONN: |
| 402 | case -EPIPE: |
| 403 | status = -ENOTCONN; |
| 404 | break; |
| 405 | default: |
| 406 | dprintk("RPC: sendmsg returned unrecognized error %d\n", |
| 407 | -status); |
Chuck Lever | 43118c2 | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 408 | xprt_disconnect(xprt); |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 409 | break; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 410 | } |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 411 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 412 | return status; |
| 413 | } |
| 414 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 415 | /** |
| 416 | * xs_close - close a socket |
| 417 | * @xprt: transport |
| 418 | * |
Chuck Lever | 3167e12 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 419 | * This is used when all requests are complete; ie, no DRC state remains |
| 420 | * on the server we want to save. |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 421 | */ |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 422 | static void xs_close(struct rpc_xprt *xprt) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 423 | { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 424 | struct socket *sock = xprt->sock; |
| 425 | struct sock *sk = xprt->inet; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 426 | |
| 427 | if (!sk) |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 428 | goto clear_close_wait; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 429 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 430 | dprintk("RPC: xs_close xprt %p\n", xprt); |
| 431 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 432 | write_lock_bh(&sk->sk_callback_lock); |
| 433 | xprt->inet = NULL; |
| 434 | xprt->sock = NULL; |
| 435 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 436 | sk->sk_user_data = NULL; |
| 437 | sk->sk_data_ready = xprt->old_data_ready; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 438 | sk->sk_state_change = xprt->old_state_change; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 439 | sk->sk_write_space = xprt->old_write_space; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 440 | write_unlock_bh(&sk->sk_callback_lock); |
| 441 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 442 | sk->sk_no_check = 0; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 443 | |
| 444 | sock_release(sock); |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 445 | clear_close_wait: |
| 446 | smp_mb__before_clear_bit(); |
| 447 | clear_bit(XPRT_CLOSE_WAIT, &xprt->state); |
| 448 | smp_mb__after_clear_bit(); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 449 | } |
| 450 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 451 | /** |
| 452 | * xs_destroy - prepare to shutdown a transport |
| 453 | * @xprt: doomed transport |
| 454 | * |
| 455 | */ |
| 456 | static void xs_destroy(struct rpc_xprt *xprt) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 457 | { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 458 | dprintk("RPC: xs_destroy xprt %p\n", xprt); |
| 459 | |
Chuck Lever | 55aa4f5 | 2005-08-11 16:25:47 -0400 | [diff] [blame] | 460 | cancel_delayed_work(&xprt->connect_worker); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 461 | flush_scheduled_work(); |
| 462 | |
| 463 | xprt_disconnect(xprt); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 464 | xs_close(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 465 | kfree(xprt->slot); |
| 466 | } |
| 467 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 468 | static inline struct rpc_xprt *xprt_from_sock(struct sock *sk) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 469 | { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 470 | return (struct rpc_xprt *) sk->sk_user_data; |
| 471 | } |
| 472 | |
| 473 | /** |
| 474 | * xs_udp_data_ready - "data ready" callback for UDP sockets |
| 475 | * @sk: socket with data to read |
| 476 | * @len: how much data to read |
| 477 | * |
| 478 | */ |
| 479 | static void xs_udp_data_ready(struct sock *sk, int len) |
| 480 | { |
| 481 | struct rpc_task *task; |
| 482 | struct rpc_xprt *xprt; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 483 | struct rpc_rqst *rovr; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 484 | struct sk_buff *skb; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 485 | int err, repsize, copied; |
| 486 | u32 _xid, *xp; |
| 487 | |
| 488 | read_lock(&sk->sk_callback_lock); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 489 | dprintk("RPC: xs_udp_data_ready...\n"); |
| 490 | if (!(xprt = xprt_from_sock(sk))) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 491 | goto out; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 492 | |
| 493 | if ((skb = skb_recv_datagram(sk, 0, 1, &err)) == NULL) |
| 494 | goto out; |
| 495 | |
| 496 | if (xprt->shutdown) |
| 497 | goto dropit; |
| 498 | |
| 499 | repsize = skb->len - sizeof(struct udphdr); |
| 500 | if (repsize < 4) { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 501 | dprintk("RPC: impossible RPC reply size %d!\n", repsize); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 502 | goto dropit; |
| 503 | } |
| 504 | |
| 505 | /* Copy the XID from the skb... */ |
| 506 | xp = skb_header_pointer(skb, sizeof(struct udphdr), |
| 507 | sizeof(_xid), &_xid); |
| 508 | if (xp == NULL) |
| 509 | goto dropit; |
| 510 | |
| 511 | /* Look up and lock the request corresponding to the given XID */ |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 512 | spin_lock(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 513 | rovr = xprt_lookup_rqst(xprt, *xp); |
| 514 | if (!rovr) |
| 515 | goto out_unlock; |
| 516 | task = rovr->rq_task; |
| 517 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 518 | if ((copied = rovr->rq_private_buf.buflen) > repsize) |
| 519 | copied = repsize; |
| 520 | |
| 521 | /* Suck it into the iovec, verify checksum if not done by hw. */ |
| 522 | if (csum_partial_copy_to_xdr(&rovr->rq_private_buf, skb)) |
| 523 | goto out_unlock; |
| 524 | |
| 525 | /* Something worked... */ |
| 526 | dst_confirm(skb->dst); |
| 527 | |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 528 | xprt_adjust_cwnd(task, copied); |
| 529 | xprt_update_rtt(task); |
| 530 | xprt_complete_rqst(task, copied); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 531 | |
| 532 | out_unlock: |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 533 | spin_unlock(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 534 | dropit: |
| 535 | skb_free_datagram(sk, skb); |
| 536 | out: |
| 537 | read_unlock(&sk->sk_callback_lock); |
| 538 | } |
| 539 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 540 | static inline size_t xs_tcp_copy_data(skb_reader_t *desc, void *p, size_t len) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 541 | { |
| 542 | if (len > desc->count) |
| 543 | len = desc->count; |
| 544 | if (skb_copy_bits(desc->skb, desc->offset, p, len)) { |
| 545 | dprintk("RPC: failed to copy %zu bytes from skb. %zu bytes remain\n", |
| 546 | len, desc->count); |
| 547 | return 0; |
| 548 | } |
| 549 | desc->offset += len; |
| 550 | desc->count -= len; |
| 551 | dprintk("RPC: copied %zu bytes from skb. %zu bytes remain\n", |
| 552 | len, desc->count); |
| 553 | return len; |
| 554 | } |
| 555 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 556 | static inline void xs_tcp_read_fraghdr(struct rpc_xprt *xprt, skb_reader_t *desc) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 557 | { |
| 558 | size_t len, used; |
| 559 | char *p; |
| 560 | |
| 561 | p = ((char *) &xprt->tcp_recm) + xprt->tcp_offset; |
| 562 | len = sizeof(xprt->tcp_recm) - xprt->tcp_offset; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 563 | used = xs_tcp_copy_data(desc, p, len); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 564 | xprt->tcp_offset += used; |
| 565 | if (used != len) |
| 566 | return; |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 567 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 568 | xprt->tcp_reclen = ntohl(xprt->tcp_recm); |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 569 | if (xprt->tcp_reclen & RPC_LAST_STREAM_FRAGMENT) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 570 | xprt->tcp_flags |= XPRT_LAST_FRAG; |
| 571 | else |
| 572 | xprt->tcp_flags &= ~XPRT_LAST_FRAG; |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 573 | xprt->tcp_reclen &= RPC_FRAGMENT_SIZE_MASK; |
| 574 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 575 | xprt->tcp_flags &= ~XPRT_COPY_RECM; |
| 576 | xprt->tcp_offset = 0; |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 577 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 578 | /* Sanity check of the record length */ |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 579 | if (unlikely(xprt->tcp_reclen < 4)) { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 580 | dprintk("RPC: invalid TCP record fragment length\n"); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 581 | xprt_disconnect(xprt); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 582 | return; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 583 | } |
| 584 | dprintk("RPC: reading TCP record fragment of length %d\n", |
| 585 | xprt->tcp_reclen); |
| 586 | } |
| 587 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 588 | static void xs_tcp_check_recm(struct rpc_xprt *xprt) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 589 | { |
| 590 | dprintk("RPC: xprt = %p, tcp_copied = %lu, tcp_offset = %u, tcp_reclen = %u, tcp_flags = %lx\n", |
| 591 | xprt, xprt->tcp_copied, xprt->tcp_offset, xprt->tcp_reclen, xprt->tcp_flags); |
| 592 | if (xprt->tcp_offset == xprt->tcp_reclen) { |
| 593 | xprt->tcp_flags |= XPRT_COPY_RECM; |
| 594 | xprt->tcp_offset = 0; |
| 595 | if (xprt->tcp_flags & XPRT_LAST_FRAG) { |
| 596 | xprt->tcp_flags &= ~XPRT_COPY_DATA; |
| 597 | xprt->tcp_flags |= XPRT_COPY_XID; |
| 598 | xprt->tcp_copied = 0; |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 603 | static inline void xs_tcp_read_xid(struct rpc_xprt *xprt, skb_reader_t *desc) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 604 | { |
| 605 | size_t len, used; |
| 606 | char *p; |
| 607 | |
| 608 | len = sizeof(xprt->tcp_xid) - xprt->tcp_offset; |
| 609 | dprintk("RPC: reading XID (%Zu bytes)\n", len); |
| 610 | p = ((char *) &xprt->tcp_xid) + xprt->tcp_offset; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 611 | used = xs_tcp_copy_data(desc, p, len); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 612 | xprt->tcp_offset += used; |
| 613 | if (used != len) |
| 614 | return; |
| 615 | xprt->tcp_flags &= ~XPRT_COPY_XID; |
| 616 | xprt->tcp_flags |= XPRT_COPY_DATA; |
| 617 | xprt->tcp_copied = 4; |
| 618 | dprintk("RPC: reading reply for XID %08x\n", |
| 619 | ntohl(xprt->tcp_xid)); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 620 | xs_tcp_check_recm(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 621 | } |
| 622 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 623 | static inline void xs_tcp_read_request(struct rpc_xprt *xprt, skb_reader_t *desc) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 624 | { |
| 625 | struct rpc_rqst *req; |
| 626 | struct xdr_buf *rcvbuf; |
| 627 | size_t len; |
| 628 | ssize_t r; |
| 629 | |
| 630 | /* Find and lock the request corresponding to this xid */ |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 631 | spin_lock(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 632 | req = xprt_lookup_rqst(xprt, xprt->tcp_xid); |
| 633 | if (!req) { |
| 634 | xprt->tcp_flags &= ~XPRT_COPY_DATA; |
| 635 | dprintk("RPC: XID %08x request not found!\n", |
| 636 | ntohl(xprt->tcp_xid)); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 637 | spin_unlock(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 638 | return; |
| 639 | } |
| 640 | |
| 641 | rcvbuf = &req->rq_private_buf; |
| 642 | len = desc->count; |
| 643 | if (len > xprt->tcp_reclen - xprt->tcp_offset) { |
| 644 | skb_reader_t my_desc; |
| 645 | |
| 646 | len = xprt->tcp_reclen - xprt->tcp_offset; |
| 647 | memcpy(&my_desc, desc, sizeof(my_desc)); |
| 648 | my_desc.count = len; |
| 649 | r = xdr_partial_copy_from_skb(rcvbuf, xprt->tcp_copied, |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 650 | &my_desc, xs_tcp_copy_data); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 651 | desc->count -= r; |
| 652 | desc->offset += r; |
| 653 | } else |
| 654 | r = xdr_partial_copy_from_skb(rcvbuf, xprt->tcp_copied, |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 655 | desc, xs_tcp_copy_data); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 656 | |
| 657 | if (r > 0) { |
| 658 | xprt->tcp_copied += r; |
| 659 | xprt->tcp_offset += r; |
| 660 | } |
| 661 | if (r != len) { |
| 662 | /* Error when copying to the receive buffer, |
| 663 | * usually because we weren't able to allocate |
| 664 | * additional buffer pages. All we can do now |
| 665 | * is turn off XPRT_COPY_DATA, so the request |
| 666 | * will not receive any additional updates, |
| 667 | * and time out. |
| 668 | * Any remaining data from this record will |
| 669 | * be discarded. |
| 670 | */ |
| 671 | xprt->tcp_flags &= ~XPRT_COPY_DATA; |
| 672 | dprintk("RPC: XID %08x truncated request\n", |
| 673 | ntohl(xprt->tcp_xid)); |
| 674 | dprintk("RPC: xprt = %p, tcp_copied = %lu, tcp_offset = %u, tcp_reclen = %u\n", |
| 675 | xprt, xprt->tcp_copied, xprt->tcp_offset, xprt->tcp_reclen); |
| 676 | goto out; |
| 677 | } |
| 678 | |
| 679 | dprintk("RPC: XID %08x read %Zd bytes\n", |
| 680 | ntohl(xprt->tcp_xid), r); |
| 681 | dprintk("RPC: xprt = %p, tcp_copied = %lu, tcp_offset = %u, tcp_reclen = %u\n", |
| 682 | xprt, xprt->tcp_copied, xprt->tcp_offset, xprt->tcp_reclen); |
| 683 | |
| 684 | if (xprt->tcp_copied == req->rq_private_buf.buflen) |
| 685 | xprt->tcp_flags &= ~XPRT_COPY_DATA; |
| 686 | else if (xprt->tcp_offset == xprt->tcp_reclen) { |
| 687 | if (xprt->tcp_flags & XPRT_LAST_FRAG) |
| 688 | xprt->tcp_flags &= ~XPRT_COPY_DATA; |
| 689 | } |
| 690 | |
| 691 | out: |
Chuck Lever | 1570c1e | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 692 | if (!(xprt->tcp_flags & XPRT_COPY_DATA)) |
| 693 | xprt_complete_rqst(req->rq_task, xprt->tcp_copied); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 694 | spin_unlock(&xprt->transport_lock); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 695 | xs_tcp_check_recm(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 696 | } |
| 697 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 698 | static inline void xs_tcp_read_discard(struct rpc_xprt *xprt, skb_reader_t *desc) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 699 | { |
| 700 | size_t len; |
| 701 | |
| 702 | len = xprt->tcp_reclen - xprt->tcp_offset; |
| 703 | if (len > desc->count) |
| 704 | len = desc->count; |
| 705 | desc->count -= len; |
| 706 | desc->offset += len; |
| 707 | xprt->tcp_offset += len; |
| 708 | dprintk("RPC: discarded %Zu bytes\n", len); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 709 | xs_tcp_check_recm(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 710 | } |
| 711 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 712 | 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] | 713 | { |
| 714 | struct rpc_xprt *xprt = rd_desc->arg.data; |
| 715 | skb_reader_t desc = { |
| 716 | .skb = skb, |
| 717 | .offset = offset, |
| 718 | .count = len, |
| 719 | .csum = 0 |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 720 | }; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 721 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 722 | dprintk("RPC: xs_tcp_data_recv started\n"); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 723 | do { |
| 724 | /* Read in a new fragment marker if necessary */ |
| 725 | /* Can we ever really expect to get completely empty fragments? */ |
| 726 | if (xprt->tcp_flags & XPRT_COPY_RECM) { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 727 | xs_tcp_read_fraghdr(xprt, &desc); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 728 | continue; |
| 729 | } |
| 730 | /* Read in the xid if necessary */ |
| 731 | if (xprt->tcp_flags & XPRT_COPY_XID) { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 732 | xs_tcp_read_xid(xprt, &desc); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 733 | continue; |
| 734 | } |
| 735 | /* Read in the request data */ |
| 736 | if (xprt->tcp_flags & XPRT_COPY_DATA) { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 737 | xs_tcp_read_request(xprt, &desc); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 738 | continue; |
| 739 | } |
| 740 | /* Skip over any trailing bytes on short reads */ |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 741 | xs_tcp_read_discard(xprt, &desc); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 742 | } while (desc.count); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 743 | dprintk("RPC: xs_tcp_data_recv done\n"); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 744 | return len - desc.count; |
| 745 | } |
| 746 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 747 | /** |
| 748 | * xs_tcp_data_ready - "data ready" callback for TCP sockets |
| 749 | * @sk: socket with data to read |
| 750 | * @bytes: how much data to read |
| 751 | * |
| 752 | */ |
| 753 | static void xs_tcp_data_ready(struct sock *sk, int bytes) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 754 | { |
| 755 | struct rpc_xprt *xprt; |
| 756 | read_descriptor_t rd_desc; |
| 757 | |
| 758 | read_lock(&sk->sk_callback_lock); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 759 | dprintk("RPC: xs_tcp_data_ready...\n"); |
| 760 | if (!(xprt = xprt_from_sock(sk))) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 761 | goto out; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 762 | if (xprt->shutdown) |
| 763 | goto out; |
| 764 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 765 | /* 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] | 766 | rd_desc.arg.data = xprt; |
| 767 | rd_desc.count = 65536; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 768 | tcp_read_sock(sk, &rd_desc, xs_tcp_data_recv); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 769 | out: |
| 770 | read_unlock(&sk->sk_callback_lock); |
| 771 | } |
| 772 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 773 | /** |
| 774 | * xs_tcp_state_change - callback to handle TCP socket state changes |
| 775 | * @sk: socket whose state has changed |
| 776 | * |
| 777 | */ |
| 778 | static void xs_tcp_state_change(struct sock *sk) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 779 | { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 780 | struct rpc_xprt *xprt; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 781 | |
| 782 | read_lock(&sk->sk_callback_lock); |
| 783 | if (!(xprt = xprt_from_sock(sk))) |
| 784 | goto out; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 785 | dprintk("RPC: xs_tcp_state_change client %p...\n", xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 786 | dprintk("RPC: state %x conn %d dead %d zapped %d\n", |
| 787 | sk->sk_state, xprt_connected(xprt), |
| 788 | sock_flag(sk, SOCK_DEAD), |
| 789 | sock_flag(sk, SOCK_ZAPPED)); |
| 790 | |
| 791 | switch (sk->sk_state) { |
| 792 | case TCP_ESTABLISHED: |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 793 | spin_lock_bh(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 794 | if (!xprt_test_and_set_connected(xprt)) { |
| 795 | /* Reset TCP record info */ |
| 796 | xprt->tcp_offset = 0; |
| 797 | xprt->tcp_reclen = 0; |
| 798 | xprt->tcp_copied = 0; |
| 799 | xprt->tcp_flags = XPRT_COPY_RECM | XPRT_COPY_XID; |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 800 | xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO; |
Chuck Lever | 44fbac2 | 2005-08-11 16:25:44 -0400 | [diff] [blame] | 801 | xprt_wake_pending_tasks(xprt, 0); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 802 | } |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 803 | spin_unlock_bh(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 804 | break; |
| 805 | case TCP_SYN_SENT: |
| 806 | case TCP_SYN_RECV: |
| 807 | break; |
Trond Myklebust | 632e3bd | 2006-01-03 09:55:55 +0100 | [diff] [blame] | 808 | case TCP_CLOSE_WAIT: |
| 809 | /* Try to schedule an autoclose RPC calls */ |
| 810 | set_bit(XPRT_CLOSE_WAIT, &xprt->state); |
| 811 | if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0) |
| 812 | schedule_work(&xprt->task_cleanup); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 813 | default: |
| 814 | xprt_disconnect(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 815 | } |
| 816 | out: |
| 817 | read_unlock(&sk->sk_callback_lock); |
| 818 | } |
| 819 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 820 | /** |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 821 | * xs_udp_write_space - callback invoked when socket buffer space |
| 822 | * becomes available |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 823 | * @sk: socket whose state has changed |
| 824 | * |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 825 | * Called when more output buffer space is available for this socket. |
| 826 | * We try not to wake our writers until they can make "significant" |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 827 | * progress, otherwise we'll waste resources thrashing kernel_sendmsg |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 828 | * with a bunch of small requests. |
| 829 | */ |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 830 | static void xs_udp_write_space(struct sock *sk) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 831 | { |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 832 | read_lock(&sk->sk_callback_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 833 | |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 834 | /* from net/core/sock.c:sock_def_write_space */ |
| 835 | if (sock_writeable(sk)) { |
| 836 | struct socket *sock; |
| 837 | struct rpc_xprt *xprt; |
| 838 | |
| 839 | if (unlikely(!(sock = sk->sk_socket))) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 840 | goto out; |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 841 | if (unlikely(!(xprt = xprt_from_sock(sk)))) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 842 | goto out; |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 843 | if (unlikely(!test_and_clear_bit(SOCK_NOSPACE, &sock->flags))) |
| 844 | goto out; |
| 845 | |
| 846 | xprt_write_space(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 847 | } |
| 848 | |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 849 | out: |
| 850 | read_unlock(&sk->sk_callback_lock); |
| 851 | } |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 852 | |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 853 | /** |
| 854 | * xs_tcp_write_space - callback invoked when socket buffer space |
| 855 | * becomes available |
| 856 | * @sk: socket whose state has changed |
| 857 | * |
| 858 | * Called when more output buffer space is available for this socket. |
| 859 | * We try not to wake our writers until they can make "significant" |
| 860 | * progress, otherwise we'll waste resources thrashing kernel_sendmsg |
| 861 | * with a bunch of small requests. |
| 862 | */ |
| 863 | static void xs_tcp_write_space(struct sock *sk) |
| 864 | { |
| 865 | read_lock(&sk->sk_callback_lock); |
| 866 | |
| 867 | /* from net/core/stream.c:sk_stream_write_space */ |
| 868 | if (sk_stream_wspace(sk) >= sk_stream_min_wspace(sk)) { |
| 869 | struct socket *sock; |
| 870 | struct rpc_xprt *xprt; |
| 871 | |
| 872 | if (unlikely(!(sock = sk->sk_socket))) |
| 873 | goto out; |
| 874 | if (unlikely(!(xprt = xprt_from_sock(sk)))) |
| 875 | goto out; |
| 876 | if (unlikely(!test_and_clear_bit(SOCK_NOSPACE, &sock->flags))) |
| 877 | goto out; |
| 878 | |
| 879 | xprt_write_space(xprt); |
| 880 | } |
| 881 | |
| 882 | out: |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 883 | read_unlock(&sk->sk_callback_lock); |
| 884 | } |
| 885 | |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 886 | static void xs_udp_do_set_buffer_size(struct rpc_xprt *xprt) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 887 | { |
| 888 | struct sock *sk = xprt->inet; |
| 889 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 890 | if (xprt->rcvsize) { |
| 891 | sk->sk_userlocks |= SOCK_RCVBUF_LOCK; |
| 892 | sk->sk_rcvbuf = xprt->rcvsize * xprt->max_reqs * 2; |
| 893 | } |
| 894 | if (xprt->sndsize) { |
| 895 | sk->sk_userlocks |= SOCK_SNDBUF_LOCK; |
| 896 | sk->sk_sndbuf = xprt->sndsize * xprt->max_reqs * 2; |
| 897 | sk->sk_write_space(sk); |
| 898 | } |
| 899 | } |
| 900 | |
Chuck Lever | 43118c2 | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 901 | /** |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 902 | * xs_udp_set_buffer_size - set send and receive limits |
Chuck Lever | 43118c2 | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 903 | * @xprt: generic transport |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 904 | * @sndsize: requested size of send buffer, in bytes |
| 905 | * @rcvsize: requested size of receive buffer, in bytes |
Chuck Lever | 43118c2 | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 906 | * |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 907 | * Set socket send and receive buffer size limits. |
Chuck Lever | 43118c2 | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 908 | */ |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 909 | 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] | 910 | { |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 911 | xprt->sndsize = 0; |
| 912 | if (sndsize) |
| 913 | xprt->sndsize = sndsize + 1024; |
| 914 | xprt->rcvsize = 0; |
| 915 | if (rcvsize) |
| 916 | xprt->rcvsize = rcvsize + 1024; |
| 917 | |
| 918 | xs_udp_do_set_buffer_size(xprt); |
Chuck Lever | 43118c2 | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 921 | /** |
| 922 | * xs_udp_timer - called when a retransmit timeout occurs on a UDP transport |
| 923 | * @task: task that timed out |
| 924 | * |
| 925 | * Adjust the congestion window after a retransmit timeout has occurred. |
| 926 | */ |
| 927 | static void xs_udp_timer(struct rpc_task *task) |
| 928 | { |
| 929 | xprt_adjust_cwnd(task, -ETIMEDOUT); |
| 930 | } |
| 931 | |
Chuck Lever | 9220041 | 2006-01-03 09:55:51 +0100 | [diff] [blame] | 932 | /** |
| 933 | * xs_set_port - reset the port number in the remote endpoint address |
| 934 | * @xprt: generic transport |
| 935 | * @port: new port number |
| 936 | * |
| 937 | */ |
| 938 | static void xs_set_port(struct rpc_xprt *xprt, unsigned short port) |
| 939 | { |
| 940 | dprintk("RPC: setting port for xprt %p to %u\n", xprt, port); |
| 941 | xprt->addr.sin_port = htons(port); |
| 942 | } |
| 943 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 944 | static int xs_bindresvport(struct rpc_xprt *xprt, struct socket *sock) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 945 | { |
| 946 | struct sockaddr_in myaddr = { |
| 947 | .sin_family = AF_INET, |
| 948 | }; |
Chuck Lever | 529b33c | 2005-08-25 16:25:54 -0700 | [diff] [blame] | 949 | int err; |
| 950 | unsigned short port = xprt->port; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 951 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 952 | do { |
| 953 | myaddr.sin_port = htons(port); |
| 954 | err = sock->ops->bind(sock, (struct sockaddr *) &myaddr, |
| 955 | sizeof(myaddr)); |
| 956 | if (err == 0) { |
| 957 | xprt->port = port; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 958 | dprintk("RPC: xs_bindresvport bound to port %u\n", |
| 959 | port); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 960 | return 0; |
| 961 | } |
Chuck Lever | 529b33c | 2005-08-25 16:25:54 -0700 | [diff] [blame] | 962 | if (port <= xprt_min_resvport) |
| 963 | port = xprt_max_resvport; |
| 964 | else |
| 965 | port--; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 966 | } while (err == -EADDRINUSE && port != xprt->port); |
| 967 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 968 | dprintk("RPC: can't bind to reserved port (%d).\n", -err); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 969 | return err; |
| 970 | } |
| 971 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 972 | /** |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 973 | * xs_udp_connect_worker - set up a UDP socket |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 974 | * @args: RPC transport to connect |
| 975 | * |
| 976 | * Invoked by a work queue tasklet. |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 977 | */ |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 978 | static void xs_udp_connect_worker(void *args) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 979 | { |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 980 | struct rpc_xprt *xprt = (struct rpc_xprt *) args; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 981 | struct socket *sock = xprt->sock; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 982 | int err, status = -EIO; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 983 | |
| 984 | if (xprt->shutdown || xprt->addr.sin_port == 0) |
| 985 | goto out; |
| 986 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 987 | dprintk("RPC: xs_udp_connect_worker for xprt %p\n", xprt); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 988 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 989 | /* Start by resetting any existing state */ |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 990 | xs_close(xprt); |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 991 | |
| 992 | if ((err = sock_create_kern(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &sock)) < 0) { |
| 993 | dprintk("RPC: can't create UDP transport socket (%d).\n", -err); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 994 | goto out; |
| 995 | } |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 996 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 997 | if (xprt->resvport && xs_bindresvport(xprt, sock) < 0) { |
| 998 | sock_release(sock); |
| 999 | goto out; |
| 1000 | } |
| 1001 | |
| 1002 | if (!xprt->inet) { |
| 1003 | struct sock *sk = sock->sk; |
| 1004 | |
| 1005 | write_lock_bh(&sk->sk_callback_lock); |
| 1006 | |
| 1007 | sk->sk_user_data = xprt; |
| 1008 | xprt->old_data_ready = sk->sk_data_ready; |
| 1009 | xprt->old_state_change = sk->sk_state_change; |
| 1010 | xprt->old_write_space = sk->sk_write_space; |
| 1011 | sk->sk_data_ready = xs_udp_data_ready; |
| 1012 | sk->sk_write_space = xs_udp_write_space; |
| 1013 | sk->sk_no_check = UDP_CSUM_NORCV; |
Trond Myklebust | b079fa7 | 2005-12-13 16:13:52 -0500 | [diff] [blame] | 1014 | sk->sk_allocation = GFP_ATOMIC; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1015 | |
| 1016 | xprt_set_connected(xprt); |
| 1017 | |
| 1018 | /* Reset to new socket */ |
| 1019 | xprt->sock = sock; |
| 1020 | xprt->inet = sk; |
| 1021 | |
| 1022 | write_unlock_bh(&sk->sk_callback_lock); |
| 1023 | } |
Chuck Lever | 470056c | 2005-08-25 16:25:56 -0700 | [diff] [blame] | 1024 | xs_udp_do_set_buffer_size(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1025 | status = 0; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1026 | out: |
| 1027 | xprt_wake_pending_tasks(xprt, status); |
| 1028 | xprt_clear_connecting(xprt); |
| 1029 | } |
| 1030 | |
Chuck Lever | 3167e12 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1031 | /* |
| 1032 | * We need to preserve the port number so the reply cache on the server can |
| 1033 | * find our cached RPC replies when we get around to reconnecting. |
| 1034 | */ |
| 1035 | static void xs_tcp_reuse_connection(struct rpc_xprt *xprt) |
| 1036 | { |
| 1037 | int result; |
| 1038 | struct socket *sock = xprt->sock; |
| 1039 | struct sockaddr any; |
| 1040 | |
| 1041 | dprintk("RPC: disconnecting xprt %p to reuse port\n", xprt); |
| 1042 | |
| 1043 | /* |
| 1044 | * Disconnect the transport socket by doing a connect operation |
| 1045 | * with AF_UNSPEC. This should return immediately... |
| 1046 | */ |
| 1047 | memset(&any, 0, sizeof(any)); |
| 1048 | any.sa_family = AF_UNSPEC; |
| 1049 | result = sock->ops->connect(sock, &any, sizeof(any), 0); |
| 1050 | if (result) |
| 1051 | dprintk("RPC: AF_UNSPEC connect return code %d\n", |
| 1052 | result); |
| 1053 | } |
| 1054 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1055 | /** |
| 1056 | * xs_tcp_connect_worker - connect a TCP socket to a remote endpoint |
| 1057 | * @args: RPC transport to connect |
| 1058 | * |
| 1059 | * Invoked by a work queue tasklet. |
| 1060 | */ |
| 1061 | static void xs_tcp_connect_worker(void *args) |
| 1062 | { |
| 1063 | struct rpc_xprt *xprt = (struct rpc_xprt *)args; |
| 1064 | struct socket *sock = xprt->sock; |
| 1065 | int err, status = -EIO; |
| 1066 | |
| 1067 | if (xprt->shutdown || xprt->addr.sin_port == 0) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1068 | goto out; |
| 1069 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1070 | dprintk("RPC: xs_tcp_connect_worker for xprt %p\n", xprt); |
| 1071 | |
Chuck Lever | 3167e12 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1072 | if (!xprt->sock) { |
| 1073 | /* start from scratch */ |
| 1074 | if ((err = sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock)) < 0) { |
| 1075 | dprintk("RPC: can't create TCP transport socket (%d).\n", -err); |
| 1076 | goto out; |
| 1077 | } |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1078 | |
Chuck Lever | 3167e12 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1079 | if (xprt->resvport && xs_bindresvport(xprt, sock) < 0) { |
| 1080 | sock_release(sock); |
| 1081 | goto out; |
| 1082 | } |
| 1083 | } else |
| 1084 | /* "close" the socket, preserving the local port */ |
| 1085 | xs_tcp_reuse_connection(xprt); |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1086 | |
| 1087 | if (!xprt->inet) { |
| 1088 | struct sock *sk = sock->sk; |
| 1089 | |
| 1090 | write_lock_bh(&sk->sk_callback_lock); |
| 1091 | |
| 1092 | sk->sk_user_data = xprt; |
| 1093 | xprt->old_data_ready = sk->sk_data_ready; |
| 1094 | xprt->old_state_change = sk->sk_state_change; |
| 1095 | xprt->old_write_space = sk->sk_write_space; |
| 1096 | sk->sk_data_ready = xs_tcp_data_ready; |
| 1097 | sk->sk_state_change = xs_tcp_state_change; |
| 1098 | sk->sk_write_space = xs_tcp_write_space; |
Trond Myklebust | b079fa7 | 2005-12-13 16:13:52 -0500 | [diff] [blame] | 1099 | sk->sk_allocation = GFP_ATOMIC; |
Chuck Lever | 3167e12 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1100 | |
| 1101 | /* socket options */ |
| 1102 | sk->sk_userlocks |= SOCK_BINDPORT_LOCK; |
| 1103 | sock_reset_flag(sk, SOCK_LINGER); |
| 1104 | tcp_sk(sk)->linger2 = 0; |
| 1105 | tcp_sk(sk)->nonagle |= TCP_NAGLE_OFF; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1106 | |
| 1107 | xprt_clear_connected(xprt); |
| 1108 | |
| 1109 | /* Reset to new socket */ |
| 1110 | xprt->sock = sock; |
| 1111 | xprt->inet = sk; |
| 1112 | |
| 1113 | write_unlock_bh(&sk->sk_callback_lock); |
| 1114 | } |
| 1115 | |
| 1116 | /* Tell the socket layer to start connecting... */ |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1117 | status = sock->ops->connect(sock, (struct sockaddr *) &xprt->addr, |
| 1118 | sizeof(xprt->addr), O_NONBLOCK); |
| 1119 | dprintk("RPC: %p connect status %d connected %d sock state %d\n", |
| 1120 | xprt, -status, xprt_connected(xprt), sock->sk->sk_state); |
| 1121 | if (status < 0) { |
| 1122 | switch (status) { |
| 1123 | case -EINPROGRESS: |
| 1124 | case -EALREADY: |
| 1125 | goto out_clear; |
Chuck Lever | 3167e12 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1126 | case -ECONNREFUSED: |
| 1127 | case -ECONNRESET: |
| 1128 | /* retry with existing socket, after a delay */ |
| 1129 | break; |
| 1130 | default: |
| 1131 | /* get rid of existing socket, and retry */ |
| 1132 | xs_close(xprt); |
| 1133 | break; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1134 | } |
| 1135 | } |
| 1136 | out: |
Chuck Lever | 44fbac2 | 2005-08-11 16:25:44 -0400 | [diff] [blame] | 1137 | xprt_wake_pending_tasks(xprt, status); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1138 | out_clear: |
Chuck Lever | 2226feb | 2005-08-11 16:25:38 -0400 | [diff] [blame] | 1139 | xprt_clear_connecting(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1140 | } |
| 1141 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1142 | /** |
| 1143 | * xs_connect - connect a socket to a remote endpoint |
| 1144 | * @task: address of RPC task that manages state of connect request |
| 1145 | * |
| 1146 | * TCP: If the remote end dropped the connection, delay reconnecting. |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1147 | * |
| 1148 | * UDP socket connects are synchronous, but we use a work queue anyway |
| 1149 | * to guarantee that even unprivileged user processes can set up a |
| 1150 | * socket on a privileged port. |
| 1151 | * |
| 1152 | * If a UDP socket connect fails, the delay behavior here prevents |
| 1153 | * retry floods (hard mounts). |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1154 | */ |
| 1155 | static void xs_connect(struct rpc_task *task) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1156 | { |
| 1157 | struct rpc_xprt *xprt = task->tk_xprt; |
| 1158 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1159 | if (xprt_test_and_set_connecting(xprt)) |
| 1160 | return; |
| 1161 | |
| 1162 | if (xprt->sock != NULL) { |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1163 | dprintk("RPC: xs_connect delayed xprt %p for %lu seconds\n", |
| 1164 | xprt, xprt->reestablish_timeout / HZ); |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1165 | schedule_delayed_work(&xprt->connect_worker, |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1166 | xprt->reestablish_timeout); |
| 1167 | xprt->reestablish_timeout <<= 1; |
| 1168 | if (xprt->reestablish_timeout > XS_TCP_MAX_REEST_TO) |
| 1169 | xprt->reestablish_timeout = XS_TCP_MAX_REEST_TO; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1170 | } else { |
| 1171 | dprintk("RPC: xs_connect scheduled xprt %p\n", xprt); |
| 1172 | schedule_work(&xprt->connect_worker); |
| 1173 | |
| 1174 | /* flush_scheduled_work can sleep... */ |
| 1175 | if (!RPC_IS_ASYNC(task)) |
| 1176 | flush_scheduled_work(); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 1180 | static struct rpc_xprt_ops xs_udp_ops = { |
Chuck Lever | 43118c2 | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 1181 | .set_buffer_size = xs_udp_set_buffer_size, |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 1182 | .reserve_xprt = xprt_reserve_xprt_cong, |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 1183 | .release_xprt = xprt_release_xprt_cong, |
Chuck Lever | 9220041 | 2006-01-03 09:55:51 +0100 | [diff] [blame] | 1184 | .set_port = xs_set_port, |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1185 | .connect = xs_connect, |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 1186 | .buf_alloc = rpc_malloc, |
| 1187 | .buf_free = rpc_free, |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 1188 | .send_request = xs_udp_send_request, |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 1189 | .set_retrans_timeout = xprt_set_retrans_timeout_rtt, |
Chuck Lever | 46c0ee8 | 2005-08-25 16:25:52 -0700 | [diff] [blame] | 1190 | .timer = xs_udp_timer, |
Chuck Lever | a58dd39 | 2005-08-25 16:25:53 -0700 | [diff] [blame] | 1191 | .release_request = xprt_release_rqst_cong, |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 1192 | .close = xs_close, |
| 1193 | .destroy = xs_destroy, |
| 1194 | }; |
| 1195 | |
| 1196 | static struct rpc_xprt_ops xs_tcp_ops = { |
Chuck Lever | 12a8046 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 1197 | .reserve_xprt = xprt_reserve_xprt, |
Chuck Lever | 49e9a89 | 2005-08-25 16:25:51 -0700 | [diff] [blame] | 1198 | .release_xprt = xprt_release_xprt, |
Chuck Lever | 9220041 | 2006-01-03 09:55:51 +0100 | [diff] [blame] | 1199 | .set_port = xs_set_port, |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 1200 | .connect = xs_connect, |
Chuck Lever | 0210714 | 2006-01-03 09:55:49 +0100 | [diff] [blame] | 1201 | .buf_alloc = rpc_malloc, |
| 1202 | .buf_free = rpc_free, |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 1203 | .send_request = xs_tcp_send_request, |
Chuck Lever | fe3aca2 | 2005-08-25 16:25:50 -0700 | [diff] [blame] | 1204 | .set_retrans_timeout = xprt_set_retrans_timeout_def, |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1205 | .close = xs_close, |
| 1206 | .destroy = xs_destroy, |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1207 | }; |
| 1208 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1209 | /** |
| 1210 | * xs_setup_udp - Set up transport to use a UDP socket |
| 1211 | * @xprt: transport to set up |
| 1212 | * @to: timeout parameters |
| 1213 | * |
| 1214 | */ |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1215 | int xs_setup_udp(struct rpc_xprt *xprt, struct rpc_timeout *to) |
| 1216 | { |
| 1217 | size_t slot_table_size; |
| 1218 | |
| 1219 | dprintk("RPC: setting up udp-ipv4 transport...\n"); |
| 1220 | |
| 1221 | xprt->max_reqs = xprt_udp_slot_table_entries; |
| 1222 | slot_table_size = xprt->max_reqs * sizeof(xprt->slot[0]); |
| 1223 | xprt->slot = kmalloc(slot_table_size, GFP_KERNEL); |
| 1224 | if (xprt->slot == NULL) |
| 1225 | return -ENOMEM; |
| 1226 | memset(xprt->slot, 0, slot_table_size); |
| 1227 | |
| 1228 | xprt->prot = IPPROTO_UDP; |
Chuck Lever | 529b33c | 2005-08-25 16:25:54 -0700 | [diff] [blame] | 1229 | xprt->port = xprt_max_resvport; |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 1230 | xprt->tsh_size = 0; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1231 | xprt->resvport = capable(CAP_NET_BIND_SERVICE) ? 1 : 0; |
| 1232 | /* XXX: header size can vary due to auth type, IPv6, etc. */ |
| 1233 | xprt->max_payload = (1U << 16) - (MAX_HEADER << 3); |
| 1234 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1235 | INIT_WORK(&xprt->connect_worker, xs_udp_connect_worker, xprt); |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1236 | xprt->bind_timeout = XS_BIND_TO; |
| 1237 | xprt->connect_timeout = XS_UDP_CONN_TO; |
| 1238 | xprt->reestablish_timeout = XS_UDP_REEST_TO; |
| 1239 | xprt->idle_timeout = XS_IDLE_DISC_TO; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1240 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 1241 | xprt->ops = &xs_udp_ops; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1242 | |
| 1243 | if (to) |
| 1244 | xprt->timeout = *to; |
| 1245 | else |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1246 | xprt_set_timeout(&xprt->timeout, 5, 5 * HZ); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1247 | |
| 1248 | return 0; |
| 1249 | } |
| 1250 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1251 | /** |
| 1252 | * xs_setup_tcp - Set up transport to use a TCP socket |
| 1253 | * @xprt: transport to set up |
| 1254 | * @to: timeout parameters |
| 1255 | * |
| 1256 | */ |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1257 | int xs_setup_tcp(struct rpc_xprt *xprt, struct rpc_timeout *to) |
| 1258 | { |
| 1259 | size_t slot_table_size; |
| 1260 | |
| 1261 | dprintk("RPC: setting up tcp-ipv4 transport...\n"); |
| 1262 | |
| 1263 | xprt->max_reqs = xprt_tcp_slot_table_entries; |
| 1264 | slot_table_size = xprt->max_reqs * sizeof(xprt->slot[0]); |
| 1265 | xprt->slot = kmalloc(slot_table_size, GFP_KERNEL); |
| 1266 | if (xprt->slot == NULL) |
| 1267 | return -ENOMEM; |
| 1268 | memset(xprt->slot, 0, slot_table_size); |
| 1269 | |
| 1270 | xprt->prot = IPPROTO_TCP; |
Chuck Lever | 529b33c | 2005-08-25 16:25:54 -0700 | [diff] [blame] | 1271 | xprt->port = xprt_max_resvport; |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 1272 | xprt->tsh_size = sizeof(rpc_fraghdr) / sizeof(u32); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1273 | xprt->resvport = capable(CAP_NET_BIND_SERVICE) ? 1 : 0; |
Chuck Lever | 808012f | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 1274 | xprt->max_payload = RPC_MAX_FRAGMENT_SIZE; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1275 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame] | 1276 | INIT_WORK(&xprt->connect_worker, xs_tcp_connect_worker, xprt); |
Chuck Lever | 03bf4b7 | 2005-08-25 16:25:55 -0700 | [diff] [blame] | 1277 | xprt->bind_timeout = XS_BIND_TO; |
| 1278 | xprt->connect_timeout = XS_TCP_CONN_TO; |
| 1279 | xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO; |
| 1280 | xprt->idle_timeout = XS_IDLE_DISC_TO; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1281 | |
Chuck Lever | 262965f | 2005-08-11 16:25:56 -0400 | [diff] [blame] | 1282 | xprt->ops = &xs_tcp_ops; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1283 | |
| 1284 | if (to) |
| 1285 | xprt->timeout = *to; |
| 1286 | else |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1287 | xprt_set_timeout(&xprt->timeout, 2, 60 * HZ); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1288 | |
| 1289 | return 0; |
| 1290 | } |