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 4f41d839face4d856b4f5b7553bbfa78737ac701..af7358277f1c340ccb5c911fa567b5a813988437 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 b52411bcfe4e7c7757799f881f2bf377cc9984a3..4ecc89301eb74d1a31d9f141fab3ea3ed4157dad 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 ca2c6efe19c956344b31250a355115c67d673979..06df08b0ee9e1b57ead1265af9f10f48a70d7f2d 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 e558f0024fe596d84e80db3b41bc1438e284b87e..6e845e51cbf3121b197a72ffba5fb2ed34ee978d 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);