It sleeps for at most the given time, but stops early once the server is exiting, as cifs_put_tcp_session() and clean_demultiplex_info() wake up server->response_q after setting CifsExiting. Use it for the waits between reconnect attempts and replace the msleep() calls in the demultiplex thread, which retries after a failed buffer allocation and waits after a negative RFC 1002 session response, so that they don't delay the exit of the server. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Fixes: 4f1fffa23769 ("cifs: commands that are retried should have replay flag set") Cc: stable@vger.kernel.org Cc: Paulo Alcantara Cc: Namjae Jeon Cc: Ronnie Sahlberg Cc: Shyam Prasad N Cc: Tom Talpey Cc: Bharath SM Cc: linux-cifs@vger.kernel.org Cc: samba-technical@lists.samba.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Stefan Metzmacher --- fs/smb/client/cifsproto.h | 2 ++ fs/smb/client/connect.c | 14 +++++--------- fs/smb/client/misc.c | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h index 15123c7b9373..769873346576 100644 --- a/fs/smb/client/cifsproto.h +++ b/fs/smb/client/cifsproto.h @@ -447,6 +447,8 @@ void cifs_wake_ses_waiters(struct cifs_ses *ses); int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, struct cifs_tcon *tcon, int aborts, bool nowait); +bool cifs_server_wait_exiting(struct TCP_Server_Info *server, + unsigned int msecs); static inline void cifs_put_smb_ses(struct cifs_ses *ses) { diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c index c2999f12af4a..d3e40dcbf049 100644 --- a/fs/smb/client/connect.c +++ b/fs/smb/client/connect.c @@ -450,9 +450,7 @@ static int __cifs_reconnect(struct TCP_Server_Info *server, * Wait before the next try, but stop * waiting once the server is exiting. */ - wait_event_timeout(server->response_q, - server->tcpStatus != CifsNeedReconnect, - 3 * HZ); + cifs_server_wait_exiting(server, 3000); } else { atomic_inc(&tcpSesReconnectCount); set_credits(server, 1); @@ -589,9 +587,7 @@ static int reconnect_dfs_server(struct TCP_Server_Info *server) * Wait before the next try, but stop * waiting once the server is exiting. */ - wait_event_timeout(server->response_q, - server->tcpStatus != CifsNeedReconnect, - 3 * HZ); + cifs_server_wait_exiting(server, 3000); continue; } /* @@ -686,7 +682,7 @@ allocate_buffers(struct TCP_Server_Info *server) server->bigbuf = (char *)cifs_buf_get(); if (!server->bigbuf) { cifs_server_dbg(VFS, "No memory for large SMB response\n"); - msleep(3000); + cifs_server_wait_exiting(server, 3000); /* retry will check if exiting */ return false; } @@ -699,7 +695,7 @@ allocate_buffers(struct TCP_Server_Info *server) server->smallbuf = (char *)cifs_small_buf_get(); if (!server->smallbuf) { cifs_server_dbg(VFS, "No memory for SMB response\n"); - msleep(1000); + cifs_server_wait_exiting(server, 1000); /* retry will check if exiting */ return false; } @@ -972,7 +968,7 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type) * mount context will fail at all. */ if (rc != 0) - msleep(2000); + cifs_server_wait_exiting(server, 2000); } else { cifs_server_dbg(VFS, "RFC 1002 negative session response (unexpected)\n"); cifs_reconnect(server, true); diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c index a0e7818d3c8d..6785a92b0924 100644 --- a/fs/smb/client/misc.c +++ b/fs/smb/client/misc.c @@ -1078,6 +1078,23 @@ int cifs_inval_name_dfs_link_error(const unsigned int xid, } #endif +/* + * Sleep for at most @msecs, but stop early once the server is exiting, + * cifs_put_tcp_session() and clean_demultiplex_info() wake up + * server->response_q after setting CifsExiting. + * + * Returns true if the server is exiting. + */ +bool cifs_server_wait_exiting(struct TCP_Server_Info *server, + unsigned int msecs) +{ + wait_event_timeout(server->response_q, + READ_ONCE(server->tcpStatus) == CifsExiting, + msecs_to_jiffies(msecs)); + + return READ_ONCE(server->tcpStatus) == CifsExiting; +} + static bool reco_wait_done(struct TCP_Server_Info *server, struct cifs_tcon *tcon, int aborts) { -- 2.43.0