Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 0/5] smb: client: don't sleep through reconnects and umount
@ 2026-12-01 16:50 Stefan Metzmacher
  2026-12-01 16:50 ` [PATCH 1/5] smb: client: stop waiting between reconnect attempts once the server exits Stefan Metzmacher
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Stefan Metzmacher @ 2026-12-01 16:50 UTC (permalink / raw)
  To: Paulo Alcantara
  Cc: metze, Namjae Jeon, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
	Bharath SM, linux-cifs, samba-technical, linux-kernel, stable

Hi Paulo,

these remove fixed sleeps from the client's reconnect and shutdown
paths, which delayed e.g. an umount after the server or the local
address went away:

  - The reconnect loops slept 3 seconds between attempts, also when
    the server was already exiting; wait on server->response_q
    instead.

  - clean_demultiplex_info() slept 46 seconds if mids were still
    pending; wait until they are gone instead (with the same maximum).

  - Add cifs_server_wait_exiting() and use it for the other sleeps in
    the demultiplex thread and for the replay back-off.

  - Soft mounts give up waiting for the reconnect once the next
    reconnect attempt failed with a local error (e.g. the address was
    removed: -EADDRNOTAVAIL, -ENETUNREACH, -ENETDOWN, -ENODEV) instead
    of 10 seconds per target; short outages like a server restart
    still keep waiting.

The fixed sleeps are gone for all transports. Giving up early on
local errors works for TCP now; for SMB over RDMA it needs smbdirect
to report such errors, which comes with separate changes for
smbdirect.

These patches were developed with the help of Claude (Anthropic),
which was used for code analysis, writing parts of the code and the
commit messages. I reviewed all changes and take full responsibility
for them.

Base: paulo-linux/cifs-next (f5ed6b20ad03).

Stefan Metzmacher (5):
  smb: client: stop waiting between reconnect attempts once the server
    exits
  smb: client: wait for pending mids instead of sleeping 46 seconds
  smb: client: add cifs_server_wait_exiting()
  smb: client: use cifs_server_wait_exiting() for the replay back-off
  smb: client: soft mounts only wait until a reconnect attempt failed
    locally

 fs/smb/client/cached_dir.c |  2 +-
 fs/smb/client/cifsglob.h   |  5 ++++
 fs/smb/client/cifsproto.h  |  2 ++
 fs/smb/client/connect.c    | 61 ++++++++++++++++++++++++++++++++++----
 fs/smb/client/file.c       |  7 +++--
 fs/smb/client/link.c       |  2 +-
 fs/smb/client/misc.c       | 46 +++++++++++++++++++++++-----
 fs/smb/client/smb2inode.c  |  6 ++--
 fs/smb/client/smb2ops.c    |  8 ++---
 fs/smb/client/smb2pdu.c    | 28 ++++++++---------
 fs/smb/client/transport.c  | 16 ++++++++++
 11 files changed, 144 insertions(+), 39 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] smb: client: stop waiting between reconnect attempts once the server exits
  2026-12-01 16:50 [PATCH 0/5] smb: client: don't sleep through reconnects and umount Stefan Metzmacher
@ 2026-12-01 16:50 ` Stefan Metzmacher
  2026-12-01 16:50 ` [PATCH 2/5] smb: client: wait for pending mids instead of sleeping 46 seconds Stefan Metzmacher
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Stefan Metzmacher @ 2026-12-01 16:50 UTC (permalink / raw)
  To: linux-cifs, samba-technical
  Cc: metze, stable, Paulo Alcantara, Namjae Jeon, Ronnie Sahlberg,
	Shyam Prasad N, Tom Talpey, Bharath SM, linux-kernel

cifs_reconnect() and the DFS reconnect loop used msleep(3000) between
failed reconnect attempts. Once cifs_put_tcp_session() marks the
server as CifsExiting, e.g. during umount, the loop still slept the
full 3 seconds before noticing it. The SIGKILL sent to cifsd doesn't
interrupt msleep() either.

Use wait_event_timeout() on server->response_q instead, so the wait
ends as soon as tcpStatus isn't CifsNeedReconnect anymore, and wake
up response_q in cifs_put_tcp_session() after setting CifsExiting.

It's not interruptible on purpose, as cifs_reconnect() is also called
from user processes and a pending signal would otherwise remove the
delay between the attempts.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Cc: Paulo Alcantara <pc@manguebit.org>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Cc: Shyam Prasad N <sprasad@microsoft.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Bharath SM <bharathsm@microsoft.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
 fs/smb/client/connect.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c
index 064b70bf1fdf..fa2bfab5e77b 100644
--- a/fs/smb/client/connect.c
+++ b/fs/smb/client/connect.c
@@ -446,7 +446,13 @@ static int __cifs_reconnect(struct TCP_Server_Info *server,
 			/* If was asked to reconnect only once, do not try it more times */
 			if (once)
 				break;
-			msleep(3000);
+			/*
+			 * Wait before the next try, but stop
+			 * waiting once the server is exiting.
+			 */
+			wait_event_timeout(server->response_q,
+					   server->tcpStatus != CifsNeedReconnect,
+					   3 * HZ);
 		} else {
 			atomic_inc(&tcpSesReconnectCount);
 			set_credits(server, 1);
@@ -579,7 +585,13 @@ static int reconnect_dfs_server(struct TCP_Server_Info *server)
 			/* Failed to reconnect socket */
 			cifs_server_unlock(server);
 			cifs_dbg(FYI, "%s: reconnect error %d\n", __func__, rc);
-			msleep(3000);
+			/*
+			 * Wait before the next try, but stop
+			 * waiting once the server is exiting.
+			 */
+			wait_event_timeout(server->response_q,
+					   server->tcpStatus != CifsNeedReconnect,
+					   3 * HZ);
 			continue;
 		}
 		/*
@@ -1769,6 +1781,8 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect)
 	spin_lock(&server->srv_lock);
 	server->tcpStatus = CifsExiting;
 	spin_unlock(&server->srv_lock);
+	/* stop a reconnect waiting before its next try */
+	wake_up_all(&server->response_q);
 
 	task = xchg(&server->tsk, NULL);
 	if (task)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] smb: client: wait for pending mids instead of sleeping 46 seconds
  2026-12-01 16:50 [PATCH 0/5] smb: client: don't sleep through reconnects and umount Stefan Metzmacher
  2026-12-01 16:50 ` [PATCH 1/5] smb: client: stop waiting between reconnect attempts once the server exits Stefan Metzmacher
