Commit 76f668be authored by Christoph Hellwig's avatar Christoph Hellwig

proc: introduce a proc_pid_ns helper

Factor out retrieving the per-sb pid namespaces from the sb private data
into an easier to understand helper.
Suggested-by: default avatarEric W. Biederman <ebiederm@xmission.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent 441bc627
...@@ -677,12 +677,7 @@ get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos) ...@@ -677,12 +677,7 @@ get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
static int children_seq_show(struct seq_file *seq, void *v) static int children_seq_show(struct seq_file *seq, void *v)
{ {
struct inode *inode = seq->private; seq_printf(seq, "%d ", pid_nr_ns(v, proc_pid_ns(seq->private)));
pid_t pid;
pid = pid_nr_ns(v, inode->i_sb->s_fs_info);
seq_printf(seq, "%d ", pid);
return 0; return 0;
} }
......
...@@ -698,7 +698,7 @@ static bool has_pid_permissions(struct pid_namespace *pid, ...@@ -698,7 +698,7 @@ static bool has_pid_permissions(struct pid_namespace *pid,
static int proc_pid_permission(struct inode *inode, int mask) static int proc_pid_permission(struct inode *inode, int mask)
{ {
struct pid_namespace *pid = inode->i_sb->s_fs_info; struct pid_namespace *pid = proc_pid_ns(inode);
struct task_struct *task; struct task_struct *task;
bool has_perms; bool has_perms;
...@@ -733,13 +733,11 @@ static const struct inode_operations proc_def_inode_operations = { ...@@ -733,13 +733,11 @@ static const struct inode_operations proc_def_inode_operations = {
static int proc_single_show(struct seq_file *m, void *v) static int proc_single_show(struct seq_file *m, void *v)
{ {
struct inode *inode = m->private; struct inode *inode = m->private;
struct pid_namespace *ns; struct pid_namespace *ns = proc_pid_ns(inode);
struct pid *pid; struct pid *pid = proc_pid(inode);
struct task_struct *task; struct task_struct *task;
int ret; int ret;
ns = inode->i_sb->s_fs_info;
pid = proc_pid(inode);
task = get_pid_task(pid, PIDTYPE_PID); task = get_pid_task(pid, PIDTYPE_PID);
if (!task) if (!task)
return -ESRCH; return -ESRCH;
...@@ -1410,7 +1408,7 @@ static const struct file_operations proc_fail_nth_operations = { ...@@ -1410,7 +1408,7 @@ static const struct file_operations proc_fail_nth_operations = {
static int sched_show(struct seq_file *m, void *v) static int sched_show(struct seq_file *m, void *v)
{ {
struct inode *inode = m->private; struct inode *inode = m->private;
struct pid_namespace *ns = inode->i_sb->s_fs_info; struct pid_namespace *ns = proc_pid_ns(inode);
struct task_struct *p; struct task_struct *p;
p = get_proc_task(inode); p = get_proc_task(inode);
...@@ -1782,8 +1780,8 @@ int pid_getattr(const struct path *path, struct kstat *stat, ...@@ -1782,8 +1780,8 @@ int pid_getattr(const struct path *path, struct kstat *stat,
u32 request_mask, unsigned int query_flags) u32 request_mask, unsigned int query_flags)
{ {
struct inode *inode = d_inode(path->dentry); struct inode *inode = d_inode(path->dentry);
struct pid_namespace *pid = proc_pid_ns(inode);
struct task_struct *task; struct task_struct *task;
struct pid_namespace *pid = path->dentry->d_sb->s_fs_info;
generic_fillattr(inode, stat); generic_fillattr(inode, stat);
...@@ -2337,7 +2335,7 @@ static int proc_timers_open(struct inode *inode, struct file *file) ...@@ -2337,7 +2335,7 @@ static int proc_timers_open(struct inode *inode, struct file *file)
return -ENOMEM; return -ENOMEM;
tp->pid = proc_pid(inode); tp->pid = proc_pid(inode);
tp->ns = inode->i_sb->s_fs_info; tp->ns = proc_pid_ns(inode);
return 0; return 0;
} }
...@@ -3239,7 +3237,7 @@ static struct tgid_iter next_tgid(struct pid_namespace *ns, struct tgid_iter ite ...@@ -3239,7 +3237,7 @@ static struct tgid_iter next_tgid(struct pid_namespace *ns, struct tgid_iter ite
int proc_pid_readdir(struct file *file, struct dir_context *ctx) int proc_pid_readdir(struct file *file, struct dir_context *ctx)
{ {
struct tgid_iter iter; struct tgid_iter iter;
struct pid_namespace *ns = file_inode(file)->i_sb->s_fs_info; struct pid_namespace *ns = proc_pid_ns(file_inode(file));
loff_t pos = ctx->pos; loff_t pos = ctx->pos;
if (pos >= PID_MAX_LIMIT + TGID_OFFSET) if (pos >= PID_MAX_LIMIT + TGID_OFFSET)
...@@ -3588,7 +3586,7 @@ static int proc_task_readdir(struct file *file, struct dir_context *ctx) ...@@ -3588,7 +3586,7 @@ static int proc_task_readdir(struct file *file, struct dir_context *ctx)
/* f_version caches the tgid value that the last readdir call couldn't /* f_version caches the tgid value that the last readdir call couldn't
* return. lseek aka telldir automagically resets f_version to 0. * return. lseek aka telldir automagically resets f_version to 0.
*/ */
ns = inode->i_sb->s_fs_info; ns = proc_pid_ns(inode);
tid = (int)file->f_version; tid = (int)file->f_version;
file->f_version = 0; file->f_version = 0;
for (task = first_tid(proc_pid(inode), tid, ctx->pos - 2, ns); for (task = first_tid(proc_pid(inode), tid, ctx->pos - 2, ns);
......
...@@ -12,7 +12,7 @@ static const char *proc_self_get_link(struct dentry *dentry, ...@@ -12,7 +12,7 @@ static const char *proc_self_get_link(struct dentry *dentry,
struct inode *inode, struct inode *inode,
struct delayed_call *done) struct delayed_call *done)
{ {
struct pid_namespace *ns = inode->i_sb->s_fs_info; struct pid_namespace *ns = proc_pid_ns(inode);
pid_t tgid = task_tgid_nr_ns(current, ns); pid_t tgid = task_tgid_nr_ns(current, ns);
char *name; char *name;
...@@ -36,7 +36,7 @@ static unsigned self_inum __ro_after_init; ...@@ -36,7 +36,7 @@ static unsigned self_inum __ro_after_init;
int proc_setup_self(struct super_block *s) int proc_setup_self(struct super_block *s)
{ {
struct inode *root_inode = d_inode(s->s_root); struct inode *root_inode = d_inode(s->s_root);
struct pid_namespace *ns = s->s_fs_info; struct pid_namespace *ns = proc_pid_ns(root_inode);
struct dentry *self; struct dentry *self;
inode_lock(root_inode); inode_lock(root_inode);
......
...@@ -12,7 +12,7 @@ static const char *proc_thread_self_get_link(struct dentry *dentry, ...@@ -12,7 +12,7 @@ static const char *proc_thread_self_get_link(struct dentry *dentry,
struct inode *inode, struct inode *inode,
struct delayed_call *done) struct delayed_call *done)
{ {
struct pid_namespace *ns = inode->i_sb->s_fs_info; struct pid_namespace *ns = proc_pid_ns(inode);
pid_t tgid = task_tgid_nr_ns(current, ns); pid_t tgid = task_tgid_nr_ns(current, ns);
pid_t pid = task_pid_nr_ns(current, ns); pid_t pid = task_pid_nr_ns(current, ns);
char *name; char *name;
...@@ -36,7 +36,7 @@ static unsigned thread_self_inum __ro_after_init; ...@@ -36,7 +36,7 @@ static unsigned thread_self_inum __ro_after_init;
int proc_setup_thread_self(struct super_block *s) int proc_setup_thread_self(struct super_block *s)
{ {
struct inode *root_inode = d_inode(s->s_root); struct inode *root_inode = d_inode(s->s_root);
struct pid_namespace *ns = s->s_fs_info; struct pid_namespace *ns = proc_pid_ns(root_inode);
struct dentry *thread_self; struct dentry *thread_self;
inode_lock(root_inode); inode_lock(root_inode);
......
...@@ -83,4 +83,10 @@ struct ns_common; ...@@ -83,4 +83,10 @@ struct ns_common;
int open_related_ns(struct ns_common *ns, int open_related_ns(struct ns_common *ns,
struct ns_common *(*get_ns)(struct ns_common *ns)); struct ns_common *(*get_ns)(struct ns_common *ns));
/* get the associated pid namespace for a file in procfs */
static inline struct pid_namespace *proc_pid_ns(struct inode *inode)
{
return inode->i_sb->s_fs_info;
}
#endif /* _LINUX_PROC_FS_H */ #endif /* _LINUX_PROC_FS_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment