mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefan Metzmacher <metze@samba.org>
To: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org
Cc: metze@samba.org, stable@vger.kernel.org,
	Paulo Alcantara <pc@manguebit.org>,
	Namjae Jeon <linkinjeon@kernel.org>,
	Ronnie Sahlberg <ronniesahlberg@gmail.com>,
	Shyam Prasad N <sprasad@microsoft.com>,
	Tom Talpey <tom@talpey.com>, Bharath SM <bharathsm@microsoft.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 08/12] smb: client: add cifs_server_wait_for_exit_ms()
Date: Fri,  4 Dec 2026 14:33:33 +0100	[thread overview]
Message-ID: <2ea5cac93cf8ffbd523a4952eee83b420a80e96e.1796391093.git.metze@samba.org> (raw)
In-Reply-To: <cover.1796391093.git.metze@samba.org>

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 to 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.

This is also a prerequisite for "smb: client: use
cifs_server_wait_for_exit_ms() for the replay back-off", so it carries the
Fixes tag of that patch as well.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Fixes: 665e18794804 ("cifs: Improve handling of NetBIOS packets")
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   |  6 +++---
 fs/smb/client/misc.c      | 17 +++++++++++++++++
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h
index 402446435105..c9ae85422f10 100644
--- a/fs/smb/client/cifsproto.h
+++ b/fs/smb/client/cifsproto.h
@@ -450,6 +450,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_for_exit_ms(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 ff26b1980bb7..c5fa675e6a11 100644
--- a/fs/smb/client/connect.c
+++ b/fs/smb/client/connect.c
@@ -690,7 +690,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_for_exit_ms(server, 3000);
 			/* retry will check if exiting */
 			return false;
 		}
@@ -703,7 +703,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_for_exit_ms(server, 1000);
 			/* retry will check if exiting */
 			return false;
 		}
@@ -976,7 +976,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_for_exit_ms(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..197f39c23119 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_for_exit_ms(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


  parent reply	other threads:[~2026-12-04 13:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 13:33 [PATCH 0/12] smb: client: don't sleep through reconnects and umount Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 01/12] smb: client: don't add a decrypted mid back to an exiting server Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 02/12] smb: client: use kref for the TCP_Server_Info object references Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 03/12] smb: client: let in-flight requests hold a TCP_Server_Info reference Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 04/12] smb: client: let the decrypt offload work " Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 05/12] smb: client: let channels hold a reference of the primary server struct Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 06/12] smb: client: stop waiting between reconnect attempts once the server exits Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 07/12] smb: client: wait for pending mids instead of sleeping 46 seconds Stefan Metzmacher
2026-12-04 13:33 ` Stefan Metzmacher [this message]
2026-12-04 13:33 ` [PATCH v2 09/12] smb: client: use cifs_server_wait_for_exit_ms() for the replay back-off Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 10/12] smb: smbdirect: fail a connect from another address family Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 11/12] smb: client: let SMB Direct connections use the srcaddr= mount option Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 12/12] smb: client: soft mounts only wait until a reconnect attempt failed locally Stefan Metzmacher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2ea5cac93cf8ffbd523a4952eee83b420a80e96e.1796391093.git.metze@samba.org \
    --to=metze@samba.org \
    --cc=bharathsm@microsoft.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pc@manguebit.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=samba-technical@lists.samba.org \
    --cc=sprasad@microsoft.com \
    --cc=stable@vger.kernel.org \
    --cc=tom@talpey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®