@ 2026-12-01 16:50 ` Stefan Metzmacher
  2026-12-01 16:50 ` [PATCH 3/5] smb: client: add cifs_server_wait_exiting() Stefan Metzmacher
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Stefan Metzmacher @ 2026-12-01 16:50 UTC (permalink / raw)
  To: linux-cifs, samba-technical
  Cc: metze, stable, Paulo Alcantara, Namjae Jeon, Ronnie Sahlberg,
	Shyam Prasad N, Tom Talpey, Bharath SM, linux-kernel

If there are still mids on pending_mid_q after the demultiplex thread
shut down the others, clean_demultiplex_info() did msleep(46000) in
order to give the waiting threads time to exit, even if they removed
their mids much earlier.

Wait on server->response_q for pending_mid_q to become empty instead,
still with 46 seconds as maximum. delete_mid() and
cifs_sync_mid_result() wake it up once they removed the last mid
while the server is exiting.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Cc: Paulo Alcantara <pc@manguebit.org>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Cc: Shyam Prasad N <sprasad@microsoft.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Bharath SM <bharathsm@microsoft.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
 fs/smb/client/connect.c   |  4 +++-
 fs/smb/client/transport.c | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c
index fa2bfab5e77b..c2999f12af4a 100644
--- a/fs/smb/client/connect.c
+++ b/fs/smb/client/connect.c
@@ -1187,7 +1187,9 @@ clean_demultiplex_info(struct TCP_Server_Info *server)
 		 * response and going ahead and killing cifsd.
 		 */
 		cifs_dbg(FYI, "Wait for exit from demultiplex thread\n");
