Commit 3aba1030 authored by Guangguan Wang's avatar Guangguan Wang Committed by David S. Miller

net/smc: align the connect behaviour with TCP

Connect with O_NONBLOCK will not be completed immediately
and returns -EINPROGRESS. It is possible to use selector/poll
for completion by selecting the socket for writing. After select
indicates writability, a second connect function call will return
0 to indicate connected successfully as TCP does, but smc returns
-EISCONN. Use socket state for smc to indicate connect state, which
can help smc aligning the connect behaviour with TCP.
Signed-off-by: default avatarGuangguan Wang <guangguan.wang@linux.alibaba.com>
Acked-by: default avatarKarsten Graul <kgraul@linux.ibm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e97e68b5
...@@ -1544,9 +1544,29 @@ static int smc_connect(struct socket *sock, struct sockaddr *addr, ...@@ -1544,9 +1544,29 @@ static int smc_connect(struct socket *sock, struct sockaddr *addr,
goto out_err; goto out_err;
lock_sock(sk); lock_sock(sk);
switch (sock->state) {
default:
rc = -EINVAL;
goto out;
case SS_CONNECTED:
rc = sk->sk_state == SMC_ACTIVE ? -EISCONN : -EINVAL;
goto out;
case SS_CONNECTING:
if (sk->sk_state == SMC_ACTIVE)
goto connected;
break;
case SS_UNCONNECTED:
sock->state = SS_CONNECTING;
break;
}
switch (sk->sk_state) { switch (sk->sk_state) {
default: default:
goto out; goto out;
case SMC_CLOSED:
rc = sock_error(sk) ? : -ECONNABORTED;
sock->state = SS_UNCONNECTED;
goto out;
case SMC_ACTIVE: case SMC_ACTIVE:
rc = -EISCONN; rc = -EISCONN;
goto out; goto out;
...@@ -1565,20 +1585,24 @@ static int smc_connect(struct socket *sock, struct sockaddr *addr, ...@@ -1565,20 +1585,24 @@ static int smc_connect(struct socket *sock, struct sockaddr *addr,
goto out; goto out;
sock_hold(&smc->sk); /* sock put in passive closing */ sock_hold(&smc->sk); /* sock put in passive closing */
if (smc->use_fallback) if (smc->use_fallback) {
sock->state = rc ? SS_CONNECTING : SS_CONNECTED;
goto out; goto out;
}
if (flags & O_NONBLOCK) { if (flags & O_NONBLOCK) {
if (queue_work(smc_hs_wq, &smc->connect_work)) if (queue_work(smc_hs_wq, &smc->connect_work))
smc->connect_nonblock = 1; smc->connect_nonblock = 1;
rc = -EINPROGRESS; rc = -EINPROGRESS;
goto out;
} else { } else {
rc = __smc_connect(smc); rc = __smc_connect(smc);
if (rc < 0) if (rc < 0)
goto out; goto out;
else
rc = 0; /* success cases including fallback */
} }
connected:
rc = 0;
sock->state = SS_CONNECTED;
out: out:
release_sock(sk); release_sock(sk);
out_err: out_err:
...@@ -1693,6 +1717,7 @@ struct sock *smc_accept_dequeue(struct sock *parent, ...@@ -1693,6 +1717,7 @@ struct sock *smc_accept_dequeue(struct sock *parent,
} }
if (new_sock) { if (new_sock) {
sock_graft(new_sk, new_sock); sock_graft(new_sk, new_sock);
new_sock->state = SS_CONNECTED;
if (isk->use_fallback) { if (isk->use_fallback) {
smc_sk(new_sk)->clcsock->file = new_sock->file; smc_sk(new_sk)->clcsock->file = new_sock->file;
isk->clcsock->file->private_data = isk->clcsock; isk->clcsock->file->private_data = isk->clcsock;
...@@ -2424,7 +2449,7 @@ static int smc_listen(struct socket *sock, int backlog) ...@@ -2424,7 +2449,7 @@ static int smc_listen(struct socket *sock, int backlog)
rc = -EINVAL; rc = -EINVAL;
if ((sk->sk_state != SMC_INIT && sk->sk_state != SMC_LISTEN) || if ((sk->sk_state != SMC_INIT && sk->sk_state != SMC_LISTEN) ||
smc->connect_nonblock) smc->connect_nonblock || sock->state != SS_UNCONNECTED)
goto out; goto out;
rc = 0; rc = 0;
...@@ -2716,6 +2741,17 @@ static int smc_shutdown(struct socket *sock, int how) ...@@ -2716,6 +2741,17 @@ static int smc_shutdown(struct socket *sock, int how)
lock_sock(sk); lock_sock(sk);
if (sock->state == SS_CONNECTING) {
if (sk->sk_state == SMC_ACTIVE)
sock->state = SS_CONNECTED;
else if (sk->sk_state == SMC_PEERCLOSEWAIT1 ||
sk->sk_state == SMC_PEERCLOSEWAIT2 ||
sk->sk_state == SMC_APPCLOSEWAIT1 ||
sk->sk_state == SMC_APPCLOSEWAIT2 ||
sk->sk_state == SMC_APPFINCLOSEWAIT)
sock->state = SS_DISCONNECTING;
}
rc = -ENOTCONN; rc = -ENOTCONN;
if ((sk->sk_state != SMC_ACTIVE) && if ((sk->sk_state != SMC_ACTIVE) &&
(sk->sk_state != SMC_PEERCLOSEWAIT1) && (sk->sk_state != SMC_PEERCLOSEWAIT1) &&
...@@ -2729,6 +2765,7 @@ static int smc_shutdown(struct socket *sock, int how) ...@@ -2729,6 +2765,7 @@ static int smc_shutdown(struct socket *sock, int how)
sk->sk_shutdown = smc->clcsock->sk->sk_shutdown; sk->sk_shutdown = smc->clcsock->sk->sk_shutdown;
if (sk->sk_shutdown == SHUTDOWN_MASK) { if (sk->sk_shutdown == SHUTDOWN_MASK) {
sk->sk_state = SMC_CLOSED; sk->sk_state = SMC_CLOSED;
sk->sk_socket->state = SS_UNCONNECTED;
sock_put(sk); sock_put(sk);
} }
goto out; goto out;
...@@ -2754,6 +2791,10 @@ static int smc_shutdown(struct socket *sock, int how) ...@@ -2754,6 +2791,10 @@ static int smc_shutdown(struct socket *sock, int how)
/* map sock_shutdown_cmd constants to sk_shutdown value range */ /* map sock_shutdown_cmd constants to sk_shutdown value range */
sk->sk_shutdown |= how + 1; sk->sk_shutdown |= how + 1;
if (sk->sk_state == SMC_CLOSED)
sock->state = SS_UNCONNECTED;
else
sock->state = SS_DISCONNECTING;
out: out:
release_sock(sk); release_sock(sk);
return rc ? rc : rc1; return rc ? rc : rc1;
...@@ -3139,6 +3180,7 @@ static int __smc_create(struct net *net, struct socket *sock, int protocol, ...@@ -3139,6 +3180,7 @@ static int __smc_create(struct net *net, struct socket *sock, int protocol,
rc = -ENOBUFS; rc = -ENOBUFS;
sock->ops = &smc_sock_ops; sock->ops = &smc_sock_ops;
sock->state = SS_UNCONNECTED;
sk = smc_sock_alloc(net, sock, protocol); sk = smc_sock_alloc(net, sock, protocol);
if (!sk) if (!sk)
goto out; goto out;
......
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