summaryrefslogtreecommitdiff
path: root/fs/file.c
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2020-11-21 02:14:28 +0300
committerEric W. Biederman <ebiederm@xmission.com>2020-12-10 21:40:10 +0300
commit3a879fb38082125cc0d8aa89b70c7f3a7cdf584b (patch)
treebd61b89ba93e2810adc3c6bd8c44530e4a020c48 /fs/file.c
parent460b4f812a9d473d4b39d87d37844f9fc30a9eb3 (diff)
downloadlinux-3a879fb38082125cc0d8aa89b70c7f3a7cdf584b.tar.xz
file: Implement task_lookup_fd_rcu
As a companion to lookup_fd_rcu implement task_lookup_fd_rcu for querying an arbitrary process about a specific file. Acked-by: Christian Brauner <christian.brauner@ubuntu.com> v1: https://lkml.kernel.org/r/20200818103713.aw46m7vprsy4vlve@wittgenstein Link: https://lkml.kernel.org/r/20201120231441.29911-11-ebiederm@xmission.com Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Diffstat (limited to 'fs/file.c')
-rw-r--r--fs/file.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/fs/file.c b/fs/file.c
index 5861c4f89419..6448523ca29e 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -865,6 +865,21 @@ struct file *fget_task(struct task_struct *task, unsigned int fd)
return file;
}
+struct file *task_lookup_fd_rcu(struct task_struct *task, unsigned int fd)
+{
+ /* Must be called with rcu_read_lock held */
+ struct files_struct *files;
+ struct file *file = NULL;
+
+ task_lock(task);
+ files = task->files;
+ if (files)
+ file = files_lookup_fd_rcu(files, fd);
+ task_unlock(task);
+
+ return file;
+}
+
/*
* Lightweight file lookup - no refcnt increment if fd table isn't shared.
*