-		msleep(46000);
+		wait_event_timeout(server->response_q,
+				   list_empty_careful(&server->pending_mid_q),
+				   46 * HZ);
 		/*
 		 * If threads still have not exited they are probably never
 		 * coming home not much else we can do but free the memory.
diff --git a/fs/smb/client/transport.c b/fs/smb/client/transport.c
index ea1f4fe42ee5..621acb2a47fe 100644
--- a/fs/smb/client/transport.c
+++ b/fs/smb/client/transport.c
@@ -113,6 +113,20 @@ void __release_mid(struct TCP_Server_Info *server, struct mid_q_entry *midEntry)
 	mempool_free(midEntry, &cifs_mid_pool);
 }
 
+/*
+ * clean_demultiplex_info() waits for the pending mids to
+ * be removed once the server is exiting.
+ */
+static void
+cifs_wake_up_mid_queue_empty_locked(struct TCP_Server_Info *server)
+{
+	lockdep_assert_held(&server->mid_queue_lock);
+
+	if (READ_ONCE(server->tcpStatus) == CifsExiting &&
+	    list_empty(&server->pending_mid_q))
+		wake_up_all(&server->response_q);
+}
+
 void
 delete_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid)
 {
@@ -121,6 +135,7 @@ delete_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid)
 	if (!mid->deleted_from_q) {
 		list_del_init(&mid->qhead);
 		mid->deleted_from_q = true;
+		cifs_wake_up_mid_queue_empty_locked(server);
 	}
 	spin_unlock(&server->mid_queue_lock);
 
@@ -804,6 +819,7 @@ int cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server
 		if (mid->deleted_from_q == false) {
 			list_del_init(&mid->qhead);
 			mid->deleted_from_q = true;
+			cifs_wake_up_mid_queue_empty_locked(server);
 		}
 		spin_unlock(&server->mid_queue_lock);
 		cifs_server_dbg(VFS, "%s: invalid mid state mid=%llu state=%d\n",
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] smb: client: add cifs_server_wait_exiting()
  2026-12-01 16:50 [PATCH 0/5] smb: client: don't sleep through reconnects and umount Stefan Metzmacher
  2026-12-01 16:50 ` [PATCH 1/5] smb: client: stop waiting between reconnect attempts once the server exits Stefan Metzmacher
  2026-12-01 16:50 ` [PATCH 2/5] smb: client: wait for pending mids instead of sleeping 46 seconds Stefan Metzmacher
