From: aloktiagi <aloktiagi@gmail.com>
To: viro@zeniv.linux.org.uk, David.Laight@ACULAB.COM,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: keescook@chromium.org, hch@infradead.org,
aloktiagi <aloktiagi@gmail.com>,
Tycho Andersen <tycho@tycho.pizza>
Subject: [RFC v2 1/3] file: Introduce iterate_fd_locked
Date: Sat, 18 Mar 2023 06:02:46 +0000 [thread overview]
Message-ID: <20230318060248.848099-1-aloktiagi@gmail.com> (raw)
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(-)
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
next reply other threads:[~2023-03-18 6:03 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-18 6:02 aloktiagi [this message]
2023-03-18 6:02 ` [RFC v2 2/3] file: allow callers to free the old file descriptor after dup2 aloktiagi
2023-03-18 6:02 ` [RFC v2 3/3] file, epoll: Implement do_replace() and eventpoll_replace() aloktiagi
2023-03-20 14:51 ` Christian Brauner
2023-03-23 22:23 ` Alok Tiagi
2023-03-24 8:23 ` [RFC v4 2/2] " Christian Brauner
2023-03-24 13:43 ` Tycho Andersen
2023-03-27 9:01 ` Christian Brauner
2023-03-27 13:06 ` Tycho Andersen
2023-03-27 13:16 ` Tycho Andersen
2023-03-27 20:39 ` Alok Tiagi
2023-03-24 6:34 [RFC v4 1/2] file: allow callers to free the old file descriptor after dup2 aloktiagi
2023-03-24 6:34 ` [RFC v4 2/2] file, epoll: Implement do_replace() and eventpoll_replace() aloktiagi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230318060248.848099-1-aloktiagi@gmail.com \
--to=aloktiagi@gmail.com \
--cc=David.Laight@ACULAB.COM \
--cc=hch@infradead.org \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tycho@tycho.pizza \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).