LKML Archive on lore.kernel.org
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: Alexey Dobriyan <adobriyan@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jslaby@suse.com>,
	Alessandro Zummo <a.zummo@towertech.it>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	linux-acpi@vger.kernel.org, drbd-dev@lists.linbit.com,
	linux-ide@vger.kernel.org, netdev@vger.kernel.org,
	linux-rtc@vger.kernel.org, megaraidlinux.pdl@broadcom.com,
	linux-scsi@vger.kernel.org, devel@driverdev.osuosl.org,
	linux-afs@lists.infradead.org, linux-ext4@vger.kernel.org,
	jfs-discussion@lists.sourceforge.net,
	netfilter-devel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 08/40] ipv{4,6}/tcp: simplify procfs registration
Date: Wed, 25 Apr 2018 17:47:55 +0200	[thread overview]
Message-ID: <20180425154827.32251-9-hch@lst.de> (raw)
In-Reply-To: <20180425154827.32251-1-hch@lst.de>

Avoid most of the afinfo indirections and just call the proc helpers
directly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 include/net/tcp.h   | 11 ++----
 net/ipv4/tcp_ipv4.c | 85 +++++++++++++++++----------------------------
 net/ipv6/tcp_ipv6.c | 27 +++++++++-----
 3 files changed, 53 insertions(+), 70 deletions(-)

diff --git a/include/net/tcp.h b/include/net/tcp.h
index 9c9b3768b350..51dc7a26a2fa 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1747,27 +1747,22 @@ enum tcp_seq_states {
 	TCP_SEQ_STATE_ESTABLISHED,
 };
 
-int tcp_seq_open(struct inode *inode, struct file *file);
+void *tcp_seq_start(struct seq_file *seq, loff_t *pos);
+void *tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos);
+void tcp_seq_stop(struct seq_file *seq, void *v);
 
 struct tcp_seq_afinfo {
-	char				*name;
 	sa_family_t			family;
-	const struct file_operations	*seq_fops;
-	struct seq_operations		seq_ops;
 };
 
 struct tcp_iter_state {
 	struct seq_net_private	p;
-	sa_family_t		family;
 	enum tcp_seq_states	state;
 	struct sock		*syn_wait_sk;
 	int			bucket, offset, sbucket, num;
 	loff_t			last_pos;
 };
 