@ 2026-12-01 16:50 ` Stefan Metzmacher
  2026-12-01 16:50 ` [PATCH 4/5] smb: client: use cifs_server_wait_exiting() for the replay back-off Stefan Metzmacher
  2026-12-01 16:50 ` [PATCH 5/5] smb: client: soft mounts only wait until a reconnect attempt failed locally Stefan Metzmacher
  4 siblings, 0 replies; 6+ messages in thread
From: Stefan Metzmacher @ 2026-12-01 16:50 UTC (permalink / raw)
  To: linux-cifs, samba-technical
  Cc: metze, stable, Paulo Alcantara, Namjae Jeon, Ronnie Sahlberg,
	Shyam Prasad N, Tom Talpey, Bharath SM, linux-kernel

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 <pc@manguebit.org>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Cc: Shyam Prasad N <sprasad@microsoft.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Bharath SM <bharathsm@microsoft.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] smb: client: use cifs_server_wait_exiting() for the replay back-off
  2026-12-01 16:50 [PATCH 0/5] smb: client: don't sleep through reconnects and umount Stefan Metzmacher
                   ` (2 preceding siblings ...)
  2026-12-01 16:50 ` [PATCH 3/5] smb: client: add cifs_server_wait_exiting() Stefan Metzmacher
@ 2026-12-01 16:50 ` Stefan Metzmacher
  2026-12-01 16:50 ` [PATCH 5/5] smb: client: soft mounts only wait until a reconnect attempt failed locally Stefan Metzmacher
  4 siblings, 0 replies; 6+ messages in thread
From: Stefan Metzmacher @ 2026-12-01 16:50 UTC (permalink / raw)
  To: linux-cifs, samba-technical
  Cc: metze, stable, Paulo Alcantara, Namjae Jeon, Ronnie Sahlberg,
	Shyam Prasad N, Tom Talpey, Bharath SM, linux-kernel

The replay of a request after smb2_should_replay() backs off with
msleep(cur_sleep), up to CIFS_MAX_SLEEP per retry. Use
cifs_server_wait_exiting() instead, so the back-off ends once the
server is exiting and the replay fails right away instead of
sleeping first.

Fixes: 4f1fffa23769 ("cifs: commands that are retried should have replay flag set")
Cc: stable@vger.kernel.org
Cc: Paulo Alcantara <pc@manguebit.org>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Cc: Shyam Prasad N <sprasad@microsoft.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Bharath SM <bharathsm@microsoft.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
 fs/smb/client/cached_dir.c |  2 +-
 fs/smb/client/file.c       |  7 ++++---
 fs/smb/client/link.c       |  2 +-
 fs/smb/client/smb2inode.c  |  6 +++---
 fs/smb/client/smb2ops.c    |  8 ++++----
 fs/smb/client/smb2pdu.c    | 28 ++++++++++++++--------------
 6 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c
index 50217f47a0ed..3b0e9bdaafe4 100644
--- a/fs/smb/client/cached_dir.c
+++ b/fs/smb/client/cached_dir.c
@@ -315,7 +315,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 
 		smb2_set_replay(server, &rqst[0]);
 		smb2_set_replay(server, &rqst[1]);
diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index e7ed1ad58f37..e7b9fd196580 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -188,7 +188,7 @@ static int cifs_reopen_file_retry(struct cifsFileInfo *cfile, bool can_flush,
 		}
 		if (!cifs_io_should_replay(subreq))
 			return rc;
-		msleep(subreq->cur_sleep);
+		cifs_server_wait_exiting(subreq->server, subreq->cur_sleep);
 	}
 }
 
@@ -473,7 +473,8 @@ static void cifs_issue_write(struct netfs_io_subrequest *subreq)
 	struct cifs_io_request *req = wdata->req;
 
 	if (wdata->cur_sleep > req->slept) {
-		msleep(wdata->cur_sleep - req->slept);
+		cifs_server_wait_exiting(wdata->server,
+					 wdata->cur_sleep - req->slept);
 		req->slept = wdata->cur_sleep;
 	}
 
@@ -647,7 +648,7 @@ static void cifs_issue_read(struct netfs_io_subrequest *subreq)
 		goto not_sent;
 
 	if (rdata->replay && rdata->cur_sleep) {
-		msleep(rdata->cur_sleep);
+		cifs_server_wait_exiting(server, rdata->cur_sleep);
 		rc = -EIO;
 		if (cifs_io_aborted(rdata))
 			goto failed;
diff --git a/fs/smb/client/link.c b/fs/smb/client/link.c
index e865aeea8dbb..81a45ffa633c 100644
--- a/fs/smb/client/link.c
+++ b/fs/smb/client/link.c
@@ -422,7 +422,7 @@ int smb2_query_mf_symlink(const unsigned int xid,
 
 	if (retries) {
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		for (int i = 0; i < num_rqst; i++)
 			smb2_set_replay(server, &rqst[i]);
 	}
diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c
index cc29ff042c56..33030d3f0d37 100644
--- a/fs/smb/client/smb2inode.c
+++ b/fs/smb/client/smb2inode.c
@@ -541,7 +541,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
 		if (retries) {
 			/* Back-off before retry */
 			if (cur_sleep)
-				msleep(cur_sleep);
+				cifs_server_wait_exiting(server, cur_sleep);
 			for (i = 1; i < num_rqst - 2; i++)
 				smb2_set_replay(server, &rqst[i]);
 		}
@@ -554,7 +554,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
 		if (retries) {
 			/* Back-off before retry */
 			if (cur_sleep)
-				msleep(cur_sleep);
+				cifs_server_wait_exiting(server, cur_sleep);
 			for (i = 0; i < num_rqst; i++)
 				smb2_set_replay(server, &rqst[i]);
 		}
@@ -1176,7 +1176,7 @@ smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		for (int i = 0; i < ARRAY_SIZE(rqst);  i++)
 			smb2_set_replay(server, &rqst[i]);
 	}
diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
index 8783738a31ad..32890a6d6619 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -1360,7 +1360,7 @@ static int smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst[0]);
 		smb2_set_replay(server, &rqst[1]);
 		smb2_set_replay(server, &rqst[2]);
@@ -1779,7 +1779,7 @@ smb2_ioctl_query_info(const unsigned int xid,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst[0]);
 		smb2_set_replay(server, &rqst[1]);
 		smb2_set_replay(server, &rqst[2]);
@@ -2672,7 +2672,7 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst[0]);
 		smb2_set_replay(server, &rqst[1]);
 	}
@@ -3079,7 +3079,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		if (!cfid) {
 			smb2_set_replay(server, &rqst[0]);
 			smb2_set_replay(server, &rqst[2]);
diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
index 5e191848ef36..d6addcba5597 100644
--- a/fs/smb/client/smb2pdu.c
+++ b/fs/smb/client/smb2pdu.c
@@ -3124,7 +3124,7 @@ int smb311_posix_mkdir(const unsigned int xid, struct inode *inode,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst);
 	}
 
@@ -3423,7 +3423,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
 
 	/* Back-off before retry */
 	if (cur_sleep)
-		msleep(cur_sleep);
+		cifs_server_wait_exiting(server, cur_sleep);
 	if (oparms->replay)
 		smb2_set_replay(server, &rqst);
 
@@ -3682,7 +3682,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst);
 	}
 
@@ -3877,7 +3877,7 @@ __SMB2_close(const unsigned int xid, struct cifs_tcon *tcon,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst);
 	}
 
@@ -4088,7 +4088,7 @@ query_info(const unsigned int xid, struct cifs_tcon *tcon,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst);
 	}
 
@@ -4273,7 +4273,7 @@ SMB2_change_notify(const unsigned int xid, struct cifs_tcon *tcon,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst);
 	}
 
@@ -4615,7 +4615,7 @@ SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst);
 	}
 
@@ -5533,7 +5533,7 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst);
 	}
 
@@ -5924,7 +5924,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst);
 	}
 
@@ -6071,7 +6071,7 @@ send_set_info(const unsigned int xid, struct cifs_tcon *tcon,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst);
 	}
 
@@ -6204,7 +6204,7 @@ SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst);
 	}
 
@@ -6332,7 +6332,7 @@ SMB311_posix_qfs_info(const unsigned int xid, struct cifs_tcon *tcon,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst);
 	}
 
@@ -6417,7 +6417,7 @@ SMB2_QFS_attr(const unsigned int xid, struct cifs_tcon *tcon,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst);
 	}
 
@@ -6520,7 +6520,7 @@ smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon,
 	if (retries) {
 		/* Back-off before retry */
 		if (cur_sleep)
-			msleep(cur_sleep);
+			cifs_server_wait_exiting(server, cur_sleep);
 		smb2_set_replay(server, &rqst);
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] smb: client: soft mounts only wait until a reconnect attempt failed locally
  2026-12-01 16:50 [PATCH 0/5] smb: client: don't sleep through reconnects and umount Stefan Metzmacher
                   ` (3 preceding siblings ...)
  2026-12-01 16:50 ` [PATCH 4/5] smb: client: use cifs_server_wait_exiting() for the replay back-off Stefan Metzmacher
@ 2026-12-01 16:50 ` Stefan Metzmacher
  4 siblings, 0 replies; 6+ messages in thread
