SUNRPC: Allow specification of TCP client connect timeout at setup
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Sat, 19 Aug 2023 21:32:23 +0000 (17:32 -0400)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Thu, 24 Aug 2023 17:24:15 +0000 (13:24 -0400)
When we create a TCP transport, the connect timeout parameters are
currently fixed to be 90s. This is problematic in the pNFS flexfiles
case, where we may have multiple mirrors, and we would like to fail over
quickly to the next mirror if a data server is down.

This patch adds the ability to specify the connection parameters at RPC
client creation time.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
include/linux/sunrpc/clnt.h
include/linux/sunrpc/xprt.h
net/sunrpc/clnt.c
net/sunrpc/xprtsock.c

index 4f41d83..af73582 100644 (file)
@@ -148,6 +148,8 @@ struct rpc_create_args {
        const struct cred       *cred;
        unsigned int            max_connect;
        struct xprtsec_parms    xprtsec;
+       unsigned long           connect_timeout;
+       unsigned long           reconnect_timeout;
 };
 
 struct rpc_add_xprt_test {
index b52411b..4ecc893 100644 (file)
@@ -351,6 +351,8 @@ struct xprt_create {
        struct rpc_xprt_switch  *bc_xps;
        unsigned int            flags;
        struct xprtsec_parms    xprtsec;
+       unsigned long           connect_timeout;
+       unsigned long           reconnect_timeout;
 };
 
 struct xprt_class {
index ca2c6ef..06df08b 100644 (file)
@@ -534,6 +534,8 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args)
                .servername = args->servername,
                .bc_xprt = args->bc_xprt,
                .xprtsec = args->xprtsec,
+               .connect_timeout = args->connect_timeout,
+               .reconnect_timeout = args->reconnect_timeout,
        };
        char servername[48];
        struct rpc_clnt *clnt;
index e558f00..6e845e5 100644 (file)
@@ -2290,8 +2290,6 @@ static void xs_tcp_set_connect_timeout(struct rpc_xprt *xprt,
                unsigned long reconnect_timeout)
 {
        struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
-       struct rpc_timeout to;
-       unsigned long initval;
 
        spin_lock(&xprt->transport_lock);
        if (reconnect_timeout < xprt->max_reconnect_timeout)
@@ -3350,8 +3348,13 @@ static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args)
        xprt->timeout = &xs_tcp_default_timeout;
 
        xprt->max_reconnect_timeout = xprt->timeout->to_maxval;
+       if (args->reconnect_timeout)
+               xprt->max_reconnect_timeout = args->reconnect_timeout;
+
        xprt->connect_timeout = xprt->timeout->to_initval *
                (xprt->timeout->to_retries + 1);
+       if (args->connect_timeout)
+               xs_tcp_do_set_connect_timeout(xprt, args->connect_timeout);
 
        INIT_WORK(&transport->recv_worker, xs_stream_data_receive_workfn);
        INIT_WORK(&transport->error_worker, xs_error_handle);