-int tcp_proc_register(struct net *net, struct tcp_seq_afinfo *afinfo);
-void tcp_proc_unregister(struct net *net, struct tcp_seq_afinfo *afinfo);
-
 extern struct request_sock_ops tcp_request_sock_ops;
 extern struct request_sock_ops tcp6_request_sock_ops;
 
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index f70586b50838..645f259d0972 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1961,6 +1961,7 @@ EXPORT_SYMBOL(tcp_v4_destroy_sock);
  */
 static void *listening_get_next(struct seq_file *seq, void *cur)
 {
+	struct tcp_seq_afinfo *afinfo = PDE_DATA(file_inode(seq->file));
 	struct tcp_iter_state *st = seq->private;
 	struct net *net = seq_file_net(seq);
 	struct inet_listen_hashbucket *ilb;
@@ -1983,7 +1984,7 @@ static void *listening_get_next(struct seq_file *seq, void *cur)
 	sk_for_each_from(sk) {
 		if (!net_eq(sock_net(sk), net))
 			continue;
-		if (sk->sk_family == st->family)
+		if (sk->sk_family == afinfo->family)
 			return sk;
 	}
 	spin_unlock(&ilb->lock);
@@ -2020,6 +2021,7 @@ static inline bool empty_bucket(const struct tcp_iter_state *st)
  */
 static void *established_get_first(struct seq_file *seq)
 {
+	struct tcp_seq_afinfo *afinfo = PDE_DATA(file_inode(seq->file));
 	struct tcp_iter_state *st = seq->private;
 	struct net *net = seq_file_net(seq);
 	void *rc = NULL;
@@ -2036,7 +2038,7 @@ static void *established_get_first(struct seq_file *seq)
 
 		spin_lock_bh(lock);
 		sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
-			if (sk->sk_family != st->family ||
+			if (sk->sk_family != afinfo->family ||
 			    !net_eq(sock_net(sk), net)) {
 				continue;
 			}
@@ -2051,6 +2053,7 @@ static void *established_get_first(struct seq_file *seq)
 
 static void *established_get_next(struct seq_file *seq, void *cur)
 {
+	struct tcp_seq_afinfo *afinfo = PDE_DATA(file_inode(seq->file));
 	struct sock *sk = cur;
 	struct hlist_nulls_node *node;
 	struct tcp_iter_state *st = seq->private;
@@ -2062,7 +2065,8 @@ static void *established_get_next(struct seq_file *seq, void *cur)
 	sk = sk_nulls_next(sk);
 
 	sk_nulls_for_each_from(sk, node) {
-		if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
+		if (sk->sk_family == afinfo->family &&
+		    net_eq(sock_net(sk), net))
 			return sk;
 	}
 
@@ -2135,7 +2139,7 @@ static void *tcp_seek_last_pos(struct seq_file *seq)
 	return rc;
 }
 
-static void *tcp_seq_start(struct seq_file *seq, loff_t *pos)
+void *tcp_seq_start(struct seq_file *seq, loff_t *pos)
 {
 	struct tcp_iter_state *st = seq->private;
 	void *rc;
@@ -2156,8 +2160,9 @@ static void *tcp_seq_start(struct seq_file *seq, loff_t *pos)
 	st->last_pos = *pos;
 	return rc;
 }
+EXPORT_SYMBOL(tcp_seq_start);
 
-static void *tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+void *tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 {
 	struct tcp_iter_state *st = seq->private;
 	void *rc = NULL;
@@ -2186,8 +2191,9 @@ static void *tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 	st->last_pos = *pos;
 	return rc;
 }
+EXPORT_SYMBOL(tcp_seq_next);
 
-static void tcp_seq_stop(struct seq_file *seq, void *v)
+void tcp_seq_stop(struct seq_file *seq, void *v)
 {
 	struct tcp_iter_state *st = seq->private;
 
@@ -2202,47 +2208,7 @@ static void tcp_seq_stop(struct seq_file *seq, void *v)
 		break;
 	}
 }
-
-int tcp_seq_open(struct inode *inode, struct file *file)
-{
-	struct tcp_seq_afinfo *afinfo = PDE_DATA(inode);
-	struct tcp_iter_state *s;
-	int err;
-
-	err = seq_open_net(inode, file, &afinfo->seq_ops,
-			  sizeof(struct tcp_iter_state));
-	if (err < 0)
-		return err;
-
-	s = ((struct seq_file *)file->private_data)->private;
-	s->family		= afinfo->family;
-	s->last_pos		= 0;
-	return 0;
-}
-EXPORT_SYMBOL(tcp_seq_open);
-
-int tcp_proc_register(struct net *net, struct tcp_seq_afinfo *afinfo)
-{
-	int rc = 0;
-	struct proc_dir_entry *p;
-
-	afinfo->seq_ops.start		= tcp_seq_start;
-	afinfo->seq_ops.next		= tcp_seq_next;
-	afinfo->seq_ops.stop		= tcp_seq_stop;
-
-	p = proc_create_data(afinfo->name, 0444, net->proc_net,
-			     afinfo->seq_fops, afinfo);
-	if (!p)
-		rc = -ENOMEM;
-	return rc;
-}
-EXPORT_SYMBOL(tcp_proc_register);
-
-void tcp_proc_unregister(struct net *net, struct tcp_seq_afinfo *afinfo)
-{
-	remove_proc_entry(afinfo->name, net->proc_net);
-}
-EXPORT_SYMBOL(tcp_proc_unregister);
+EXPORT_SYMBOL(tcp_seq_stop);
 
 static void get_openreq4(const struct request_sock *req,
 			 struct seq_file *f, int i)
@@ -2377,6 +2343,19 @@ static int tcp4_seq_show(struct seq_file *seq, void *v)
 	return 0;
 }
 
+static const struct seq_operations tcp4_seq_ops = {
+	.show		= tcp4_seq_show,
+	.start		= tcp_seq_start,
+	.next		= tcp_seq_next,
+	.stop		= tcp_seq_stop,
+};
+
+static int tcp_seq_open(struct inode *inode, struct file *file)
+{
+	return seq_open_net(inode, file, &tcp4_seq_ops,
+			  sizeof(struct tcp_iter_state));
+}
+
 static const struct file_operations tcp_afinfo_seq_fops = {
 	.open    = tcp_seq_open,
 	.read    = seq_read,
@@ -2385,22 +2364,20 @@ static const struct file_operations tcp_afinfo_seq_fops = {
 };
 
 static struct tcp_seq_afinfo tcp4_seq_afinfo = {
-	.name		= "tcp",
 	.family		= AF_INET,
-	.seq_fops	= &tcp_afinfo_seq_fops,
-	.seq_ops	= {
-		.show		= tcp4_seq_show,
-	},
 };
 
 static int __net_init tcp4_proc_init_net(struct net *net)
 {
-	return tcp_proc_register(net, &tcp4_seq_afinfo);
+	if (!proc_create_data("tcp", 0444, net->proc_net,
+			&tcp_afinfo_seq_fops, &tcp4_seq_afinfo))
+		return -ENOMEM;
+	return 0;
 }
 
 static void __net_exit tcp4_proc_exit_net(struct net *net)
 {
-	tcp_proc_unregister(net, &tcp4_seq_afinfo);
+	remove_proc_entry("tcp", net->proc_net);
 }
 
 static struct pernet_operations tcp4_net_ops = {
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 6d664d83cd16..c0329bb1692f 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1909,30 +1909,41 @@ static int tcp6_seq_show(struct seq_file *seq, void *v)
 	return 0;
 }
 
+static const struct seq_operations tcp6_seq_ops = {
+	.show		= tcp6_seq_show,
+	.start		= tcp_seq_start,
+	.next		= tcp_seq_next,
+	.stop		= tcp_seq_stop,
+};
+
+static int tcp6_seq_open(struct inode *inode, struct file *file)
+{
+	return seq_open_net(inode, file, &tcp6_seq_ops,
+			  sizeof(struct tcp_iter_state));
+}
+
 static const struct file_operations tcp6_afinfo_seq_fops = {
-	.open    = tcp_seq_open,
+	.open    = tcp6_seq_open,
 	.read    = seq_read,
 	.llseek  = seq_lseek,
 	.release = seq_release_net
 };
 
 static struct tcp_seq_afinfo tcp6_seq_afinfo = {
-	.name		= "tcp6",
 	.family		= AF_INET6,
-	.seq_fops	= &tcp6_afinfo_seq_fops,
-	.seq_ops	= {
-		.show		= tcp6_seq_show,
-	},
 };
 
 int __net_init tcp6_proc_init(struct net *net)
 {
-	return tcp_proc_register(net, &tcp6_seq_afinfo);
+	if (!proc_create_data("tcp6", 0444, net->proc_net,
+			&tcp6_afinfo_seq_fops, &tcp6_seq_afinfo))
+		return -ENOMEM;
+	return 0;
 }
 
 void tcp6_proc_exit(struct net *net)
 {
-	tcp_proc_unregister(net, &tcp6_seq_afinfo);
+	remove_proc_entry("tcp6", net->proc_net);
 }
 #endif
 
-- 
2.17.0

  parent reply	other threads:[~2018-04-25 15:47 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-25 15:47 simplify procfs code for seq_file instances V2 Christoph Hellwig
2018-04-25 15:47 ` [PATCH 01/40] net/can: single_open_net needs to be paired with single_release_net Christoph Hellwig
2018-04-25 15:47 ` [PATCH 02/40] proc: simplify proc_register calling conventions Christoph Hellwig
2018-04-25 15:47 ` [PATCH 03/40] proc: add a proc_create_reg helper Christoph Hellwig
2018-04-25 15:47 ` [PATCH 04/40] proc: introduce proc_create_seq{,_data} Christoph Hellwig
2018-04-25 15:47 ` [PATCH 05/40] proc: introduce proc_create_seq_private Christoph Hellwig
2018-04-25 15:47 ` [PATCH 06/40] proc: introduce proc_create_single{,_data} Christoph Hellwig
2018-04-26  1:45   ` Finn Thain
2018-05-15 13:58     ` Christoph Hellwig
2018-04-25 15:47 ` [PATCH 07/40] ipv{4,6}/udp{,lite}: simplify proc registration Christoph Hellwig
2018-04-25 15:47 ` Christoph Hellwig [this message]
2018-04-25 15:47 ` [PATCH 09/40] ipv{4,6}/ping: simplify proc file creation Christoph Hellwig
2018-04-25 15:47 ` [PATCH 10/40] ipv{4, 6}/raw: simplify ѕeq_file code Christoph Hellwig
2018-04-25 15:47 ` [PATCH 11/40] ipv6/flowlabel: simplify pid namespace lookup Christoph Hellwig
2018-05-05 12:37   ` Eric W. Biederman
2018-05-15 14:56     ` Christoph Hellwig
2018-05-17  5:28       ` Eric W. Biederman
2018-05-17  6:42         ` Christoph Hellwig
2018-05-17 19:14           ` Eric W. Biederman
2018-04-25 15:47 ` [PATCH 12/40] net/kcm: simplify proc registration Christoph Hellwig
2018-04-25 15:48 ` [PATCH 13/40] netfilter/x_tables: simplify ѕeq_file code Christoph Hellwig
2018-04-25 15:48 ` [PATCH 14/40] net: move seq_file_single_net to <linux/seq_file_net.h> Christoph Hellwig
2018-04-25 15:48 ` [PATCH 15/40] proc: introduce proc_create_net{,_data} Christoph Hellwig
2018-04-25 15:48 ` [PATCH 16/40] proc: introduce proc_create_net_single Christoph Hellwig
2018-04-25 15:48 ` [PATCH 17/40] acpi/battery: simplify procfs code Christoph Hellwig
2018-04-25 15:48 ` [PATCH 18/40] sgi-gru: " Christoph Hellwig
2018-04-25 15:48 ` [PATCH 19/40] megaraid: " Christoph Hellwig
2018-04-25 15:48 ` [PATCH 20/40] sg: " Christoph Hellwig
2018-04-25 15:48 ` [PATCH 21/40] afs: " Christoph Hellwig
2018-04-30 23:20   ` [PATCH 0/3] afs: Network-namespacing and proc David Howells
2018-04-30 23:20     ` [PATCH 1/3] afs: Rearrange fs/afs/proc.c David Howells
2018-05-15 13:43       ` Christoph Hellwig
2018-04-30 23:20     ` [PATCH 2/3] proc: Add a way to make network proc files writable David Howells
2018-05-15 13:48       ` Christoph Hellwig
2018-05-15 14:16       ` David Howells
2018-04-30 23:20     ` [PATCH 3/3] afs: Implement namespacing David Howells
2018-05-15 13:53       ` Christoph Hellwig
2018-05-15 14:28       ` 'Adding' a writable proc file under /proc/net/afs/ [was [PATCH 3/3] afs: Implement namespacing] David Howells
2018-04-25 15:48 ` [PATCH 22/40] ext4: simplify procfs code Christoph Hellwig
2018-04-25 15:48 ` [PATCH 23/40] jfs: " Christoph Hellwig
2018-04-25 15:48 ` [PATCH 24/40] staging/rtl8192u: " Christoph Hellwig
2018-04-25 15:48 ` [PATCH 25/40] resource: switch to proc_create_seq_data Christoph Hellwig
2018-04-25 15:48 ` [PATCH 26/40] drbd: switch to proc_create_single Christoph Hellwig
2018-04-25 15:48 ` [PATCH 27/40] rtc/proc: switch to proc_create_single_data Christoph Hellwig
2018-04-25 18:25   ` Alexandre Belloni
2018-04-25 15:48 ` [PATCH 28/40] bonding: switch to proc_create_seq_data Christoph Hellwig
2018-04-25 15:48 ` [PATCH 29/40] hostap: switch to proc_create_{seq,single}_data Christoph Hellwig
2018-04-25 15:48 ` [PATCH 30/40] neigh: switch to proc_create_seq_data Christoph Hellwig
2018-04-25 15:48 ` [PATCH 31/40] netfilter/xt_hashlimit: switch to proc_create_{seq, single}_data Christoph Hellwig
2018-04-25 15:48 ` [PATCH 32/40] netfilter/x_tables: switch to proc_create_seq_private Christoph Hellwig
2018-04-25 15:48 ` [PATCH 33/40] bluetooth: switch to proc_create_seq_data Christoph Hellwig
2018-04-25 15:48 ` [PATCH 34/40] atm: simplify procfs code Christoph Hellwig
2018-05-05 12:51   ` Eric W. Biederman
2018-05-15 14:12     ` Christoph Hellwig
2018-05-17  1:15       ` Eric W. Biederman
2018-04-25 15:48 ` [PATCH 35/40] atm: switch to proc_create_seq_private Christoph Hellwig
2018-04-25 15:48 ` [PATCH 36/40] isdn: replace ->proc_fops with ->proc_show Christoph Hellwig
2018-04-25 15:48 ` [PATCH 37/40] proc: don't detour through seq->private to get the inode Christoph Hellwig
2018-04-25 15:48 ` [PATCH 38/40] ide: remove ide_driver_proc_write Christoph Hellwig
2018-05-05 13:09   ` Eric W. Biederman
2018-04-25 15:48 ` [PATCH 39/40] ide: replace ->proc_fops with ->proc_show Christoph Hellwig
2018-04-25 15:48 ` [PATCH 40/40] tty: " Christoph Hellwig
2018-04-30 13:19 ` [PATCH 04/40] proc: introduce proc_create_seq{,_data} David Howells
2018-05-15 14:42   ` Christoph Hellwig
2018-04-30 15:38 ` simplify procfs code for seq_file instances V2 David Howells
2018-05-06 17:19 ` Alexey Dobriyan
2018-05-06 17:45   ` Al Viro
2018-05-09 16:53     ` Alexey Dobriyan
2018-05-15 14:03   ` Christoph Hellwig

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=20180425154827.32251-9-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 \
    --subject='Re: [PATCH 08/40] ipv{4,6}/tcp: simplify procfs registration' \
    /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

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).