netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Andrew Morton <akpm@linux-foundation.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-rtc@vger.kernel.org,
	Alessandro Zummo <a.zummo@towertech.it>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
	linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	jfs-discussion@lists.sourceforge.net,
	linux-afs@lists.infradead.org, linux-acpi@vger.kernel.org,
	netdev@vger.kernel.org, netfilter-devel@vger.kernel.org,
	Jiri Slaby <jslaby@suse.com>,
	linux-ext4@vger.kernel.org, Alexey Dobriyan <adobriyan@gmail.com>,
	megaraidlinux.pdl@broadcom.com, drbd-dev@lists.linbit.com
Subject: [PATCH 02/42] proc: introduce a proc_pid_ns helper
Date: Wed, 16 May 2018 11:43:06 +0200	[thread overview]
Message-ID: <20180516094346.20506-3-hch@lst.de> (raw)
In-Reply-To: <20180516094346.20506-1-hch@lst.de>

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>
---
 fs/proc/array.c         |  7 +------
 fs/proc/base.c          | 18 ++++++++----------
 fs/proc/self.c          |  4 ++--
 fs/proc/thread_self.c   |  4 ++--
 include/linux/proc_fs.h |  6 ++++++
 5 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index ae2c807fd719..911f66924d81 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -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)
 {
-	struct inode *inode = seq->private;
-	pid_t pid;
-
-	pid = pid_nr_ns(v, inode->i_sb->s_fs_info);
-	seq_printf(seq, "%d ", pid);
-
+	seq_printf(seq, "%d ", pid_nr_ns(v, proc_pid_ns(seq->private)));
 	return 0;
 }
 
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 1b2ede6abcdf..29237cad19fd 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -698,7 +698,7 @@ static bool has_pid_permissions(struct pid_namespace *pid,
 
 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;
 	bool has_perms;
 
@@ -733,13 +733,11 @@ static const struct inode_operations proc_def_inode_operations = {
 static int proc_single_show(struct seq_file *m, void *v)
 {
 	struct inode *inode = m->private;
-	struct pid_namespace *ns;
-	struct pid *pid;
+	struct pid_namespace *ns = proc_pid_ns(inode);
+	struct pid *pid = proc_pid(inode);
 	struct task_struct *task;
 	int ret;
 
-	ns = inode->i_sb->s_fs_info;
-	pid = proc_pid(inode);
 	task = get_pid_task(pid, PIDTYPE_PID);
 	if (!task)
 		return -ESRCH;
@@ -1410,7 +1408,7 @@ static const struct file_operations proc_fail_nth_operations = {
 static int sched_show(struct seq_file *m, void *v)
 {
 	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;
 
 	p = get_proc_task(inode);
@@ -1782,8 +1780,8 @@ int pid_getattr(const struct path *path, struct kstat *stat,
 		u32 request_mask, unsigned int query_flags)
 {
 	struct inode *inode = d_inode(path->dentry);
+	struct pid_namespace *pid = proc_pid_ns(inode);
 	struct task_struct *task;
-	struct pid_namespace *pid = path->dentry->d_sb->s_fs_info;
 
 	generic_fillattr(inode, stat);
 
@@ -2337,7 +2335,7 @@ static int proc_timers_open(struct inode *inode, struct file *file)
 		return -ENOMEM;
 
 	tp->pid = proc_pid(inode);
-	tp->ns = inode->i_sb->s_fs_info;
+	tp->ns = proc_pid_ns(inode);
 	return 0;
 }
 
@@ -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)
 {
 	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;
 
 	if (pos >= PID_MAX_LIMIT + TGID_OFFSET)
@@ -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
 	 * 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;
 	file->f_version = 0;
 	for (task = first_tid(proc_pid(inode), tid, ctx->pos - 2, ns);
diff --git a/fs/proc/self.c b/fs/proc/self.c
index 4d7d061696b3..127265e5c55f 100644
--- a/fs/proc/self.c
+++ b/fs/proc/self.c
@@ -12,7 +12,7 @@ static const char *proc_self_get_link(struct dentry *dentry,
 				      struct inode *inode,
 				      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);
 	char *name;
 
@@ -36,7 +36,7 @@ static unsigned self_inum __ro_after_init;
 int proc_setup_self(struct super_block *s)
 {
 	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;
 	
 	inode_lock(root_inode);
diff --git a/fs/proc/thread_self.c b/fs/proc/thread_self.c
index 9d2efaca499f..b905010ca9eb 100644
--- a/fs/proc/thread_self.c
+++ b/fs/proc/thread_self.c
@@ -12,7 +12,7 @@ static const char *proc_thread_self_get_link(struct dentry *dentry,
 					     struct inode *inode,
 					     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 pid = task_pid_nr_ns(current, ns);
 	char *name;
@@ -36,7 +36,7 @@ static unsigned thread_self_inum __ro_after_init;
 int proc_setup_thread_self(struct super_block *s)
 {
 	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;
 
 	inode_lock(root_inode);
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 928ef9e4d912..4edcde510631 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -83,4 +83,10 @@ struct ns_common;
 int open_related_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 */
-- 
2.17.0

  parent reply	other threads:[~2018-05-16  9:43 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-16  9:43 simplify procfs code for seq_file instances V3 Christoph Hellwig
     [not found] ` <20180516094346.20506-1-hch-jcswGhMUV9g@public.gmane.org>
2018-05-16  9:43   ` [PATCH 01/42] net/can: single_open_net needs to be paired with single_release_net Christoph Hellwig
2018-05-16  9:43 ` Christoph Hellwig [this message]
2018-05-16  9:43 ` [PATCH 03/42] proc: don't detour through seq->private to get the inode Christoph Hellwig
2018-05-16  9:43 ` [PATCH 04/42] proc: simplify proc_register calling conventions Christoph Hellwig
2018-05-16  9:43 ` [PATCH 05/42] proc: add a proc_create_reg helper Christoph Hellwig
2018-05-16  9:43 ` [PATCH 06/42] proc: introduce proc_create_seq{,_data} Christoph Hellwig
2018-05-16  9:43 ` [PATCH 07/42] proc: introduce proc_create_seq_private Christoph Hellwig
2018-05-16  9:43 ` [PATCH 08/42] proc: introduce proc_create_single{,_data} Christoph Hellwig
2018-05-16  9:43 ` [PATCH 09/42] ipv{4,6}/udp{,lite}: simplify proc registration Christoph Hellwig
2018-05-16  9:43 ` [PATCH 10/42] ipv{4,6}/tcp: simplify procfs registration Christoph Hellwig
2018-05-16  9:43 ` [PATCH 11/42] ipv{4,6}/ping: simplify proc file creation Christoph Hellwig
2018-05-16  9:43 ` [PATCH 12/42] ipv{4, 6}/raw: simplify ѕeq_file code Christoph Hellwig
2018-05-16  9:43 ` [PATCH 13/42] ipv6/flowlabel: simplify pid namespace lookup Christoph Hellwig
2018-05-16  9:43 ` [PATCH 14/42] net/kcm: simplify proc registration Christoph Hellwig
2018-05-16  9:43 ` [PATCH 15/42] netfilter/x_tables: simplify ѕeq_file code Christoph Hellwig
2018-05-16  9:43 ` [PATCH 16/42] net: move seq_file_single_net to <linux/seq_file_net.h> Christoph Hellwig
2018-05-16  9:43 ` [PATCH 17/42] proc: introduce proc_create_net{,_data} Christoph Hellwig
2018-05-16  9:43 ` [PATCH 18/42] proc: introduce proc_create_net_single Christoph Hellwig
2018-05-16  9:43 ` [PATCH 19/42] acpi/battery: simplify procfs code Christoph Hellwig
2018-05-16  9:43 ` [PATCH 20/42] sgi-gru: " Christoph Hellwig
2018-05-16  9:43 ` [PATCH 21/42] megaraid: " Christoph Hellwig
2018-05-16  9:43 ` [PATCH 22/42] sg: " Christoph Hellwig
2018-05-16  9:43 ` [PATCH 23/42] afs: " Christoph Hellwig
2018-05-16  9:43 ` [PATCH 24/42] ext4: " Christoph Hellwig
2018-05-16  9:43 ` [PATCH 25/42] jfs: " Christoph Hellwig
2018-05-16 13:15   ` [Jfs-discussion] " Dave Kleikamp
2018-05-16  9:43 ` [PATCH 26/42] staging/rtl8192u: " Christoph Hellwig
2018-05-16  9:43 ` [PATCH 27/42] resource: switch to proc_create_seq_data Christoph Hellwig
2018-05-16  9:43 ` [PATCH 28/42] drbd: switch to proc_create_single Christoph Hellwig
     [not found]   ` <20180516094346.20506-29-hch-jcswGhMUV9g@public.gmane.org>
2018-05-18 12:55     ` Lars Ellenberg
2018-05-16  9:43 ` [PATCH 29/42] rtc/proc: switch to proc_create_single_data Christoph Hellwig
2018-05-16  9:43 ` [PATCH 30/42] bonding: switch to proc_create_seq_data Christoph Hellwig
2018-05-16  9:43 ` [PATCH 31/42] hostap: switch to proc_create_{seq,single}_data Christoph Hellwig
2018-05-16  9:43 ` [PATCH 32/42] neigh: switch to proc_create_seq_data Christoph Hellwig
2018-05-16  9:43 ` [PATCH 33/42] netfilter/xt_hashlimit: switch to proc_create_{seq, single}_data Christoph Hellwig
2018-05-16  9:43 ` [PATCH 34/42] netfilter/x_tables: switch to proc_create_seq_private Christoph Hellwig
2018-05-16  9:43 ` [PATCH 35/42] bluetooth: switch to proc_create_seq_data Christoph Hellwig
2018-05-16  9:43 ` [PATCH 36/42] atm: simplify procfs code Christoph Hellwig
2018-05-16  9:43 ` [PATCH 37/42] atm: switch to proc_create_seq_private Christoph Hellwig
2018-05-16  9:43 ` [PATCH 38/42] isdn: replace ->proc_fops with ->proc_show Christoph Hellwig
2018-05-18  8:43   ` Paul Bolle
     [not found]     ` <4e7091873e8a220c454a7ce5a3f52edc5b5c3e3a.camel-IWqWACnzNjzz+pZb47iToQ@public.gmane.org>
2018-05-18  8:58       ` Christoph Hellwig
2018-05-16  9:43 ` [PATCH 39/42] ide: remove ide_driver_proc_write Christoph Hellwig
2018-05-16  9:43 ` [PATCH 40/42] ide: replace ->proc_fops with ->proc_show Christoph Hellwig
2018-05-16  9:43 ` [PATCH 41/42] tty: " Christoph Hellwig
2018-05-16  9:58   ` Greg Kroah-Hartman
2018-05-16  9:43 ` [PATCH 42/42] proc: update SIZEOF_PDE_INLINE_NAME for the new pde fields Christoph Hellwig
2018-05-16 13:28 ` simplify procfs code for seq_file instances V3 Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180516094346.20506-3-hch@lst.de \
    --to=hch@lst.de \
    --cc=a.zummo@towertech.it \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=drbd-dev@lists.linbit.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jfs-discussion@lists.sourceforge.net \
    --cc=jslaby@suse.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=megaraidlinux.pdl@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).