SUNRPC: Don't call connect() more than once on a TCP socket
From: Trond Myklebust <trond.myklebust@hammerspace.com> commit 89f42494f92f448747bd8a7ab1ae8b5d5520577d upstream. Avoid socket state races due to repeated calls to ->connect() using the same socket. If connect() returns 0 due to the connection having completed, but we are in fact in a closing state, then we may leave the XPRT_CONNECTING flag set on the transport. Reported-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de> Fixes: 3be232f11a3c ("SUNRPC: Prevent immediate close+reconnect") Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> [meenashanmugam: Fix merge conflict in xs_tcp_setup_socket] Signed-off-by: Meena Shanmugam <meenashanmugam@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
aa4d71edd6
commit
975a0f14d5
@ -90,6 +90,7 @@ struct sock_xprt {
|
|||||||
#define XPRT_SOCK_WAKE_WRITE (5)
|
#define XPRT_SOCK_WAKE_WRITE (5)
|
||||||
#define XPRT_SOCK_WAKE_PENDING (6)
|
#define XPRT_SOCK_WAKE_PENDING (6)
|
||||||
#define XPRT_SOCK_WAKE_DISCONNECT (7)
|
#define XPRT_SOCK_WAKE_DISCONNECT (7)
|
||||||
|
#define XPRT_SOCK_CONNECT_SENT (8)
|
||||||
|
|
||||||
#endif /* __KERNEL__ */
|
#endif /* __KERNEL__ */
|
||||||
|
|
||||||
|
@ -2384,10 +2384,14 @@ static void xs_tcp_setup_socket(struct work_struct *work)
|
|||||||
struct rpc_xprt *xprt = &transport->xprt;
|
struct rpc_xprt *xprt = &transport->xprt;
|
||||||
int status = -EIO;
|
int status = -EIO;
|
||||||
|
|
||||||
if (!sock) {
|
if (xprt_connected(xprt))
|
||||||
sock = xs_create_sock(xprt, transport,
|
goto out;
|
||||||
xs_addr(xprt)->sa_family, SOCK_STREAM,
|
if (test_and_clear_bit(XPRT_SOCK_CONNECT_SENT,
|
||||||
IPPROTO_TCP, true);
|
&transport->sock_state) ||
|
||||||
|
!sock) {
|
||||||
|
xs_reset_transport(transport);
|
||||||
|
sock = xs_create_sock(xprt, transport, xs_addr(xprt)->sa_family,
|
||||||
|
SOCK_STREAM, IPPROTO_TCP, true);
|
||||||
if (IS_ERR(sock)) {
|
if (IS_ERR(sock)) {
|
||||||
status = PTR_ERR(sock);
|
status = PTR_ERR(sock);
|
||||||
goto out;
|
goto out;
|
||||||
@ -2418,6 +2422,8 @@ static void xs_tcp_setup_socket(struct work_struct *work)
|
|||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
case -EINPROGRESS:
|
case -EINPROGRESS:
|
||||||
|
set_bit(XPRT_SOCK_CONNECT_SENT, &transport->sock_state);
|
||||||
|
fallthrough;
|
||||||
case -EALREADY:
|
case -EALREADY:
|
||||||
xprt_unlock_connect(xprt, transport);
|
xprt_unlock_connect(xprt, transport);
|
||||||
return;
|
return;
|
||||||
@ -2469,13 +2475,9 @@ static void xs_connect(struct rpc_xprt *xprt, struct rpc_task *task)
|
|||||||
|
|
||||||
WARN_ON_ONCE(!xprt_lock_connect(xprt, task, transport));
|
WARN_ON_ONCE(!xprt_lock_connect(xprt, task, transport));
|
||||||
|
|
||||||
if (transport->sock != NULL && !xprt_connecting(xprt)) {
|
if (transport->sock != NULL) {
|
||||||
dprintk("RPC: xs_connect delayed xprt %p for %lu "
|
dprintk("RPC: xs_connect delayed xprt %p for %lu "
|
||||||
"seconds\n",
|
"seconds\n", xprt, xprt->reestablish_timeout / HZ);
|
||||||
xprt, xprt->reestablish_timeout / HZ);
|
|
||||||
|
|
||||||
/* Start by resetting any existing state */
|
|
||||||
xs_reset_transport(transport);
|
|
||||||
|
|
||||||
delay = xprt_reconnect_delay(xprt);
|
delay = xprt_reconnect_delay(xprt);
|
||||||
xprt_reconnect_backoff(xprt, XS_TCP_INIT_REEST_TO);
|
xprt_reconnect_backoff(xprt, XS_TCP_INIT_REEST_TO);
|
||||||
|
Loading…
Reference in New Issue
Block a user