Merge tag 'threads-v5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner...
[linux-2.6-microblaze.git] / fs / file.c
index fb7081b..a364e1a 100644 (file)
--- a/fs/file.c
+++ b/fs/file.c
@@ -708,9 +708,9 @@ void do_close_on_exec(struct files_struct *files)
        spin_unlock(&files->file_lock);
 }
 
-static struct file *__fget(unsigned int fd, fmode_t mask, unsigned int refs)
+static struct file *__fget_files(struct files_struct *files, unsigned int fd,
+                                fmode_t mask, unsigned int refs)
 {
-       struct files_struct *files = current->files;
        struct file *file;
 
        rcu_read_lock();
@@ -731,6 +731,12 @@ loop:
        return file;
 }
 
+static inline struct file *__fget(unsigned int fd, fmode_t mask,
+                                 unsigned int refs)
+{
+       return __fget_files(current->files, fd, mask, refs);
+}
+
 struct file *fget_many(unsigned int fd, unsigned int refs)
 {
        return __fget(fd, FMODE_PATH, refs);
@@ -748,6 +754,18 @@ struct file *fget_raw(unsigned int fd)
 }
 EXPORT_SYMBOL(fget_raw);
 
+struct file *fget_task(struct task_struct *task, unsigned int fd)
+{
+       struct file *file = NULL;
+
+       task_lock(task);
+       if (task->files)
+               file = __fget_files(task->files, fd, 0, 1);
+       task_unlock(task);
+
+       return file;
+}
+
 /*
  * Lightweight file lookup - no refcnt increment if fd table isn't shared.
  *