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 1/9] smb/client: factor out cifs_new_dir_fileinfo()
Date: Wed, 1 Jul 2026 08:24:59 +0000 [thread overview]
Message-ID: <20260701082507.786487-2-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.
Both readdir and notify can need directory private data before a
search handle exists. Move the common cifsFileInfo allocation and
initialization into a helper so those paths share the same setup.
Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
fs/smb/client/cifsproto.h | 2 ++
fs/smb/client/file.c | 24 ++++++++++++++++++++++++
fs/smb/client/readdir.c | 14 ++++++--------
3 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h
index c4ababcb51a3..dfbad6bc0a9b 100644
--- a/fs/smb/client/cifsproto.h
+++ b/fs/smb/client/cifsproto.h
@@ -267,6 +267,8 @@ void cifs_close_all_deferred_files(struct cifs_tcon *tcon);
void cifs_close_all_deferred_files_sb(struct cifs_sb_info *cifs_sb);
void cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon,
struct dentry *dentry);
+struct cifsFileInfo *cifs_new_dir_fileinfo(struct file *file,
+ struct tcon_link *tlink);
void cifs_mark_open_handles_for_deleted_file(struct inode *inode,
const char *path);
diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index 8b25d6c9ec5e..f1e854f381d9 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -660,6 +660,30 @@ cifs_down_write(struct rw_semaphore *sem)
static void cifsFileInfo_put_work(struct work_struct *work);
void serverclose_work(struct work_struct *work);
+struct cifsFileInfo *cifs_new_dir_fileinfo(struct file *file,
+ struct tcon_link *tlink)
+{
+ struct cifsFileInfo *cfile, *old;
+
+ cfile = kzalloc_obj(struct cifsFileInfo);
+ if (!cfile)
+ return NULL;
+
+ spin_lock_init(&cfile->file_info_lock);
+ mutex_init(&cfile->fh_mutex);
+ cfile->invalidHandle = true;
+ cfile->tlink = cifs_get_tlink(tlink);
+
+ old = cmpxchg(&file->private_data, NULL, cfile);
+ if (old) {
+ cifs_put_tlink(cfile->tlink);
+ kfree(cfile);
+ return old;
+ }
+
+ return cfile;
+}
+
struct cifsFileInfo *cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
struct tcon_link *tlink, __u32 oplock,
const char *symlink_target)
diff --git a/fs/smb/client/readdir.c b/fs/smb/client/readdir.c
index a50c86bbe60f..f108e719e683 100644
--- a/fs/smb/client/readdir.c
+++ b/fs/smb/client/readdir.c
@@ -355,20 +355,17 @@ _initiate_cifs_search(const unsigned int xid, struct file *file,
__u16 search_flags;
int rc = 0;
- if (file->private_data == NULL) {
+ if (!file->private_data) {
tlink = cifs_sb_tlink(cifs_sb);
if (IS_ERR(tlink))
return PTR_ERR(tlink);
- cifsFile = kzalloc_obj(struct cifsFileInfo);
- if (cifsFile == NULL) {
+ cifsFile = cifs_new_dir_fileinfo(file, tlink);
+ if (!cifsFile) {
rc = -ENOMEM;
goto error_exit;
}
- spin_lock_init(&cifsFile->file_info_lock);
- file->private_data = cifsFile;
- cifsFile->tlink = cifs_get_tlink(tlink);
- tcon = tlink_tcon(tlink);
+ tcon = tlink_tcon(cifsFile->tlink);
} else {
cifsFile = file->private_data;
tcon = tlink_tcon(cifsFile->tlink);
@@ -1125,7 +1122,8 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)
* Ensure FindFirst doesn't fail before doing filldir() for '.' and
* '..'. Otherwise we won't be able to notify VFS in case of failure.
*/
- if (file->private_data == NULL) {
+ cifsFile = file->private_data;
+ if (!cifsFile || cifsFile->invalidHandle) {
rc = initiate_cifs_search(xid, file, full_path);
cifs_dbg(FYI, "initiate cifs search rc %d\n", rc);
if (rc)
--
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 ` ChenXiaoSong [this message]
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 ` [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-2-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