aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorTrond Myklebust <trond.myklebust@primarydata.com>2016-06-24 10:55:48 -0400
committerJ. Bruce Fields <bfields@redhat.com>2016-07-13 15:53:45 -0400
commitfa9251afc33c81606d70cfe91800a779096442ec (patch)
tree225c60074ba34e6bfda178544f8cd54ca34326d4 /net
parent069c225b88202c84bdbe18bed9e30e77924fdd0a (diff)
SUNRPC: Call the default socket callbacks instead of open coding
Rather than code up our own versions of the socket callbacks, just call the defaults. This also allows us to merge svc_udp_data_ready() and svc_tcp_data_ready(). Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'net')
-rw-r--r--net/sunrpc/svcsock.c88
1 files changed, 19 insertions, 69 deletions
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index abe2da602fb8..03134708deeb 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -60,7 +60,6 @@
60 60
61static struct svc_sock *svc_setup_socket(struct svc_serv *, struct socket *, 61static struct svc_sock *svc_setup_socket(struct svc_serv *, struct socket *,
62 int flags); 62 int flags);
63static void svc_udp_data_ready(struct sock *);
64static int svc_udp_recvfrom(struct svc_rqst *); 63static int svc_udp_recvfrom(struct svc_rqst *);
65static int svc_udp_sendto(struct svc_rqst *); 64static int svc_udp_sendto(struct svc_rqst *);
66static void svc_sock_detach(struct svc_xprt *); 65static void svc_sock_detach(struct svc_xprt *);
@@ -398,48 +397,21 @@ static int svc_sock_secure_port(struct svc_rqst *rqstp)
398 return svc_port_is_privileged(svc_addr(rqstp)); 397 return svc_port_is_privileged(svc_addr(rqstp));
399} 398}
400 399
401static bool sunrpc_waitqueue_active(wait_queue_head_t *wq)
402{
403 if (!wq)
404 return false;
405 /*
406 * There should normally be a memory * barrier here--see
407 * wq_has_sleeper().
408 *
409 * It appears that isn't currently necessary, though, basically
410 * because callers all appear to have sufficient memory barriers
411 * between the time the relevant change is made and the
412 * time they call these callbacks.
413 *
414 * The nfsd code itself doesn't actually explicitly wait on
415 * these waitqueues, but it may wait on them for example in
416 * sendpage() or sendmsg() calls. (And those may be the only
417 * places, since it it uses nonblocking reads.)
418 *
419 * Maybe we should add the memory barriers anyway, but these are
420 * hot paths so we'd need to be convinced there's no sigificant
421 * penalty.
422 */
423 return waitqueue_active(wq);
424}
425
426/* 400/*
427 * INET callback when data has been received on the socket. 401 * INET callback when data has been received on the socket.
428 */ 402 */
429static void svc_udp_data_ready(struct sock *sk) 403static void svc_data_ready(struct sock *sk)
430{ 404{
431 struct svc_sock *svsk = (struct svc_sock *)sk->sk_user_data; 405 struct svc_sock *svsk = (struct svc_sock *)sk->sk_user_data;
432 wait_queue_head_t *wq = sk_sleep(sk);
433 406
434 if (svsk) { 407 if (svsk) {
435 dprintk("svc: socket %p(inet %p), busy=%d\n", 408 dprintk("svc: socket %p(inet %p), busy=%d\n",
436 svsk, sk, 409 svsk, sk,
437 test_bit(XPT_BUSY, &svsk->sk_xprt.xpt_flags)); 410 test_bit(XPT_BUSY, &svsk->sk_xprt.xpt_flags));
411 svsk->sk_odata(sk);
438 set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); 412 set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
439 svc_xprt_enqueue(&svsk->sk_xprt); 413 svc_xprt_enqueue(&svsk->sk_xprt);
440 } 414 }
441 if (sunrpc_waitqueue_active(wq))
442 wake_up_interruptible(wq);
443} 415}
444 416
445/* 417/*
@@ -448,19 +420,13 @@ static void svc_udp_data_ready(struct sock *sk)
448static void svc_write_space(struct sock *sk) 420static void svc_write_space(struct sock *sk)
449{ 421{
450 struct svc_sock *svsk = (struct svc_sock *)(sk->sk_user_data); 422 struct svc_sock *svsk = (struct svc_sock *)(sk->sk_user_data);
451 wait_queue_head_t *wq = sk_sleep(sk);
452 423
453 if (svsk) { 424 if (svsk) {
454 dprintk("svc: socket %p(inet %p), write_space busy=%d\n", 425 dprintk("svc: socket %p(inet %p), write_space busy=%d\n",
455 svsk, sk, test_bit(XPT_BUSY, &svsk->sk_xprt.xpt_flags)); 426 svsk, sk, test_bit(XPT_BUSY, &svsk->sk_xprt.xpt_flags));
427 svsk->sk_owspace(sk);
456 svc_xprt_enqueue(&svsk->sk_xprt); 428 svc_xprt_enqueue(&svsk->sk_xprt);
457 } 429 }
458
459 if (sunrpc_waitqueue_active(wq)) {
460 dprintk("RPC svc_write_space: someone sleeping on %p\n",
461 svsk);
462 wake_up_interruptible(wq);
463 }
464} 430}
465 431
466static int svc_tcp_has_wspace(struct svc_xprt *xprt) 432static int svc_tcp_has_wspace(struct svc_xprt *xprt)
@@ -485,11 +451,15 @@ static void svc_tcp_write_space(struct sock *sk)
485 struct svc_sock *svsk = (struct svc_sock *)(sk->sk_user_data); 451 struct svc_sock *svsk = (struct svc_sock *)(sk->sk_user_data);
486 struct socket *sock = sk->sk_socket; 452 struct socket *sock = sk->sk_socket;
487 453
454 if (!svsk)
455 return;
456
488 if (!sk_stream_is_writeable(sk) || !sock) 457 if (!sk_stream_is_writeable(sk) || !sock)
489 return; 458 return;
490 if (!svsk || svc_tcp_has_wspace(&svsk->sk_xprt)) 459 if (svc_tcp_has_wspace(&svsk->sk_xprt)) {
491 clear_bit(SOCK_NOSPACE, &sock->flags); 460 clear_bit(SOCK_NOSPACE, &sock->flags);
492 svc_write_space(sk); 461 svc_write_space(sk);
462 }
493} 463}
494 464
495static void svc_tcp_adjust_wspace(struct svc_xprt *xprt) 465static void svc_tcp_adjust_wspace(struct svc_xprt *xprt)
@@ -746,7 +716,7 @@ static void svc_udp_init(struct svc_sock *svsk, struct svc_serv *serv)
746 svc_xprt_init(sock_net(svsk->sk_sock->sk), &svc_udp_class, 716 svc_xprt_init(sock_net(svsk->sk_sock->sk), &svc_udp_class,
747 &svsk->sk_xprt, serv); 717 &svsk->sk_xprt, serv);
748 clear_bit(XPT_CACHE_AUTH, &svsk->sk_xprt.xpt_flags); 718 clear_bit(XPT_CACHE_AUTH, &svsk->sk_xprt.xpt_flags);
749 svsk->sk_sk->sk_data_ready = svc_udp_data_ready; 719 svsk->sk_sk->sk_data_ready = svc_data_ready;
750 svsk->sk_sk->sk_write_space = svc_write_space; 720 svsk->sk_sk->sk_write_space = svc_write_space;
751 721
752 /* initialise setting must have enough space to 722 /* initialise setting must have enough space to
@@ -786,11 +756,12 @@ static void svc_udp_init(struct svc_sock *svsk, struct svc_serv *serv)
786static void svc_tcp_listen_data_ready(struct sock *sk) 756static void svc_tcp_listen_data_ready(struct sock *sk)
787{ 757{
788 struct svc_sock *svsk = (struct svc_sock *)sk->sk_user_data; 758 struct svc_sock *svsk = (struct svc_sock *)sk->sk_user_data;
789 wait_queue_head_t *wq;
790 759
791 dprintk("svc: socket %p TCP (listen) state change %d\n", 760 dprintk("svc: socket %p TCP (listen) state change %d\n",
792 sk, sk->sk_state); 761 sk, sk->sk_state);
793 762
763 if (svsk)
764 svsk->sk_odata(sk);
794 /* 765 /*
795 * This callback may called twice when a new connection 766 * This callback may called twice when a new connection
796 * is established as a child socket inherits everything 767 * is established as a child socket inherits everything
@@ -808,10 +779,6 @@ static void svc_tcp_listen_data_ready(struct sock *sk)
808 } else 779 } else
809 printk("svc: socket %p: no user data\n", sk); 780 printk("svc: socket %p: no user data\n", sk);
810 } 781 }
811
812 wq = sk_sleep(sk);
813 if (sunrpc_waitqueue_active(wq))
814 wake_up_interruptible_all(wq);
815} 782}
816 783
817/* 784/*
@@ -820,7 +787,6 @@ static void svc_tcp_listen_data_ready(struct sock *sk)
820static void svc_tcp_state_change(struct sock *sk) 787static void svc_tcp_state_change(struct sock *sk)
821{ 788{
822 struct svc_sock *svsk = (struct svc_sock *)sk->sk_user_data; 789 struct svc_sock *svsk = (struct svc_sock *)sk->sk_user_data;
823 wait_queue_head_t *wq = sk_sleep(sk);
824 790
825 dprintk("svc: socket %p TCP (connected) state change %d (svsk %p)\n", 791 dprintk("svc: socket %p TCP (connected) state change %d (svsk %p)\n",
826 sk, sk->sk_state, sk->sk_user_data); 792 sk, sk->sk_state, sk->sk_user_data);
@@ -828,26 +794,10 @@ static void svc_tcp_state_change(struct sock *sk)
828 if (!svsk) 794 if (!svsk)
829 printk("svc: socket %p: no user data\n", sk); 795 printk("svc: socket %p: no user data\n", sk);
830 else { 796 else {
797 svsk->sk_ostate(sk);
831 set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags); 798 set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags);
832 svc_xprt_enqueue(&svsk->sk_xprt); 799 svc_xprt_enqueue(&svsk->sk_xprt);
833 } 800 }
834 if (sunrpc_waitqueue_active(wq))
835 wake_up_interruptible_all(wq);
836}
837
838static void svc_tcp_data_ready(struct sock *sk)
839{
840 struct svc_sock *svsk = (struct svc_sock *)sk->sk_user_data;
841 wait_queue_head_t *wq = sk_sleep(sk);
842
843 dprintk("svc: socket %p TCP data ready (svsk %p)\n",
844 sk, sk->sk_user_data);
845 if (svsk) {
846 set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
847 svc_xprt_enqueue(&svsk->sk_xprt);
848 }
849 if (sunrpc_waitqueue_active(wq))
850 wake_up_interruptible(wq);
851} 801}
852 802
853/* 803/*
@@ -901,6 +851,11 @@ static struct svc_xprt *svc_tcp_accept(struct svc_xprt *xprt)
901 dprintk("%s: connect from %s\n", serv->sv_name, 851 dprintk("%s: connect from %s\n", serv->sv_name,
902 __svc_print_addr(sin, buf, sizeof(buf))); 852 __svc_print_addr(sin, buf, sizeof(buf)));
903 853
854 /* Reset the inherited callbacks before calling svc_setup_socket */
855 newsock->sk->sk_state_change = svsk->sk_ostate;
856 newsock->sk->sk_data_ready = svsk->sk_odata;
857 newsock->sk->sk_write_space = svsk->sk_owspace;
858
904 /* make sure that a write doesn't block forever when 859 /* make sure that a write doesn't block forever when
905 * low on memory 860 * low on memory
906 */ 861 */
@@ -1357,7 +1312,7 @@ static void svc_tcp_init(struct svc_sock *svsk, struct svc_serv *serv)
1357 } else { 1312 } else {
1358 dprintk("setting up TCP socket for reading\n"); 1313 dprintk("setting up TCP socket for reading\n");
1359 sk->sk_state_change = svc_tcp_state_change; 1314 sk->sk_state_change = svc_tcp_state_change;
1360 sk->sk_data_ready = svc_tcp_data_ready; 1315 sk->sk_data_ready = svc_data_ready;
1361 sk->sk_write_space = svc_tcp_write_space; 1316 sk->sk_write_space = svc_tcp_write_space;
1362 1317
1363 svsk->sk_reclen = 0; 1318 svsk->sk_reclen = 0;
@@ -1606,7 +1561,6 @@ static void svc_sock_detach(struct svc_xprt *xprt)
1606{ 1561{
1607 struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt); 1562 struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt);
1608 struct sock *sk = svsk->sk_sk; 1563 struct sock *sk = svsk->sk_sk;
1609 wait_queue_head_t *wq;
1610 1564
1611 dprintk("svc: svc_sock_detach(%p)\n", svsk); 1565 dprintk("svc: svc_sock_detach(%p)\n", svsk);
1612 1566
@@ -1617,10 +1571,6 @@ static void svc_sock_detach(struct svc_xprt *xprt)
1617 sk->sk_write_space = svsk->sk_owspace; 1571 sk->sk_write_space = svsk->sk_owspace;
1618 sk->sk_user_data = NULL; 1572 sk->sk_user_data = NULL;
1619 release_sock(sk); 1573 release_sock(sk);
1620
1621 wq = sk_sleep(sk);
1622 if (sunrpc_waitqueue_active(wq))
1623 wake_up_interruptible(wq);
1624} 1574}
1625 1575
1626/* 1576/*