Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+19 -20
+1 -6
fs/proc/array.c
··· 677 677 678 678 static int children_seq_show(struct seq_file *seq, void *v) 679 679 { 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))); 686 681 return 0; 687 682 } 688 683
+8 -10
fs/proc/base.c
··· 698 698 699 699 static int proc_pid_permission(struct inode *inode, int mask) 700 700 { 701 - struct pid_namespace *pid = inode->i_sb->s_fs_info; 701 + struct pid_namespace *pid = proc_pid_ns(inode); 702 702 struct task_struct *task; 703 703 bool has_perms; 704 704 ··· 733 733 static int proc_single_show(struct seq_file *m, void *v) 734 734 { 735 735 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); 738 738 struct task_struct *task; 739 739 int ret; 740 740 741 - ns = inode->i_sb->s_fs_info; 742 - pid = proc_pid(inode); 743 741 task = get_pid_task(pid, PIDTYPE_PID); 744 742 if (!task) 745 743 return -ESRCH; ··· 1408 1410 static int sched_show(struct seq_file *m, void *v) 1409 1411 { 1410 1412 struct inode *inode = m->private; 1411 - struct pid_namespace *ns = inode->i_sb->s_fs_info; 1413 + struct pid_namespace *ns = proc_pid_ns(inode); 1412 1414 struct task_struct *p; 1413 1415 1414 1416 p = get_proc_task(inode); ··· 1780 1782 u32 request_mask, unsigned int query_flags) 1781 1783 { 1782 1784 struct inode *inode = d_inode(path->dentry); 1785 + struct pid_namespace *pid = proc_pid_ns(inode); 1783 1786 struct task_struct *task; 1784 - struct pid_namespace *pid = path->dentry->d_sb->s_fs_info; 1785 1787 1786 1788 generic_fillattr(inode, stat); 1787 1789 ··· 2335 2337 return -ENOMEM; 2336 2338 2337 2339 tp->pid = proc_pid(inode); 2338 - tp->ns = inode->i_sb->s_fs_info; 2340 + tp->ns = proc_pid_ns(inode); 2339 2341 return 0; 2340 2342 } 2341 2343 ··· 3237 3239 int proc_pid_readdir(struct file *file, struct dir_context *ctx) 3238 3240 { 3239 3241 struct tgid_iter iter; 3240 - struct pid_namespace *ns = file_inode(file)->i_sb->s_fs_info; 3242 + struct pid_namespace *ns = proc_pid_ns(file_inode(file)); 3241 3243 loff_t pos = ctx->pos; 3242 3244 3243 3245 if (pos >= PID_MAX_LIMIT + TGID_OFFSET) ··· 3586 3588 /* f_version caches the tgid value that the last readdir call couldn't 3587 3589 * return. lseek aka telldir automagically resets f_version to 0. 3588 3590 */ 3589 - ns = inode->i_sb->s_fs_info; 3591 + ns = proc_pid_ns(inode); 3590 3592 tid = (int)file->f_version; 3591 3593 file->f_version = 0; 3592 3594 for (task = first_tid(proc_pid(inode), tid, ctx->pos - 2, ns);
+2 -2
fs/proc/self.c
··· 12 12 struct inode *inode, 13 13 struct delayed_call *done) 14 14 { 15 - struct pid_namespace *ns = inode->i_sb->s_fs_info; 15 + struct pid_namespace *ns = proc_pid_ns(inode); 16 16 pid_t tgid = task_tgid_nr_ns(current, ns); 17 17 char *name; 18 18 ··· 36 36 int proc_setup_self(struct super_block *s) 37 37 { 38 38 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); 40 40 struct dentry *self; 41 41 42 42 inode_lock(root_inode);
+2 -2
fs/proc/thread_self.c
··· 12 12 struct inode *inode, 13 13 struct delayed_call *done) 14 14 { 15 - struct pid_namespace *ns = inode->i_sb->s_fs_info; 15 + struct pid_namespace *ns = proc_pid_ns(inode); 16 16 pid_t tgid = task_tgid_nr_ns(current, ns); 17 17 pid_t pid = task_pid_nr_ns(current, ns); 18 18 char *name; ··· 36 36 int proc_setup_thread_self(struct super_block *s) 37 37 { 38 38 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); 40 40 struct dentry *thread_self; 41 41 42 42 inode_lock(root_inode);
+6
include/linux/proc_fs.h
··· 83 83 int open_related_ns(struct ns_common *ns, 84 84 struct ns_common *(*get_ns)(struct ns_common *ns)); 85 85 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 + 86 92 #endif /* _LINUX_PROC_FS_H */