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 09/12] smb: client: use cifs_server_wait_for_exit_ms() for the replay back-off
Date: Fri, 4 Dec 2026 14:33:34 +0100 [thread overview]
Message-ID: <f46468f22d6414ab24e805894c008a40dacce83e.1796391093.git.metze@samba.org> (raw)
In-Reply-To: <cover.1796391093.git.metze@samba.org>
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_for_exit_ms() instead, so the back-off ends once the
server is exiting and the replay fails right away instead of
sleeping first.
The back-off of a write retry pass is shared by its subrequests, it is
only recorded in req->slept if it wasn't ended early, so the
subrequests on other channels still back off. The reopen in
cifs_reopen_file_retry() picks a channel of the session for each
attempt, so its back-off waits on the primary server of the session,
which exits together with the session, instead of the channel of the
subrequest.
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 | 20 +++++++++++++++-----
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, 38 insertions(+), 28 deletions(-)
diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c
index 50217f47a0ed..cde48aa13710 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_for_exit_ms(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..4863b7f8ddbb 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -188,7 +188,12 @@ static int cifs_reopen_file_retry(struct cifsFileInfo *cfile, bool can_flush,
}
if (!cifs_io_should_replay(subreq))
return rc;
- msleep(subreq->cur_sleep);
+ /*
+ * The reopen picks a channel of the session for each
+ * attempt, so wait on the primary server, which exits
+ * together with the session.
+ */
+ cifs_server_wait_for_exit_ms(ses->server, subreq->cur_sleep);
}
}
@@ -472,10 +477,15 @@ static void cifs_issue_write(struct netfs_io_subrequest *subreq)
container_of(subreq, struct cifs_io_subrequest, subreq);
struct cifs_io_request *req = wdata->req;
- if (wdata->cur_sleep > req->slept) {
- msleep(wdata->cur_sleep - req->slept);
+ /*
+ * Only record the back-off for the other subrequests of this
+ * pass if it really happened, not if it ended early, because
+ * the server of this subrequest is exiting.
+ */
+ if (wdata->cur_sleep > req->slept &&
+ !cifs_server_wait_for_exit_ms(wdata->server,
+ wdata->cur_sleep - req->slept))
req->slept = wdata->cur_sleep;
- }
if (unlikely(wdata->deferred || cifs_writeback_dying(subreq))) {
subreq->work.func = cifs_issue_write_worker;
@@ -647,7 +657,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_for_exit_ms(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..b26fb2b0f997 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_for_exit_ms(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..5e9a18b50ae2 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_for_exit_ms(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_for_exit_ms(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_for_exit_ms(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 0ba6345ed656..ab0b0baaa448 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -1362,7 +1362,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_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst[0]);
smb2_set_replay(server, &rqst[1]);
smb2_set_replay(server, &rqst[2]);
@@ -1781,7 +1781,7 @@ smb2_ioctl_query_info(const unsigned int xid,
if (retries) {
/* Back-off before retry */
if (cur_sleep)
- msleep(cur_sleep);
+ cifs_server_wait_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst[0]);
smb2_set_replay(server, &rqst[1]);
smb2_set_replay(server, &rqst[2]);
@@ -2674,7 +2674,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_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst[0]);
smb2_set_replay(server, &rqst[1]);
}
@@ -3081,7 +3081,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_for_exit_ms(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 8d6c11099f6a..4134705b3cbc 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_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst);
}
@@ -3425,7 +3425,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_for_exit_ms(server, cur_sleep);
if (oparms->replay)
smb2_set_replay(server, &rqst);
@@ -3690,7 +3690,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_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst);
}
@@ -3885,7 +3885,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_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst);
}
@@ -4096,7 +4096,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_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst);
}
@@ -4281,7 +4281,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_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst);
}
@@ -4623,7 +4623,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_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst);
}
@@ -5541,7 +5541,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_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst);
}
@@ -5932,7 +5932,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_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst);
}
@@ -6079,7 +6079,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_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst);
}
@@ -6212,7 +6212,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_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst);
}
@@ -6340,7 +6340,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_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst);
}
@@ -6425,7 +6425,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_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst);
}
@@ -6528,7 +6528,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_for_exit_ms(server, cur_sleep);
smb2_set_replay(server, &rqst);
}
--
2.43.0
next prev 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 ` [PATCH v2 08/12] smb: client: add cifs_server_wait_for_exit_ms() Stefan Metzmacher
2026-12-04 13:33 ` Stefan Metzmacher [this message]
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=f46468f22d6414ab24e805894c008a40dacce83e.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®