diff mbox series

[RFC,v3,1/3] file: Introduce iterate_fd_locked

Message ID 20230324051526.963702-1-aloktiagi@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series [RFC,v3,1/3] file: Introduce iterate_fd_locked | expand

Commit Message

Alok Tiagi March 24, 2023, 5:15 a.m. UTC
Callers holding the files->file_lock lock can call iterate_fd_locked instead of
iterate_fd

Signed-off-by: aloktiagi <aloktiagi@gmail.com>
Reviewed-by: Tycho Andersen <tycho@tycho.pizza>
---
 fs/file.c               | 21 +++++++++++++++------
 include/linux/fdtable.h |  3 +++
 2 files changed, 18 insertions(+), 6 deletions(-)

Comments

Matthew Wilcox March 24, 2023, 5:20 a.m. UTC | #1
On Fri, Mar 24, 2023 at 05:15:24AM +0000, aloktiagi wrote:
> Callers holding the files->file_lock lock can call iterate_fd_locked instead of
> iterate_fd

You no longer call iterate_fd_locked() in patch 3/3, so this patch can
be dropped?
Alok Tiagi March 24, 2023, 5:52 a.m. UTC | #2
On Fri, Mar 24, 2023 at 05:20:50AM +0000, Matthew Wilcox wrote:
> On Fri, Mar 24, 2023 at 05:15:24AM +0000, aloktiagi wrote:
> > Callers holding the files->file_lock lock can call iterate_fd_locked instead of
> > iterate_fd
> 
> You no longer call iterate_fd_locked() in patch 3/3, so this patch can
> be dropped?

yes looks like we won't need this patch and can be dropped. Thank you.
diff mbox series

Patch

diff --git a/fs/file.c b/fs/file.c
index c942c89ca4cd..4b2346b8a5ee 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -1295,15 +1295,12 @@  int f_dupfd(unsigned int from, struct file *file, unsigned flags)
 	return err;
 }
 
-int iterate_fd(struct files_struct *files, unsigned n,
-		int (*f)(const void *, struct file *, unsigned),
-		const void *p)
+int iterate_fd_locked(struct files_struct *files, unsigned n,
+                int (*f)(const void *, struct file *, unsigned),
+                const void *p)
 {
 	struct fdtable *fdt;
 	int res = 0;
-	if (!files)
-		return 0;
-	spin_lock(&files->file_lock);
 	for (fdt = files_fdtable(files); n < fdt->max_fds; n++) {
 		struct file *file;
 		file = rcu_dereference_check_fdtable(files, fdt->fd[n]);
@@ -1313,6 +1310,18 @@  int iterate_fd(struct files_struct *files, unsigned n,
 		if (res)
 			break;
 	}
+	return res;
+}
+
+int iterate_fd(struct files_struct *files, unsigned n,
+		int (*f)(const void *, struct file *, unsigned),
+		const void *p)
+{
+	int res = 0;
+	if (!files)
+		return 0;
+	spin_lock(&files->file_lock);
+	res = iterate_fd_locked(files, n, f, p);
 	spin_unlock(&files->file_lock);
 	return res;
 }
diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
index e066816f3519..14882520d1fe 100644
--- a/include/linux/fdtable.h
+++ b/include/linux/fdtable.h
@@ -122,6 +122,9 @@  void do_close_on_exec(struct files_struct *);
 int iterate_fd(struct files_struct *, unsigned,
 		int (*)(const void *, struct file *, unsigned),
 		const void *);
+int iterate_fd_locked(struct files_struct *, unsigned,
+			int (*)(const void *, struct file *, unsigned),
+			const void *);
 
 extern int close_fd(unsigned int fd);
 extern int __close_range(unsigned int fd, unsigned int max_fd, unsigned int flags);