Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

smb: client: relax session and tcon reconnect attempts

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>

authored by

Paulo Alcantara and committed by
Steve French
855982a5 4ae4dde6

+26 -5
+21
fs/smb/client/cifsglob.h
··· 745 745 struct session_key session_key; 746 746 unsigned long lstrp; /* when we got last response from this server */ 747 747 unsigned long neg_start; /* when negotiate started (jiffies) */ 748 + unsigned long reconn_delay; /* when resched session and tcon reconnect */ 748 749 struct cifs_secmech secmech; /* crypto sec mech functs, descriptors */ 749 750 #define CIFS_NEGFLAVOR_UNENCAP 1 /* wct == 17, but no ext_sec */ 750 751 #define CIFS_NEGFLAVOR_EXTENDED 2 /* wct == 17, ext_sec bit set */ ··· 2292 2291 struct hmac_sha256_ctx *hmac; 2293 2292 struct shash_desc *shash; 2294 2293 }; 2294 + 2295 + #define CIFS_RECONN_DELAY_SECS 30 2296 + #define CIFS_MAX_RECONN_DELAY (4 * CIFS_RECONN_DELAY_SECS) 2297 + 2298 + static inline void cifs_queue_server_reconn(struct TCP_Server_Info *server) 2299 + { 2300 + if (!delayed_work_pending(&server->reconnect)) { 2301 + WRITE_ONCE(server->reconn_delay, 0); 2302 + mod_delayed_work(cifsiod_wq, &server->reconnect, 0); 2303 + } 2304 + } 2305 + 2306 + static inline void cifs_requeue_server_reconn(struct TCP_Server_Info *server) 2307 + { 2308 + unsigned long delay = READ_ONCE(server->reconn_delay); 2309 + 2310 + delay = umin(delay + CIFS_RECONN_DELAY_SECS, CIFS_MAX_RECONN_DELAY); 2311 + WRITE_ONCE(server->reconn_delay, delay); 2312 + queue_delayed_work(cifsiod_wq, &server->reconnect, delay * HZ); 2313 + } 2295 2314 2296 2315 #endif /* _CIFS_GLOB_H */
+2 -2
fs/smb/client/connect.c
··· 425 425 spin_unlock(&server->srv_lock); 426 426 cifs_swn_reset_server_dstaddr(server); 427 427 cifs_server_unlock(server); 428 - mod_delayed_work(cifsiod_wq, &server->reconnect, 0); 428 + cifs_queue_server_reconn(server); 429 429 } 430 430 } while (server->tcpStatus == CifsNeedReconnect); 431 431 ··· 564 564 spin_unlock(&server->srv_lock); 565 565 cifs_swn_reset_server_dstaddr(server); 566 566 cifs_server_unlock(server); 567 - mod_delayed_work(cifsiod_wq, &server->reconnect, 0); 567 + cifs_queue_server_reconn(server); 568 568 } while (server->tcpStatus == CifsNeedReconnect); 569 569 570 570 dfs_cache_noreq_update_tgthint(ref_path, target_hint);
+3 -3
fs/smb/client/smb2pdu.c
··· 497 497 spin_unlock(&ses->ses_lock); 498 498 499 499 if (smb2_command != SMB2_INTERNAL_CMD) 500 - mod_delayed_work(cifsiod_wq, &server->reconnect, 0); 500 + cifs_queue_server_reconn(server); 501 501 502 502 atomic_inc(&tconInfoReconnectCount); 503 503 out: ··· 4316 4316 done: 4317 4317 cifs_dbg(FYI, "Reconnecting tcons and channels finished\n"); 4318 4318 if (resched) 4319 - queue_delayed_work(cifsiod_wq, &server->reconnect, 2 * HZ); 4319 + cifs_requeue_server_reconn(server); 4320 4320 mutex_unlock(&pserver->reconnect_mutex); 4321 4321 4322 4322 /* now we can safely release srv struct */ ··· 4340 4340 server->ops->need_neg(server)) { 4341 4341 spin_unlock(&server->srv_lock); 4342 4342 /* No need to send echo on newly established connections */ 4343 - mod_delayed_work(cifsiod_wq, &server->reconnect, 0); 4343 + cifs_queue_server_reconn(server); 4344 4344 return rc; 4345 4345 } 4346 4346 spin_unlock(&server->srv_lock);