Skip to content

Commit 76f668b

Browse files
author
Christoph Hellwig
committed
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: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 441bc62 commit 76f668b

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

fs/proc/array.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,7 @@ get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
677677

678678
static int children_seq_show(struct seq_file *seq, void *v)
679679
{
680-
struct inode *inode = seq->private;
681-
pid_t pid;
682-
683-
pid = pid_nr_ns(v, inode->i_sb->s_fs_info);
684-
seq_printf(seq, "%d ", pid);
685-
680+
seq_printf(seq, "%d ", pid_nr_ns(v, proc_pid_ns(seq->private)));
686681
return 0;
687682
}
688683

fs/proc/base.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ static bool has_pid_permissions(struct pid_namespace *pid,
698698

699699
static int proc_pid_permission(struct inode *inode, int mask)
700700
{
701-
struct pid_namespace *pid = inode->i_sb->s_fs_info;
701+
struct pid_namespace *pid = proc_pid_ns(inode);
702702
struct task_struct *task;
703703
bool has_perms;
704704

@@ -733,13 +733,11 @@ static const struct inode_operations proc_def_inode_operations = {
733733
static int proc_single_show(struct seq_file *m, void *v)
734734
{
735735
struct inode *inode = m->private;
736-
struct pid_namespace *ns;
737-
struct pid *pid;
736+
struct pid_namespace *ns = proc_pid_ns(inode);
737+
struct pid *pid = proc_pid(inode);
738738
struct task_struct *task;
739739
int ret;
740740

741-
ns = inode->i_sb->s_fs_info;
742-
pid = proc_pid(inode);
743741
task = get_pid_task(pid, PIDTYPE_PID);
744742
if (!task)
745743
return -ESRCH;
@@ -1410,7 +1408,7 @@ static const struct file_operations proc_fail_nth_operations = {
14101408
static int sched_show(struct seq_file *m, void *v)
14111409
{
14121410
struct inode *inode = m->private;
1413-
struct pid_namespace *ns = inode->i_sb->s_fs_info;
1411+
struct pid_namespace *ns = proc_pid_ns(inode);
14141412
struct task_struct *p;
14151413

14161414
p = get_proc_task(inode);
@@ -1782,8 +1780,8 @@ int pid_getattr(const struct path *path, struct kstat *stat,
17821780
u32 request_mask, unsigned int query_flags)
17831781
{
17841782
struct inode *inode = d_inode(path->dentry);
1783+
struct pid_namespace *pid = proc_pid_ns(inode);
17851784
struct task_struct *task;
1786-
struct pid_namespace *pid = path->dentry->d_sb->s_fs_info;
17871785

17881786
generic_fillattr(inode, stat);
17891787

@@ -2337,7 +2335,7 @@ static int proc_timers_open(struct inode *inode, struct file *file)
23372335
return -ENOMEM;
23382336

23392337
tp->pid = proc_pid(inode);
2340-
tp->ns = inode->i_sb->s_fs_info;
2338+
tp->ns = proc_pid_ns(inode);
23412339
return 0;
23422340
}
23432341

@@ -3239,7 +3237,7 @@ static struct tgid_iter next_tgid(struct pid_namespace *ns, struct tgid_iter ite
32393237
int proc_pid_readdir(struct file *file, struct dir_context *ctx)
32403238
{
32413239
struct tgid_iter iter;
3242-
struct pid_namespace *ns = file_inode(file)->i_sb->s_fs_info;
3240+
struct pid_namespace *ns = proc_pid_ns(file_inode(file));
32433241
loff_t pos = ctx->pos;
32443242

32453243
if (pos >= PID_MAX_LIMIT + TGID_OFFSET)
@@ -3588,7 +3586,7 @@ static int proc_task_readdir(struct file *file, struct dir_context *ctx)
35883586
/* f_version caches the tgid value that the last readdir call couldn't
35893587
* return. lseek aka telldir automagically resets f_version to 0.
35903588
*/
3591-
ns = inode->i_sb->s_fs_info;
3589+
ns = proc_pid_ns(inode);
35923590
tid = (int)file->f_version;
35933591
file->f_version = 0;
35943592
for (task = first_tid(proc_pid(inode), tid, ctx->pos - 2, ns);

fs/proc/self.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static const char *proc_self_get_link(struct dentry *dentry,
1212
struct inode *inode,
1313
struct delayed_call *done)
1414
{
15-
struct pid_namespace *ns = inode->i_sb->s_fs_info;
15+
struct pid_namespace *ns = proc_pid_ns(inode);
1616
pid_t tgid = task_tgid_nr_ns(current, ns);
1717
char *name;
1818

@@ -36,7 +36,7 @@ static unsigned self_inum __ro_after_init;
3636
int proc_setup_self(struct super_block *s)
3737
{
3838
struct inode *root_inode = d_inode(s->s_root);
39-
struct pid_namespace *ns = s->s_fs_info;
39+
struct pid_namespace *ns = proc_pid_ns(root_inode);
4040
struct dentry *self;
4141

4242
inode_lock(root_inode);

fs/proc/thread_self.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static const char *proc_thread_self_get_link(struct dentry *dentry,
1212
struct inode *inode,
1313
struct delayed_call *done)
1414
{
15-
struct pid_namespace *ns = inode->i_sb->s_fs_info;
15+
struct pid_namespace *ns = proc_pid_ns(inode);
1616
pid_t tgid = task_tgid_nr_ns(current, ns);
1717
pid_t pid = task_pid_nr_ns(current, ns);
1818
char *name;
@@ -36,7 +36,7 @@ static unsigned thread_self_inum __ro_after_init;
3636
int proc_setup_thread_self(struct super_block *s)
3737
{
3838
struct inode *root_inode = d_inode(s->s_root);
39-
struct pid_namespace *ns = s->s_fs_info;
39+
struct pid_namespace *ns = proc_pid_ns(root_inode);
4040
struct dentry *thread_self;
4141

4242
inode_lock(root_inode);

include/linux/proc_fs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,10 @@ struct ns_common;
8383
int open_related_ns(struct ns_common *ns,
8484
struct ns_common *(*get_ns)(struct ns_common *ns));
8585

86+
/* get the associated pid namespace for a file in procfs */
87+
static inline struct pid_namespace *proc_pid_ns(struct inode *inode)
88+
{
89+
return inode->i_sb->s_fs_info;
90+
}
91+
8692
#endif /* _LINUX_PROC_FS_H */

0 commit comments

Comments
 (0)