smb/server: promote S_DEL_ON_CLS to S_DEL_PENDING when close
Subsystems (2)
[email protected]
reviewerPATCH 1/1 smb/server: promote S_DEL_ON_CLS to S_DEL_PENDING when close
From: ChenXiaoSong <[email protected]>
Reproducer:
1. server: systemctl start ksmbd
2. client: mount -t cifs //${server_ip}/export /mnt
3. client: C program: openat(AT_FDCWD, "/mnt", O_RDWR | O_TMPFILE, 0600)
Do not treat FILE_DELETE_ON_CLOSE_LE as delete pending while files remain open.
This patch fixes xfstests generic/004.
--- fs/smb/server/vfs_cache.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
fs/smb/server/vfs_cache.c +12 -4
@@ -211,7 +211,7 @@ int ksmbd_query_inode_status(struct dentry *dentry)return ret;down_read (&ci->m_lock); -if (ci->m_flags & (S_DEL_PENDING |S_DEL_ON_CLS )) +if (ci->m_flags &S_DEL_PENDING ) ret =KSMBD_INODE_STATUS_PENDING_DELETE ;else ret =KSMBD_INODE_STATUS_OK ;
@@ -227,7 +227,7 @@ bool ksmbd_inode_pending_delete(struct ksmbd_file *fp)int ret;down_read (&ci->m_lock); - ret = (ci->m_flags & (S_DEL_PENDING |S_DEL_ON_CLS )); + ret = (ci->m_flags &S_DEL_PENDING );up_read (&ci->m_lock);return ret;
@@ -395,12 +395,20 @@ static void __ksmbd_inode_close(struct ksmbd_file *fp) } } +down_write (&ci->m_lock); +/* Promote S_DEL_ON_CLS to S_DEL_PENDING when close */ +if (ci->m_flags &S_DEL_ON_CLS ) { + ci->m_flags &= ~S_DEL_ON_CLS ; + ci->m_flags |=S_DEL_PENDING ; + } +up_write (&ci->m_lock); +if (atomic_dec_and_test (&ci->m_count)) {bool do_unlink = false;down_write (&ci->m_lock); -if (ci->m_flags & (S_DEL_ON_CLS |S_DEL_PENDING )) { - ci->m_flags &= ~(S_DEL_ON_CLS |S_DEL_PENDING ); +if (ci->m_flags &S_DEL_PENDING ) { + ci->m_flags &= ~S_DEL_PENDING ; do_unlink = true; }up_write (&ci->m_lock);
Signature · 1 line
2.54.0
Good job, your fix worked when I tried it
You can add tested-by if you want
Quoted 70 lines · On Mon, May 18, 2026 at 10:24 AM <[email protected]> wrote:
From: ChenXiaoSong <[email protected]>
Reproducer:
1. server: systemctl start ksmbd
2. client: mount -t cifs //${server_ip}/export /mnt
3. client: C program:openat(AT_FDCWD, "/mnt", O_RDWR | O_TMPFILE, 0600)Do not treat
FILE_DELETE_ON_CLOSE_LEas delete pending while files remain open.This patch fixes xfstests generic/004.
Co-developed-by Huiwen He <[email protected]>Signed-off-by Huiwen He <[email protected]>Signed-off-by ChenXiaoSong <[email protected]>--- fs/smb/server/vfs_cache.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)fs/smb/server/vfs_cache.c +12
-5@@ -211,7 +211,7 @@ int ksmbd_query_inode_status(struct dentry *dentry)return ret;down_read (&ci->m_lock); -if (ci->m_flags & (S_DEL_PENDING |S_DEL_ON_CLS )) +if (ci->m_flags &S_DEL_PENDING ) ret =KSMBD_INODE_STATUS_PENDING_DELETE ;else ret =KSMBD_INODE_STATUS_OK ;@@ -227,7 +227,7 @@ bool ksmbd_inode_pending_delete(struct ksmbd_file *fp)int ret;down_read (&ci->m_lock); - ret = (ci->m_flags & (S_DEL_PENDING |S_DEL_ON_CLS )); + ret = (ci->m_flags &S_DEL_PENDING );up_read (&ci->m_lock);return ret;@@ -395,12 +395,20 @@ static void __ksmbd_inode_close(struct ksmbd_file *fp) } } +down_write (&ci->m_lock); +/* Promote S_DEL_ON_CLS to S_DEL_PENDING when close */ +if (ci->m_flags &S_DEL_ON_CLS ) { + ci->m_flags &= ~S_DEL_ON_CLS ; + ci->m_flags |=S_DEL_PENDING ; + } +up_write (&ci->m_lock); +if (atomic_dec_and_test (&ci->m_count)) {bool do_unlink = false;down_write (&ci->m_lock); -if (ci->m_flags & (S_DEL_ON_CLS |S_DEL_PENDING )) { - ci->m_flags &= ~(S_DEL_ON_CLS |S_DEL_PENDING ); +if (ci->m_flags &S_DEL_PENDING ) { + ci->m_flags &= ~S_DEL_PENDING ; do_unlink = true; }up_write (&ci->m_lock); --2.54.0
Signature · 3 lines
Thanks, Steve
Namjae Jeon
maintainerfs/smb/server/vfs_cache.c static void __ksmbd_inode_close(struct ksmbd_file *fp) · line 405
Quoted 8 lines
fs/smb/server/vfs_cache.c +8
-0+down_write (&ci->m_lock); +/* Promote S_DEL_ON_CLS to S_DEL_PENDING when close */ +if (ci->m_flags &S_DEL_ON_CLS ) { + ci->m_flags &= ~S_DEL_ON_CLS ; + ci->m_flags |=S_DEL_PENDING ; + } +up_write (&ci->m_lock); +
Why do we need to promote S_DEL_ON_CLS to S_DEL_PENDING here?
ChenXiaoSong
reviewerS_DEL_ON_CLS flag only triggers deletion when the file is closed.
I also checked the Samba implementation, S_DEL_ON_CLS corresponds to Samba's initial_delete_on_close, and S_DEL_PENDING corresponds to Samba's delete_on_close. Samba promotes initial_delete_on_close to delete_on_close in close_share_mode_lock_prepare().
If my understanding is incorrect, please let me know.
Quoted 9 lines · Namjae Jeon
fs/smb/server/vfs_cache.c static void __ksmbd_inode_close(struct ksmbd_file *fp) · line 405
Quoted 8 lines
fs/smb/server/vfs_cache.c +8
-0+down_write (&ci->m_lock); +/* Promote S_DEL_ON_CLS to S_DEL_PENDING when close */ +if (ci->m_flags &S_DEL_ON_CLS ) { + ci->m_flags &= ~S_DEL_ON_CLS ; + ci->m_flags |=S_DEL_PENDING ; + } +up_write (&ci->m_lock); +Why do we need to promote
S_DEL_ON_CLStoS_DEL_PENDINGhere?
Quoted 12 lines · On Tue, May 19, 2026 at 12:24 AM <[email protected]> wrote:
From: ChenXiaoSong <[email protected]>
Reproducer:
1. server: systemctl start ksmbd
2. client: mount -t cifs //${server_ip}/export /mnt
3. client: C program:openat(AT_FDCWD, "/mnt", O_RDWR | O_TMPFILE, 0600)Do not treat
FILE_DELETE_ON_CLOSE_LEas delete pending while files remain open.
Quoted 6 lines
This patch fixes xfstests generic/004.
Co-developed-by Huiwen He <[email protected]>Signed-off-by Huiwen He <[email protected]>Signed-off-by ChenXiaoSong <[email protected]>
Applied it to #ksmbd-for-next-next.
Thanks!