file: Implement task_lookup_fd_rcu
[ Upstream commit 3a879fb38082125cc0d8aa89b70c7f3a7cdf584b ] 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> Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
566924f14c
commit
d1c2b8d006
2 changed files with 17 additions and 0 deletions
15
fs/file.c
15
fs/file.c
|
@ -911,6 +911,21 @@ struct file *fget_task(struct task_struct *task, unsigned int fd)
|
||||||
return file;
|
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.
|
* Lightweight file lookup - no refcnt increment if fd table isn't shared.
|
||||||
*
|
*
|
||||||
|
|
|
@ -110,6 +110,8 @@ static inline struct file *lookup_fd_rcu(unsigned int fd)
|
||||||
return files_lookup_fd_rcu(current->files, fd);
|
return files_lookup_fd_rcu(current->files, fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct file *task_lookup_fd_rcu(struct task_struct *task, unsigned int fd);
|
||||||
|
|
||||||
struct task_struct;
|
struct task_struct;
|
||||||
|
|
||||||
struct files_struct *get_files_struct(struct task_struct *);
|
struct files_struct *get_files_struct(struct task_struct *);
|
||||||
|
|
Loading…
Reference in a new issue