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 2/5] smb: client: wait for pending mids instead of sleeping 46 seconds
Date: Tue, 1 Dec 2026 17:50:43 +0100 [thread overview]
Message-ID: <e339c8cb35afd070271bed3b47f323beb9f1078f.1796142565.git.metze@samba.org> (raw)
In-Reply-To: <cover.1796142565.git.metze@samba.org>
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
next prev parent reply other threads:[~2026-12-01 16:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=e339c8cb35afd070271bed3b47f323beb9f1078f.1796142565.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®