From: Stefan Metzmacher @ 2026-12-01 16:50 UTC (permalink / raw)
  To: linux-cifs, samba-technical
  Cc: metze, stable, Paulo Alcantara, Namjae Jeon, Ronnie Sahlberg,
	Shyam Prasad N, Tom Talpey, Bharath SM, linux-kernel

On soft mounts cifs_wait_for_server_reconnect() waited up to 10
seconds (per target) for the reconnect, even if the reconnect attempts
failed right away, e.g. because the local address used for the
connection was removed. This delays e.g. the statfs() umount(8) does
before calling umount(2) by 10 seconds.

Count the reconnect attempts that failed with an error indicating a
local problem, -EADDRNOTAVAIL or -ENODEV if the local address or the
network device used for the connection is gone, and -ENETUNREACH or
-ENETDOWN if the local network is down or has no route to the server,
in server->reconnect_local_failures and wake up server->response_q
after each of them, so that requests on soft mounts give up once the
next such reconnect attempt failed.

Note that a short local outage, e.g. while the link is down for a few
seconds during a cable replug or a Wi-Fi roam, now also makes requests
on soft mounts fail after about 3 seconds instead of 10. That's what
soft mounts are for, hard mounts hide it as before.

For other errors the requests wait up to 10 seconds as before, e.g.
while the server restarts the first attempt may fail with
-ECONNREFUSED and the next one succeeds, so the 10 second wait still
hides such a short outage from the applications. Hard mounts still
keep waiting.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Fixes: aa24d1e96924 ("CIFS: Process reconnects for SMB2 shares")
Cc: stable@vger.kernel.org
Cc: Paulo Alcantara <pc@manguebit.org>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Cc: Shyam Prasad N <sprasad@microsoft.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Bharath SM <bharathsm@microsoft.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
 fs/smb/client/cifsglob.h |  5 +++++
 fs/smb/client/connect.c  | 37 +++++++++++++++++++++++++++++++++++++
 fs/smb/client/misc.c     | 29 ++++++++++++++++++++++-------
 3 files changed, 64 insertions(+), 7 deletions(-)

diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h
index 3bfa9b1bacf5..a59eb91a0ff3 100644
--- a/fs/smb/client/cifsglob.h
+++ b/fs/smb/client/cifsglob.h
@@ -742,6 +742,11 @@ struct TCP_Server_Info {
 	char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
 	__u32 sequence_number; /* for signing, protected by srv_mutex */
 	__u32 reconnect_instance; /* incremented on each reconnect */
+	/*
+	 * incremented on each reconnect attempt that failed
+	 * because of a local problem, protected by srv_lock
+	 */
+	unsigned int reconnect_local_failures;
 	__le32 session_key_id; /* retrieved from negotiate response and send in session setup request */
 	struct session_key session_key;
 	unsigned long lstrp; /* when we got last response from this server */
diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c
index d3e40dcbf049..7aef771c67b5 100644
--- a/fs/smb/client/connect.c
+++ b/fs/smb/client/connect.c
@@ -393,6 +393,41 @@ static bool cifs_tcp_ses_needs_reconnect(struct TCP_Server_Info *server, int num
 	return true;
 }
 
+/*
+ * Errors that indicate a local problem, which is not expected to go
+ * away within a few seconds, e.g. the local address or the network
+ * device used for the connection is gone. Other errors, e.g.
+ * -ECONNREFUSED while the server restarts, may be transient.
+ */
+static bool cifs_reconnect_error_is_local(int rc)
+{
+	switch (rc) {
+	case -EADDRNOTAVAIL:
+	case -ENETUNREACH:
+	case -ENETDOWN:
+	case -ENODEV:
+		return true;
+	}
+
+	return false;
+}
+
+/*
+ * Let the requests waiting in cifs_wait_for_server_reconnect()
+ * on soft mounts know that a reconnect attempt failed because
+ * of a local problem.
+ */
+static void cifs_reconnect_failed(struct TCP_Server_Info *server, int rc)
+{
+	if (!cifs_reconnect_error_is_local(rc))
+		return;
+
+	spin_lock(&server->srv_lock);
+	server->reconnect_local_failures++;
+	spin_unlock(&server->srv_lock);
+	wake_up_all(&server->response_q);
+}
+
 /*
  * cifs tcp session reconnection
  *
@@ -443,6 +478,7 @@ static int __cifs_reconnect(struct TCP_Server_Info *server,
 		if (rc) {
 			cifs_server_unlock(server);
 			cifs_dbg(FYI, "%s: reconnect error %d\n", __func__, rc);
+			cifs_reconnect_failed(server, rc);
 			/* If was asked to reconnect only once, do not try it more times */
 			if (once)
 				break;
@@ -583,6 +619,7 @@ static int reconnect_dfs_server(struct TCP_Server_Info *server)
 			/* Failed to reconnect socket */
 			cifs_server_unlock(server);
 			cifs_dbg(FYI, "%s: reconnect error %d\n", __func__, rc);
+			cifs_reconnect_failed(server, rc);
 			/*
 			 * Wait before the next try, but stop
 			 * waiting once the server is exiting.
diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c
index 6785a92b0924..3231bc1e1b4b 100644
--- a/fs/smb/client/misc.c
+++ b/fs/smb/client/misc.c
@@ -1096,17 +1096,27 @@ bool cifs_server_wait_exiting(struct TCP_Server_Info *server,
 }
 
 static bool reco_wait_done(struct TCP_Server_Info *server,
-			   struct cifs_tcon *tcon, int aborts)
+			   struct cifs_tcon *tcon, int aborts,
+			   unsigned int failures)
 {
-	return server->tcpStatus != CifsNeedReconnect ||
-		atomic_read(&tcon->umount_aborts) != aborts ||
-		cifs_tcon_dying(tcon);
+	if (server->tcpStatus != CifsNeedReconnect ||
+	    atomic_read(&tcon->umount_aborts) != aborts ||
+	    cifs_tcon_dying(tcon))
+		return true;
+
+	/*
+	 * soft mounts only wait until the next reconnect
+	 * attempt failed because of a local problem
+	 */
+	return !tcon->retry &&
+	       READ_ONCE(server->reconnect_local_failures) != failures;
 }
 
 int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server,
 				   struct cifs_tcon *tcon, int aborts,
 				   bool nowait)
 {
+	unsigned int failures;
 	int timeout = 10;
 	int rc;
 
@@ -1120,6 +1130,7 @@ int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server,
 		return -EAGAIN;
 	}
 	timeout *= server->nr_targets;
