Skip to contentSkip to conversation

smb: client: fix filename matching of deferred files

PATCH In review Paulo Alcantara 3 participants 4 messages Sep 17, 2025 – Sep 18, 2025

Subsystems (2)
lore
Share & tools
lore

Paulo Alcantara

author maintainer
#0 lore raw

PATCH v2 1/1 smb: client: fix filename matching of deferred files

Fix the following case where the client would end up closing both deferred files (foo.tmp & foo) after unlink(foo) due to strstr() call in cifs_close_deferred_file_under_dentry():

  fd1 = openat(AT_FDCWD, "foo", O_WRONLY|O_CREAT|O_TRUNC, 0666);
  fd2 = openat(AT_FDCWD, "foo.tmp", O_WRONLY|O_CREAT|O_TRUNC, 0666);
  close(fd1);
  close(fd2);
  unlink("foo");
Fixes e3fc065682eb ("cifs: Deferred close performance improvements")
Cc Enzo Matsumiya <[email protected]>
Cc Frank Sorenson <[email protected]>
Cc David Howells <[email protected]>
---
 fs/smb/client/cifsproto.h |  4 ++--
 fs/smb/client/inode.c     |  6 +++---
 fs/smb/client/misc.c      | 36 +++++++++++++++---------------------
 3 files changed, 20 insertions(+), 26 deletions(-)
fs/smb/client/cifsproto.h +2 -2
index c34c533b2efa..e8fba98690ce 100644
@@ -312,8 +312,8 @@ extern void cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode);
 
 extern void cifs_close_all_deferred_files(struct cifs_tcon *cifs_tcon);
 
-extern void cifs_close_deferred_file_under_dentry(struct cifs_tcon *cifs_tcon,
-				const char *path);
+void cifs_close_deferred_file_under_dentry(struct cifs_tcon *cifs_tcon,
+					   struct dentry *dentry);
 
 extern void cifs_mark_open_handles_for_deleted_file(struct inode *inode,
 				const char *path);
fs/smb/client/inode.c +3 -3
index 11d442e8b3d6..1703f1285d36 100644
@@ -1984,7 +1984,7 @@ static int __cifs_unlink(struct inode *dir, struct dentry *dentry, bool sillyren
 	}
 
 	netfs_wait_for_outstanding_io(inode);
-	cifs_close_deferred_file_under_dentry(tcon, full_path);
+	cifs_close_deferred_file_under_dentry(tcon, dentry);
 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
 	if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP &
 				le64_to_cpu(tcon->fsUnixInfo.Capability))) {
@@ -2538,10 +2538,10 @@ cifs_rename2(struct mnt_idmap *idmap, struct inode *source_dir,
 		goto cifs_rename_exit;
 	}
 
-	cifs_close_deferred_file_under_dentry(tcon, from_name);
+	cifs_close_deferred_file_under_dentry(tcon, source_dentry);
 	if (d_inode(target_dentry) != NULL) {
 		netfs_wait_for_outstanding_io(d_inode(target_dentry));
-		cifs_close_deferred_file_under_dentry(tcon, to_name);
+		cifs_close_deferred_file_under_dentry(tcon, target_dentry);
 	}
 
 	rc = cifs_do_rename(xid, source_dentry, from_name, target_dentry,
fs/smb/client/misc.c +15 -21
index da23cc12a52c..350542d57249 100644
@@ -832,33 +832,28 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon)
 		kfree(tmp_list);
 	}
 }
-void
-cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)
+
+void cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon,
+					   struct dentry *dentry)
 {
-	struct cifsFileInfo *cfile;
 	struct file_list *tmp_list, *tmp_next_list;
-	void *page;
-	const char *full_path;
+	struct cifsFileInfo *cfile;
 	LIST_HEAD(file_head);
 
-	page = alloc_dentry_path();
 	spin_lock(&tcon->open_file_lock);
 	list_for_each_entry(cfile, &tcon->openFileList, tlist) {
-		full_path = build_path_from_dentry(cfile->dentry, page);
-		if (strstr(full_path, path)) {
-			if (delayed_work_pending(&cfile->deferred)) {
-				if (cancel_delayed_work(&cfile->deferred)) {
-					spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
-					cifs_del_deferred_close(cfile);
-					spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
+		if (cfile->dentry == dentry &&
+		    delayed_work_pending(&cfile->deferred) &&
+		    cancel_delayed_work(&cfile->deferred)) {
+			spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
+			cifs_del_deferred_close(cfile);
+			spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
 
-					tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC);
-					if (tmp_list == NULL)
-						break;
-					tmp_list->cfile = cfile;
-					list_add_tail(&tmp_list->list, &file_head);
-				}
-			}
+			tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC);
+			if (tmp_list == NULL)
+				break;
+			tmp_list->cfile = cfile;
+			list_add_tail(&tmp_list->list, &file_head);
 		}
 	}
 	spin_unlock(&tcon->open_file_lock);
@@ -868,7 +863,6 @@ cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)
 		list_del(&tmp_list->list);
 		kfree(tmp_list);
 	}
-	free_dentry_path(page);
 }
 
 /*
Signature · 1 line
2.51.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 117 lines · Paulo Alcantara

Fix the following case where the client would end up closing both deferred files (foo.tmp & foo) after unlink(foo) due to strstr() call in cifs_close_deferred_file_under_dentry():

fd1 = openat(AT_FDCWD, "foo", O_WRONLY|O_CREAT|O_TRUNC, 0666); fd2 = openat(AT_FDCWD, "foo.tmp", O_WRONLY|O_CREAT|O_TRUNC, 0666); close(fd1);
close(fd2);
unlink("foo");

Fixes e3fc065682eb ("cifs: Deferred close performance improvements")
Cc Enzo Matsumiya <[email protected]>
Cc Frank Sorenson <[email protected]>
Cc David Howells <[email protected]>

---

fs/smb/client/cifsproto.h |  4 ++--
fs/smb/client/inode.c     |  6 +++---
fs/smb/client/misc.c      | 36 +++++++++++++++---------------------
3 files changed, 20 insertions(+), 26 deletions(-)
fs/smb/client/cifsproto.h +2 -2
index c34c533b2efa..e8fba98690ce 100644
@@ -312,8 +312,8 @@ extern void cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode);
 
 extern void cifs_close_all_deferred_files(struct cifs_tcon *cifs_tcon);
 
-extern void cifs_close_deferred_file_under_dentry(struct cifs_tcon *cifs_tcon,
-				const char *path);
+void cifs_close_deferred_file_under_dentry(struct cifs_tcon *cifs_tcon,
+					   struct dentry *dentry);
 
 extern void cifs_mark_open_handles_for_deleted_file(struct inode *inode,
 				const char *path);
fs/smb/client/inode.c +3 -3
index 11d442e8b3d6..1703f1285d36 100644
@@ -1984,7 +1984,7 @@ static int __cifs_unlink(struct inode *dir, struct dentry *dentry, bool sillyren
 	}
 
 	netfs_wait_for_outstanding_io(inode);
-	cifs_close_deferred_file_under_dentry(tcon, full_path);
+	cifs_close_deferred_file_under_dentry(tcon, dentry);
 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
 	if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP &
 				le64_to_cpu(tcon->fsUnixInfo.Capability))) {
@@ -2538,10 +2538,10 @@ cifs_rename2(struct mnt_idmap *idmap, struct inode *source_dir,
 		goto cifs_rename_exit;
 	}
 
-	cifs_close_deferred_file_under_dentry(tcon, from_name);
+	cifs_close_deferred_file_under_dentry(tcon, source_dentry);
 	if (d_inode(target_dentry) != NULL) {
 		netfs_wait_for_outstanding_io(d_inode(target_dentry));
-		cifs_close_deferred_file_under_dentry(tcon, to_name);
+		cifs_close_deferred_file_under_dentry(tcon, target_dentry);
 	}
 
 	rc = cifs_do_rename(xid, source_dentry, from_name, target_dentry,
fs/smb/client/misc.c +15 -20
index da23cc12a52c..350542d57249 100644
@@ -832,33 +832,28 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon)
 		kfree(tmp_list);
 	}
 }
-void
-cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)
+
+void cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon,
+					   struct dentry *dentry)
 {
-	struct cifsFileInfo *cfile;
 	struct file_list *tmp_list, *tmp_next_list;
-	void *page;
-	const char *full_path;
+	struct cifsFileInfo *cfile;
 	LIST_HEAD(file_head);
 
-	page = alloc_dentry_path();
 	spin_lock(&tcon->open_file_lock);
 	list_for_each_entry(cfile, &tcon->openFileList, tlist) {
-		full_path = build_path_from_dentry(cfile->dentry, page);
-		if (strstr(full_path, path)) {
-			if (delayed_work_pending(&cfile->deferred)) {
-				if (cancel_delayed_work(&cfile->deferred)) {
-					spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
-					cifs_del_deferred_close(cfile);
-					spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
+		if (cfile->dentry == dentry &&
+		    delayed_work_pending(&cfile->deferred) &&
+		    cancel_delayed_work(&cfile->deferred)) {
+			spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
+			cifs_del_deferred_close(cfile);
+			spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
 
-					tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC);
-					if (tmp_list == NULL)
-						break;
-					tmp_list->cfile = cfile;
-					list_add_tail(&tmp_list->list, &file_head);
-				}
-			}
+			tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC);
+			if (tmp_list == NULL)
+				break;
+			tmp_list->cfile = cfile;
+			list_add_tail(&tmp_list->list, &file_head);
 		}
 	}
 	spin_unlock(&tcon->open_file_lock);

fs/smb/client/misc.c cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path) · line 868

Quoted 7 lines
fs/smb/client/misc.c +0 -1
@@ -868,7 +863,6 @@ cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)
 		list_del(&tmp_list->list);
 		kfree(tmp_list);
 	}
-	free_dentry_path(page);
 }
 
 /*

Cheers,

Enzo

Reviewed-by Enzo Matsumiya
#2 lore raw

minor cosmetic change done to the patch (see attached)

from:
if (cfile->dentry == dentry &&
to:
if ((cfile->dentry == dentry) &&

Quoted 133 lines · Enzo Matsumiya
Quoted 117 lines · Paulo Alcantara

Fix the following case where the client would end up closing both deferred files (foo.tmp & foo) after unlink(foo) due to strstr() call in cifs_close_deferred_file_under_dentry():

fd1 = openat(AT_FDCWD, "foo", O_WRONLY|O_CREAT|O_TRUNC, 0666); fd2 = openat(AT_FDCWD, "foo.tmp", O_WRONLY|O_CREAT|O_TRUNC, 0666); close(fd1);
close(fd2);
unlink("foo");

Fixes e3fc065682eb ("cifs: Deferred close performance improvements")
Cc Enzo Matsumiya <[email protected]>
Cc Frank Sorenson <[email protected]>
Cc David Howells <[email protected]>

---

fs/smb/client/cifsproto.h |  4 ++--
fs/smb/client/inode.c     |  6 +++---
fs/smb/client/misc.c      | 36 +++++++++++++++---------------------
3 files changed, 20 insertions(+), 26 deletions(-)
fs/smb/client/cifsproto.h +2 -2
index c34c533b2efa..e8fba98690ce 100644
@@ -312,8 +312,8 @@ extern void cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode);
 
 extern void cifs_close_all_deferred_files(struct cifs_tcon *cifs_tcon);
 
-extern void cifs_close_deferred_file_under_dentry(struct cifs_tcon *cifs_tcon,
-                              const char *path);
+void cifs_close_deferred_file_under_dentry(struct cifs_tcon *cifs_tcon,
+                                         struct dentry *dentry);
 
 extern void cifs_mark_open_handles_for_deleted_file(struct inode *inode,
                              const char *path);
fs/smb/client/inode.c +3 -3
index 11d442e8b3d6..1703f1285d36 100644
@@ -1984,7 +1984,7 @@ static int __cifs_unlink(struct inode *dir, struct dentry *dentry, bool sillyren
      }
 
      netfs_wait_for_outstanding_io(inode);
-      cifs_close_deferred_file_under_dentry(tcon, full_path);
+      cifs_close_deferred_file_under_dentry(tcon, dentry);
 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
      if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP &
                              le64_to_cpu(tcon->fsUnixInfo.Capability))) {
@@ -2538,10 +2538,10 @@ cifs_rename2(struct mnt_idmap *idmap, struct inode *source_dir,
              goto cifs_rename_exit;
      }
 
-      cifs_close_deferred_file_under_dentry(tcon, from_name);
+      cifs_close_deferred_file_under_dentry(tcon, source_dentry);
      if (d_inode(target_dentry) != NULL) {
              netfs_wait_for_outstanding_io(d_inode(target_dentry));
-              cifs_close_deferred_file_under_dentry(tcon, to_name);
+              cifs_close_deferred_file_under_dentry(tcon, target_dentry);
      }
 
      rc = cifs_do_rename(xid, source_dentry, from_name, target_dentry,
fs/smb/client/misc.c +15 -20
index da23cc12a52c..350542d57249 100644
@@ -832,33 +832,28 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon)
              kfree(tmp_list);
      }
 }
-void
-cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)
+
+void cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon,
+                                         struct dentry *dentry)
 {
-      struct cifsFileInfo *cfile;
      struct file_list *tmp_list, *tmp_next_list;
-      void *page;
-      const char *full_path;
+      struct cifsFileInfo *cfile;
      LIST_HEAD(file_head);
 
-      page = alloc_dentry_path();
      spin_lock(&tcon->open_file_lock);
      list_for_each_entry(cfile, &tcon->openFileList, tlist) {
-              full_path = build_path_from_dentry(cfile->dentry, page);
-              if (strstr(full_path, path)) {
-                      if (delayed_work_pending(&cfile->deferred)) {
-                              if (cancel_delayed_work(&cfile->deferred)) {
-                                      spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
-                                      cifs_del_deferred_close(cfile);
-                                      spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
+              if (cfile->dentry == dentry &&
+                  delayed_work_pending(&cfile->deferred) &&
+                  cancel_delayed_work(&cfile->deferred)) {
+                      spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
+                      cifs_del_deferred_close(cfile);
+                      spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
 
-                                      tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC);
-                                      if (tmp_list == NULL)
-                                              break;
-                                      tmp_list->cfile = cfile;
-                                      list_add_tail(&tmp_list->list, &file_head);
-                              }
-                      }
+                      tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC);
+                      if (tmp_list == NULL)
+                              break;
+                      tmp_list->cfile = cfile;
+                      list_add_tail(&tmp_list->list, &file_head);
              }
      }
      spin_unlock(&tcon->open_file_lock);

fs/smb/client/misc.c cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path) · line 868

Quoted 7 lines
fs/smb/client/misc.c +0 -1
@@ -868,7 +863,6 @@ cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)
              list_del(&tmp_list->list);
              kfree(tmp_list);
      }
-      free_dentry_path(page);
 }
 
 /*

Cheers,

Enzo

Signature · 3 lines
Thanks,

Steve

From 40cdd5b1c8c11342467dcb392e3c860d2f4eefe7 Mon Sep 17 00:00:00 2001
From: Paulo Alcantara <[email protected]>
Date: Wed, 17 Sep 2025 16:03:22 -0300
Subject: [PATCH 2/8] smb: client: fix filename matching of deferred files

Fix the following case where the client would end up closing both deferred files (foo.tmp & foo) after unlink(foo) due to strstr() call in cifs_close_deferred_file_under_dentry():

  fd1 = openat(AT_FDCWD, "foo", O_WRONLY|O_CREAT|O_TRUNC, 0666);
  fd2 = openat(AT_FDCWD, "foo.tmp", O_WRONLY|O_CREAT|O_TRUNC, 0666);
  close(fd1);
  close(fd2);
  unlink("foo");
Fixes e3fc065682eb ("cifs: Deferred close performance improvements")
Cc Frank Sorenson <[email protected]>
Cc David Howells <[email protected]>
---
 fs/smb/client/cifsproto.h |  4 ++--
 fs/smb/client/inode.c     |  6 +++---
 fs/smb/client/misc.c      | 38 ++++++++++++++++----------------------
 3 files changed, 21 insertions(+), 27 deletions(-)
fs/smb/client/cifsproto.h +2 -2
index c34c533b2efa..e8fba98690ce 100644
@@ -312,8 +312,8 @@ extern void cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode);
 
 extern void cifs_close_all_deferred_files(struct cifs_tcon *cifs_tcon);
 
-extern void cifs_close_deferred_file_under_dentry(struct cifs_tcon *cifs_tcon,
-				const char *path);
+void cifs_close_deferred_file_under_dentry(struct cifs_tcon *cifs_tcon,
+					   struct dentry *dentry);
 
 extern void cifs_mark_open_handles_for_deleted_file(struct inode *inode,
 				const char *path);
fs/smb/client/inode.c +3 -3
index 11d442e8b3d6..1703f1285d36 100644
@@ -1984,7 +1984,7 @@ static int __cifs_unlink(struct inode *dir, struct dentry *dentry, bool sillyren
 	}
 
 	netfs_wait_for_outstanding_io(inode);
-	cifs_close_deferred_file_under_dentry(tcon, full_path);
+	cifs_close_deferred_file_under_dentry(tcon, dentry);
 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
 	if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP &
 				le64_to_cpu(tcon->fsUnixInfo.Capability))) {
@@ -2538,10 +2538,10 @@ cifs_rename2(struct mnt_idmap *idmap, struct inode *source_dir,
 		goto cifs_rename_exit;
 	}
 
-	cifs_close_deferred_file_under_dentry(tcon, from_name);
+	cifs_close_deferred_file_under_dentry(tcon, source_dentry);
 	if (d_inode(target_dentry) != NULL) {
 		netfs_wait_for_outstanding_io(d_inode(target_dentry));
-		cifs_close_deferred_file_under_dentry(tcon, to_name);
+		cifs_close_deferred_file_under_dentry(tcon, target_dentry);
 	}
 
 	rc = cifs_do_rename(xid, source_dentry, from_name, target_dentry,
fs/smb/client/misc.c +16 -22
index da23cc12a52c..350542d57249 100644
@@ -832,33 +832,28 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon)
 		kfree(tmp_list);
 	}
 }
-void
-cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)
+
+void cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon,
+					   struct dentry *dentry)
 {
-	struct cifsFileInfo *cfile;
 	struct file_list *tmp_list, *tmp_next_list;
-	void *page;
-	const char *full_path;
+	struct cifsFileInfo *cfile;
 	LIST_HEAD(file_head);
 
-	page = alloc_dentry_path();
 	spin_lock(&tcon->open_file_lock);
 	list_for_each_entry(cfile, &tcon->openFileList, tlist) {
-		full_path = build_path_from_dentry(cfile->dentry, page);
-		if (strstr(full_path, path)) {
-			if (delayed_work_pending(&cfile->deferred)) {
-				if (cancel_delayed_work(&cfile->deferred)) {
-					spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
-					cifs_del_deferred_close(cfile);
-					spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
-
-					tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC);
-					if (tmp_list == NULL)
-						break;
-					tmp_list->cfile = cfile;
-					list_add_tail(&tmp_list->list, &file_head);
-				}
-			}
+		if ((cfile->dentry == dentry) &&
+		    delayed_work_pending(&cfile->deferred) &&
+		    cancel_delayed_work(&cfile->deferred)) {
+			spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
+			cifs_del_deferred_close(cfile);
+			spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
+
+			tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC);
+			if (tmp_list == NULL)
+				break;
+			tmp_list->cfile = cfile;
+			list_add_tail(&tmp_list->list, &file_head);
 		}
 	}
 	spin_unlock(&tcon->open_file_lock);
@@ -868,7 +863,6 @@ cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)
 		list_del(&tmp_list->list);
 		kfree(tmp_list);
 	}
-	free_dentry_path(page);
 }
 
 /*
Signature · 1 line
2.48.1
#3 lore raw
Quoted 6 lines · Steve French

minor cosmetic change done to the patch (see attached)

from:
if (cfile->dentry == dentry &&
to:
if ((cfile->dentry == dentry) &&

IMHO those only makes sense if for either correctness or easier understanding, e.g.:

Quoted 1 line

if (x && (y || z))

or

Quoted 1 line

if ((x & y) && z)

Otherwise it only adds pollution and maybe confusion to the code. Example of complete unnecessary extra wrapping in file.c and cifsacl.c (but there are several others I've seen around):

Quoted 3 lines

if ((!open_file->invalidHandle)) {

if ((!ctsid) || (!cwsid))

My 2c only, up to you of course.

Cheers,

Enzo

Quoted 141 lines · Enzo Matsumiya
Quoted 133 lines · Paulo Alcantara
Quoted 117 lines

Fix the following case where the client would end up closing both deferred files (foo.tmp & foo) after unlink(foo) due to strstr() call in cifs_close_deferred_file_under_dentry():

fd1 = openat(AT_FDCWD, "foo", O_WRONLY|O_CREAT|O_TRUNC, 0666); fd2 = openat(AT_FDCWD, "foo.tmp", O_WRONLY|O_CREAT|O_TRUNC, 0666); close(fd1);
close(fd2);
unlink("foo");

Fixes e3fc065682eb ("cifs: Deferred close performance improvements")
Cc Enzo Matsumiya <[email protected]>
Cc Frank Sorenson <[email protected]>
Cc David Howells <[email protected]>

---

fs/smb/client/cifsproto.h |  4 ++--
fs/smb/client/inode.c     |  6 +++---
fs/smb/client/misc.c      | 36 +++++++++++++++---------------------
3 files changed, 20 insertions(+), 26 deletions(-)
fs/smb/client/cifsproto.h +2 -2
index c34c533b2efa..e8fba98690ce 100644
@@ -312,8 +312,8 @@ extern void cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode);
 
 extern void cifs_close_all_deferred_files(struct cifs_tcon *cifs_tcon);
 
-extern void cifs_close_deferred_file_under_dentry(struct cifs_tcon *cifs_tcon,
-                              const char *path);
+void cifs_close_deferred_file_under_dentry(struct cifs_tcon *cifs_tcon,
+                                         struct dentry *dentry);
 
 extern void cifs_mark_open_handles_for_deleted_file(struct inode *inode,
                              const char *path);
fs/smb/client/inode.c +3 -3
index 11d442e8b3d6..1703f1285d36 100644
@@ -1984,7 +1984,7 @@ static int __cifs_unlink(struct inode *dir, struct dentry *dentry, bool sillyren
      }
 
      netfs_wait_for_outstanding_io(inode);
-      cifs_close_deferred_file_under_dentry(tcon, full_path);
+      cifs_close_deferred_file_under_dentry(tcon, dentry);
 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
      if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP &
                              le64_to_cpu(tcon->fsUnixInfo.Capability))) {
@@ -2538,10 +2538,10 @@ cifs_rename2(struct mnt_idmap *idmap, struct inode *source_dir,
              goto cifs_rename_exit;
      }
 
-      cifs_close_deferred_file_under_dentry(tcon, from_name);
+      cifs_close_deferred_file_under_dentry(tcon, source_dentry);
      if (d_inode(target_dentry) != NULL) {
              netfs_wait_for_outstanding_io(d_inode(target_dentry));
-              cifs_close_deferred_file_under_dentry(tcon, to_name);
+              cifs_close_deferred_file_under_dentry(tcon, target_dentry);
      }
 
      rc = cifs_do_rename(xid, source_dentry, from_name, target_dentry,
fs/smb/client/misc.c +15 -20
index da23cc12a52c..350542d57249 100644
@@ -832,33 +832,28 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon)
              kfree(tmp_list);
      }
 }
-void
-cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)
+
+void cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon,
+                                         struct dentry *dentry)
 {
-      struct cifsFileInfo *cfile;
      struct file_list *tmp_list, *tmp_next_list;
-      void *page;
-      const char *full_path;
+      struct cifsFileInfo *cfile;
      LIST_HEAD(file_head);
 
-      page = alloc_dentry_path();
      spin_lock(&tcon->open_file_lock);
      list_for_each_entry(cfile, &tcon->openFileList, tlist) {
-              full_path = build_path_from_dentry(cfile->dentry, page);
-              if (strstr(full_path, path)) {
-                      if (delayed_work_pending(&cfile->deferred)) {
-                              if (cancel_delayed_work(&cfile->deferred)) {
-                                      spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
-                                      cifs_del_deferred_close(cfile);
-                                      spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
+              if (cfile->dentry == dentry &&
+                  delayed_work_pending(&cfile->deferred) &&
+                  cancel_delayed_work(&cfile->deferred)) {
+                      spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
+                      cifs_del_deferred_close(cfile);
+                      spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
 
-                                      tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC);
-                                      if (tmp_list == NULL)
-                                              break;
-                                      tmp_list->cfile = cfile;
-                                      list_add_tail(&tmp_list->list, &file_head);
-                              }
-                      }
+                      tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC);
+                      if (tmp_list == NULL)
+                              break;
+                      tmp_list->cfile = cfile;
+                      list_add_tail(&tmp_list->list, &file_head);
              }
      }
      spin_unlock(&tcon->open_file_lock);

fs/smb/client/misc.c cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path) · line 868

Quoted 7 lines
fs/smb/client/misc.c +0 -1
@@ -868,7 +863,6 @@ cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)
              list_del(&tmp_list->list);
              kfree(tmp_list);
      }
-      free_dentry_path(page);
 }
 
 /*

Cheers,

Enzo

Signature · 3 lines
Thanks,

Steve