NFSv4: Cap the transport reconnection timer at 1/2 lease period
authorTrond Myklebust <trond.myklebust@primarydata.com>
Fri, 5 Aug 2016 23:03:31 +0000 (19:03 -0400)
committerTrond Myklebust <trond.myklebust@primarydata.com>
Fri, 5 Aug 2016 23:22:22 +0000 (19:22 -0400)
We don't want to miss a lease period renewal due to the TCP connection
failing to reconnect in a timely fashion. To ensure this doesn't happen,
cap the reconnection timer so that we retry the connection attempt
at least every 1/2 lease period.

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
fs/nfs/nfs4renewd.c
include/linux/sunrpc/clnt.h
net/sunrpc/clnt.c

index 062029ab344a2bbe85322d7f0b2ec8071637f151..82e77198d17efdf656315f39c3d50c4d9aa568a9 100644 (file)
@@ -151,6 +151,9 @@ void nfs4_set_lease_period(struct nfs_client *clp,
        clp->cl_lease_time = lease;
        clp->cl_last_renewal = lastrenewed;
        spin_unlock(&clp->cl_lock);
+
+       /* Cap maximum reconnect timeout at 1/2 lease period */
+       rpc_cap_max_reconnect_timeout(clp->cl_rpcclient, lease >> 1);
 }
 
 /*
index b6810c92b8bb14d9ef8c9d1036a0b25d40530ac3..5c02b0691587797e303758eb74a4cad7d5e577ff 100644 (file)
@@ -195,6 +195,8 @@ int         rpc_clnt_add_xprt(struct rpc_clnt *, struct xprt_create *,
                                struct rpc_xprt *,
                                void *),
                        void *data);
+void           rpc_cap_max_reconnect_timeout(struct rpc_clnt *clnt,
+                       unsigned long timeo);
 
 const char *rpc_proc_name(const struct rpc_task *task);
 #endif /* __KERNEL__ */
index faac5472d14db825eca22f289e3cfd578290b1ad..7f79fb7dc6a00d6cc4082815d35fab4c60be1943 100644 (file)
@@ -2676,6 +2676,27 @@ out_put_switch:
 }
 EXPORT_SYMBOL_GPL(rpc_clnt_add_xprt);
 
+static int
+rpc_xprt_cap_max_reconnect_timeout(struct rpc_clnt *clnt,
+               struct rpc_xprt *xprt,
+               void *data)
+{
+       unsigned long timeout = *((unsigned long *)data);
+
+       if (timeout < xprt->max_reconnect_timeout)
+               xprt->max_reconnect_timeout = timeout;
+       return 0;
+}
+
+void
+rpc_cap_max_reconnect_timeout(struct rpc_clnt *clnt, unsigned long timeo)
+{
+       rpc_clnt_iterate_for_each_xprt(clnt,
+                       rpc_xprt_cap_max_reconnect_timeout,
+                       &timeo);
+}
+EXPORT_SYMBOL_GPL(rpc_cap_max_reconnect_timeout);
+
 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
 static void rpc_show_header(void)
 {