]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
smb: client: relax session and tcon reconnect attempts
authorPaulo Alcantara <pc@manguebit.org>
Thu, 4 Dec 2025 18:06:23 +0000 (15:06 -0300)
committerSteve French <stfrench@microsoft.com>
Fri, 5 Dec 2025 23:40:33 +0000 (17:40 -0600)
When the client re-establishes connection to the server, it will queue
a worker thread that will attempt to reconnect sessions and tcons on
every two seconds, which is kinda overkill as it is a very common
scenario when having expired passwords or KRB5 TGT tickets, or deleted
shares.

Use an exponential backoff strategy to handle session/tcon reconnect
attempts in the worker thread to prevent the client from overloading
the system when it is very unlikely to re-establish any session/tcon
soon while client is idle.

Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>
Reviewed-by: David Howells <dhowells@redhat.com>
Cc: Pierguido Lambri <plambri@redhat.com>
Cc: linux-cifs@vger.kernel.org
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/cifsglob.h
fs/smb/client/connect.c
fs/smb/client/smb2pdu.c

index f9c1f553ffd00c77ddaf3a21eeec4999576c931e..3eca5bfb7030301265eac7addbe8ffcdd4bee9d8 100644 (file)
@@ -745,6 +745,7 @@ struct TCP_Server_Info {
        struct session_key session_key;
        unsigned long lstrp; /* when we got last response from this server */
        unsigned long neg_start; /* when negotiate started (jiffies) */
+       unsigned long reconn_delay; /* when resched session and tcon reconnect */
        struct cifs_secmech secmech; /* crypto sec mech functs, descriptors */
 #define        CIFS_NEGFLAVOR_UNENCAP  1       /* wct == 17, but no ext_sec */
 #define        CIFS_NEGFLAVOR_EXTENDED 2       /* wct == 17, ext_sec bit set */
@@ -2292,4 +2293,24 @@ struct cifs_calc_sig_ctx {
        struct shash_desc *shash;
 };
 
+#define CIFS_RECONN_DELAY_SECS 30
+#define CIFS_MAX_RECONN_DELAY  (4 * CIFS_RECONN_DELAY_SECS)
+
+static inline void cifs_queue_server_reconn(struct TCP_Server_Info *server)
+{
+       if (!delayed_work_pending(&server->reconnect)) {
+               WRITE_ONCE(server->reconn_delay, 0);
+               mod_delayed_work(cifsiod_wq, &server->reconnect, 0);
+       }
+}
+
+static inline void cifs_requeue_server_reconn(struct TCP_Server_Info *server)
+{
+       unsigned long delay = READ_ONCE(server->reconn_delay);
+
+       delay = umin(delay + CIFS_RECONN_DELAY_SECS, CIFS_MAX_RECONN_DELAY);
+       WRITE_ONCE(server->reconn_delay, delay);
+       queue_delayed_work(cifsiod_wq, &server->reconnect, delay * HZ);
+}
+
 #endif /* _CIFS_GLOB_H */
index cca6c722598d64d56052502269790dbd7fb42eef..0d4f45444380f3ed129fbeeac0d7ca5c6186bdb4 100644 (file)
@@ -425,7 +425,7 @@ static int __cifs_reconnect(struct TCP_Server_Info *server,
                        spin_unlock(&server->srv_lock);
                        cifs_swn_reset_server_dstaddr(server);
                        cifs_server_unlock(server);
-                       mod_delayed_work(cifsiod_wq, &server->reconnect, 0);
+                       cifs_queue_server_reconn(server);
                }
        } while (server->tcpStatus == CifsNeedReconnect);
 
@@ -564,7 +564,7 @@ static int reconnect_dfs_server(struct TCP_Server_Info *server)
                spin_unlock(&server->srv_lock);
                cifs_swn_reset_server_dstaddr(server);
                cifs_server_unlock(server);
-               mod_delayed_work(cifsiod_wq, &server->reconnect, 0);
+               cifs_queue_server_reconn(server);
        } while (server->tcpStatus == CifsNeedReconnect);
 
        dfs_cache_noreq_update_tgthint(ref_path, target_hint);
index dec9968ffb488970d87bde1d7929bee3d5f2b90b..c9f437cd29a2110cb34cd183c8ebd9ef27dac17a 100644 (file)
@@ -497,7 +497,7 @@ skip_add_channels:
        spin_unlock(&ses->ses_lock);
 
        if (smb2_command != SMB2_INTERNAL_CMD)
-               mod_delayed_work(cifsiod_wq, &server->reconnect, 0);
+               cifs_queue_server_reconn(server);
 
        atomic_inc(&tconInfoReconnectCount);
 out:
@@ -4316,7 +4316,7 @@ void smb2_reconnect_server(struct work_struct *work)
 done:
        cifs_dbg(FYI, "Reconnecting tcons and channels finished\n");
        if (resched)
-               queue_delayed_work(cifsiod_wq, &server->reconnect, 2 * HZ);
+               cifs_requeue_server_reconn(server);
        mutex_unlock(&pserver->reconnect_mutex);
 
        /* now we can safely release srv struct */
@@ -4340,7 +4340,7 @@ SMB2_echo(struct TCP_Server_Info *server)
            server->ops->need_neg(server)) {
                spin_unlock(&server->srv_lock);
                /* No need to send echo on newly established connections */
-               mod_delayed_work(cifsiod_wq, &server->reconnect, 0);
+               cifs_queue_server_reconn(server);
                return rc;
        }
        spin_unlock(&server->srv_lock);