Commit b61d59ff authored by Trond Myklebust's avatar Trond Myklebust

SUNRPC: xs_tcp_connect_worker{4,6}: merge common code

Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 25fe6142
...@@ -1738,33 +1738,29 @@ static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock) ...@@ -1738,33 +1738,29 @@ static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
} }
/** /**
* xs_tcp_connect_worker4 - connect a TCP socket to a remote endpoint * xs_tcp_setup_socket - create a TCP socket and connect to a remote endpoint
* @work: RPC transport to connect * @xprt: RPC transport to connect
* @transport: socket transport to connect
* @create_sock: function to create a socket of the correct type
* *
* Invoked by a work queue tasklet. * Invoked by a work queue tasklet.
*/ */
static void xs_tcp_connect_worker4(struct work_struct *work) static void xs_tcp_setup_socket(struct rpc_xprt *xprt,
struct sock_xprt *transport,
struct socket *(*create_sock)(struct rpc_xprt *,
struct sock_xprt *))
{ {
struct sock_xprt *transport =
container_of(work, struct sock_xprt, connect_worker.work);
struct rpc_xprt *xprt = &transport->xprt;
struct socket *sock = transport->sock; struct socket *sock = transport->sock;
int err, status = -EIO; int status = -EIO;
if (xprt->shutdown) if (xprt->shutdown)
goto out; goto out;
if (!sock) { if (!sock) {
clear_bit(XPRT_CONNECTION_ABORT, &xprt->state); clear_bit(XPRT_CONNECTION_ABORT, &xprt->state);
/* start from scratch */ sock = create_sock(xprt, transport);
if ((err = sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock)) < 0) { if (IS_ERR(sock)) {
dprintk("RPC: can't create TCP transport socket (%d).\n", -err); status = PTR_ERR(sock);
goto out;
}
xs_reclassify_socket4(sock);
if (xs_bind4(transport, sock) < 0) {
sock_release(sock);
goto out; goto out;
} }
} else { } else {
...@@ -1808,74 +1804,82 @@ out: ...@@ -1808,74 +1804,82 @@ out:
xprt_wake_pending_tasks(xprt, status); xprt_wake_pending_tasks(xprt, status);
} }
static struct socket *xs_create_tcp_sock4(struct rpc_xprt *xprt,
struct sock_xprt *transport)
{
struct socket *sock;
int err;
/* start from scratch */
err = sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &sock);
if (err < 0) {
dprintk("RPC: can't create TCP transport socket (%d).\n",
-err);
goto out_err;
}
xs_reclassify_socket4(sock);
if (xs_bind4(transport, sock) < 0) {
sock_release(sock);
goto out_err;
}
return sock;
out_err:
return ERR_PTR(-EIO);
}
/** /**
* xs_tcp_connect_worker6 - connect a TCP socket to a remote endpoint * xs_tcp_connect_worker4 - connect a TCP socket to a remote endpoint
* @work: RPC transport to connect * @work: RPC transport to connect
* *
* Invoked by a work queue tasklet. * Invoked by a work queue tasklet.
*/ */
static void xs_tcp_connect_worker6(struct work_struct *work) static void xs_tcp_connect_worker4(struct work_struct *work)
{ {
struct sock_xprt *transport = struct sock_xprt *transport =
container_of(work, struct sock_xprt, connect_worker.work); container_of(work, struct sock_xprt, connect_worker.work);
struct rpc_xprt *xprt = &transport->xprt; struct rpc_xprt *xprt = &transport->xprt;
struct socket *sock = transport->sock;
int err, status = -EIO;
if (xprt->shutdown) xs_tcp_setup_socket(xprt, transport, xs_create_tcp_sock4);
goto out; }
if (!sock) {
clear_bit(XPRT_CONNECTION_ABORT, &xprt->state);
/* start from scratch */
if ((err = sock_create_kern(PF_INET6, SOCK_STREAM, IPPROTO_TCP, &sock)) < 0) {
dprintk("RPC: can't create TCP transport socket (%d).\n", -err);
goto out;
}
xs_reclassify_socket6(sock);
if (xs_bind6(transport, sock) < 0) { static struct socket *xs_create_tcp_sock6(struct rpc_xprt *xprt,
sock_release(sock); struct sock_xprt *transport)
goto out; {
} struct socket *sock;
} else { int err;
int abort_and_exit;
abort_and_exit = test_and_clear_bit(XPRT_CONNECTION_ABORT, /* start from scratch */
&xprt->state); err = sock_create_kern(PF_INET6, SOCK_STREAM, IPPROTO_TCP, &sock);
/* "close" the socket, preserving the local port */ if (err < 0) {
xs_tcp_reuse_connection(xprt, transport); dprintk("RPC: can't create TCP transport socket (%d).\n",
-err);
goto out_err;
}
xs_reclassify_socket6(sock);
if (abort_and_exit) if (xs_bind6(transport, sock) < 0) {
goto out_eagain; sock_release(sock);
goto out_err;
} }
return sock;
out_err:
return ERR_PTR(-EIO);
}
dprintk("RPC: worker connecting xprt %p to address: %s\n", /**
xprt, xprt->address_strings[RPC_DISPLAY_ALL]); * xs_tcp_connect_worker6 - connect a TCP socket to a remote endpoint
* @work: RPC transport to connect
*
* Invoked by a work queue tasklet.
*/
static void xs_tcp_connect_worker6(struct work_struct *work)
{
struct sock_xprt *transport =
container_of(work, struct sock_xprt, connect_worker.work);
struct rpc_xprt *xprt = &transport->xprt;
status = xs_tcp_finish_connecting(xprt, sock); xs_tcp_setup_socket(xprt, transport, xs_create_tcp_sock6);
dprintk("RPC: %p connect status %d connected %d sock state %d\n",
xprt, -status, xprt_connected(xprt), sock->sk->sk_state);
switch (status) {
case -ECONNREFUSED:
case -ECONNRESET:
case -ENETUNREACH:
/* retry with existing socket, after a delay */
case 0:
case -EINPROGRESS:
case -EALREADY:
xprt_clear_connecting(xprt);
return;
}
/* get rid of existing socket, and retry */
xs_tcp_shutdown(xprt);
printk("%s: connect returned unhandled error %d\n",
__func__, status);
out_eagain:
status = -EAGAIN;
out:
xprt_clear_connecting(xprt);
xprt_wake_pending_tasks(xprt, status);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment