[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230302182207.456311-1-aloktiagi@gmail.com>
Date: Thu, 2 Mar 2023 18:22:05 +0000
From: aloktiagi <aloktiagi@...il.com>
To: viro@...iv.linux.org.uk, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: keescook@...omium.org, hch@...radead.org,
aloktiagi <aloktiagi@...il.com>,
Tycho Andersen <tycho@...ho.pizza>
Subject: [RFC 1/3] file: Introduce iterate_fd_locked
Callers holding the files->file_lock lock can call iterate_fd_locked instead of
iterate_fd
Signed-off-by: aloktiagi <aloktiagi@...il.com>
Reviewed-by: Tycho Andersen <tycho@...ho.pizza>
---
fs/file.c | 21 +++++++++++++++------
include/linux/fdtable.h | 3 +++
2 files changed, 18 insertions(+), 6 deletions(-)
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);
--
2.34.1
Powered by blists - more mailing lists