Skip to content

Commit 3a107f0

Browse files
Trond Myklebustamschuma-ntap
authored andcommitted
SUNRPC: Set the TCP_SYNCNT to match the socket timeout
Set the TCP SYN count so that we abort the connection attempt at around the expected timeout value. Signed-off-by: Trond Myklebust <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 88975a5 commit 3a107f0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

net/sunrpc/xprtsock.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,9 +2230,13 @@ static void xs_tcp_set_socket_timeouts(struct rpc_xprt *xprt,
22302230
struct socket *sock)
22312231
{
22322232
struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2233+
struct net *net = sock_net(sock->sk);
2234+
unsigned long connect_timeout;
2235+
unsigned long syn_retries;
22332236
unsigned int keepidle;
22342237
unsigned int keepcnt;
22352238
unsigned int timeo;
2239+
unsigned long t;
22362240

22372241
spin_lock(&xprt->transport_lock);
22382242
keepidle = DIV_ROUND_UP(xprt->timeout->to_initval, HZ);
@@ -2250,6 +2254,16 @@ static void xs_tcp_set_socket_timeouts(struct rpc_xprt *xprt,
22502254

22512255
/* TCP user timeout (see RFC5482) */
22522256
tcp_sock_set_user_timeout(sock->sk, timeo);
2257+
2258+
/* Connect timeout */
2259+
connect_timeout = max_t(unsigned long,
2260+
DIV_ROUND_UP(xprt->connect_timeout, HZ), 1);
2261+
syn_retries = max_t(unsigned long,
2262+
READ_ONCE(net->ipv4.sysctl_tcp_syn_retries), 1);
2263+
for (t = 0; t <= syn_retries && (1UL << t) < connect_timeout; t++)
2264+
;
2265+
if (t <= syn_retries)
2266+
tcp_sock_set_syncnt(sock->sk, t - 1);
22532267
}
22542268

22552269
static void xs_tcp_set_connect_timeout(struct rpc_xprt *xprt,

0 commit comments

Comments
 (0)