From: ChenXiaoSong <chenxiaosong@chenxiaosong.com>
To: smfrench@gmail.com, linkinjeon@kernel.org, pc@manguebit.org,
ronniesahlberg@gmail.com, sprasad@microsoft.com, tom@talpey.com,
bharathsm@microsoft.com, senozhatsky@chromium.org,
dhowells@redhat.com, metze@samba.org
Cc: linux-cifs@vger.kernel.org, ChenXiaoSong <chenxiaosong@kylinos.cn>
Subject: [PATCH 5/9] smb/client: retry change notify after invalid cached handle
Date: Wed, 1 Jul 2026 08:25:03 +0000 [thread overview]
Message-ID: <20260701082507.786487-6-chenxiaosong@chenxiaosong.com> (raw)
In-Reply-To: <20260701082507.786487-1-chenxiaosong@chenxiaosong.com>
From: ChenXiaoSong <chenxiaosong@kylinos.cn>
The notify ioctl caches a separate FID in cifsFileInfo. That
handle is not reopened by cifs_reopen_file(), so it can become
stale across reconnects. If the server returns STATUS_INVALID_HANDLE
for the cached FID, SMB2_change_notify() maps it to -EBADF, but
smb3_notify() kept reusing the bad handle.
Invalidate the cached notify FID on -EBADF and retry once so the
next attempt opens a fresh handle. Clear only if the cached FID
still matches the failed one to avoid racing with another thread
that reopened it.
Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
fs/smb/client/smb2ops.c | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
index d6a33acc62ff..9c2455b5fb03 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -2365,7 +2365,21 @@ smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
return rc;
}
-
+static void
+smb3_notify_invalidate_fid(struct cifsFileInfo *cfile,
+ const struct cifs_fid *fid)
+{
+ mutex_lock(&cfile->notify_fid_mutex);
+ if (cfile->has_notify_fid &&
+ cfile->notify_fid.persistent_fid == fid->persistent_fid &&
+ cfile->notify_fid.volatile_fid == fid->volatile_fid) {
+ cfile->has_notify_fid = false;
+ memset(&cfile->notify_fid, 0, sizeof(cfile->notify_fid));
+ cifs_put_tlink(cfile->notify_tlink);
+ cfile->notify_tlink = NULL;
+ }
+ mutex_unlock(&cfile->notify_fid_mutex);
+}
static int
smb3_notify(const unsigned int xid, struct file *pfile,
@@ -2388,6 +2402,7 @@ smb3_notify(const unsigned int xid, struct file *pfile,
u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
int rc = 0;
__u32 ret_len = 0;
+ bool retry = false;
if (return_changes) {
if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify_info))) {
@@ -2418,6 +2433,7 @@ smb3_notify(const unsigned int xid, struct file *pfile,
cfile = pfile->private_data;
}
+retry_notify:
mutex_lock(&cfile->notify_fid_mutex);
if (!cfile->has_notify_fid) {
page = alloc_dentry_path();
@@ -2468,7 +2484,23 @@ smb3_notify(const unsigned int xid, struct file *pfile,
rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
notify.watch_tree, notify.completion_filter,
notify.data_len, &returned_ioctl_info, &ret_len);
-
+ if (rc == -EBADF) {
+ smb3_notify_invalidate_fid(cfile, &fid);
+ if (retry)
+ goto notify_done;
+
+ kfree(returned_ioctl_info);
+ returned_ioctl_info = NULL;
+ free_dentry_path(page);
+ page = NULL;
+ kfree(utf16_path);
+ utf16_path = NULL;
+ ret_len = 0;
+ retry = true;
+ goto retry_notify;
+ }
+
+notify_done:
cifs_dbg(FYI, "change notify for %pd rc %d\n", dentry, rc);
if (return_changes && (ret_len > 0) && (notify.data_len > 0)) {
if (ret_len > notify.data_len)
--
2.54.0
next prev parent reply other threads:[~2026-07-01 8:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-01 8:24 [PATCH 0/9] smb/client: improve change notify support ChenXiaoSong
2026-07-01 8:24 ` [PATCH 1/9] smb/client: factor out cifs_new_dir_fileinfo() ChenXiaoSong
2026-07-01 8:25 ` [PATCH 2/9] smb/client: close cached notify handles on closedir ChenXiaoSong
2026-07-01 8:25 ` [PATCH 3/9] smb/client: prepare notify ioctl per-open state ChenXiaoSong
2026-07-01 8:25 ` [PATCH 4/9] smb/client: cache SMB3 change notify handles ChenXiaoSong
2026-07-01 8:25 ` ChenXiaoSong [this message]
2026-07-01 8:25 ` [PATCH 6/9] smb/client: add helpers for sending cancel requests ChenXiaoSong
2026-07-01 8:25 ` [PATCH 7/9] smb/client: remember async ids from SMB2 pending responses ChenXiaoSong
2026-07-01 8:25 ` [PATCH 8/9] smb/client: send SMB2 cancel requests ChenXiaoSong
2026-07-01 8:25 ` [PATCH 9/9] smb/client: make SMB2 change notify interruptible ChenXiaoSong
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=20260701082507.786487-6-chenxiaosong@chenxiaosong.com \
--to=chenxiaosong@chenxiaosong.com \
--cc=bharathsm@microsoft.com \
--cc=chenxiaosong@kylinos.cn \
--cc=dhowells@redhat.com \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=metze@samba.org \
--cc=pc@manguebit.org \
--cc=ronniesahlberg@gmail.com \
--cc=senozhatsky@chromium.org \
--cc=smfrench@gmail.com \
--cc=sprasad@microsoft.com \
--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