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> |
| 31 | #include <linux/file.h> |
| 32 | |
| 33 | #include <net/sock.h> |
| 34 | #include <net/checksum.h> |
| 35 | #include <net/udp.h> |
| 36 | #include <net/tcp.h> |
| 37 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 38 | /* |
| 39 | * Maximum port number to use when requesting a reserved port. |
| 40 | */ |
| 41 | #define XS_MAX_RESVPORT (800U) |
| 42 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 43 | #ifdef RPC_DEBUG |
| 44 | # undef RPC_DEBUG_DATA |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 45 | # define RPCDBG_FACILITY RPCDBG_TRANS |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 46 | #endif |
| 47 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 48 | #ifdef RPC_DEBUG_DATA |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 49 | static void xs_pktdump(char *msg, u32 *packet, unsigned int count) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 50 | { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 51 | u8 *buf = (u8 *) packet; |
| 52 | int j; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 53 | |
| 54 | dprintk("RPC: %s\n", msg); |
| 55 | for (j = 0; j < count && j < 128; j += 4) { |
| 56 | if (!(j & 31)) { |
| 57 | if (j) |
| 58 | dprintk("\n"); |
| 59 | dprintk("0x%04x ", j); |
| 60 | } |
| 61 | dprintk("%02x%02x%02x%02x ", |
| 62 | buf[j], buf[j+1], buf[j+2], buf[j+3]); |
| 63 | } |
| 64 | dprintk("\n"); |
| 65 | } |
| 66 | #else |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 67 | static inline void xs_pktdump(char *msg, u32 *packet, unsigned int count) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 68 | { |
| 69 | /* NOP */ |
| 70 | } |
| 71 | #endif |
| 72 | |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 73 | #define XS_SENDMSG_FLAGS (MSG_DONTWAIT | MSG_NOSIGNAL) |
| 74 | |
| 75 | static inline int xs_send_head(struct socket *sock, struct sockaddr *addr, int addrlen, struct xdr_buf *xdr, unsigned int base, unsigned int len) |
| 76 | { |
| 77 | struct kvec iov = { |
| 78 | .iov_base = xdr->head[0].iov_base + base, |
| 79 | .iov_len = len - base, |
| 80 | }; |
| 81 | struct msghdr msg = { |
| 82 | .msg_name = addr, |
| 83 | .msg_namelen = addrlen, |
| 84 | .msg_flags = XS_SENDMSG_FLAGS, |
| 85 | }; |
| 86 | |
| 87 | if (xdr->len > len) |
| 88 | msg.msg_flags |= MSG_MORE; |
| 89 | |
| 90 | if (likely(iov.iov_len)) |
| 91 | return kernel_sendmsg(sock, &msg, &iov, 1, iov.iov_len); |
| 92 | return kernel_sendmsg(sock, &msg, NULL, 0, 0); |
| 93 | } |
| 94 | |
| 95 | static int xs_send_tail(struct socket *sock, struct xdr_buf *xdr, unsigned int base, unsigned int len) |
| 96 | { |
| 97 | struct kvec iov = { |
| 98 | .iov_base = xdr->tail[0].iov_base + base, |
| 99 | .iov_len = len - base, |
| 100 | }; |
| 101 | struct msghdr msg = { |
| 102 | .msg_flags = XS_SENDMSG_FLAGS, |
| 103 | }; |
| 104 | |
| 105 | return kernel_sendmsg(sock, &msg, &iov, 1, iov.iov_len); |
| 106 | } |
| 107 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 108 | /** |
| 109 | * xs_sendpages - write pages directly to a socket |
| 110 | * @sock: socket to send on |
| 111 | * @addr: UDP only -- address of destination |
| 112 | * @addrlen: UDP only -- length of destination address |
| 113 | * @xdr: buffer containing this request |
| 114 | * @base: starting position in the buffer |
| 115 | * |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 116 | */ |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 117 | 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] | 118 | { |
| 119 | struct page **ppage = xdr->pages; |
| 120 | unsigned int len, pglen = xdr->page_len; |
| 121 | int err, ret = 0; |
| 122 | ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int); |
| 123 | |
| 124 | len = xdr->head[0].iov_len; |
| 125 | if (base < len || (addr != NULL && base == 0)) { |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 126 | err = xs_send_head(sock, addr, addrlen, xdr, base, len); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 127 | if (ret == 0) |
| 128 | ret = err; |
| 129 | else if (err > 0) |
| 130 | ret += err; |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 131 | if (err != (len - base)) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 132 | goto out; |
| 133 | base = 0; |
| 134 | } else |
| 135 | base -= len; |
| 136 | |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 137 | if (unlikely(pglen == 0)) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 138 | goto copy_tail; |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 139 | if (unlikely(base >= pglen)) { |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 140 | base -= pglen; |
| 141 | goto copy_tail; |
| 142 | } |
| 143 | if (base || xdr->page_base) { |
| 144 | pglen -= base; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 145 | base += xdr->page_base; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 146 | ppage += base >> PAGE_CACHE_SHIFT; |
| 147 | base &= ~PAGE_CACHE_MASK; |
| 148 | } |
| 149 | |
| 150 | sendpage = sock->ops->sendpage ? : sock_no_sendpage; |
| 151 | do { |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 152 | int flags = XS_SENDMSG_FLAGS; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 153 | |
| 154 | len = PAGE_CACHE_SIZE; |
| 155 | if (base) |
| 156 | len -= base; |
| 157 | if (pglen < len) |
| 158 | len = pglen; |
| 159 | |
| 160 | if (pglen != len || xdr->tail[0].iov_len != 0) |
| 161 | flags |= MSG_MORE; |
| 162 | |
| 163 | /* Hmm... We might be dealing with highmem pages */ |
| 164 | if (PageHighMem(*ppage)) |
| 165 | sendpage = sock_no_sendpage; |
| 166 | err = sendpage(sock, *ppage, base, len, flags); |
| 167 | if (ret == 0) |
| 168 | ret = err; |
| 169 | else if (err > 0) |
| 170 | ret += err; |
| 171 | if (err != len) |
| 172 | goto out; |
| 173 | base = 0; |
| 174 | ppage++; |
| 175 | } while ((pglen -= len) != 0); |
| 176 | copy_tail: |
| 177 | len = xdr->tail[0].iov_len; |
| 178 | if (base < len) { |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 179 | err = xs_send_tail(sock, xdr, base, len); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 180 | if (ret == 0) |
| 181 | ret = err; |
| 182 | else if (err > 0) |
| 183 | ret += err; |
| 184 | } |
| 185 | out: |
| 186 | return ret; |
| 187 | } |
| 188 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 189 | /** |
| 190 | * xs_sendmsg - write an RPC request to a socket |
| 191 | * @xprt: generic transport |
| 192 | * @req: the RPC request to write |
| 193 | * |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 194 | */ |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 195 | static int xs_sendmsg(struct rpc_xprt *xprt, struct rpc_rqst *req) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 196 | { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 197 | struct socket *sock = xprt->sock; |
| 198 | struct xdr_buf *xdr = &req->rq_snd_buf; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 199 | struct sockaddr *addr = NULL; |
| 200 | int addrlen = 0; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 201 | unsigned int skip; |
| 202 | int result; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 203 | |
| 204 | if (!sock) |
| 205 | return -ENOTCONN; |
| 206 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 207 | xs_pktdump("packet data:", |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 208 | req->rq_svec->iov_base, |
| 209 | req->rq_svec->iov_len); |
| 210 | |
| 211 | /* For UDP, we need to provide an address */ |
| 212 | if (!xprt->stream) { |
| 213 | addr = (struct sockaddr *) &xprt->addr; |
| 214 | addrlen = sizeof(xprt->addr); |
| 215 | } |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 216 | /* Don't repeat bytes */ |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 217 | skip = req->rq_bytes_sent; |
| 218 | |
| 219 | clear_bit(SOCK_ASYNC_NOSPACE, &sock->flags); |
Chuck Lever | b4b5cc8 | 2005-08-11 16:25:29 -0400 | [diff] [blame] | 220 | result = xs_sendpages(sock, addr, addrlen, xdr, skip); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 221 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 222 | dprintk("RPC: xs_sendmsg(%d) = %d\n", xdr->len - skip, result); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 223 | |
| 224 | if (result >= 0) |
| 225 | return result; |
| 226 | |
| 227 | switch (result) { |
| 228 | case -ECONNREFUSED: |
| 229 | /* When the server has died, an ICMP port unreachable message |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 230 | * prompts ECONNREFUSED. */ |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 231 | case -EAGAIN: |
| 232 | break; |
| 233 | case -ECONNRESET: |
| 234 | case -ENOTCONN: |
| 235 | case -EPIPE: |
| 236 | /* connection broken */ |
| 237 | if (xprt->stream) |
| 238 | result = -ENOTCONN; |
| 239 | break; |
| 240 | default: |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 241 | break; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 242 | } |
| 243 | return result; |
| 244 | } |
| 245 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 246 | /** |
| 247 | * xs_send_request - write an RPC request to a socket |
| 248 | * @task: address of RPC task that manages the state of an RPC request |
| 249 | * |
| 250 | * Return values: |
| 251 | * 0: The request has been sent |
| 252 | * EAGAIN: The socket was blocked, please call again later to |
| 253 | * complete the request |
| 254 | * other: Some other error occured, the request was not sent |
| 255 | * |
| 256 | * XXX: In the case of soft timeouts, should we eventually give up |
| 257 | * if the socket is not able to make progress? |
| 258 | */ |
| 259 | static int xs_send_request(struct rpc_task *task) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 260 | { |
| 261 | struct rpc_rqst *req = task->tk_rqstp; |
| 262 | struct rpc_xprt *xprt = req->rq_xprt; |
| 263 | int status, retry = 0; |
| 264 | |
| 265 | /* set up everything as needed. */ |
| 266 | /* Write the record marker */ |
| 267 | if (xprt->stream) { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 268 | u32 *marker = req->rq_svec[0].iov_base; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 269 | |
| 270 | *marker = htonl(0x80000000|(req->rq_slen-sizeof(*marker))); |
| 271 | } |
| 272 | |
| 273 | /* Continue transmitting the packet/record. We must be careful |
| 274 | * to cope with writespace callbacks arriving _after_ we have |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 275 | * called sendmsg(). |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 276 | */ |
| 277 | while (1) { |
| 278 | req->rq_xtime = jiffies; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 279 | status = xs_sendmsg(xprt, req); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 280 | |
| 281 | if (status < 0) |
| 282 | break; |
| 283 | |
| 284 | if (xprt->stream) { |
| 285 | req->rq_bytes_sent += status; |
| 286 | |
| 287 | /* If we've sent the entire packet, immediately |
| 288 | * reset the count of bytes sent. */ |
| 289 | if (req->rq_bytes_sent >= req->rq_slen) { |
| 290 | req->rq_bytes_sent = 0; |
| 291 | return 0; |
| 292 | } |
| 293 | } else { |
| 294 | if (status >= req->rq_slen) |
| 295 | return 0; |
| 296 | status = -EAGAIN; |
| 297 | break; |
| 298 | } |
| 299 | |
| 300 | dprintk("RPC: %4d xmit incomplete (%d left of %d)\n", |
| 301 | task->tk_pid, req->rq_slen - req->rq_bytes_sent, |
| 302 | req->rq_slen); |
| 303 | |
| 304 | status = -EAGAIN; |
| 305 | if (retry++ > 50) |
| 306 | break; |
| 307 | } |
| 308 | |
| 309 | if (status == -EAGAIN) { |
| 310 | if (test_bit(SOCK_ASYNC_NOSPACE, &xprt->sock->flags)) { |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 311 | /* Protect against races with write_space */ |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 312 | spin_lock_bh(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 313 | /* Don't race with disconnect */ |
| 314 | if (!xprt_connected(xprt)) |
| 315 | task->tk_status = -ENOTCONN; |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 316 | else if (test_bit(SOCK_NOSPACE, &xprt->sock->flags)) |
| 317 | xprt_wait_for_buffer_space(task); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 318 | spin_unlock_bh(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 319 | return status; |
| 320 | } |
| 321 | /* Keep holding the socket if it is blocked */ |
| 322 | rpc_delay(task, HZ>>4); |
| 323 | } |
| 324 | return status; |
| 325 | } |
| 326 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 327 | /** |
| 328 | * xs_close - close a socket |
| 329 | * @xprt: transport |
| 330 | * |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 331 | */ |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 332 | static void xs_close(struct rpc_xprt *xprt) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 333 | { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 334 | struct socket *sock = xprt->sock; |
| 335 | struct sock *sk = xprt->inet; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 336 | |
| 337 | if (!sk) |
| 338 | return; |
| 339 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 340 | dprintk("RPC: xs_close xprt %p\n", xprt); |
| 341 | |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 342 | write_lock_bh(&sk->sk_callback_lock); |
| 343 | xprt->inet = NULL; |
| 344 | xprt->sock = NULL; |
| 345 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 346 | sk->sk_user_data = NULL; |
| 347 | sk->sk_data_ready = xprt->old_data_ready; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 348 | sk->sk_state_change = xprt->old_state_change; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 349 | sk->sk_write_space = xprt->old_write_space; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 350 | write_unlock_bh(&sk->sk_callback_lock); |
| 351 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 352 | sk->sk_no_check = 0; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 353 | |
| 354 | sock_release(sock); |
| 355 | } |
| 356 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 357 | /** |
| 358 | * xs_destroy - prepare to shutdown a transport |
| 359 | * @xprt: doomed transport |
| 360 | * |
| 361 | */ |
| 362 | static void xs_destroy(struct rpc_xprt *xprt) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 363 | { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 364 | dprintk("RPC: xs_destroy xprt %p\n", xprt); |
| 365 | |
Chuck Lever | 55aa4f5 | 2005-08-11 16:25:47 -0400 | [diff] [blame] | 366 | cancel_delayed_work(&xprt->connect_worker); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 367 | flush_scheduled_work(); |
| 368 | |
| 369 | xprt_disconnect(xprt); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 370 | xs_close(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 371 | kfree(xprt->slot); |
| 372 | } |
| 373 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 374 | static inline struct rpc_xprt *xprt_from_sock(struct sock *sk) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 375 | { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 376 | return (struct rpc_xprt *) sk->sk_user_data; |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * xs_udp_data_ready - "data ready" callback for UDP sockets |
| 381 | * @sk: socket with data to read |
| 382 | * @len: how much data to read |
| 383 | * |
| 384 | */ |
| 385 | static void xs_udp_data_ready(struct sock *sk, int len) |
| 386 | { |
| 387 | struct rpc_task *task; |
| 388 | struct rpc_xprt *xprt; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 389 | struct rpc_rqst *rovr; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 390 | struct sk_buff *skb; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 391 | int err, repsize, copied; |
| 392 | u32 _xid, *xp; |
| 393 | |
| 394 | read_lock(&sk->sk_callback_lock); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 395 | dprintk("RPC: xs_udp_data_ready...\n"); |
| 396 | if (!(xprt = xprt_from_sock(sk))) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 397 | goto out; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 398 | |
| 399 | if ((skb = skb_recv_datagram(sk, 0, 1, &err)) == NULL) |
| 400 | goto out; |
| 401 | |
| 402 | if (xprt->shutdown) |
| 403 | goto dropit; |
| 404 | |
| 405 | repsize = skb->len - sizeof(struct udphdr); |
| 406 | if (repsize < 4) { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 407 | dprintk("RPC: impossible RPC reply size %d!\n", repsize); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 408 | goto dropit; |
| 409 | } |
| 410 | |
| 411 | /* Copy the XID from the skb... */ |
| 412 | xp = skb_header_pointer(skb, sizeof(struct udphdr), |
| 413 | sizeof(_xid), &_xid); |
| 414 | if (xp == NULL) |
| 415 | goto dropit; |
| 416 | |
| 417 | /* Look up and lock the request corresponding to the given XID */ |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 418 | spin_lock(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 419 | rovr = xprt_lookup_rqst(xprt, *xp); |
| 420 | if (!rovr) |
| 421 | goto out_unlock; |
| 422 | task = rovr->rq_task; |
| 423 | |
| 424 | dprintk("RPC: %4d received reply\n", task->tk_pid); |
| 425 | |
| 426 | if ((copied = rovr->rq_private_buf.buflen) > repsize) |
| 427 | copied = repsize; |
| 428 | |
| 429 | /* Suck it into the iovec, verify checksum if not done by hw. */ |
| 430 | if (csum_partial_copy_to_xdr(&rovr->rq_private_buf, skb)) |
| 431 | goto out_unlock; |
| 432 | |
| 433 | /* Something worked... */ |
| 434 | dst_confirm(skb->dst); |
| 435 | |
| 436 | xprt_complete_rqst(xprt, rovr, copied); |
| 437 | |
| 438 | out_unlock: |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 439 | spin_unlock(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 440 | dropit: |
| 441 | skb_free_datagram(sk, skb); |
| 442 | out: |
| 443 | read_unlock(&sk->sk_callback_lock); |
| 444 | } |
| 445 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 446 | 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] | 447 | { |
| 448 | if (len > desc->count) |
| 449 | len = desc->count; |
| 450 | if (skb_copy_bits(desc->skb, desc->offset, p, len)) { |
| 451 | dprintk("RPC: failed to copy %zu bytes from skb. %zu bytes remain\n", |
| 452 | len, desc->count); |
| 453 | return 0; |
| 454 | } |
| 455 | desc->offset += len; |
| 456 | desc->count -= len; |
| 457 | dprintk("RPC: copied %zu bytes from skb. %zu bytes remain\n", |
| 458 | len, desc->count); |
| 459 | return len; |
| 460 | } |
| 461 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 462 | 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] | 463 | { |
| 464 | size_t len, used; |
| 465 | char *p; |
| 466 | |
| 467 | p = ((char *) &xprt->tcp_recm) + xprt->tcp_offset; |
| 468 | len = sizeof(xprt->tcp_recm) - xprt->tcp_offset; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 469 | used = xs_tcp_copy_data(desc, p, len); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 470 | xprt->tcp_offset += used; |
| 471 | if (used != len) |
| 472 | return; |
| 473 | xprt->tcp_reclen = ntohl(xprt->tcp_recm); |
| 474 | if (xprt->tcp_reclen & 0x80000000) |
| 475 | xprt->tcp_flags |= XPRT_LAST_FRAG; |
| 476 | else |
| 477 | xprt->tcp_flags &= ~XPRT_LAST_FRAG; |
| 478 | xprt->tcp_reclen &= 0x7fffffff; |
| 479 | xprt->tcp_flags &= ~XPRT_COPY_RECM; |
| 480 | xprt->tcp_offset = 0; |
| 481 | /* Sanity check of the record length */ |
| 482 | if (xprt->tcp_reclen < 4) { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 483 | dprintk("RPC: invalid TCP record fragment length\n"); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 484 | xprt_disconnect(xprt); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 485 | return; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 486 | } |
| 487 | dprintk("RPC: reading TCP record fragment of length %d\n", |
| 488 | xprt->tcp_reclen); |
| 489 | } |
| 490 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 491 | static void xs_tcp_check_recm(struct rpc_xprt *xprt) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 492 | { |
| 493 | dprintk("RPC: xprt = %p, tcp_copied = %lu, tcp_offset = %u, tcp_reclen = %u, tcp_flags = %lx\n", |
| 494 | xprt, xprt->tcp_copied, xprt->tcp_offset, xprt->tcp_reclen, xprt->tcp_flags); |
| 495 | if (xprt->tcp_offset == xprt->tcp_reclen) { |
| 496 | xprt->tcp_flags |= XPRT_COPY_RECM; |
| 497 | xprt->tcp_offset = 0; |
| 498 | if (xprt->tcp_flags & XPRT_LAST_FRAG) { |
| 499 | xprt->tcp_flags &= ~XPRT_COPY_DATA; |
| 500 | xprt->tcp_flags |= XPRT_COPY_XID; |
| 501 | xprt->tcp_copied = 0; |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 506 | 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] | 507 | { |
| 508 | size_t len, used; |
| 509 | char *p; |
| 510 | |
| 511 | len = sizeof(xprt->tcp_xid) - xprt->tcp_offset; |
| 512 | dprintk("RPC: reading XID (%Zu bytes)\n", len); |
| 513 | p = ((char *) &xprt->tcp_xid) + xprt->tcp_offset; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 514 | used = xs_tcp_copy_data(desc, p, len); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 515 | xprt->tcp_offset += used; |
| 516 | if (used != len) |
| 517 | return; |
| 518 | xprt->tcp_flags &= ~XPRT_COPY_XID; |
| 519 | xprt->tcp_flags |= XPRT_COPY_DATA; |
| 520 | xprt->tcp_copied = 4; |
| 521 | dprintk("RPC: reading reply for XID %08x\n", |
| 522 | ntohl(xprt->tcp_xid)); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 523 | xs_tcp_check_recm(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 524 | } |
| 525 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 526 | 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] | 527 | { |
| 528 | struct rpc_rqst *req; |
| 529 | struct xdr_buf *rcvbuf; |
| 530 | size_t len; |
| 531 | ssize_t r; |
| 532 | |
| 533 | /* Find and lock the request corresponding to this xid */ |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 534 | spin_lock(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 535 | req = xprt_lookup_rqst(xprt, xprt->tcp_xid); |
| 536 | if (!req) { |
| 537 | xprt->tcp_flags &= ~XPRT_COPY_DATA; |
| 538 | dprintk("RPC: XID %08x request not found!\n", |
| 539 | ntohl(xprt->tcp_xid)); |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 540 | spin_unlock(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 541 | return; |
| 542 | } |
| 543 | |
| 544 | rcvbuf = &req->rq_private_buf; |
| 545 | len = desc->count; |
| 546 | if (len > xprt->tcp_reclen - xprt->tcp_offset) { |
| 547 | skb_reader_t my_desc; |
| 548 | |
| 549 | len = xprt->tcp_reclen - xprt->tcp_offset; |
| 550 | memcpy(&my_desc, desc, sizeof(my_desc)); |
| 551 | my_desc.count = len; |
| 552 | r = xdr_partial_copy_from_skb(rcvbuf, xprt->tcp_copied, |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 553 | &my_desc, xs_tcp_copy_data); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 554 | desc->count -= r; |
| 555 | desc->offset += r; |
| 556 | } else |
| 557 | r = xdr_partial_copy_from_skb(rcvbuf, xprt->tcp_copied, |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 558 | desc, xs_tcp_copy_data); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 559 | |
| 560 | if (r > 0) { |
| 561 | xprt->tcp_copied += r; |
| 562 | xprt->tcp_offset += r; |
| 563 | } |
| 564 | if (r != len) { |
| 565 | /* Error when copying to the receive buffer, |
| 566 | * usually because we weren't able to allocate |
| 567 | * additional buffer pages. All we can do now |
| 568 | * is turn off XPRT_COPY_DATA, so the request |
| 569 | * will not receive any additional updates, |
| 570 | * and time out. |
| 571 | * Any remaining data from this record will |
| 572 | * be discarded. |
| 573 | */ |
| 574 | xprt->tcp_flags &= ~XPRT_COPY_DATA; |
| 575 | dprintk("RPC: XID %08x truncated request\n", |
| 576 | ntohl(xprt->tcp_xid)); |
| 577 | dprintk("RPC: xprt = %p, tcp_copied = %lu, tcp_offset = %u, tcp_reclen = %u\n", |
| 578 | xprt, xprt->tcp_copied, xprt->tcp_offset, xprt->tcp_reclen); |
| 579 | goto out; |
| 580 | } |
| 581 | |
| 582 | dprintk("RPC: XID %08x read %Zd bytes\n", |
| 583 | ntohl(xprt->tcp_xid), r); |
| 584 | dprintk("RPC: xprt = %p, tcp_copied = %lu, tcp_offset = %u, tcp_reclen = %u\n", |
| 585 | xprt, xprt->tcp_copied, xprt->tcp_offset, xprt->tcp_reclen); |
| 586 | |
| 587 | if (xprt->tcp_copied == req->rq_private_buf.buflen) |
| 588 | xprt->tcp_flags &= ~XPRT_COPY_DATA; |
| 589 | else if (xprt->tcp_offset == xprt->tcp_reclen) { |
| 590 | if (xprt->tcp_flags & XPRT_LAST_FRAG) |
| 591 | xprt->tcp_flags &= ~XPRT_COPY_DATA; |
| 592 | } |
| 593 | |
| 594 | out: |
| 595 | if (!(xprt->tcp_flags & XPRT_COPY_DATA)) { |
| 596 | dprintk("RPC: %4d received reply complete\n", |
| 597 | req->rq_task->tk_pid); |
| 598 | xprt_complete_rqst(xprt, req, xprt->tcp_copied); |
| 599 | } |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 600 | spin_unlock(&xprt->transport_lock); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 601 | xs_tcp_check_recm(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 602 | } |
| 603 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 604 | 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] | 605 | { |
| 606 | size_t len; |
| 607 | |
| 608 | len = xprt->tcp_reclen - xprt->tcp_offset; |
| 609 | if (len > desc->count) |
| 610 | len = desc->count; |
| 611 | desc->count -= len; |
| 612 | desc->offset += len; |
| 613 | xprt->tcp_offset += len; |
| 614 | dprintk("RPC: discarded %Zu bytes\n", len); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 615 | xs_tcp_check_recm(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 616 | } |
| 617 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 618 | 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] | 619 | { |
| 620 | struct rpc_xprt *xprt = rd_desc->arg.data; |
| 621 | skb_reader_t desc = { |
| 622 | .skb = skb, |
| 623 | .offset = offset, |
| 624 | .count = len, |
| 625 | .csum = 0 |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 626 | }; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 627 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 628 | dprintk("RPC: xs_tcp_data_recv started\n"); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 629 | do { |
| 630 | /* Read in a new fragment marker if necessary */ |
| 631 | /* Can we ever really expect to get completely empty fragments? */ |
| 632 | if (xprt->tcp_flags & XPRT_COPY_RECM) { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 633 | xs_tcp_read_fraghdr(xprt, &desc); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 634 | continue; |
| 635 | } |
| 636 | /* Read in the xid if necessary */ |
| 637 | if (xprt->tcp_flags & XPRT_COPY_XID) { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 638 | xs_tcp_read_xid(xprt, &desc); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 639 | continue; |
| 640 | } |
| 641 | /* Read in the request data */ |
| 642 | if (xprt->tcp_flags & XPRT_COPY_DATA) { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 643 | xs_tcp_read_request(xprt, &desc); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 644 | continue; |
| 645 | } |
| 646 | /* Skip over any trailing bytes on short reads */ |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 647 | xs_tcp_read_discard(xprt, &desc); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 648 | } while (desc.count); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 649 | dprintk("RPC: xs_tcp_data_recv done\n"); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 650 | return len - desc.count; |
| 651 | } |
| 652 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 653 | /** |
| 654 | * xs_tcp_data_ready - "data ready" callback for TCP sockets |
| 655 | * @sk: socket with data to read |
| 656 | * @bytes: how much data to read |
| 657 | * |
| 658 | */ |
| 659 | static void xs_tcp_data_ready(struct sock *sk, int bytes) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 660 | { |
| 661 | struct rpc_xprt *xprt; |
| 662 | read_descriptor_t rd_desc; |
| 663 | |
| 664 | read_lock(&sk->sk_callback_lock); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 665 | dprintk("RPC: xs_tcp_data_ready...\n"); |
| 666 | if (!(xprt = xprt_from_sock(sk))) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 667 | goto out; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 668 | if (xprt->shutdown) |
| 669 | goto out; |
| 670 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 671 | /* 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] | 672 | rd_desc.arg.data = xprt; |
| 673 | rd_desc.count = 65536; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 674 | tcp_read_sock(sk, &rd_desc, xs_tcp_data_recv); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 675 | out: |
| 676 | read_unlock(&sk->sk_callback_lock); |
| 677 | } |
| 678 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 679 | /** |
| 680 | * xs_tcp_state_change - callback to handle TCP socket state changes |
| 681 | * @sk: socket whose state has changed |
| 682 | * |
| 683 | */ |
| 684 | static void xs_tcp_state_change(struct sock *sk) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 685 | { |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 686 | struct rpc_xprt *xprt; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 687 | |
| 688 | read_lock(&sk->sk_callback_lock); |
| 689 | if (!(xprt = xprt_from_sock(sk))) |
| 690 | goto out; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 691 | dprintk("RPC: xs_tcp_state_change client %p...\n", xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 692 | dprintk("RPC: state %x conn %d dead %d zapped %d\n", |
| 693 | sk->sk_state, xprt_connected(xprt), |
| 694 | sock_flag(sk, SOCK_DEAD), |
| 695 | sock_flag(sk, SOCK_ZAPPED)); |
| 696 | |
| 697 | switch (sk->sk_state) { |
| 698 | case TCP_ESTABLISHED: |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 699 | spin_lock_bh(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 700 | if (!xprt_test_and_set_connected(xprt)) { |
| 701 | /* Reset TCP record info */ |
| 702 | xprt->tcp_offset = 0; |
| 703 | xprt->tcp_reclen = 0; |
| 704 | xprt->tcp_copied = 0; |
| 705 | xprt->tcp_flags = XPRT_COPY_RECM | XPRT_COPY_XID; |
Chuck Lever | 44fbac2 | 2005-08-11 16:25:44 -0400 | [diff] [blame] | 706 | xprt_wake_pending_tasks(xprt, 0); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 707 | } |
Chuck Lever | 4a0f8c0 | 2005-08-11 16:25:32 -0400 | [diff] [blame] | 708 | spin_unlock_bh(&xprt->transport_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 709 | break; |
| 710 | case TCP_SYN_SENT: |
| 711 | case TCP_SYN_RECV: |
| 712 | break; |
| 713 | default: |
| 714 | xprt_disconnect(xprt); |
| 715 | break; |
| 716 | } |
| 717 | out: |
| 718 | read_unlock(&sk->sk_callback_lock); |
| 719 | } |
| 720 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 721 | /** |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 722 | * xs_udp_write_space - callback invoked when socket buffer space |
| 723 | * becomes available |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 724 | * @sk: socket whose state has changed |
| 725 | * |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 726 | * Called when more output buffer space is available for this socket. |
| 727 | * We try not to wake our writers until they can make "significant" |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 728 | * progress, otherwise we'll waste resources thrashing kernel_sendmsg |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 729 | * with a bunch of small requests. |
| 730 | */ |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 731 | static void xs_udp_write_space(struct sock *sk) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 732 | { |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 733 | read_lock(&sk->sk_callback_lock); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 734 | |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 735 | /* from net/core/sock.c:sock_def_write_space */ |
| 736 | if (sock_writeable(sk)) { |
| 737 | struct socket *sock; |
| 738 | struct rpc_xprt *xprt; |
| 739 | |
| 740 | if (unlikely(!(sock = sk->sk_socket))) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 741 | goto out; |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 742 | if (unlikely(!(xprt = xprt_from_sock(sk)))) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 743 | goto out; |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 744 | if (unlikely(!test_and_clear_bit(SOCK_NOSPACE, &sock->flags))) |
| 745 | goto out; |
| 746 | |
| 747 | xprt_write_space(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 748 | } |
| 749 | |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 750 | out: |
| 751 | read_unlock(&sk->sk_callback_lock); |
| 752 | } |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 753 | |
Chuck Lever | c7b2cae | 2005-08-11 16:25:50 -0400 | [diff] [blame] | 754 | /** |
| 755 | * xs_tcp_write_space - callback invoked when socket buffer space |
| 756 | * becomes available |
| 757 | * @sk: socket whose state has changed |
| 758 | * |
| 759 | * Called when more output buffer space is available for this socket. |
| 760 | * We try not to wake our writers until they can make "significant" |
| 761 | * progress, otherwise we'll waste resources thrashing kernel_sendmsg |
| 762 | * with a bunch of small requests. |
| 763 | */ |
| 764 | static void xs_tcp_write_space(struct sock *sk) |
| 765 | { |
| 766 | read_lock(&sk->sk_callback_lock); |
| 767 | |
| 768 | /* from net/core/stream.c:sk_stream_write_space */ |
| 769 | if (sk_stream_wspace(sk) >= sk_stream_min_wspace(sk)) { |
| 770 | struct socket *sock; |
| 771 | struct rpc_xprt *xprt; |
| 772 | |
| 773 | if (unlikely(!(sock = sk->sk_socket))) |
| 774 | goto out; |
| 775 | if (unlikely(!(xprt = xprt_from_sock(sk)))) |
| 776 | goto out; |
| 777 | if (unlikely(!test_and_clear_bit(SOCK_NOSPACE, &sock->flags))) |
| 778 | goto out; |
| 779 | |
| 780 | xprt_write_space(xprt); |
| 781 | } |
| 782 | |
| 783 | out: |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 784 | read_unlock(&sk->sk_callback_lock); |
| 785 | } |
| 786 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 787 | /** |
| 788 | * xs_set_buffer_size - set send and receive limits |
| 789 | * @xprt: generic transport |
| 790 | * |
| 791 | * Set socket send and receive limits based on the |
| 792 | * sndsize and rcvsize fields in the generic transport |
| 793 | * structure. This applies only to UDP sockets. |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 794 | */ |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 795 | static void xs_set_buffer_size(struct rpc_xprt *xprt) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 796 | { |
| 797 | struct sock *sk = xprt->inet; |
| 798 | |
| 799 | if (xprt->stream) |
| 800 | return; |
| 801 | if (xprt->rcvsize) { |
| 802 | sk->sk_userlocks |= SOCK_RCVBUF_LOCK; |
| 803 | sk->sk_rcvbuf = xprt->rcvsize * xprt->max_reqs * 2; |
| 804 | } |
| 805 | if (xprt->sndsize) { |
| 806 | sk->sk_userlocks |= SOCK_SNDBUF_LOCK; |
| 807 | sk->sk_sndbuf = xprt->sndsize * xprt->max_reqs * 2; |
| 808 | sk->sk_write_space(sk); |
| 809 | } |
| 810 | } |
| 811 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 812 | static int xs_bindresvport(struct rpc_xprt *xprt, struct socket *sock) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 813 | { |
| 814 | struct sockaddr_in myaddr = { |
| 815 | .sin_family = AF_INET, |
| 816 | }; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 817 | int err, port; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 818 | |
| 819 | /* Were we already bound to a given port? Try to reuse it */ |
| 820 | port = xprt->port; |
| 821 | do { |
| 822 | myaddr.sin_port = htons(port); |
| 823 | err = sock->ops->bind(sock, (struct sockaddr *) &myaddr, |
| 824 | sizeof(myaddr)); |
| 825 | if (err == 0) { |
| 826 | xprt->port = port; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 827 | dprintk("RPC: xs_bindresvport bound to port %u\n", |
| 828 | port); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 829 | return 0; |
| 830 | } |
| 831 | if (--port == 0) |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 832 | port = XS_MAX_RESVPORT; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 833 | } while (err == -EADDRINUSE && port != xprt->port); |
| 834 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 835 | dprintk("RPC: can't bind to reserved port (%d).\n", -err); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 836 | return err; |
| 837 | } |
| 838 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 839 | /** |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame^] | 840 | * xs_udp_connect_worker - set up a UDP socket |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 841 | * @args: RPC transport to connect |
| 842 | * |
| 843 | * Invoked by a work queue tasklet. |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 844 | */ |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame^] | 845 | static void xs_udp_connect_worker(void *args) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 846 | { |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame^] | 847 | struct rpc_xprt *xprt = (struct rpc_xprt *) args; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 848 | struct socket *sock = xprt->sock; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame^] | 849 | int err, status = -EIO; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 850 | |
| 851 | if (xprt->shutdown || xprt->addr.sin_port == 0) |
| 852 | goto out; |
| 853 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame^] | 854 | dprintk("RPC: xs_udp_connect_worker for xprt %p\n", xprt); |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 855 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame^] | 856 | /* Start by resetting any existing state */ |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 857 | xs_close(xprt); |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame^] | 858 | |
| 859 | if ((err = sock_create_kern(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &sock)) < 0) { |
| 860 | dprintk("RPC: can't create UDP transport socket (%d).\n", -err); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 861 | goto out; |
| 862 | } |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 863 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame^] | 864 | if (xprt->resvport && xs_bindresvport(xprt, sock) < 0) { |
| 865 | sock_release(sock); |
| 866 | goto out; |
| 867 | } |
| 868 | |
| 869 | if (!xprt->inet) { |
| 870 | struct sock *sk = sock->sk; |
| 871 | |
| 872 | write_lock_bh(&sk->sk_callback_lock); |
| 873 | |
| 874 | sk->sk_user_data = xprt; |
| 875 | xprt->old_data_ready = sk->sk_data_ready; |
| 876 | xprt->old_state_change = sk->sk_state_change; |
| 877 | xprt->old_write_space = sk->sk_write_space; |
| 878 | sk->sk_data_ready = xs_udp_data_ready; |
| 879 | sk->sk_write_space = xs_udp_write_space; |
| 880 | sk->sk_no_check = UDP_CSUM_NORCV; |
| 881 | |
| 882 | xprt_set_connected(xprt); |
| 883 | |
| 884 | /* Reset to new socket */ |
| 885 | xprt->sock = sock; |
| 886 | xprt->inet = sk; |
| 887 | |
| 888 | write_unlock_bh(&sk->sk_callback_lock); |
| 889 | } |
| 890 | xs_set_buffer_size(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 891 | status = 0; |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame^] | 892 | out: |
| 893 | xprt_wake_pending_tasks(xprt, status); |
| 894 | xprt_clear_connecting(xprt); |
| 895 | } |
| 896 | |
| 897 | /** |
| 898 | * xs_tcp_connect_worker - connect a TCP socket to a remote endpoint |
| 899 | * @args: RPC transport to connect |
| 900 | * |
| 901 | * Invoked by a work queue tasklet. |
| 902 | */ |
| 903 | static void xs_tcp_connect_worker(void *args) |
| 904 | { |
| 905 | struct rpc_xprt *xprt = (struct rpc_xprt *)args; |
| 906 | struct socket *sock = xprt->sock; |
| 907 | int err, status = -EIO; |
| 908 | |
| 909 | if (xprt->shutdown || xprt->addr.sin_port == 0) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 910 | goto out; |
| 911 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame^] | 912 | dprintk("RPC: xs_tcp_connect_worker for xprt %p\n", xprt); |
| 913 | |
| 914 | /* Start by resetting any existing socket state */ |
| 915 | xs_close(xprt); |
| 916 | |
| 917 | if ((err = sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock)) < 0) { |
| 918 | dprintk("RPC: can't create TCP transport socket (%d).\n", -err); |
| 919 | goto out; |
| 920 | } |
| 921 | |
| 922 | if (xprt->resvport && xs_bindresvport(xprt, sock) < 0) { |
| 923 | sock_release(sock); |
| 924 | goto out; |
| 925 | } |
| 926 | |
| 927 | if (!xprt->inet) { |
| 928 | struct sock *sk = sock->sk; |
| 929 | |
| 930 | write_lock_bh(&sk->sk_callback_lock); |
| 931 | |
| 932 | sk->sk_user_data = xprt; |
| 933 | xprt->old_data_ready = sk->sk_data_ready; |
| 934 | xprt->old_state_change = sk->sk_state_change; |
| 935 | xprt->old_write_space = sk->sk_write_space; |
| 936 | sk->sk_data_ready = xs_tcp_data_ready; |
| 937 | sk->sk_state_change = xs_tcp_state_change; |
| 938 | sk->sk_write_space = xs_tcp_write_space; |
| 939 | tcp_sk(sk)->nonagle = 1; |
| 940 | |
| 941 | xprt_clear_connected(xprt); |
| 942 | |
| 943 | /* Reset to new socket */ |
| 944 | xprt->sock = sock; |
| 945 | xprt->inet = sk; |
| 946 | |
| 947 | write_unlock_bh(&sk->sk_callback_lock); |
| 948 | } |
| 949 | |
| 950 | /* Tell the socket layer to start connecting... */ |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 951 | status = sock->ops->connect(sock, (struct sockaddr *) &xprt->addr, |
| 952 | sizeof(xprt->addr), O_NONBLOCK); |
| 953 | dprintk("RPC: %p connect status %d connected %d sock state %d\n", |
| 954 | xprt, -status, xprt_connected(xprt), sock->sk->sk_state); |
| 955 | if (status < 0) { |
| 956 | switch (status) { |
| 957 | case -EINPROGRESS: |
| 958 | case -EALREADY: |
| 959 | goto out_clear; |
| 960 | } |
| 961 | } |
| 962 | out: |
Chuck Lever | 44fbac2 | 2005-08-11 16:25:44 -0400 | [diff] [blame] | 963 | xprt_wake_pending_tasks(xprt, status); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 964 | out_clear: |
Chuck Lever | 2226feb | 2005-08-11 16:25:38 -0400 | [diff] [blame] | 965 | xprt_clear_connecting(xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 966 | } |
| 967 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 968 | /** |
| 969 | * xs_connect - connect a socket to a remote endpoint |
| 970 | * @task: address of RPC task that manages state of connect request |
| 971 | * |
| 972 | * TCP: If the remote end dropped the connection, delay reconnecting. |
| 973 | */ |
| 974 | static void xs_connect(struct rpc_task *task) |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 975 | { |
| 976 | struct rpc_xprt *xprt = task->tk_xprt; |
| 977 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame^] | 978 | if (xprt_test_and_set_connecting(xprt)) |
| 979 | return; |
| 980 | |
| 981 | if (xprt->sock != NULL) { |
| 982 | dprintk("RPC: xs_connect delayed xprt %p\n", xprt); |
| 983 | schedule_delayed_work(&xprt->connect_worker, |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 984 | RPC_REESTABLISH_TIMEOUT); |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame^] | 985 | } else { |
| 986 | dprintk("RPC: xs_connect scheduled xprt %p\n", xprt); |
| 987 | schedule_work(&xprt->connect_worker); |
| 988 | |
| 989 | /* flush_scheduled_work can sleep... */ |
| 990 | if (!RPC_IS_ASYNC(task)) |
| 991 | flush_scheduled_work(); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 995 | static struct rpc_xprt_ops xs_ops = { |
| 996 | .set_buffer_size = xs_set_buffer_size, |
| 997 | .connect = xs_connect, |
| 998 | .send_request = xs_send_request, |
| 999 | .close = xs_close, |
| 1000 | .destroy = xs_destroy, |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1001 | }; |
| 1002 | |
| 1003 | extern unsigned int xprt_udp_slot_table_entries; |
| 1004 | extern unsigned int xprt_tcp_slot_table_entries; |
| 1005 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1006 | /** |
| 1007 | * xs_setup_udp - Set up transport to use a UDP socket |
| 1008 | * @xprt: transport to set up |
| 1009 | * @to: timeout parameters |
| 1010 | * |
| 1011 | */ |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1012 | int xs_setup_udp(struct rpc_xprt *xprt, struct rpc_timeout *to) |
| 1013 | { |
| 1014 | size_t slot_table_size; |
| 1015 | |
| 1016 | dprintk("RPC: setting up udp-ipv4 transport...\n"); |
| 1017 | |
| 1018 | xprt->max_reqs = xprt_udp_slot_table_entries; |
| 1019 | slot_table_size = xprt->max_reqs * sizeof(xprt->slot[0]); |
| 1020 | xprt->slot = kmalloc(slot_table_size, GFP_KERNEL); |
| 1021 | if (xprt->slot == NULL) |
| 1022 | return -ENOMEM; |
| 1023 | memset(xprt->slot, 0, slot_table_size); |
| 1024 | |
| 1025 | xprt->prot = IPPROTO_UDP; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1026 | xprt->port = XS_MAX_RESVPORT; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1027 | xprt->stream = 0; |
| 1028 | xprt->nocong = 0; |
| 1029 | xprt->cwnd = RPC_INITCWND; |
| 1030 | xprt->resvport = capable(CAP_NET_BIND_SERVICE) ? 1 : 0; |
| 1031 | /* XXX: header size can vary due to auth type, IPv6, etc. */ |
| 1032 | xprt->max_payload = (1U << 16) - (MAX_HEADER << 3); |
| 1033 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame^] | 1034 | INIT_WORK(&xprt->connect_worker, xs_udp_connect_worker, xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1035 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1036 | xprt->ops = &xs_ops; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1037 | |
| 1038 | if (to) |
| 1039 | xprt->timeout = *to; |
| 1040 | else |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1041 | xprt_set_timeout(&xprt->timeout, 5, 5 * HZ); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1042 | |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1046 | /** |
| 1047 | * xs_setup_tcp - Set up transport to use a TCP socket |
| 1048 | * @xprt: transport to set up |
| 1049 | * @to: timeout parameters |
| 1050 | * |
| 1051 | */ |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1052 | int xs_setup_tcp(struct rpc_xprt *xprt, struct rpc_timeout *to) |
| 1053 | { |
| 1054 | size_t slot_table_size; |
| 1055 | |
| 1056 | dprintk("RPC: setting up tcp-ipv4 transport...\n"); |
| 1057 | |
| 1058 | xprt->max_reqs = xprt_tcp_slot_table_entries; |
| 1059 | slot_table_size = xprt->max_reqs * sizeof(xprt->slot[0]); |
| 1060 | xprt->slot = kmalloc(slot_table_size, GFP_KERNEL); |
| 1061 | if (xprt->slot == NULL) |
| 1062 | return -ENOMEM; |
| 1063 | memset(xprt->slot, 0, slot_table_size); |
| 1064 | |
| 1065 | xprt->prot = IPPROTO_TCP; |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1066 | xprt->port = XS_MAX_RESVPORT; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1067 | xprt->stream = 1; |
| 1068 | xprt->nocong = 1; |
| 1069 | xprt->cwnd = RPC_MAXCWND(xprt); |
| 1070 | xprt->resvport = capable(CAP_NET_BIND_SERVICE) ? 1 : 0; |
| 1071 | xprt->max_payload = (1U << 31) - 1; |
| 1072 | |
Chuck Lever | b0d93ad | 2005-08-11 16:25:53 -0400 | [diff] [blame^] | 1073 | INIT_WORK(&xprt->connect_worker, xs_tcp_connect_worker, xprt); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1074 | |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1075 | xprt->ops = &xs_ops; |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1076 | |
| 1077 | if (to) |
| 1078 | xprt->timeout = *to; |
| 1079 | else |
Chuck Lever | 9903cd1 | 2005-08-11 16:25:26 -0400 | [diff] [blame] | 1080 | xprt_set_timeout(&xprt->timeout, 2, 60 * HZ); |
Chuck Lever | a246b01 | 2005-08-11 16:25:23 -0400 | [diff] [blame] | 1081 | |
| 1082 | return 0; |
| 1083 | } |