diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index ec1679ad4a87..3a0263df104b 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -2648,11 +2648,8 @@ cifs_rename2(struct mnt_idmap *idmap, struct inode *source_dir, if (d_really_is_positive(target_dentry)) { if (!rc) { struct inode *inode = d_inode(target_dentry); - /* - * Samba and ksmbd servers allow renaming a target - * directory that is open, so make sure to update - * ->i_nlink and then mark it as delete pending. - */ + + /* Update the target link count after rename. */ if (S_ISDIR(inode->i_mode)) { drop_cached_dir_by_name(xid, tcon, to_name, cifs_sb); spin_lock(&inode->i_lock); @@ -2663,6 +2660,10 @@ cifs_rename2(struct mnt_idmap *idmap, struct inode *source_dir, CIFS_I(inode)->time = 0; /* force reval */ inode_set_ctime_current(inode); inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode)); + } else { + cifs_mark_open_handles_for_deleted_file(inode, to_name); + cifs_drop_nlink(inode); + inode_set_ctime_current(inode); } } else if (rc == -EACCES || rc == -EEXIST) { /*