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 2/9] smb/client: close cached notify handles on closedir
Date: Wed, 1 Jul 2026 08:25:00 +0000 [thread overview]
Message-ID: <20260701082507.786487-3-chenxiaosong@chenxiaosong.com> (raw)
In-Reply-To: <20260701082507.786487-1-chenxiaosong@chenxiaosong.com>
From: ChenXiaoSong <chenxiaosong@kylinos.cn>
This patch was split out to make it easier to review.
Add storage for a change-notify FID in cifsFileInfo and close it from
the directory release path. This gives notify users a per-open lifetime
for the extra handle without changing how smb3_notify opens it yet.
Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
fs/smb/client/cifsglob.h | 4 ++++
fs/smb/client/file.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h
index 99f9e6dca62b..1250518997fb 100644
--- a/fs/smb/client/cifsglob.h
+++ b/fs/smb/client/cifsglob.h
@@ -1459,6 +1459,10 @@ struct cifsFileInfo {
int count;
spinlock_t file_info_lock; /* protects four flag/count fields above */
struct mutex fh_mutex; /* prevents reopen race after dead ses*/
+ struct mutex notify_fid_mutex;
+ struct cifs_fid notify_fid;
+ struct tcon_link *notify_tlink;
+ bool has_notify_fid:1;
struct cifs_search_info srch_inf;
struct work_struct oplock_break; /* work for oplock breaks */
struct work_struct put; /* work for the final part of _put */
diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index f1e854f381d9..6cb4068fe06e 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -671,6 +671,7 @@ struct cifsFileInfo *cifs_new_dir_fileinfo(struct file *file,
spin_lock_init(&cfile->file_info_lock);
mutex_init(&cfile->fh_mutex);
+ mutex_init(&cfile->notify_fid_mutex);
cfile->invalidHandle = true;
cfile->tlink = cifs_get_tlink(tlink);
@@ -733,6 +734,7 @@ struct cifsFileInfo *cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
INIT_WORK(&cfile->serverclose, serverclose_work);
INIT_DELAYED_WORK(&cfile->deferred, smb2_deferred_work_close);
mutex_init(&cfile->fh_mutex);
+ mutex_init(&cfile->notify_fid_mutex);
spin_lock_init(&cfile->file_info_lock);
/*
@@ -1548,6 +1550,32 @@ cifs_reopen_persistent_handles(struct cifs_tcon *tcon)
}
}
+static void cifs_close_notify_fid(unsigned int xid, struct cifsFileInfo *cfile)
+{
+ struct cifs_tcon *tcon;
+ struct TCP_Server_Info *server;
+ int rc = 0;
+
+ mutex_lock(&cfile->notify_fid_mutex);
+ if (!cfile->has_notify_fid)
+ goto unlock;
+
+ tcon = tlink_tcon(cfile->notify_tlink);
+ server = tcon->ses->server;
+ if (server->ops->close_dir)
+ rc = server->ops->close_dir(xid, tcon, &cfile->notify_fid);
+ else if (server->ops->close)
+ rc = server->ops->close(xid, tcon, &cfile->notify_fid);
+
+ cifs_dbg(FYI, "Closing cached notify handle with rc %d\n", rc);
+ cfile->has_notify_fid = false;
+ cifs_put_tlink(cfile->notify_tlink);
+ cfile->notify_tlink = NULL;
+
+unlock:
+ mutex_unlock(&cfile->notify_fid_mutex);
+}
+
int cifs_closedir(struct inode *inode, struct file *file)
{
int rc = 0;
@@ -1567,6 +1595,8 @@ int cifs_closedir(struct inode *inode, struct file *file)
server = tcon->ses->server;
cifs_dbg(FYI, "Freeing private data in close dir\n");
+ cifs_close_notify_fid(xid, cfile);
+
spin_lock(&cfile->file_info_lock);
if (server->ops->dir_needs_close(cfile)) {
cfile->invalidHandle = true;
--
2.54.0
next prev parent reply other threads:[~2026-07-01 8:25 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 ` ChenXiaoSong [this message]
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 ` [PATCH 5/9] smb/client: retry change notify after invalid cached handle ChenXiaoSong
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-3-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