| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * linux/net/sunrpc/svcsock.c |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 43 | 44 | #include <net/tcp.h> |
|---|
| 44 | 45 | #include <net/tcp_states.h> |
|---|
| 45 | 46 | #include <linux/uaccess.h> |
|---|
| 47 | +#include <linux/highmem.h> |
|---|
| 46 | 48 | #include <asm/ioctls.h> |
|---|
| 47 | | -#include <trace/events/skb.h> |
|---|
| 48 | 49 | |
|---|
| 49 | 50 | #include <linux/sunrpc/types.h> |
|---|
| 50 | 51 | #include <linux/sunrpc/clnt.h> |
|---|
| .. | .. |
|---|
| 54 | 55 | #include <linux/sunrpc/stats.h> |
|---|
| 55 | 56 | #include <linux/sunrpc/xprt.h> |
|---|
| 56 | 57 | |
|---|
| 58 | +#include <trace/events/sunrpc.h> |
|---|
| 59 | + |
|---|
| 60 | +#include "socklib.h" |
|---|
| 57 | 61 | #include "sunrpc.h" |
|---|
| 58 | 62 | |
|---|
| 59 | 63 | #define RPCDBG_FACILITY RPCDBG_SVCXPRT |
|---|
| .. | .. |
|---|
| 70 | 74 | static struct svc_xprt *svc_create_socket(struct svc_serv *, int, |
|---|
| 71 | 75 | struct net *, struct sockaddr *, |
|---|
| 72 | 76 | int, int); |
|---|
| 73 | | -#if defined(CONFIG_SUNRPC_BACKCHANNEL) |
|---|
| 74 | | -static struct svc_xprt *svc_bc_create_socket(struct svc_serv *, int, |
|---|
| 75 | | - struct net *, struct sockaddr *, |
|---|
| 76 | | - int, int); |
|---|
| 77 | | -static void svc_bc_sock_free(struct svc_xprt *xprt); |
|---|
| 78 | | -#endif /* CONFIG_SUNRPC_BACKCHANNEL */ |
|---|
| 79 | | - |
|---|
| 80 | 77 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
|---|
| 81 | 78 | static struct lock_class_key svc_key[2]; |
|---|
| 82 | 79 | static struct lock_class_key svc_slock_key[2]; |
|---|
| .. | .. |
|---|
| 113 | 110 | } |
|---|
| 114 | 111 | #endif |
|---|
| 115 | 112 | |
|---|
| 116 | | -/* |
|---|
| 117 | | - * Release an skbuff after use |
|---|
| 113 | +/** |
|---|
| 114 | + * svc_tcp_release_rqst - Release transport-related resources |
|---|
| 115 | + * @rqstp: request structure with resources to be released |
|---|
| 116 | + * |
|---|
| 118 | 117 | */ |
|---|
| 119 | | -static void svc_release_skb(struct svc_rqst *rqstp) |
|---|
| 118 | +static void svc_tcp_release_rqst(struct svc_rqst *rqstp) |
|---|
| 120 | 119 | { |
|---|
| 121 | 120 | struct sk_buff *skb = rqstp->rq_xprt_ctxt; |
|---|
| 122 | 121 | |
|---|
| 123 | 122 | if (skb) { |
|---|
| 124 | 123 | struct svc_sock *svsk = |
|---|
| 125 | 124 | container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt); |
|---|
| 126 | | - rqstp->rq_xprt_ctxt = NULL; |
|---|
| 127 | 125 | |
|---|
| 128 | | - dprintk("svc: service %p, releasing skb %p\n", rqstp, skb); |
|---|
| 126 | + rqstp->rq_xprt_ctxt = NULL; |
|---|
| 129 | 127 | skb_free_datagram_locked(svsk->sk_sk, skb); |
|---|
| 130 | 128 | } |
|---|
| 131 | 129 | } |
|---|
| 132 | 130 | |
|---|
| 133 | | -static void svc_release_udp_skb(struct svc_rqst *rqstp) |
|---|
| 131 | +/** |
|---|
| 132 | + * svc_udp_release_rqst - Release transport-related resources |
|---|
| 133 | + * @rqstp: request structure with resources to be released |
|---|
| 134 | + * |
|---|
| 135 | + */ |
|---|
| 136 | +static void svc_udp_release_rqst(struct svc_rqst *rqstp) |
|---|
| 134 | 137 | { |
|---|
| 135 | 138 | struct sk_buff *skb = rqstp->rq_xprt_ctxt; |
|---|
| 136 | 139 | |
|---|
| 137 | 140 | if (skb) { |
|---|
| 138 | 141 | rqstp->rq_xprt_ctxt = NULL; |
|---|
| 139 | | - |
|---|
| 140 | | - dprintk("svc: service %p, releasing skb %p\n", rqstp, skb); |
|---|
| 141 | 142 | consume_skb(skb); |
|---|
| 142 | 143 | } |
|---|
| 143 | 144 | } |
|---|
| .. | .. |
|---|
| 180 | 181 | } |
|---|
| 181 | 182 | } |
|---|
| 182 | 183 | |
|---|
| 183 | | -/* |
|---|
| 184 | | - * send routine intended to be shared by the fore- and back-channel |
|---|
| 185 | | - */ |
|---|
| 186 | | -int svc_send_common(struct socket *sock, struct xdr_buf *xdr, |
|---|
| 187 | | - struct page *headpage, unsigned long headoffset, |
|---|
| 188 | | - struct page *tailpage, unsigned long tailoffset) |
|---|
| 184 | +static int svc_sock_read_payload(struct svc_rqst *rqstp, unsigned int offset, |
|---|
| 185 | + unsigned int length) |
|---|
| 189 | 186 | { |
|---|
| 190 | | - int result; |
|---|
| 191 | | - int size; |
|---|
| 192 | | - struct page **ppage = xdr->pages; |
|---|
| 193 | | - size_t base = xdr->page_base; |
|---|
| 194 | | - unsigned int pglen = xdr->page_len; |
|---|
| 195 | | - unsigned int flags = MSG_MORE | MSG_SENDPAGE_NOTLAST; |
|---|
| 196 | | - int slen; |
|---|
| 197 | | - int len = 0; |
|---|
| 198 | | - |
|---|
| 199 | | - slen = xdr->len; |
|---|
| 200 | | - |
|---|
| 201 | | - /* send head */ |
|---|
| 202 | | - if (slen == xdr->head[0].iov_len) |
|---|
| 203 | | - flags = 0; |
|---|
| 204 | | - len = kernel_sendpage(sock, headpage, headoffset, |
|---|
| 205 | | - xdr->head[0].iov_len, flags); |
|---|
| 206 | | - if (len != xdr->head[0].iov_len) |
|---|
| 207 | | - goto out; |
|---|
| 208 | | - slen -= xdr->head[0].iov_len; |
|---|
| 209 | | - if (slen == 0) |
|---|
| 210 | | - goto out; |
|---|
| 211 | | - |
|---|
| 212 | | - /* send page data */ |
|---|
| 213 | | - size = PAGE_SIZE - base < pglen ? PAGE_SIZE - base : pglen; |
|---|
| 214 | | - while (pglen > 0) { |
|---|
| 215 | | - if (slen == size) |
|---|
| 216 | | - flags = 0; |
|---|
| 217 | | - result = kernel_sendpage(sock, *ppage, base, size, flags); |
|---|
| 218 | | - if (result > 0) |
|---|
| 219 | | - len += result; |
|---|
| 220 | | - if (result != size) |
|---|
| 221 | | - goto out; |
|---|
| 222 | | - slen -= size; |
|---|
| 223 | | - pglen -= size; |
|---|
| 224 | | - size = PAGE_SIZE < pglen ? PAGE_SIZE : pglen; |
|---|
| 225 | | - base = 0; |
|---|
| 226 | | - ppage++; |
|---|
| 227 | | - } |
|---|
| 228 | | - |
|---|
| 229 | | - /* send tail */ |
|---|
| 230 | | - if (xdr->tail[0].iov_len) { |
|---|
| 231 | | - result = kernel_sendpage(sock, tailpage, tailoffset, |
|---|
| 232 | | - xdr->tail[0].iov_len, 0); |
|---|
| 233 | | - if (result > 0) |
|---|
| 234 | | - len += result; |
|---|
| 235 | | - } |
|---|
| 236 | | - |
|---|
| 237 | | -out: |
|---|
| 238 | | - return len; |
|---|
| 239 | | -} |
|---|
| 240 | | - |
|---|
| 241 | | - |
|---|
| 242 | | -/* |
|---|
| 243 | | - * Generic sendto routine |
|---|
| 244 | | - */ |
|---|
| 245 | | -static int svc_sendto(struct svc_rqst *rqstp, struct xdr_buf *xdr) |
|---|
| 246 | | -{ |
|---|
| 247 | | - struct svc_sock *svsk = |
|---|
| 248 | | - container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt); |
|---|
| 249 | | - struct socket *sock = svsk->sk_sock; |
|---|
| 250 | | - union { |
|---|
| 251 | | - struct cmsghdr hdr; |
|---|
| 252 | | - long all[SVC_PKTINFO_SPACE / sizeof(long)]; |
|---|
| 253 | | - } buffer; |
|---|
| 254 | | - struct cmsghdr *cmh = &buffer.hdr; |
|---|
| 255 | | - int len = 0; |
|---|
| 256 | | - unsigned long tailoff; |
|---|
| 257 | | - unsigned long headoff; |
|---|
| 258 | | - RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]); |
|---|
| 259 | | - |
|---|
| 260 | | - if (rqstp->rq_prot == IPPROTO_UDP) { |
|---|
| 261 | | - struct msghdr msg = { |
|---|
| 262 | | - .msg_name = &rqstp->rq_addr, |
|---|
| 263 | | - .msg_namelen = rqstp->rq_addrlen, |
|---|
| 264 | | - .msg_control = cmh, |
|---|
| 265 | | - .msg_controllen = sizeof(buffer), |
|---|
| 266 | | - .msg_flags = MSG_MORE, |
|---|
| 267 | | - }; |
|---|
| 268 | | - |
|---|
| 269 | | - svc_set_cmsg_data(rqstp, cmh); |
|---|
| 270 | | - |
|---|
| 271 | | - if (sock_sendmsg(sock, &msg) < 0) |
|---|
| 272 | | - goto out; |
|---|
| 273 | | - } |
|---|
| 274 | | - |
|---|
| 275 | | - tailoff = ((unsigned long)xdr->tail[0].iov_base) & (PAGE_SIZE-1); |
|---|
| 276 | | - headoff = 0; |
|---|
| 277 | | - len = svc_send_common(sock, xdr, rqstp->rq_respages[0], headoff, |
|---|
| 278 | | - rqstp->rq_respages[0], tailoff); |
|---|
| 279 | | - |
|---|
| 280 | | -out: |
|---|
| 281 | | - dprintk("svc: socket %p sendto([%p %zu... ], %d) = %d (addr %s)\n", |
|---|
| 282 | | - svsk, xdr->head[0].iov_base, xdr->head[0].iov_len, |
|---|
| 283 | | - xdr->len, len, svc_print_addr(rqstp, buf, sizeof(buf))); |
|---|
| 284 | | - |
|---|
| 285 | | - return len; |
|---|
| 187 | + return 0; |
|---|
| 286 | 188 | } |
|---|
| 287 | 189 | |
|---|
| 288 | 190 | /* |
|---|
| .. | .. |
|---|
| 322 | 224 | return len; |
|---|
| 323 | 225 | } |
|---|
| 324 | 226 | |
|---|
| 227 | +#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE |
|---|
| 228 | +static void svc_flush_bvec(const struct bio_vec *bvec, size_t size, size_t seek) |
|---|
| 229 | +{ |
|---|
| 230 | + struct bvec_iter bi = { |
|---|
| 231 | + .bi_size = size + seek, |
|---|
| 232 | + }; |
|---|
| 233 | + struct bio_vec bv; |
|---|
| 234 | + |
|---|
| 235 | + bvec_iter_advance(bvec, &bi, seek & PAGE_MASK); |
|---|
| 236 | + for_each_bvec(bv, bvec, bi, bi) |
|---|
| 237 | + flush_dcache_page(bv.bv_page); |
|---|
| 238 | +} |
|---|
| 239 | +#else |
|---|
| 240 | +static inline void svc_flush_bvec(const struct bio_vec *bvec, size_t size, |
|---|
| 241 | + size_t seek) |
|---|
| 242 | +{ |
|---|
| 243 | +} |
|---|
| 244 | +#endif |
|---|
| 245 | + |
|---|
| 325 | 246 | /* |
|---|
| 326 | | - * Generic recvfrom routine. |
|---|
| 247 | + * Read from @rqstp's transport socket. The incoming message fills whole |
|---|
| 248 | + * pages in @rqstp's rq_pages array until the last page of the message |
|---|
| 249 | + * has been received into a partial page. |
|---|
| 327 | 250 | */ |
|---|
| 328 | | -static int svc_recvfrom(struct svc_rqst *rqstp, struct kvec *iov, int nr, |
|---|
| 329 | | - int buflen) |
|---|
| 251 | +static ssize_t svc_tcp_read_msg(struct svc_rqst *rqstp, size_t buflen, |
|---|
| 252 | + size_t seek) |
|---|
| 330 | 253 | { |
|---|
| 331 | 254 | struct svc_sock *svsk = |
|---|
| 332 | 255 | container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt); |
|---|
| 333 | | - struct msghdr msg = { |
|---|
| 334 | | - .msg_flags = MSG_DONTWAIT, |
|---|
| 335 | | - }; |
|---|
| 336 | | - int len; |
|---|
| 256 | + struct bio_vec *bvec = rqstp->rq_bvec; |
|---|
| 257 | + struct msghdr msg = { NULL }; |
|---|
| 258 | + unsigned int i; |
|---|
| 259 | + ssize_t len; |
|---|
| 260 | + size_t t; |
|---|
| 337 | 261 | |
|---|
| 338 | 262 | rqstp->rq_xprt_hlen = 0; |
|---|
| 339 | 263 | |
|---|
| 340 | 264 | clear_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); |
|---|
| 341 | | - iov_iter_kvec(&msg.msg_iter, READ | ITER_KVEC, iov, nr, buflen); |
|---|
| 342 | | - len = sock_recvmsg(svsk->sk_sock, &msg, msg.msg_flags); |
|---|
| 265 | + |
|---|
| 266 | + for (i = 0, t = 0; t < buflen; i++, t += PAGE_SIZE) { |
|---|
| 267 | + bvec[i].bv_page = rqstp->rq_pages[i]; |
|---|
| 268 | + bvec[i].bv_len = PAGE_SIZE; |
|---|
| 269 | + bvec[i].bv_offset = 0; |
|---|
| 270 | + } |
|---|
| 271 | + rqstp->rq_respages = &rqstp->rq_pages[i]; |
|---|
| 272 | + rqstp->rq_next_page = rqstp->rq_respages + 1; |
|---|
| 273 | + |
|---|
| 274 | + iov_iter_bvec(&msg.msg_iter, READ, bvec, i, buflen); |
|---|
| 275 | + if (seek) { |
|---|
| 276 | + iov_iter_advance(&msg.msg_iter, seek); |
|---|
| 277 | + buflen -= seek; |
|---|
| 278 | + } |
|---|
| 279 | + len = sock_recvmsg(svsk->sk_sock, &msg, MSG_DONTWAIT); |
|---|
| 280 | + if (len > 0) |
|---|
| 281 | + svc_flush_bvec(bvec, len, seek); |
|---|
| 282 | + |
|---|
| 343 | 283 | /* If we read a full record, then assume there may be more |
|---|
| 344 | 284 | * data to read (stream based sockets only!) |
|---|
| 345 | 285 | */ |
|---|
| 346 | 286 | if (len == buflen) |
|---|
| 347 | 287 | set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); |
|---|
| 348 | 288 | |
|---|
| 349 | | - dprintk("svc: socket %p recvfrom(%p, %zu) = %d\n", |
|---|
| 350 | | - svsk, iov[0].iov_base, iov[0].iov_len, len); |
|---|
| 351 | 289 | return len; |
|---|
| 352 | | -} |
|---|
| 353 | | - |
|---|
| 354 | | -static int svc_partial_recvfrom(struct svc_rqst *rqstp, |
|---|
| 355 | | - struct kvec *iov, int nr, |
|---|
| 356 | | - int buflen, unsigned int base) |
|---|
| 357 | | -{ |
|---|
| 358 | | - size_t save_iovlen; |
|---|
| 359 | | - void *save_iovbase; |
|---|
| 360 | | - unsigned int i; |
|---|
| 361 | | - int ret; |
|---|
| 362 | | - |
|---|
| 363 | | - if (base == 0) |
|---|
| 364 | | - return svc_recvfrom(rqstp, iov, nr, buflen); |
|---|
| 365 | | - |
|---|
| 366 | | - for (i = 0; i < nr; i++) { |
|---|
| 367 | | - if (iov[i].iov_len > base) |
|---|
| 368 | | - break; |
|---|
| 369 | | - base -= iov[i].iov_len; |
|---|
| 370 | | - } |
|---|
| 371 | | - save_iovlen = iov[i].iov_len; |
|---|
| 372 | | - save_iovbase = iov[i].iov_base; |
|---|
| 373 | | - iov[i].iov_len -= base; |
|---|
| 374 | | - iov[i].iov_base += base; |
|---|
| 375 | | - ret = svc_recvfrom(rqstp, &iov[i], nr - i, buflen); |
|---|
| 376 | | - iov[i].iov_len = save_iovlen; |
|---|
| 377 | | - iov[i].iov_base = save_iovbase; |
|---|
| 378 | | - return ret; |
|---|
| 379 | 290 | } |
|---|
| 380 | 291 | |
|---|
| 381 | 292 | /* |
|---|
| .. | .. |
|---|
| 411 | 322 | struct svc_sock *svsk = (struct svc_sock *)sk->sk_user_data; |
|---|
| 412 | 323 | |
|---|
| 413 | 324 | if (svsk) { |
|---|
| 414 | | - dprintk("svc: socket %p(inet %p), busy=%d\n", |
|---|
| 415 | | - svsk, sk, |
|---|
| 416 | | - test_bit(XPT_BUSY, &svsk->sk_xprt.xpt_flags)); |
|---|
| 417 | | - |
|---|
| 418 | 325 | /* Refer to svc_setup_socket() for details. */ |
|---|
| 419 | 326 | rmb(); |
|---|
| 420 | 327 | svsk->sk_odata(sk); |
|---|
| 328 | + trace_svcsock_data_ready(&svsk->sk_xprt, 0); |
|---|
| 421 | 329 | if (!test_and_set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags)) |
|---|
| 422 | 330 | svc_xprt_enqueue(&svsk->sk_xprt); |
|---|
| 423 | 331 | } |
|---|
| .. | .. |
|---|
| 431 | 339 | struct svc_sock *svsk = (struct svc_sock *)(sk->sk_user_data); |
|---|
| 432 | 340 | |
|---|
| 433 | 341 | if (svsk) { |
|---|
| 434 | | - dprintk("svc: socket %p(inet %p), write_space busy=%d\n", |
|---|
| 435 | | - svsk, sk, test_bit(XPT_BUSY, &svsk->sk_xprt.xpt_flags)); |
|---|
| 436 | | - |
|---|
| 437 | 342 | /* Refer to svc_setup_socket() for details. */ |
|---|
| 438 | 343 | rmb(); |
|---|
| 344 | + trace_svcsock_write_space(&svsk->sk_xprt, 0); |
|---|
| 439 | 345 | svsk->sk_owspace(sk); |
|---|
| 440 | 346 | svc_xprt_enqueue(&svsk->sk_xprt); |
|---|
| 441 | 347 | } |
|---|
| .. | .. |
|---|
| 452 | 358 | |
|---|
| 453 | 359 | static void svc_tcp_kill_temp_xprt(struct svc_xprt *xprt) |
|---|
| 454 | 360 | { |
|---|
| 455 | | - struct svc_sock *svsk; |
|---|
| 456 | | - struct socket *sock; |
|---|
| 457 | | - struct linger no_linger = { |
|---|
| 458 | | - .l_onoff = 1, |
|---|
| 459 | | - .l_linger = 0, |
|---|
| 460 | | - }; |
|---|
| 361 | + struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt); |
|---|
| 461 | 362 | |
|---|
| 462 | | - svsk = container_of(xprt, struct svc_sock, sk_xprt); |
|---|
| 463 | | - sock = svsk->sk_sock; |
|---|
| 464 | | - kernel_setsockopt(sock, SOL_SOCKET, SO_LINGER, |
|---|
| 465 | | - (char *)&no_linger, sizeof(no_linger)); |
|---|
| 363 | + sock_no_linger(svsk->sk_sock->sk); |
|---|
| 466 | 364 | } |
|---|
| 467 | 365 | |
|---|
| 468 | 366 | /* |
|---|
| .. | .. |
|---|
| 520 | 418 | return 0; |
|---|
| 521 | 419 | } |
|---|
| 522 | 420 | |
|---|
| 523 | | -/* |
|---|
| 524 | | - * Receive a datagram from a UDP socket. |
|---|
| 421 | +/** |
|---|
| 422 | + * svc_udp_recvfrom - Receive a datagram from a UDP socket. |
|---|
| 423 | + * @rqstp: request structure into which to receive an RPC Call |
|---|
| 424 | + * |
|---|
| 425 | + * Called in a loop when XPT_DATA has been set. |
|---|
| 426 | + * |
|---|
| 427 | + * Returns: |
|---|
| 428 | + * On success, the number of bytes in a received RPC Call, or |
|---|
| 429 | + * %0 if a complete RPC Call message was not ready to return |
|---|
| 525 | 430 | */ |
|---|
| 526 | 431 | static int svc_udp_recvfrom(struct svc_rqst *rqstp) |
|---|
| 527 | 432 | { |
|---|
| .. | .. |
|---|
| 555 | 460 | svc_sock_setbufsize(svsk, serv->sv_nrthreads + 3); |
|---|
| 556 | 461 | |
|---|
| 557 | 462 | clear_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); |
|---|
| 558 | | - skb = NULL; |
|---|
| 559 | 463 | err = kernel_recvmsg(svsk->sk_sock, &msg, NULL, |
|---|
| 560 | 464 | 0, 0, MSG_PEEK | MSG_DONTWAIT); |
|---|
| 561 | | - if (err >= 0) |
|---|
| 562 | | - skb = skb_recv_udp(svsk->sk_sk, 0, 1, &err); |
|---|
| 465 | + if (err < 0) |
|---|
| 466 | + goto out_recv_err; |
|---|
| 467 | + skb = skb_recv_udp(svsk->sk_sk, 0, 1, &err); |
|---|
| 468 | + if (!skb) |
|---|
| 469 | + goto out_recv_err; |
|---|
| 563 | 470 | |
|---|
| 564 | | - if (skb == NULL) { |
|---|
| 565 | | - if (err != -EAGAIN) { |
|---|
| 566 | | - /* possibly an icmp error */ |
|---|
| 567 | | - dprintk("svc: recvfrom returned error %d\n", -err); |
|---|
| 568 | | - set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); |
|---|
| 569 | | - } |
|---|
| 570 | | - return 0; |
|---|
| 571 | | - } |
|---|
| 572 | 471 | len = svc_addr_len(svc_addr(rqstp)); |
|---|
| 573 | 472 | rqstp->rq_addrlen = len; |
|---|
| 574 | 473 | if (skb->tstamp == 0) { |
|---|
| .. | .. |
|---|
| 579 | 478 | sock_write_timestamp(svsk->sk_sk, skb->tstamp); |
|---|
| 580 | 479 | set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); /* there may be more data... */ |
|---|
| 581 | 480 | |
|---|
| 582 | | - len = skb->len; |
|---|
| 481 | + len = skb->len; |
|---|
| 583 | 482 | rqstp->rq_arg.len = len; |
|---|
| 483 | + trace_svcsock_udp_recv(&svsk->sk_xprt, len); |
|---|
| 584 | 484 | |
|---|
| 585 | 485 | rqstp->rq_prot = IPPROTO_UDP; |
|---|
| 586 | 486 | |
|---|
| 587 | | - if (!svc_udp_get_dest_address(rqstp, cmh)) { |
|---|
| 588 | | - net_warn_ratelimited("svc: received unknown control message %d/%d; dropping RPC reply datagram\n", |
|---|
| 589 | | - cmh->cmsg_level, cmh->cmsg_type); |
|---|
| 590 | | - goto out_free; |
|---|
| 591 | | - } |
|---|
| 487 | + if (!svc_udp_get_dest_address(rqstp, cmh)) |
|---|
| 488 | + goto out_cmsg_err; |
|---|
| 592 | 489 | rqstp->rq_daddrlen = svc_addr_len(svc_daddr(rqstp)); |
|---|
| 593 | 490 | |
|---|
| 594 | 491 | if (skb_is_nonlinear(skb)) { |
|---|
| 595 | 492 | /* we have to copy */ |
|---|
| 596 | 493 | local_bh_disable(); |
|---|
| 597 | | - if (csum_partial_copy_to_xdr(&rqstp->rq_arg, skb)) { |
|---|
| 598 | | - local_bh_enable(); |
|---|
| 599 | | - /* checksum error */ |
|---|
| 600 | | - goto out_free; |
|---|
| 601 | | - } |
|---|
| 494 | + if (csum_partial_copy_to_xdr(&rqstp->rq_arg, skb)) |
|---|
| 495 | + goto out_bh_enable; |
|---|
| 602 | 496 | local_bh_enable(); |
|---|
| 603 | 497 | consume_skb(skb); |
|---|
| 604 | 498 | } else { |
|---|
| .. | .. |
|---|
| 626 | 520 | serv->sv_stats->netudpcnt++; |
|---|
| 627 | 521 | |
|---|
| 628 | 522 | return len; |
|---|
| 523 | + |
|---|
| 524 | +out_recv_err: |
|---|
| 525 | + if (err != -EAGAIN) { |
|---|
| 526 | + /* possibly an icmp error */ |
|---|
| 527 | + set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); |
|---|
| 528 | + } |
|---|
| 529 | + trace_svcsock_udp_recv_err(&svsk->sk_xprt, err); |
|---|
| 530 | + return 0; |
|---|
| 531 | +out_cmsg_err: |
|---|
| 532 | + net_warn_ratelimited("svc: received unknown control message %d/%d; dropping RPC reply datagram\n", |
|---|
| 533 | + cmh->cmsg_level, cmh->cmsg_type); |
|---|
| 534 | + goto out_free; |
|---|
| 535 | +out_bh_enable: |
|---|
| 536 | + local_bh_enable(); |
|---|
| 629 | 537 | out_free: |
|---|
| 630 | 538 | kfree_skb(skb); |
|---|
| 631 | 539 | return 0; |
|---|
| 632 | 540 | } |
|---|
| 633 | 541 | |
|---|
| 634 | | -static int |
|---|
| 635 | | -svc_udp_sendto(struct svc_rqst *rqstp) |
|---|
| 542 | +/** |
|---|
| 543 | + * svc_udp_sendto - Send out a reply on a UDP socket |
|---|
| 544 | + * @rqstp: completed svc_rqst |
|---|
| 545 | + * |
|---|
| 546 | + * xpt_mutex ensures @rqstp's whole message is written to the socket |
|---|
| 547 | + * without interruption. |
|---|
| 548 | + * |
|---|
| 549 | + * Returns the number of bytes sent, or a negative errno. |
|---|
| 550 | + */ |
|---|
| 551 | +static int svc_udp_sendto(struct svc_rqst *rqstp) |
|---|
| 636 | 552 | { |
|---|
| 637 | | - int error; |
|---|
| 553 | + struct svc_xprt *xprt = rqstp->rq_xprt; |
|---|
| 554 | + struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt); |
|---|
| 555 | + struct xdr_buf *xdr = &rqstp->rq_res; |
|---|
| 556 | + union { |
|---|
| 557 | + struct cmsghdr hdr; |
|---|
| 558 | + long all[SVC_PKTINFO_SPACE / sizeof(long)]; |
|---|
| 559 | + } buffer; |
|---|
| 560 | + struct cmsghdr *cmh = &buffer.hdr; |
|---|
| 561 | + struct msghdr msg = { |
|---|
| 562 | + .msg_name = &rqstp->rq_addr, |
|---|
| 563 | + .msg_namelen = rqstp->rq_addrlen, |
|---|
| 564 | + .msg_control = cmh, |
|---|
| 565 | + .msg_controllen = sizeof(buffer), |
|---|
| 566 | + }; |
|---|
| 567 | + unsigned int sent; |
|---|
| 568 | + int err; |
|---|
| 638 | 569 | |
|---|
| 639 | | - svc_release_udp_skb(rqstp); |
|---|
| 570 | + svc_udp_release_rqst(rqstp); |
|---|
| 640 | 571 | |
|---|
| 641 | | - error = svc_sendto(rqstp, &rqstp->rq_res); |
|---|
| 642 | | - if (error == -ECONNREFUSED) |
|---|
| 572 | + svc_set_cmsg_data(rqstp, cmh); |
|---|
| 573 | + |
|---|
| 574 | + mutex_lock(&xprt->xpt_mutex); |
|---|
| 575 | + |
|---|
| 576 | + if (svc_xprt_is_dead(xprt)) |
|---|
| 577 | + goto out_notconn; |
|---|
| 578 | + |
|---|
| 579 | + err = xprt_sock_sendmsg(svsk->sk_sock, &msg, xdr, 0, 0, &sent); |
|---|
| 580 | + xdr_free_bvec(xdr); |
|---|
| 581 | + if (err == -ECONNREFUSED) { |
|---|
| 643 | 582 | /* ICMP error on earlier request. */ |
|---|
| 644 | | - error = svc_sendto(rqstp, &rqstp->rq_res); |
|---|
| 583 | + err = xprt_sock_sendmsg(svsk->sk_sock, &msg, xdr, 0, 0, &sent); |
|---|
| 584 | + xdr_free_bvec(xdr); |
|---|
| 585 | + } |
|---|
| 586 | + trace_svcsock_udp_send(xprt, err); |
|---|
| 645 | 587 | |
|---|
| 646 | | - return error; |
|---|
| 647 | | -} |
|---|
| 588 | + mutex_unlock(&xprt->xpt_mutex); |
|---|
| 589 | + if (err < 0) |
|---|
| 590 | + return err; |
|---|
| 591 | + return sent; |
|---|
| 648 | 592 | |
|---|
| 649 | | -static void svc_udp_prep_reply_hdr(struct svc_rqst *rqstp) |
|---|
| 650 | | -{ |
|---|
| 593 | +out_notconn: |
|---|
| 594 | + mutex_unlock(&xprt->xpt_mutex); |
|---|
| 595 | + return -ENOTCONN; |
|---|
| 651 | 596 | } |
|---|
| 652 | 597 | |
|---|
| 653 | 598 | static int svc_udp_has_wspace(struct svc_xprt *xprt) |
|---|
| .. | .. |
|---|
| 690 | 635 | .xpo_create = svc_udp_create, |
|---|
| 691 | 636 | .xpo_recvfrom = svc_udp_recvfrom, |
|---|
| 692 | 637 | .xpo_sendto = svc_udp_sendto, |
|---|
| 693 | | - .xpo_release_rqst = svc_release_udp_skb, |
|---|
| 638 | + .xpo_read_payload = svc_sock_read_payload, |
|---|
| 639 | + .xpo_release_rqst = svc_udp_release_rqst, |
|---|
| 694 | 640 | .xpo_detach = svc_sock_detach, |
|---|
| 695 | 641 | .xpo_free = svc_sock_free, |
|---|
| 696 | | - .xpo_prep_reply_hdr = svc_udp_prep_reply_hdr, |
|---|
| 697 | 642 | .xpo_has_wspace = svc_udp_has_wspace, |
|---|
| 698 | 643 | .xpo_accept = svc_udp_accept, |
|---|
| 699 | 644 | .xpo_secure_port = svc_sock_secure_port, |
|---|
| .. | .. |
|---|
| 710 | 655 | |
|---|
| 711 | 656 | static void svc_udp_init(struct svc_sock *svsk, struct svc_serv *serv) |
|---|
| 712 | 657 | { |
|---|
| 713 | | - int err, level, optname, one = 1; |
|---|
| 714 | | - |
|---|
| 715 | 658 | svc_xprt_init(sock_net(svsk->sk_sock->sk), &svc_udp_class, |
|---|
| 716 | 659 | &svsk->sk_xprt, serv); |
|---|
| 717 | 660 | clear_bit(XPT_CACHE_AUTH, &svsk->sk_xprt.xpt_flags); |
|---|
| .. | .. |
|---|
| 731 | 674 | /* make sure we get destination address info */ |
|---|
| 732 | 675 | switch (svsk->sk_sk->sk_family) { |
|---|
| 733 | 676 | case AF_INET: |
|---|
| 734 | | - level = SOL_IP; |
|---|
| 735 | | - optname = IP_PKTINFO; |
|---|
| 677 | + ip_sock_set_pktinfo(svsk->sk_sock->sk); |
|---|
| 736 | 678 | break; |
|---|
| 737 | 679 | case AF_INET6: |
|---|
| 738 | | - level = SOL_IPV6; |
|---|
| 739 | | - optname = IPV6_RECVPKTINFO; |
|---|
| 680 | + ip6_sock_set_recvpktinfo(svsk->sk_sock->sk); |
|---|
| 740 | 681 | break; |
|---|
| 741 | 682 | default: |
|---|
| 742 | 683 | BUG(); |
|---|
| 743 | 684 | } |
|---|
| 744 | | - err = kernel_setsockopt(svsk->sk_sock, level, optname, |
|---|
| 745 | | - (char *)&one, sizeof(one)); |
|---|
| 746 | | - dprintk("svc: kernel_setsockopt returned %d\n", err); |
|---|
| 747 | 685 | } |
|---|
| 748 | 686 | |
|---|
| 749 | 687 | /* |
|---|
| .. | .. |
|---|
| 754 | 692 | { |
|---|
| 755 | 693 | struct svc_sock *svsk = (struct svc_sock *)sk->sk_user_data; |
|---|
| 756 | 694 | |
|---|
| 757 | | - dprintk("svc: socket %p TCP (listen) state change %d\n", |
|---|
| 758 | | - sk, sk->sk_state); |
|---|
| 759 | | - |
|---|
| 760 | | - if (svsk) { |
|---|
| 761 | | - /* Refer to svc_setup_socket() for details. */ |
|---|
| 762 | | - rmb(); |
|---|
| 763 | | - svsk->sk_odata(sk); |
|---|
| 764 | | - } |
|---|
| 765 | | - |
|---|
| 766 | 695 | /* |
|---|
| 767 | 696 | * This callback may called twice when a new connection |
|---|
| 768 | 697 | * is established as a child socket inherits everything |
|---|
| .. | .. |
|---|
| 771 | 700 | * when one of child sockets become ESTABLISHED. |
|---|
| 772 | 701 | * 2) data_ready method of the child socket may be called |
|---|
| 773 | 702 | * when it receives data before the socket is accepted. |
|---|
| 774 | | - * In case of 2, we should ignore it silently. |
|---|
| 703 | + * In case of 2, we should ignore it silently and DO NOT |
|---|
| 704 | + * dereference svsk. |
|---|
| 775 | 705 | */ |
|---|
| 776 | | - if (sk->sk_state == TCP_LISTEN) { |
|---|
| 777 | | - if (svsk) { |
|---|
| 778 | | - set_bit(XPT_CONN, &svsk->sk_xprt.xpt_flags); |
|---|
| 779 | | - svc_xprt_enqueue(&svsk->sk_xprt); |
|---|
| 780 | | - } else |
|---|
| 781 | | - printk("svc: socket %p: no user data\n", sk); |
|---|
| 706 | + if (sk->sk_state != TCP_LISTEN) |
|---|
| 707 | + return; |
|---|
| 708 | + |
|---|
| 709 | + if (svsk) { |
|---|
| 710 | + /* Refer to svc_setup_socket() for details. */ |
|---|
| 711 | + rmb(); |
|---|
| 712 | + svsk->sk_odata(sk); |
|---|
| 713 | + set_bit(XPT_CONN, &svsk->sk_xprt.xpt_flags); |
|---|
| 714 | + svc_xprt_enqueue(&svsk->sk_xprt); |
|---|
| 782 | 715 | } |
|---|
| 783 | 716 | } |
|---|
| 784 | 717 | |
|---|
| .. | .. |
|---|
| 789 | 722 | { |
|---|
| 790 | 723 | struct svc_sock *svsk = (struct svc_sock *)sk->sk_user_data; |
|---|
| 791 | 724 | |
|---|
| 792 | | - dprintk("svc: socket %p TCP (connected) state change %d (svsk %p)\n", |
|---|
| 793 | | - sk, sk->sk_state, sk->sk_user_data); |
|---|
| 794 | | - |
|---|
| 795 | | - if (!svsk) |
|---|
| 796 | | - printk("svc: socket %p: no user data\n", sk); |
|---|
| 797 | | - else { |
|---|
| 725 | + if (svsk) { |
|---|
| 798 | 726 | /* Refer to svc_setup_socket() for details. */ |
|---|
| 799 | 727 | rmb(); |
|---|
| 800 | 728 | svsk->sk_ostate(sk); |
|---|
| 729 | + trace_svcsock_tcp_state(&svsk->sk_xprt, svsk->sk_sock); |
|---|
| 801 | 730 | if (sk->sk_state != TCP_ESTABLISHED) { |
|---|
| 802 | 731 | set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags); |
|---|
| 803 | 732 | svc_xprt_enqueue(&svsk->sk_xprt); |
|---|
| .. | .. |
|---|
| 818 | 747 | struct socket *newsock; |
|---|
| 819 | 748 | struct svc_sock *newsvsk; |
|---|
| 820 | 749 | int err, slen; |
|---|
| 821 | | - RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]); |
|---|
| 822 | 750 | |
|---|
| 823 | | - dprintk("svc: tcp_accept %p sock %p\n", svsk, sock); |
|---|
| 824 | 751 | if (!sock) |
|---|
| 825 | 752 | return NULL; |
|---|
| 826 | 753 | |
|---|
| .. | .. |
|---|
| 833 | 760 | else if (err != -EAGAIN) |
|---|
| 834 | 761 | net_warn_ratelimited("%s: accept failed (err %d)!\n", |
|---|
| 835 | 762 | serv->sv_name, -err); |
|---|
| 763 | + trace_svcsock_accept_err(xprt, serv->sv_name, err); |
|---|
| 836 | 764 | return NULL; |
|---|
| 837 | 765 | } |
|---|
| 838 | 766 | set_bit(XPT_CONN, &svsk->sk_xprt.xpt_flags); |
|---|
| 839 | 767 | |
|---|
| 840 | 768 | err = kernel_getpeername(newsock, sin); |
|---|
| 841 | 769 | if (err < 0) { |
|---|
| 842 | | - net_warn_ratelimited("%s: peername failed (err %d)!\n", |
|---|
| 843 | | - serv->sv_name, -err); |
|---|
| 770 | + trace_svcsock_getpeername_err(xprt, serv->sv_name, err); |
|---|
| 844 | 771 | goto failed; /* aborted connection or whatever */ |
|---|
| 845 | 772 | } |
|---|
| 846 | 773 | slen = err; |
|---|
| 847 | | - |
|---|
| 848 | | - /* Ideally, we would want to reject connections from unauthorized |
|---|
| 849 | | - * hosts here, but when we get encryption, the IP of the host won't |
|---|
| 850 | | - * tell us anything. For now just warn about unpriv connections. |
|---|
| 851 | | - */ |
|---|
| 852 | | - if (!svc_port_is_privileged(sin)) { |
|---|
| 853 | | - dprintk("%s: connect from unprivileged port: %s\n", |
|---|
| 854 | | - serv->sv_name, |
|---|
| 855 | | - __svc_print_addr(sin, buf, sizeof(buf))); |
|---|
| 856 | | - } |
|---|
| 857 | | - dprintk("%s: connect from %s\n", serv->sv_name, |
|---|
| 858 | | - __svc_print_addr(sin, buf, sizeof(buf))); |
|---|
| 859 | 774 | |
|---|
| 860 | 775 | /* Reset the inherited callbacks before calling svc_setup_socket */ |
|---|
| 861 | 776 | newsock->sk->sk_state_change = svsk->sk_ostate; |
|---|
| .. | .. |
|---|
| 874 | 789 | svc_xprt_set_remote(&newsvsk->sk_xprt, sin, slen); |
|---|
| 875 | 790 | err = kernel_getsockname(newsock, sin); |
|---|
| 876 | 791 | slen = err; |
|---|
| 877 | | - if (unlikely(err < 0)) { |
|---|
| 878 | | - dprintk("svc_tcp_accept: kernel_getsockname error %d\n", -err); |
|---|
| 792 | + if (unlikely(err < 0)) |
|---|
| 879 | 793 | slen = offsetof(struct sockaddr, sa_data); |
|---|
| 880 | | - } |
|---|
| 881 | 794 | svc_xprt_set_local(&newsvsk->sk_xprt, sin, slen); |
|---|
| 882 | 795 | |
|---|
| 883 | 796 | if (sock_is_loopback(newsock->sk)) |
|---|
| .. | .. |
|---|
| 894 | 807 | return NULL; |
|---|
| 895 | 808 | } |
|---|
| 896 | 809 | |
|---|
| 897 | | -static unsigned int svc_tcp_restore_pages(struct svc_sock *svsk, struct svc_rqst *rqstp) |
|---|
| 810 | +static size_t svc_tcp_restore_pages(struct svc_sock *svsk, |
|---|
| 811 | + struct svc_rqst *rqstp) |
|---|
| 898 | 812 | { |
|---|
| 899 | | - unsigned int i, len, npages; |
|---|
| 813 | + size_t len = svsk->sk_datalen; |
|---|
| 814 | + unsigned int i, npages; |
|---|
| 900 | 815 | |
|---|
| 901 | | - if (svsk->sk_datalen == 0) |
|---|
| 816 | + if (!len) |
|---|
| 902 | 817 | return 0; |
|---|
| 903 | | - len = svsk->sk_datalen; |
|---|
| 904 | 818 | npages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT; |
|---|
| 905 | 819 | for (i = 0; i < npages; i++) { |
|---|
| 906 | 820 | if (rqstp->rq_pages[i] != NULL) |
|---|
| .. | .. |
|---|
| 949 | 863 | } |
|---|
| 950 | 864 | |
|---|
| 951 | 865 | /* |
|---|
| 952 | | - * Receive fragment record header. |
|---|
| 953 | | - * If we haven't gotten the record length yet, get the next four bytes. |
|---|
| 866 | + * Receive fragment record header into sk_marker. |
|---|
| 954 | 867 | */ |
|---|
| 955 | | -static int svc_tcp_recv_record(struct svc_sock *svsk, struct svc_rqst *rqstp) |
|---|
| 868 | +static ssize_t svc_tcp_read_marker(struct svc_sock *svsk, |
|---|
| 869 | + struct svc_rqst *rqstp) |
|---|
| 956 | 870 | { |
|---|
| 957 | | - struct svc_serv *serv = svsk->sk_xprt.xpt_server; |
|---|
| 958 | | - unsigned int want; |
|---|
| 959 | | - int len; |
|---|
| 871 | + ssize_t want, len; |
|---|
| 960 | 872 | |
|---|
| 873 | + /* If we haven't gotten the record length yet, |
|---|
| 874 | + * get the next four bytes. |
|---|
| 875 | + */ |
|---|
| 961 | 876 | if (svsk->sk_tcplen < sizeof(rpc_fraghdr)) { |
|---|
| 877 | + struct msghdr msg = { NULL }; |
|---|
| 962 | 878 | struct kvec iov; |
|---|
| 963 | 879 | |
|---|
| 964 | 880 | want = sizeof(rpc_fraghdr) - svsk->sk_tcplen; |
|---|
| 965 | | - iov.iov_base = ((char *) &svsk->sk_reclen) + svsk->sk_tcplen; |
|---|
| 881 | + iov.iov_base = ((char *)&svsk->sk_marker) + svsk->sk_tcplen; |
|---|
| 966 | 882 | iov.iov_len = want; |
|---|
| 967 | | - if ((len = svc_recvfrom(rqstp, &iov, 1, want)) < 0) |
|---|
| 968 | | - goto error; |
|---|
| 883 | + iov_iter_kvec(&msg.msg_iter, READ, &iov, 1, want); |
|---|
| 884 | + len = sock_recvmsg(svsk->sk_sock, &msg, MSG_DONTWAIT); |
|---|
| 885 | + if (len < 0) |
|---|
| 886 | + return len; |
|---|
| 969 | 887 | svsk->sk_tcplen += len; |
|---|
| 970 | | - |
|---|
| 971 | 888 | if (len < want) { |
|---|
| 972 | | - dprintk("svc: short recvfrom while reading record " |
|---|
| 973 | | - "length (%d of %d)\n", len, want); |
|---|
| 974 | | - return -EAGAIN; |
|---|
| 889 | + /* call again to read the remaining bytes */ |
|---|
| 890 | + goto err_short; |
|---|
| 975 | 891 | } |
|---|
| 976 | | - |
|---|
| 977 | | - dprintk("svc: TCP record, %d bytes\n", svc_sock_reclen(svsk)); |
|---|
| 892 | + trace_svcsock_marker(&svsk->sk_xprt, svsk->sk_marker); |
|---|
| 978 | 893 | if (svc_sock_reclen(svsk) + svsk->sk_datalen > |
|---|
| 979 | | - serv->sv_max_mesg) { |
|---|
| 980 | | - net_notice_ratelimited("RPC: fragment too large: %d\n", |
|---|
| 981 | | - svc_sock_reclen(svsk)); |
|---|
| 982 | | - goto err_delete; |
|---|
| 983 | | - } |
|---|
| 894 | + svsk->sk_xprt.xpt_server->sv_max_mesg) |
|---|
| 895 | + goto err_too_large; |
|---|
| 984 | 896 | } |
|---|
| 985 | | - |
|---|
| 986 | 897 | return svc_sock_reclen(svsk); |
|---|
| 987 | | -error: |
|---|
| 988 | | - dprintk("RPC: TCP recv_record got %d\n", len); |
|---|
| 989 | | - return len; |
|---|
| 990 | | -err_delete: |
|---|
| 898 | + |
|---|
| 899 | +err_too_large: |
|---|
| 900 | + net_notice_ratelimited("svc: %s %s RPC fragment too large: %d\n", |
|---|
| 901 | + __func__, svsk->sk_xprt.xpt_server->sv_name, |
|---|
| 902 | + svc_sock_reclen(svsk)); |
|---|
| 991 | 903 | set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags); |
|---|
| 904 | +err_short: |
|---|
| 992 | 905 | return -EAGAIN; |
|---|
| 993 | 906 | } |
|---|
| 994 | 907 | |
|---|
| .. | .. |
|---|
| 1006 | 919 | |
|---|
| 1007 | 920 | if (!bc_xprt) |
|---|
| 1008 | 921 | return -EAGAIN; |
|---|
| 1009 | | - spin_lock(&bc_xprt->recv_lock); |
|---|
| 922 | + spin_lock(&bc_xprt->queue_lock); |
|---|
| 1010 | 923 | req = xprt_lookup_rqst(bc_xprt, xid); |
|---|
| 1011 | 924 | if (!req) |
|---|
| 1012 | 925 | goto unlock_notfound; |
|---|
| .. | .. |
|---|
| 1024 | 937 | memcpy(dst->iov_base, src->iov_base, src->iov_len); |
|---|
| 1025 | 938 | xprt_complete_rqst(req->rq_task, rqstp->rq_arg.len); |
|---|
| 1026 | 939 | rqstp->rq_arg.len = 0; |
|---|
| 1027 | | - spin_unlock(&bc_xprt->recv_lock); |
|---|
| 940 | + spin_unlock(&bc_xprt->queue_lock); |
|---|
| 1028 | 941 | return 0; |
|---|
| 1029 | 942 | unlock_notfound: |
|---|
| 1030 | 943 | printk(KERN_NOTICE |
|---|
| .. | .. |
|---|
| 1033 | 946 | __func__, ntohl(calldir), |
|---|
| 1034 | 947 | bc_xprt, ntohl(xid)); |
|---|
| 1035 | 948 | unlock_eagain: |
|---|
| 1036 | | - spin_unlock(&bc_xprt->recv_lock); |
|---|
| 949 | + spin_unlock(&bc_xprt->queue_lock); |
|---|
| 1037 | 950 | return -EAGAIN; |
|---|
| 1038 | | -} |
|---|
| 1039 | | - |
|---|
| 1040 | | -static int copy_pages_to_kvecs(struct kvec *vec, struct page **pages, int len) |
|---|
| 1041 | | -{ |
|---|
| 1042 | | - int i = 0; |
|---|
| 1043 | | - int t = 0; |
|---|
| 1044 | | - |
|---|
| 1045 | | - while (t < len) { |
|---|
| 1046 | | - vec[i].iov_base = page_address(pages[i]); |
|---|
| 1047 | | - vec[i].iov_len = PAGE_SIZE; |
|---|
| 1048 | | - i++; |
|---|
| 1049 | | - t += PAGE_SIZE; |
|---|
| 1050 | | - } |
|---|
| 1051 | | - return i; |
|---|
| 1052 | 951 | } |
|---|
| 1053 | 952 | |
|---|
| 1054 | 953 | static void svc_tcp_fragment_received(struct svc_sock *svsk) |
|---|
| 1055 | 954 | { |
|---|
| 1056 | 955 | /* If we have more data, signal svc_xprt_enqueue() to try again */ |
|---|
| 1057 | | - dprintk("svc: TCP %s record (%d bytes)\n", |
|---|
| 1058 | | - svc_sock_final_rec(svsk) ? "final" : "nonfinal", |
|---|
| 1059 | | - svc_sock_reclen(svsk)); |
|---|
| 1060 | 956 | svsk->sk_tcplen = 0; |
|---|
| 1061 | | - svsk->sk_reclen = 0; |
|---|
| 957 | + svsk->sk_marker = xdr_zero; |
|---|
| 1062 | 958 | } |
|---|
| 1063 | 959 | |
|---|
| 1064 | | -/* |
|---|
| 1065 | | - * Receive data from a TCP socket. |
|---|
| 960 | +/** |
|---|
| 961 | + * svc_tcp_recvfrom - Receive data from a TCP socket |
|---|
| 962 | + * @rqstp: request structure into which to receive an RPC Call |
|---|
| 963 | + * |
|---|
| 964 | + * Called in a loop when XPT_DATA has been set. |
|---|
| 965 | + * |
|---|
| 966 | + * Read the 4-byte stream record marker, then use the record length |
|---|
| 967 | + * in that marker to set up exactly the resources needed to receive |
|---|
| 968 | + * the next RPC message into @rqstp. |
|---|
| 969 | + * |
|---|
| 970 | + * Returns: |
|---|
| 971 | + * On success, the number of bytes in a received RPC Call, or |
|---|
| 972 | + * %0 if a complete RPC Call message was not ready to return |
|---|
| 973 | + * |
|---|
| 974 | + * The zero return case handles partial receives and callback Replies. |
|---|
| 975 | + * The state of a partial receive is preserved in the svc_sock for |
|---|
| 976 | + * the next call to svc_tcp_recvfrom. |
|---|
| 1066 | 977 | */ |
|---|
| 1067 | 978 | static int svc_tcp_recvfrom(struct svc_rqst *rqstp) |
|---|
| 1068 | 979 | { |
|---|
| 1069 | 980 | struct svc_sock *svsk = |
|---|
| 1070 | 981 | container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt); |
|---|
| 1071 | 982 | struct svc_serv *serv = svsk->sk_xprt.xpt_server; |
|---|
| 1072 | | - int len; |
|---|
| 1073 | | - struct kvec *vec; |
|---|
| 1074 | | - unsigned int want, base; |
|---|
| 983 | + size_t want, base; |
|---|
| 984 | + ssize_t len; |
|---|
| 1075 | 985 | __be32 *p; |
|---|
| 1076 | 986 | __be32 calldir; |
|---|
| 1077 | | - int pnum; |
|---|
| 1078 | 987 | |
|---|
| 1079 | | - dprintk("svc: tcp_recv %p data %d conn %d close %d\n", |
|---|
| 1080 | | - svsk, test_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags), |
|---|
| 1081 | | - test_bit(XPT_CONN, &svsk->sk_xprt.xpt_flags), |
|---|
| 1082 | | - test_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags)); |
|---|
| 1083 | | - |
|---|
| 1084 | | - len = svc_tcp_recv_record(svsk, rqstp); |
|---|
| 988 | + clear_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); |
|---|
| 989 | + len = svc_tcp_read_marker(svsk, rqstp); |
|---|
| 1085 | 990 | if (len < 0) |
|---|
| 1086 | 991 | goto error; |
|---|
| 1087 | 992 | |
|---|
| 1088 | 993 | base = svc_tcp_restore_pages(svsk, rqstp); |
|---|
| 1089 | | - want = svc_sock_reclen(svsk) - (svsk->sk_tcplen - sizeof(rpc_fraghdr)); |
|---|
| 1090 | | - |
|---|
| 1091 | | - vec = rqstp->rq_vec; |
|---|
| 1092 | | - |
|---|
| 1093 | | - pnum = copy_pages_to_kvecs(&vec[0], &rqstp->rq_pages[0], |
|---|
| 1094 | | - svsk->sk_datalen + want); |
|---|
| 1095 | | - |
|---|
| 1096 | | - rqstp->rq_respages = &rqstp->rq_pages[pnum]; |
|---|
| 1097 | | - rqstp->rq_next_page = rqstp->rq_respages + 1; |
|---|
| 1098 | | - |
|---|
| 1099 | | - /* Now receive data */ |
|---|
| 1100 | | - len = svc_partial_recvfrom(rqstp, vec, pnum, want, base); |
|---|
| 994 | + want = len - (svsk->sk_tcplen - sizeof(rpc_fraghdr)); |
|---|
| 995 | + len = svc_tcp_read_msg(rqstp, base + want, base); |
|---|
| 1101 | 996 | if (len >= 0) { |
|---|
| 997 | + trace_svcsock_tcp_recv(&svsk->sk_xprt, len); |
|---|
| 1102 | 998 | svsk->sk_tcplen += len; |
|---|
| 1103 | 999 | svsk->sk_datalen += len; |
|---|
| 1104 | 1000 | } |
|---|
| 1105 | | - if (len != want || !svc_sock_final_rec(svsk)) { |
|---|
| 1106 | | - svc_tcp_save_pages(svsk, rqstp); |
|---|
| 1107 | | - if (len < 0 && len != -EAGAIN) |
|---|
| 1108 | | - goto err_delete; |
|---|
| 1109 | | - if (len == want) |
|---|
| 1110 | | - svc_tcp_fragment_received(svsk); |
|---|
| 1111 | | - else |
|---|
| 1112 | | - dprintk("svc: incomplete TCP record (%d of %d)\n", |
|---|
| 1113 | | - (int)(svsk->sk_tcplen - sizeof(rpc_fraghdr)), |
|---|
| 1114 | | - svc_sock_reclen(svsk)); |
|---|
| 1115 | | - goto err_noclose; |
|---|
| 1116 | | - } |
|---|
| 1117 | | - |
|---|
| 1118 | | - if (svsk->sk_datalen < 8) { |
|---|
| 1119 | | - svsk->sk_datalen = 0; |
|---|
| 1120 | | - goto err_delete; /* client is nuts. */ |
|---|
| 1121 | | - } |
|---|
| 1001 | + if (len != want || !svc_sock_final_rec(svsk)) |
|---|
| 1002 | + goto err_incomplete; |
|---|
| 1003 | + if (svsk->sk_datalen < 8) |
|---|
| 1004 | + goto err_nuts; |
|---|
| 1122 | 1005 | |
|---|
| 1123 | 1006 | rqstp->rq_arg.len = svsk->sk_datalen; |
|---|
| 1124 | 1007 | rqstp->rq_arg.page_base = 0; |
|---|
| .. | .. |
|---|
| 1153 | 1036 | |
|---|
| 1154 | 1037 | return rqstp->rq_arg.len; |
|---|
| 1155 | 1038 | |
|---|
| 1039 | +err_incomplete: |
|---|
| 1040 | + svc_tcp_save_pages(svsk, rqstp); |
|---|
| 1041 | + if (len < 0 && len != -EAGAIN) |
|---|
| 1042 | + goto err_delete; |
|---|
| 1043 | + if (len == want) |
|---|
| 1044 | + svc_tcp_fragment_received(svsk); |
|---|
| 1045 | + else |
|---|
| 1046 | + trace_svcsock_tcp_recv_short(&svsk->sk_xprt, |
|---|
| 1047 | + svc_sock_reclen(svsk), |
|---|
| 1048 | + svsk->sk_tcplen - sizeof(rpc_fraghdr)); |
|---|
| 1049 | + goto err_noclose; |
|---|
| 1156 | 1050 | error: |
|---|
| 1157 | 1051 | if (len != -EAGAIN) |
|---|
| 1158 | 1052 | goto err_delete; |
|---|
| 1159 | | - dprintk("RPC: TCP recvfrom got EAGAIN\n"); |
|---|
| 1053 | + trace_svcsock_tcp_recv_eagain(&svsk->sk_xprt, 0); |
|---|
| 1160 | 1054 | return 0; |
|---|
| 1055 | +err_nuts: |
|---|
| 1056 | + svsk->sk_datalen = 0; |
|---|
| 1161 | 1057 | err_delete: |
|---|
| 1162 | | - printk(KERN_NOTICE "%s: recvfrom returned errno %d\n", |
|---|
| 1163 | | - svsk->sk_xprt.xpt_server->sv_name, -len); |
|---|
| 1058 | + trace_svcsock_tcp_recv_err(&svsk->sk_xprt, len); |
|---|
| 1164 | 1059 | set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags); |
|---|
| 1165 | 1060 | err_noclose: |
|---|
| 1166 | 1061 | return 0; /* record not complete */ |
|---|
| 1167 | 1062 | } |
|---|
| 1168 | 1063 | |
|---|
| 1169 | | -/* |
|---|
| 1170 | | - * Send out data on TCP socket. |
|---|
| 1171 | | - */ |
|---|
| 1172 | | -static int svc_tcp_sendto(struct svc_rqst *rqstp) |
|---|
| 1064 | +static int svc_tcp_send_kvec(struct socket *sock, const struct kvec *vec, |
|---|
| 1065 | + int flags) |
|---|
| 1173 | 1066 | { |
|---|
| 1174 | | - struct xdr_buf *xbufp = &rqstp->rq_res; |
|---|
| 1175 | | - int sent; |
|---|
| 1176 | | - __be32 reclen; |
|---|
| 1177 | | - |
|---|
| 1178 | | - svc_release_skb(rqstp); |
|---|
| 1179 | | - |
|---|
| 1180 | | - /* Set up the first element of the reply kvec. |
|---|
| 1181 | | - * Any other kvecs that may be in use have been taken |
|---|
| 1182 | | - * care of by the server implementation itself. |
|---|
| 1183 | | - */ |
|---|
| 1184 | | - reclen = htonl(0x80000000|((xbufp->len ) - 4)); |
|---|
| 1185 | | - memcpy(xbufp->head[0].iov_base, &reclen, 4); |
|---|
| 1186 | | - |
|---|
| 1187 | | - sent = svc_sendto(rqstp, &rqstp->rq_res); |
|---|
| 1188 | | - if (sent != xbufp->len) { |
|---|
| 1189 | | - printk(KERN_NOTICE |
|---|
| 1190 | | - "rpc-srv/tcp: %s: %s %d when sending %d bytes " |
|---|
| 1191 | | - "- shutting down socket\n", |
|---|
| 1192 | | - rqstp->rq_xprt->xpt_server->sv_name, |
|---|
| 1193 | | - (sent<0)?"got error":"sent only", |
|---|
| 1194 | | - sent, xbufp->len); |
|---|
| 1195 | | - set_bit(XPT_CLOSE, &rqstp->rq_xprt->xpt_flags); |
|---|
| 1196 | | - svc_xprt_enqueue(rqstp->rq_xprt); |
|---|
| 1197 | | - sent = -EAGAIN; |
|---|
| 1198 | | - } |
|---|
| 1199 | | - return sent; |
|---|
| 1067 | + return kernel_sendpage(sock, virt_to_page(vec->iov_base), |
|---|
| 1068 | + offset_in_page(vec->iov_base), |
|---|
| 1069 | + vec->iov_len, flags); |
|---|
| 1200 | 1070 | } |
|---|
| 1201 | 1071 | |
|---|
| 1202 | 1072 | /* |
|---|
| 1203 | | - * Setup response header. TCP has a 4B record length field. |
|---|
| 1073 | + * kernel_sendpage() is used exclusively to reduce the number of |
|---|
| 1074 | + * copy operations in this path. Therefore the caller must ensure |
|---|
| 1075 | + * that the pages backing @xdr are unchanging. |
|---|
| 1076 | + * |
|---|
| 1077 | + * In addition, the logic assumes that * .bv_len is never larger |
|---|
| 1078 | + * than PAGE_SIZE. |
|---|
| 1204 | 1079 | */ |
|---|
| 1205 | | -void svc_tcp_prep_reply_hdr(struct svc_rqst *rqstp) |
|---|
| 1080 | +static int svc_tcp_sendmsg(struct socket *sock, struct msghdr *msg, |
|---|
| 1081 | + struct xdr_buf *xdr, rpc_fraghdr marker, |
|---|
| 1082 | + unsigned int *sentp) |
|---|
| 1206 | 1083 | { |
|---|
| 1207 | | - struct kvec *resv = &rqstp->rq_res.head[0]; |
|---|
| 1084 | + const struct kvec *head = xdr->head; |
|---|
| 1085 | + const struct kvec *tail = xdr->tail; |
|---|
| 1086 | + struct kvec rm = { |
|---|
| 1087 | + .iov_base = &marker, |
|---|
| 1088 | + .iov_len = sizeof(marker), |
|---|
| 1089 | + }; |
|---|
| 1090 | + int flags, ret; |
|---|
| 1208 | 1091 | |
|---|
| 1209 | | - /* tcp needs a space for the record length... */ |
|---|
| 1210 | | - svc_putnl(resv, 0); |
|---|
| 1092 | + *sentp = 0; |
|---|
| 1093 | + ret = xdr_alloc_bvec(xdr, GFP_KERNEL); |
|---|
| 1094 | + if (ret < 0) |
|---|
| 1095 | + return ret; |
|---|
| 1096 | + |
|---|
| 1097 | + msg->msg_flags = MSG_MORE; |
|---|
| 1098 | + ret = kernel_sendmsg(sock, msg, &rm, 1, rm.iov_len); |
|---|
| 1099 | + if (ret < 0) |
|---|
| 1100 | + return ret; |
|---|
| 1101 | + *sentp += ret; |
|---|
| 1102 | + if (ret != rm.iov_len) |
|---|
| 1103 | + return -EAGAIN; |
|---|
| 1104 | + |
|---|
| 1105 | + flags = head->iov_len < xdr->len ? MSG_MORE | MSG_SENDPAGE_NOTLAST : 0; |
|---|
| 1106 | + ret = svc_tcp_send_kvec(sock, head, flags); |
|---|
| 1107 | + if (ret < 0) |
|---|
| 1108 | + return ret; |
|---|
| 1109 | + *sentp += ret; |
|---|
| 1110 | + if (ret != head->iov_len) |
|---|
| 1111 | + goto out; |
|---|
| 1112 | + |
|---|
| 1113 | + if (xdr->page_len) { |
|---|
| 1114 | + unsigned int offset, len, remaining; |
|---|
| 1115 | + struct bio_vec *bvec; |
|---|
| 1116 | + |
|---|
| 1117 | + bvec = xdr->bvec + (xdr->page_base >> PAGE_SHIFT); |
|---|
| 1118 | + offset = offset_in_page(xdr->page_base); |
|---|
| 1119 | + remaining = xdr->page_len; |
|---|
| 1120 | + flags = MSG_MORE | MSG_SENDPAGE_NOTLAST; |
|---|
| 1121 | + while (remaining > 0) { |
|---|
| 1122 | + if (remaining <= PAGE_SIZE && tail->iov_len == 0) |
|---|
| 1123 | + flags = 0; |
|---|
| 1124 | + |
|---|
| 1125 | + len = min(remaining, bvec->bv_len - offset); |
|---|
| 1126 | + ret = kernel_sendpage(sock, bvec->bv_page, |
|---|
| 1127 | + bvec->bv_offset + offset, |
|---|
| 1128 | + len, flags); |
|---|
| 1129 | + if (ret < 0) |
|---|
| 1130 | + return ret; |
|---|
| 1131 | + *sentp += ret; |
|---|
| 1132 | + if (ret != len) |
|---|
| 1133 | + goto out; |
|---|
| 1134 | + remaining -= len; |
|---|
| 1135 | + offset = 0; |
|---|
| 1136 | + bvec++; |
|---|
| 1137 | + } |
|---|
| 1138 | + } |
|---|
| 1139 | + |
|---|
| 1140 | + if (tail->iov_len) { |
|---|
| 1141 | + ret = svc_tcp_send_kvec(sock, tail, 0); |
|---|
| 1142 | + if (ret < 0) |
|---|
| 1143 | + return ret; |
|---|
| 1144 | + *sentp += ret; |
|---|
| 1145 | + } |
|---|
| 1146 | + |
|---|
| 1147 | +out: |
|---|
| 1148 | + return 0; |
|---|
| 1149 | +} |
|---|
| 1150 | + |
|---|
| 1151 | +/** |
|---|
| 1152 | + * svc_tcp_sendto - Send out a reply on a TCP socket |
|---|
| 1153 | + * @rqstp: completed svc_rqst |
|---|
| 1154 | + * |
|---|
| 1155 | + * xpt_mutex ensures @rqstp's whole message is written to the socket |
|---|
| 1156 | + * without interruption. |
|---|
| 1157 | + * |
|---|
| 1158 | + * Returns the number of bytes sent, or a negative errno. |
|---|
| 1159 | + */ |
|---|
| 1160 | +static int svc_tcp_sendto(struct svc_rqst *rqstp) |
|---|
| 1161 | +{ |
|---|
| 1162 | + struct svc_xprt *xprt = rqstp->rq_xprt; |
|---|
| 1163 | + struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt); |
|---|
| 1164 | + struct xdr_buf *xdr = &rqstp->rq_res; |
|---|
| 1165 | + rpc_fraghdr marker = cpu_to_be32(RPC_LAST_STREAM_FRAGMENT | |
|---|
| 1166 | + (u32)xdr->len); |
|---|
| 1167 | + struct msghdr msg = { |
|---|
| 1168 | + .msg_flags = 0, |
|---|
| 1169 | + }; |
|---|
| 1170 | + unsigned int sent; |
|---|
| 1171 | + int err; |
|---|
| 1172 | + |
|---|
| 1173 | + svc_tcp_release_rqst(rqstp); |
|---|
| 1174 | + |
|---|
| 1175 | + mutex_lock(&xprt->xpt_mutex); |
|---|
| 1176 | + if (svc_xprt_is_dead(xprt)) |
|---|
| 1177 | + goto out_notconn; |
|---|
| 1178 | + err = svc_tcp_sendmsg(svsk->sk_sock, &msg, xdr, marker, &sent); |
|---|
| 1179 | + xdr_free_bvec(xdr); |
|---|
| 1180 | + trace_svcsock_tcp_send(xprt, err < 0 ? (long)err : sent); |
|---|
| 1181 | + if (err < 0 || sent != (xdr->len + sizeof(marker))) |
|---|
| 1182 | + goto out_close; |
|---|
| 1183 | + mutex_unlock(&xprt->xpt_mutex); |
|---|
| 1184 | + return sent; |
|---|
| 1185 | + |
|---|
| 1186 | +out_notconn: |
|---|
| 1187 | + mutex_unlock(&xprt->xpt_mutex); |
|---|
| 1188 | + return -ENOTCONN; |
|---|
| 1189 | +out_close: |
|---|
| 1190 | + pr_notice("rpc-srv/tcp: %s: %s %d when sending %d bytes - shutting down socket\n", |
|---|
| 1191 | + xprt->xpt_server->sv_name, |
|---|
| 1192 | + (err < 0) ? "got error" : "sent", |
|---|
| 1193 | + (err < 0) ? err : sent, xdr->len); |
|---|
| 1194 | + set_bit(XPT_CLOSE, &xprt->xpt_flags); |
|---|
| 1195 | + svc_xprt_enqueue(xprt); |
|---|
| 1196 | + mutex_unlock(&xprt->xpt_mutex); |
|---|
| 1197 | + return -EAGAIN; |
|---|
| 1211 | 1198 | } |
|---|
| 1212 | 1199 | |
|---|
| 1213 | 1200 | static struct svc_xprt *svc_tcp_create(struct svc_serv *serv, |
|---|
| .. | .. |
|---|
| 1218 | 1205 | return svc_create_socket(serv, IPPROTO_TCP, net, sa, salen, flags); |
|---|
| 1219 | 1206 | } |
|---|
| 1220 | 1207 | |
|---|
| 1221 | | -#if defined(CONFIG_SUNRPC_BACKCHANNEL) |
|---|
| 1222 | | -static struct svc_xprt *svc_bc_create_socket(struct svc_serv *, int, |
|---|
| 1223 | | - struct net *, struct sockaddr *, |
|---|
| 1224 | | - int, int); |
|---|
| 1225 | | -static void svc_bc_sock_free(struct svc_xprt *xprt); |
|---|
| 1226 | | - |
|---|
| 1227 | | -static struct svc_xprt *svc_bc_tcp_create(struct svc_serv *serv, |
|---|
| 1228 | | - struct net *net, |
|---|
| 1229 | | - struct sockaddr *sa, int salen, |
|---|
| 1230 | | - int flags) |
|---|
| 1231 | | -{ |
|---|
| 1232 | | - return svc_bc_create_socket(serv, IPPROTO_TCP, net, sa, salen, flags); |
|---|
| 1233 | | -} |
|---|
| 1234 | | - |
|---|
| 1235 | | -static void svc_bc_tcp_sock_detach(struct svc_xprt *xprt) |
|---|
| 1236 | | -{ |
|---|
| 1237 | | -} |
|---|
| 1238 | | - |
|---|
| 1239 | | -static const struct svc_xprt_ops svc_tcp_bc_ops = { |
|---|
| 1240 | | - .xpo_create = svc_bc_tcp_create, |
|---|
| 1241 | | - .xpo_detach = svc_bc_tcp_sock_detach, |
|---|
| 1242 | | - .xpo_free = svc_bc_sock_free, |
|---|
| 1243 | | - .xpo_prep_reply_hdr = svc_tcp_prep_reply_hdr, |
|---|
| 1244 | | - .xpo_secure_port = svc_sock_secure_port, |
|---|
| 1245 | | -}; |
|---|
| 1246 | | - |
|---|
| 1247 | | -static struct svc_xprt_class svc_tcp_bc_class = { |
|---|
| 1248 | | - .xcl_name = "tcp-bc", |
|---|
| 1249 | | - .xcl_owner = THIS_MODULE, |
|---|
| 1250 | | - .xcl_ops = &svc_tcp_bc_ops, |
|---|
| 1251 | | - .xcl_max_payload = RPCSVC_MAXPAYLOAD_TCP, |
|---|
| 1252 | | -}; |
|---|
| 1253 | | - |
|---|
| 1254 | | -static void svc_init_bc_xprt_sock(void) |
|---|
| 1255 | | -{ |
|---|
| 1256 | | - svc_reg_xprt_class(&svc_tcp_bc_class); |
|---|
| 1257 | | -} |
|---|
| 1258 | | - |
|---|
| 1259 | | -static void svc_cleanup_bc_xprt_sock(void) |
|---|
| 1260 | | -{ |
|---|
| 1261 | | - svc_unreg_xprt_class(&svc_tcp_bc_class); |
|---|
| 1262 | | -} |
|---|
| 1263 | | -#else /* CONFIG_SUNRPC_BACKCHANNEL */ |
|---|
| 1264 | | -static void svc_init_bc_xprt_sock(void) |
|---|
| 1265 | | -{ |
|---|
| 1266 | | -} |
|---|
| 1267 | | - |
|---|
| 1268 | | -static void svc_cleanup_bc_xprt_sock(void) |
|---|
| 1269 | | -{ |
|---|
| 1270 | | -} |
|---|
| 1271 | | -#endif /* CONFIG_SUNRPC_BACKCHANNEL */ |
|---|
| 1272 | | - |
|---|
| 1273 | 1208 | static const struct svc_xprt_ops svc_tcp_ops = { |
|---|
| 1274 | 1209 | .xpo_create = svc_tcp_create, |
|---|
| 1275 | 1210 | .xpo_recvfrom = svc_tcp_recvfrom, |
|---|
| 1276 | 1211 | .xpo_sendto = svc_tcp_sendto, |
|---|
| 1277 | | - .xpo_release_rqst = svc_release_skb, |
|---|
| 1212 | + .xpo_read_payload = svc_sock_read_payload, |
|---|
| 1213 | + .xpo_release_rqst = svc_tcp_release_rqst, |
|---|
| 1278 | 1214 | .xpo_detach = svc_tcp_sock_detach, |
|---|
| 1279 | 1215 | .xpo_free = svc_sock_free, |
|---|
| 1280 | | - .xpo_prep_reply_hdr = svc_tcp_prep_reply_hdr, |
|---|
| 1281 | 1216 | .xpo_has_wspace = svc_tcp_has_wspace, |
|---|
| 1282 | 1217 | .xpo_accept = svc_tcp_accept, |
|---|
| 1283 | 1218 | .xpo_secure_port = svc_sock_secure_port, |
|---|
| .. | .. |
|---|
| 1296 | 1231 | { |
|---|
| 1297 | 1232 | svc_reg_xprt_class(&svc_tcp_class); |
|---|
| 1298 | 1233 | svc_reg_xprt_class(&svc_udp_class); |
|---|
| 1299 | | - svc_init_bc_xprt_sock(); |
|---|
| 1300 | 1234 | } |
|---|
| 1301 | 1235 | |
|---|
| 1302 | 1236 | void svc_cleanup_xprt_sock(void) |
|---|
| 1303 | 1237 | { |
|---|
| 1304 | 1238 | svc_unreg_xprt_class(&svc_tcp_class); |
|---|
| 1305 | 1239 | svc_unreg_xprt_class(&svc_udp_class); |
|---|
| 1306 | | - svc_cleanup_bc_xprt_sock(); |
|---|
| 1307 | 1240 | } |
|---|
| 1308 | 1241 | |
|---|
| 1309 | 1242 | static void svc_tcp_init(struct svc_sock *svsk, struct svc_serv *serv) |
|---|
| .. | .. |
|---|
| 1315 | 1248 | set_bit(XPT_CACHE_AUTH, &svsk->sk_xprt.xpt_flags); |
|---|
| 1316 | 1249 | set_bit(XPT_CONG_CTRL, &svsk->sk_xprt.xpt_flags); |
|---|
| 1317 | 1250 | if (sk->sk_state == TCP_LISTEN) { |
|---|
| 1318 | | - dprintk("setting up TCP socket for listening\n"); |
|---|
| 1319 | 1251 | strcpy(svsk->sk_xprt.xpt_remotebuf, "listener"); |
|---|
| 1320 | 1252 | set_bit(XPT_LISTENER, &svsk->sk_xprt.xpt_flags); |
|---|
| 1321 | 1253 | sk->sk_data_ready = svc_tcp_listen_data_ready; |
|---|
| 1322 | 1254 | set_bit(XPT_CONN, &svsk->sk_xprt.xpt_flags); |
|---|
| 1323 | 1255 | } else { |
|---|
| 1324 | | - dprintk("setting up TCP socket for reading\n"); |
|---|
| 1325 | 1256 | sk->sk_state_change = svc_tcp_state_change; |
|---|
| 1326 | 1257 | sk->sk_data_ready = svc_data_ready; |
|---|
| 1327 | 1258 | sk->sk_write_space = svc_write_space; |
|---|
| 1328 | 1259 | |
|---|
| 1329 | | - svsk->sk_reclen = 0; |
|---|
| 1260 | + svsk->sk_marker = xdr_zero; |
|---|
| 1330 | 1261 | svsk->sk_tcplen = 0; |
|---|
| 1331 | 1262 | svsk->sk_datalen = 0; |
|---|
| 1332 | 1263 | memset(&svsk->sk_pages[0], 0, sizeof(svsk->sk_pages)); |
|---|
| .. | .. |
|---|
| 1371 | 1302 | int pmap_register = !(flags & SVC_SOCK_ANONYMOUS); |
|---|
| 1372 | 1303 | int err = 0; |
|---|
| 1373 | 1304 | |
|---|
| 1374 | | - dprintk("svc: svc_setup_socket %p\n", sock); |
|---|
| 1375 | 1305 | svsk = kzalloc(sizeof(*svsk), GFP_KERNEL); |
|---|
| 1376 | 1306 | if (!svsk) |
|---|
| 1377 | 1307 | return ERR_PTR(-ENOMEM); |
|---|
| .. | .. |
|---|
| 1408 | 1338 | else |
|---|
| 1409 | 1339 | svc_tcp_init(svsk, serv); |
|---|
| 1410 | 1340 | |
|---|
| 1411 | | - dprintk("svc: svc_setup_socket created %p (inet %p), " |
|---|
| 1412 | | - "listen %d close %d\n", |
|---|
| 1413 | | - svsk, svsk->sk_sk, |
|---|
| 1414 | | - test_bit(XPT_LISTENER, &svsk->sk_xprt.xpt_flags), |
|---|
| 1415 | | - test_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags)); |
|---|
| 1416 | | - |
|---|
| 1341 | + trace_svcsock_new_socket(sock); |
|---|
| 1417 | 1342 | return svsk; |
|---|
| 1418 | 1343 | } |
|---|
| 1419 | 1344 | |
|---|
| .. | .. |
|---|
| 1439 | 1364 | * @fd: file descriptor of the new listener |
|---|
| 1440 | 1365 | * @name_return: pointer to buffer to fill in with name of listener |
|---|
| 1441 | 1366 | * @len: size of the buffer |
|---|
| 1367 | + * @cred: credential |
|---|
| 1442 | 1368 | * |
|---|
| 1443 | 1369 | * Fills in socket name and returns positive length of name if successful. |
|---|
| 1444 | 1370 | * Name is terminated with '\n'. On error, returns a negative errno |
|---|
| 1445 | 1371 | * value. |
|---|
| 1446 | 1372 | */ |
|---|
| 1447 | 1373 | int svc_addsock(struct svc_serv *serv, const int fd, char *name_return, |
|---|
| 1448 | | - const size_t len) |
|---|
| 1374 | + const size_t len, const struct cred *cred) |
|---|
| 1449 | 1375 | { |
|---|
| 1450 | 1376 | int err = 0; |
|---|
| 1451 | 1377 | struct socket *so = sockfd_lookup(fd, &err); |
|---|
| .. | .. |
|---|
| 1478 | 1404 | salen = kernel_getsockname(svsk->sk_sock, sin); |
|---|
| 1479 | 1405 | if (salen >= 0) |
|---|
| 1480 | 1406 | svc_xprt_set_local(&svsk->sk_xprt, sin, salen); |
|---|
| 1407 | + svsk->sk_xprt.xpt_cred = get_cred(cred); |
|---|
| 1481 | 1408 | svc_add_new_perm_xprt(serv, &svsk->sk_xprt); |
|---|
| 1482 | 1409 | return svc_one_sock_name(svsk, name_return, len); |
|---|
| 1483 | 1410 | out: |
|---|
| .. | .. |
|---|
| 1503 | 1430 | struct sockaddr *newsin = (struct sockaddr *)&addr; |
|---|
| 1504 | 1431 | int newlen; |
|---|
| 1505 | 1432 | int family; |
|---|
| 1506 | | - int val; |
|---|
| 1507 | | - RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]); |
|---|
| 1508 | | - |
|---|
| 1509 | | - dprintk("svc: svc_create_socket(%s, %d, %s)\n", |
|---|
| 1510 | | - serv->sv_program->pg_name, protocol, |
|---|
| 1511 | | - __svc_print_addr(sin, buf, sizeof(buf))); |
|---|
| 1512 | 1433 | |
|---|
| 1513 | 1434 | if (protocol != IPPROTO_UDP && protocol != IPPROTO_TCP) { |
|---|
| 1514 | 1435 | printk(KERN_WARNING "svc: only UDP and TCP " |
|---|
| .. | .. |
|---|
| 1539 | 1460 | * getting requests from IPv4 remotes. Those should |
|---|
| 1540 | 1461 | * be shunted to a PF_INET listener via rpcbind. |
|---|
| 1541 | 1462 | */ |
|---|
| 1542 | | - val = 1; |
|---|
| 1543 | 1463 | if (family == PF_INET6) |
|---|
| 1544 | | - kernel_setsockopt(sock, SOL_IPV6, IPV6_V6ONLY, |
|---|
| 1545 | | - (char *)&val, sizeof(val)); |
|---|
| 1546 | | - |
|---|
| 1464 | + ip6_sock_set_v6only(sock->sk); |
|---|
| 1547 | 1465 | if (type == SOCK_STREAM) |
|---|
| 1548 | 1466 | sock->sk->sk_reuse = SK_CAN_REUSE; /* allow address reuse */ |
|---|
| 1549 | 1467 | error = kernel_bind(sock, sin, len); |
|---|
| .. | .. |
|---|
| 1568 | 1486 | svc_xprt_set_local(&svsk->sk_xprt, newsin, newlen); |
|---|
| 1569 | 1487 | return (struct svc_xprt *)svsk; |
|---|
| 1570 | 1488 | bummer: |
|---|
| 1571 | | - dprintk("svc: svc_create_socket error = %d\n", -error); |
|---|
| 1572 | 1489 | sock_release(sock); |
|---|
| 1573 | 1490 | return ERR_PTR(error); |
|---|
| 1574 | 1491 | } |
|---|
| .. | .. |
|---|
| 1581 | 1498 | { |
|---|
| 1582 | 1499 | struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt); |
|---|
| 1583 | 1500 | struct sock *sk = svsk->sk_sk; |
|---|
| 1584 | | - |
|---|
| 1585 | | - dprintk("svc: svc_sock_detach(%p)\n", svsk); |
|---|
| 1586 | 1501 | |
|---|
| 1587 | 1502 | /* put back the old socket callbacks */ |
|---|
| 1588 | 1503 | lock_sock(sk); |
|---|
| .. | .. |
|---|
| 1600 | 1515 | { |
|---|
| 1601 | 1516 | struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt); |
|---|
| 1602 | 1517 | |
|---|
| 1603 | | - dprintk("svc: svc_tcp_sock_detach(%p)\n", svsk); |
|---|
| 1604 | | - |
|---|
| 1605 | 1518 | svc_sock_detach(xprt); |
|---|
| 1606 | 1519 | |
|---|
| 1607 | 1520 | if (!test_bit(XPT_LISTENER, &xprt->xpt_flags)) { |
|---|
| .. | .. |
|---|
| 1616 | 1529 | static void svc_sock_free(struct svc_xprt *xprt) |
|---|
| 1617 | 1530 | { |
|---|
| 1618 | 1531 | struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt); |
|---|
| 1619 | | - dprintk("svc: svc_sock_free(%p)\n", svsk); |
|---|
| 1620 | 1532 | |
|---|
| 1621 | 1533 | if (svsk->sk_sock->file) |
|---|
| 1622 | 1534 | sockfd_put(svsk->sk_sock); |
|---|
| .. | .. |
|---|
| 1624 | 1536 | sock_release(svsk->sk_sock); |
|---|
| 1625 | 1537 | kfree(svsk); |
|---|
| 1626 | 1538 | } |
|---|
| 1627 | | - |
|---|
| 1628 | | -#if defined(CONFIG_SUNRPC_BACKCHANNEL) |
|---|
| 1629 | | -/* |
|---|
| 1630 | | - * Create a back channel svc_xprt which shares the fore channel socket. |
|---|
| 1631 | | - */ |
|---|
| 1632 | | -static struct svc_xprt *svc_bc_create_socket(struct svc_serv *serv, |
|---|
| 1633 | | - int protocol, |
|---|
| 1634 | | - struct net *net, |
|---|
| 1635 | | - struct sockaddr *sin, int len, |
|---|
| 1636 | | - int flags) |
|---|
| 1637 | | -{ |
|---|
| 1638 | | - struct svc_sock *svsk; |
|---|
| 1639 | | - struct svc_xprt *xprt; |
|---|
| 1640 | | - |
|---|
| 1641 | | - if (protocol != IPPROTO_TCP) { |
|---|
| 1642 | | - printk(KERN_WARNING "svc: only TCP sockets" |
|---|
| 1643 | | - " supported on shared back channel\n"); |
|---|
| 1644 | | - return ERR_PTR(-EINVAL); |
|---|
| 1645 | | - } |
|---|
| 1646 | | - |
|---|
| 1647 | | - svsk = kzalloc(sizeof(*svsk), GFP_KERNEL); |
|---|
| 1648 | | - if (!svsk) |
|---|
| 1649 | | - return ERR_PTR(-ENOMEM); |
|---|
| 1650 | | - |
|---|
| 1651 | | - xprt = &svsk->sk_xprt; |
|---|
| 1652 | | - svc_xprt_init(net, &svc_tcp_bc_class, xprt, serv); |
|---|
| 1653 | | - set_bit(XPT_CONG_CTRL, &svsk->sk_xprt.xpt_flags); |
|---|
| 1654 | | - |
|---|
| 1655 | | - serv->sv_bc_xprt = xprt; |
|---|
| 1656 | | - |
|---|
| 1657 | | - return xprt; |
|---|
| 1658 | | -} |
|---|
| 1659 | | - |
|---|
| 1660 | | -/* |
|---|
| 1661 | | - * Free a back channel svc_sock. |
|---|
| 1662 | | - */ |
|---|
| 1663 | | -static void svc_bc_sock_free(struct svc_xprt *xprt) |
|---|
| 1664 | | -{ |
|---|
| 1665 | | - if (xprt) |
|---|
| 1666 | | - kfree(container_of(xprt, struct svc_sock, sk_xprt)); |
|---|
| 1667 | | -} |
|---|
| 1668 | | -#endif /* CONFIG_SUNRPC_BACKCHANNEL */ |
|---|