+	failures = server->reconnect_local_failures;
 	spin_unlock(&server->srv_lock);
 
 	/*
@@ -1127,14 +1138,18 @@ int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server,
 	 * reconnect -- should be greater than cifs socket timeout which is 7
 	 * seconds.
 	 *
-	 * On "soft" mounts we wait once. Hard mounts keep retrying until
-	 * process is killed or server comes back on-line.
+	 * On "soft" mounts we wait once, but only until the next reconnect
+	 * attempt failed because of a local problem, e.g. it can't succeed
+	 * if the local address is gone.
+	 * Hard mounts keep retrying until process is killed or server comes
+	 * back on-line.
 	 */
 	do {
 		rc = wait_event_interruptible_timeout(server->response_q,
 						      reco_wait_done(server,
 								     tcon,
-								     aborts),
+								     aborts,
+								     failures),
 						      timeout * HZ);
 		if (rc < 0) {
 			cifs_dbg(FYI, "%s: aborting reconnect due to received signal\n",
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-01 16:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 16:50 [PATCH 0/5] smb: client: don't sleep through reconnects and umount Stefan Metzmacher
2026-12-01 16:50 ` [PATCH 1/5] smb: client: stop waiting between reconnect attempts once the server exits Stefan Metzmacher
2026-12-01 16:50 ` [PATCH 2/5] smb: client: wait for pending mids instead of sleeping 46 seconds Stefan Metzmacher
2026-12-01 16:50 ` [PATCH 3/5] smb: client: add cifs_server_wait_exiting() Stefan Metzmacher
2026-12-01 16:50 ` [PATCH 4/5] smb: client: use cifs_server_wait_exiting() for the replay back-off Stefan Metzmacher
2026-12-01 16:50 ` [PATCH 5/5] smb: client: soft mounts only wait until a reconnect attempt failed locally Stefan Metzmacher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox