Skip to content

Commit 3e6ff89

Browse files
Trond Myklebustamschuma-ntap
authored andcommitted
SUNRPC: Refactor and simplify connect timeout
Instead of requiring the requests to redrive the connection several times, just let the TCP connect code manage it now that we've adjusted the TCP_SYNCNT value. Signed-off-by: Trond Myklebust <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 3a107f0 commit 3e6ff89

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

net/sunrpc/xprtsock.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,6 +2266,25 @@ static void xs_tcp_set_socket_timeouts(struct rpc_xprt *xprt,
22662266
tcp_sock_set_syncnt(sock->sk, t - 1);
22672267
}
22682268

2269+
static void xs_tcp_do_set_connect_timeout(struct rpc_xprt *xprt,
2270+
unsigned long connect_timeout)
2271+
{
2272+
struct sock_xprt *transport =
2273+
container_of(xprt, struct sock_xprt, xprt);
2274+
struct rpc_timeout to;
2275+
unsigned long initval;
2276+
2277+
memcpy(&to, xprt->timeout, sizeof(to));
2278+
/* Arbitrary lower limit */
2279+
initval = max_t(unsigned long, connect_timeout, XS_TCP_INIT_REEST_TO);
2280+
to.to_initval = initval;
2281+
to.to_maxval = initval;
2282+
to.to_retries = 0;
2283+
memcpy(&transport->tcp_timeout, &to, sizeof(transport->tcp_timeout));
2284+
xprt->timeout = &transport->tcp_timeout;
2285+
xprt->connect_timeout = connect_timeout;
2286+
}
2287+
22692288
static void xs_tcp_set_connect_timeout(struct rpc_xprt *xprt,
22702289
unsigned long connect_timeout,
22712290
unsigned long reconnect_timeout)
@@ -2277,19 +2296,8 @@ static void xs_tcp_set_connect_timeout(struct rpc_xprt *xprt,
22772296
spin_lock(&xprt->transport_lock);
22782297
if (reconnect_timeout < xprt->max_reconnect_timeout)
22792298
xprt->max_reconnect_timeout = reconnect_timeout;
2280-
if (connect_timeout < xprt->connect_timeout) {
2281-
memcpy(&to, xprt->timeout, sizeof(to));
2282-
initval = DIV_ROUND_UP(connect_timeout, to.to_retries + 1);
2283-
/* Arbitrary lower limit */
2284-
if (initval < XS_TCP_INIT_REEST_TO << 1)
2285-
initval = XS_TCP_INIT_REEST_TO << 1;
2286-
to.to_initval = initval;
2287-
to.to_maxval = initval;
2288-
memcpy(&transport->tcp_timeout, &to,
2289-
sizeof(transport->tcp_timeout));
2290-
xprt->timeout = &transport->tcp_timeout;
2291-
xprt->connect_timeout = connect_timeout;
2292-
}
2299+
if (connect_timeout < xprt->connect_timeout)
2300+
xs_tcp_do_set_connect_timeout(xprt, connect_timeout);
22932301
set_bit(XPRT_SOCK_UPD_TIMEOUT, &transport->sock_state);
22942302
spin_unlock(&xprt->transport_lock);
22952303
}

0 commit comments

Comments
 (0)