net/smc: improve state change handling after close wait
When a socket is closed or shutdown, smc waits for data being transmitted in certain states. If the state changes during this wait, the close switch depending on state should be reentered. In addition, state change is avoided if sending of close or shutdown fails. Signed-off-by: Ursula Braun <ubraun@linux.vnet.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
86e780d3a3
commit
bbb96bf236
|
@ -165,9 +165,9 @@ int smc_close_active(struct smc_sock *smc)
|
||||||
0 : sock_flag(sk, SOCK_LINGER) ?
|
0 : sock_flag(sk, SOCK_LINGER) ?
|
||||||
sk->sk_lingertime : SMC_MAX_STREAM_WAIT_TIMEOUT;
|
sk->sk_lingertime : SMC_MAX_STREAM_WAIT_TIMEOUT;
|
||||||
|
|
||||||
again:
|
|
||||||
old_state = sk->sk_state;
|
old_state = sk->sk_state;
|
||||||
switch (old_state) {
|
again:
|
||||||
|
switch (sk->sk_state) {
|
||||||
case SMC_INIT:
|
case SMC_INIT:
|
||||||
sk->sk_state = SMC_CLOSED;
|
sk->sk_state = SMC_CLOSED;
|
||||||
if (smc->smc_listen_work.func)
|
if (smc->smc_listen_work.func)
|
||||||
|
@ -194,6 +194,8 @@ again:
|
||||||
if (sk->sk_state == SMC_ACTIVE) {
|
if (sk->sk_state == SMC_ACTIVE) {
|
||||||
/* send close request */
|
/* send close request */
|
||||||
rc = smc_close_final(conn);
|
rc = smc_close_final(conn);
|
||||||
|
if (rc)
|
||||||
|
break;
|
||||||
sk->sk_state = SMC_PEERCLOSEWAIT1;
|
sk->sk_state = SMC_PEERCLOSEWAIT1;
|
||||||
} else {
|
} else {
|
||||||
/* peer event has changed the state */
|
/* peer event has changed the state */
|
||||||
|
@ -206,6 +208,8 @@ again:
|
||||||
!smc_close_sent_any_close(conn)) {
|
!smc_close_sent_any_close(conn)) {
|
||||||
/* just shutdown wr done, send close request */
|
/* just shutdown wr done, send close request */
|
||||||
rc = smc_close_final(conn);
|
rc = smc_close_final(conn);
|
||||||
|
if (rc)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
sk->sk_state = SMC_CLOSED;
|
sk->sk_state = SMC_CLOSED;
|
||||||
break;
|
break;
|
||||||
|
@ -216,12 +220,13 @@ again:
|
||||||
release_sock(sk);
|
release_sock(sk);
|
||||||
cancel_delayed_work_sync(&conn->tx_work);
|
cancel_delayed_work_sync(&conn->tx_work);
|
||||||
lock_sock(sk);
|
lock_sock(sk);
|
||||||
if (sk->sk_err != ECONNABORTED) {
|
if (sk->sk_state != SMC_APPCLOSEWAIT1 &&
|
||||||
|
sk->sk_state != SMC_APPCLOSEWAIT2)
|
||||||
|
goto again;
|
||||||
/* confirm close from peer */
|
/* confirm close from peer */
|
||||||
rc = smc_close_final(conn);
|
rc = smc_close_final(conn);
|
||||||
if (rc)
|
if (rc)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
if (smc_cdc_rxed_any_close(conn))
|
if (smc_cdc_rxed_any_close(conn))
|
||||||
/* peer has closed the socket already */
|
/* peer has closed the socket already */
|
||||||
sk->sk_state = SMC_CLOSED;
|
sk->sk_state = SMC_CLOSED;
|
||||||
|
@ -235,6 +240,8 @@ again:
|
||||||
!smc_close_sent_any_close(conn)) {
|
!smc_close_sent_any_close(conn)) {
|
||||||
/* just shutdown wr done, send close request */
|
/* just shutdown wr done, send close request */
|
||||||
rc = smc_close_final(conn);
|
rc = smc_close_final(conn);
|
||||||
|
if (rc)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
/* peer sending PeerConnectionClosed will cause transition */
|
/* peer sending PeerConnectionClosed will cause transition */
|
||||||
break;
|
break;
|
||||||
|
@ -401,20 +408,21 @@ int smc_close_shutdown_write(struct smc_sock *smc)
|
||||||
0 : sock_flag(sk, SOCK_LINGER) ?
|
0 : sock_flag(sk, SOCK_LINGER) ?
|
||||||
sk->sk_lingertime : SMC_MAX_STREAM_WAIT_TIMEOUT;
|
sk->sk_lingertime : SMC_MAX_STREAM_WAIT_TIMEOUT;
|
||||||
|
|
||||||
again:
|
|
||||||
old_state = sk->sk_state;
|
old_state = sk->sk_state;
|
||||||
switch (old_state) {
|
again:
|
||||||
|
switch (sk->sk_state) {
|
||||||
case SMC_ACTIVE:
|
case SMC_ACTIVE:
|
||||||
smc_close_stream_wait(smc, timeout);
|
smc_close_stream_wait(smc, timeout);
|
||||||
release_sock(sk);
|
release_sock(sk);
|
||||||
cancel_delayed_work_sync(&conn->tx_work);
|
cancel_delayed_work_sync(&conn->tx_work);
|
||||||
lock_sock(sk);
|
lock_sock(sk);
|
||||||
|
if (sk->sk_state != SMC_ACTIVE)
|
||||||
|
goto again;
|
||||||
/* send close wr request */
|
/* send close wr request */
|
||||||
rc = smc_close_wr(conn);
|
rc = smc_close_wr(conn);
|
||||||
if (sk->sk_state == SMC_ACTIVE)
|
if (rc)
|
||||||
|
break;
|
||||||
sk->sk_state = SMC_PEERCLOSEWAIT1;
|
sk->sk_state = SMC_PEERCLOSEWAIT1;
|
||||||
else
|
|
||||||
goto again;
|
|
||||||
break;
|
break;
|
||||||
case SMC_APPCLOSEWAIT1:
|
case SMC_APPCLOSEWAIT1:
|
||||||
/* passive close */
|
/* passive close */
|
||||||
|
@ -423,8 +431,12 @@ again:
|
||||||
release_sock(sk);
|
release_sock(sk);
|
||||||
cancel_delayed_work_sync(&conn->tx_work);
|
cancel_delayed_work_sync(&conn->tx_work);
|
||||||
lock_sock(sk);
|
lock_sock(sk);
|
||||||
|
if (sk->sk_state != SMC_APPCLOSEWAIT1)
|
||||||
|
goto again;
|
||||||
/* confirm close from peer */
|
/* confirm close from peer */
|
||||||
rc = smc_close_wr(conn);
|
rc = smc_close_wr(conn);
|
||||||
|
if (rc)
|
||||||
|
break;
|
||||||
sk->sk_state = SMC_APPCLOSEWAIT2;
|
sk->sk_state = SMC_APPCLOSEWAIT2;
|
||||||
break;
|
break;
|
||||||
case SMC_APPCLOSEWAIT2:
|
case SMC_APPCLOSEWAIT2:
|
||||||
|
|
Loading…
Reference in New Issue