diff options
author | Pavel Emelyanov <xemul@parallels.com> | 2010-10-04 08:54:26 -0400 |
---|---|---|
committer | J. Bruce Fields <bfields@redhat.com> | 2010-10-19 10:48:14 -0400 |
commit | 22f793268de3b4dff8abfcd873ba7afc1f34224f (patch) | |
tree | 0e67fb80ab92a83a07cfe2b21648e80e44a281ed /net/sunrpc | |
parent | b65c0310611af73569f94c526a1e2323d99b380a (diff) |
sunrpc: Factor out v4 sockets creation
The UDPv4 and TCPv4 socket creation callbacks now look very similar.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Reviewed-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'net/sunrpc')
-rw-r--r-- | net/sunrpc/xprtsock.c | 63 |
1 files changed, 26 insertions, 37 deletions
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index df53dc55841d..b73a605c0847 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c | |||
@@ -1631,6 +1631,30 @@ static inline void xs_reclassify_socket6(struct socket *sock) | |||
1631 | } | 1631 | } |
1632 | #endif | 1632 | #endif |
1633 | 1633 | ||
1634 | static struct socket *xs_create_sock4(struct rpc_xprt *xprt, | ||
1635 | struct sock_xprt *transport, int type, int protocol) | ||
1636 | { | ||
1637 | struct socket *sock; | ||
1638 | int err; | ||
1639 | |||
1640 | err = __sock_create(xprt->xprt_net, PF_INET, type, protocol, &sock, 1); | ||
1641 | if (err < 0) { | ||
1642 | dprintk("RPC: can't create %d transport socket (%d).\n", | ||
1643 | protocol, -err); | ||
1644 | goto out; | ||
1645 | } | ||
1646 | xs_reclassify_socket4(sock); | ||
1647 | |||
1648 | if (xs_bind4(transport, sock)) { | ||
1649 | sock_release(sock); | ||
1650 | goto out; | ||
1651 | } | ||
1652 | |||
1653 | return sock; | ||
1654 | out: | ||
1655 | return ERR_PTR(err); | ||
1656 | } | ||
1657 | |||
1634 | static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock) | 1658 | static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock) |
1635 | { | 1659 | { |
1636 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); | 1660 | struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); |
@@ -1700,24 +1724,7 @@ out: | |||
1700 | static struct socket *xs_create_udp_sock4(struct rpc_xprt *xprt, | 1724 | static struct socket *xs_create_udp_sock4(struct rpc_xprt *xprt, |
1701 | struct sock_xprt *transport) | 1725 | struct sock_xprt *transport) |
1702 | { | 1726 | { |
1703 | struct socket *sock; | 1727 | return xs_create_sock4(xprt, transport, SOCK_DGRAM, IPPROTO_UDP); |
1704 | int err; | ||
1705 | |||
1706 | err = __sock_create(xprt->xprt_net, PF_INET, SOCK_DGRAM, IPPROTO_UDP, &sock, 1); | ||
1707 | if (err < 0) { | ||
1708 | dprintk("RPC: can't create UDP transport socket (%d).\n", -err); | ||
1709 | goto out; | ||
1710 | } | ||
1711 | xs_reclassify_socket4(sock); | ||
1712 | |||
1713 | if (xs_bind4(transport, sock)) { | ||
1714 | sock_release(sock); | ||
1715 | goto out; | ||
1716 | } | ||
1717 | |||
1718 | return sock; | ||
1719 | out: | ||
1720 | return ERR_PTR(err); | ||
1721 | } | 1728 | } |
1722 | 1729 | ||
1723 | static void xs_udp_connect_worker4(struct work_struct *work) | 1730 | static void xs_udp_connect_worker4(struct work_struct *work) |
@@ -1943,25 +1950,7 @@ out: | |||
1943 | static struct socket *xs_create_tcp_sock4(struct rpc_xprt *xprt, | 1950 | static struct socket *xs_create_tcp_sock4(struct rpc_xprt *xprt, |
1944 | struct sock_xprt *transport) | 1951 | struct sock_xprt *transport) |
1945 | { | 1952 | { |
1946 | struct socket *sock; | 1953 | return xs_create_sock4(xprt, transport, SOCK_STREAM, IPPROTO_TCP); |
1947 | int err; | ||
1948 | |||
1949 | /* start from scratch */ | ||
1950 | err = __sock_create(xprt->xprt_net, PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock, 1); | ||
1951 | if (err < 0) { | ||
1952 | dprintk("RPC: can't create TCP transport socket (%d).\n", | ||
1953 | -err); | ||
1954 | goto out_err; | ||
1955 | } | ||
1956 | xs_reclassify_socket4(sock); | ||
1957 | |||
1958 | if (xs_bind4(transport, sock) < 0) { | ||
1959 | sock_release(sock); | ||
1960 | goto out_err; | ||
1961 | } | ||
1962 | return sock; | ||
1963 | out_err: | ||
1964 | return ERR_PTR(-EIO); | ||
1965 | } | 1954 | } |
1966 | 1955 | ||
1967 | /** | 1956 | /** |