linux-ext4.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, Corey Minyard <minyard@acm.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 07/39] ipv{4, 6}/ping: simplify proc file creation
Date: Thu, 19 Apr 2018 14:41:08 +0200	[thread overview]
Message-ID: <20180419124140.9309-8-hch@lst.de> (raw)
In-Reply-To: <20180419124140.9309-1-hch@lst.de>

Remove the pointless ping_seq_afinfo indirection and make the code look
like most other protocols.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 include/net/ping.h | 11 ----------
 net/ipv4/ping.c    | 50 +++++++++++++---------------------------------
 net/ipv6/ping.c    | 35 +++++++++++++++++++++-----------
 3 files changed, 37 insertions(+), 59 deletions(-)

diff --git a/include/net/ping.h b/include/net/ping.h
index 4cd90d6b5c25..fd080e043a6e 100644
--- a/include/net/ping.h
+++ b/include/net/ping.h
@@ -83,20 +83,9 @@ int  ping_queue_rcv_skb(struct sock *sk, struct sk_buff *skb);
 bool ping_rcv(struct sk_buff *skb);
 
 #ifdef CONFIG_PROC_FS
-struct ping_seq_afinfo {
-	char				*name;
-	sa_family_t			family;
-	const struct file_operations	*seq_fops;
-	const struct seq_operations	seq_ops;
-};
-
-extern const struct file_operations ping_seq_fops;
-
 void *ping_seq_start(struct seq_file *seq, loff_t *pos, sa_family_t family);
 void *ping_seq_next(struct seq_file *seq, void *v, loff_t *pos);
 void ping_seq_stop(struct seq_file *seq, void *v);
-int ping_proc_register(struct net *net, struct ping_seq_afinfo *afinfo);
-void ping_proc_unregister(struct net *net, struct ping_seq_afinfo *afinfo);
 
 int __init ping_proc_init(void);
 void ping_proc_exit(void);
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
index 05e47d777009..83170ebf5dfc 100644
--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -1147,58 +1147,36 @@ static int ping_v4_seq_show(struct seq_file *seq, void *v)
 	return 0;
 }
 
-static int ping_seq_open(struct inode *inode, struct file *file)
+static const struct seq_operations ping_v4_seq_ops = {
+	.start		= ping_v4_seq_start,
+	.show		= ping_v4_seq_show,
+	.next		= ping_seq_next,
+	.stop		= ping_seq_stop,
+};
+
+static int ping_v4_seq_open(struct inode *inode, struct file *file)
 {
-	struct ping_seq_afinfo *afinfo = PDE_DATA(inode);
-	return seq_open_net(inode, file, &afinfo->seq_ops,
+	return seq_open_net(inode, file, &ping_v4_seq_ops,
 			   sizeof(struct ping_iter_state));
 }
 
-const struct file_operations ping_seq_fops = {
-	.open		= ping_seq_open,
+const struct file_operations ping_v4_seq_fops = {
+	.open		= ping_v4_seq_open,
 	.read		= seq_read,
 	.llseek		= seq_lseek,
 	.release	= seq_release_net,
 };
-EXPORT_SYMBOL_GPL(ping_seq_fops);
-
-static struct ping_seq_afinfo ping_v4_seq_afinfo = {
-	.name		= "icmp",
-	.family		= AF_INET,
-	.seq_fops	= &ping_seq_fops,
-	.seq_ops	= {
-		.start		= ping_v4_seq_start,
-		.show		= ping_v4_seq_show,
-		.next		= ping_seq_next,
-		.stop		= ping_seq_stop,
-	},
-};
 
-int ping_proc_register(struct net *net, struct ping_seq_afinfo *afinfo)
+static int __net_init ping_v4_proc_init_net(struct net *net)
 {
-	struct proc_dir_entry *p;
-	p = proc_create_data(afinfo->name, 0444, net->proc_net,
-			     afinfo->seq_fops, afinfo);
-	if (!p)
+	if (!proc_create("icmp", 0444, net->proc_net, &ping_v4_seq_fops))
 		return -ENOMEM;
 	return 0;
 }
-EXPORT_SYMBOL_GPL(ping_proc_register);
-
-void ping_proc_unregister(struct net *net, struct ping_seq_afinfo *afinfo)
-{
-	remove_proc_entry(afinfo->name, net->proc_net);
-}
-EXPORT_SYMBOL_GPL(ping_proc_unregister);
-
-static int __net_init ping_v4_proc_init_net(struct net *net)
-{
-	return ping_proc_register(net, &ping_v4_seq_afinfo);
-}
 
 static void __net_exit ping_v4_proc_exit_net(struct net *net)
 {
-	ping_proc_unregister(net, &ping_v4_seq_afinfo);
+	remove_proc_entry("icmp", net->proc_net);
 }
 
 static struct pernet_operations ping_v4_net_ops = {
diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
index 746eeae7f581..45d5c8e0f2bf 100644
--- a/net/ipv6/ping.c
+++ b/net/ipv6/ping.c
@@ -24,6 +24,7 @@
 #include <net/protocol.h>
 #include <net/udp.h>
 #include <net/transp_v6.h>
+#include <linux/proc_fs.h>
 #include <net/ping.h>
 
 /* Compatibility glue so we can support IPv6 when it's compiled as a module */
@@ -215,26 +216,36 @@ static int ping_v6_seq_show(struct seq_file *seq, void *v)
 	return 0;
 }
 
-static struct ping_seq_afinfo ping_v6_seq_afinfo = {
-	.name		= "icmp6",
-	.family		= AF_INET6,
-	.seq_fops       = &ping_seq_fops,
-	.seq_ops	= {
-		.start		= ping_v6_seq_start,
-		.show		= ping_v6_seq_show,
-		.next		= ping_seq_next,
-		.stop		= ping_seq_stop,
-	},
+static const struct seq_operations ping_v6_seq_ops = {
+	.start		= ping_v6_seq_start,
+	.show		= ping_v6_seq_show,
+	.next		= ping_seq_next,
+	.stop		= ping_seq_stop,
+};
+
+static int ping_v6_seq_open(struct inode *inode, struct file *file)
+{
+	return seq_open_net(inode, file, &ping_v6_seq_ops,
+			   sizeof(struct ping_iter_state));
+}
+
+const struct file_operations ping_v6_seq_fops = {
+	.open		= ping_v6_seq_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= seq_release_net,
 };
 
 static int __net_init ping_v6_proc_init_net(struct net *net)
 {
-	return ping_proc_register(net, &ping_v6_seq_afinfo);
+	if (!proc_create("icmp6", 0444, net->proc_net, &ping_v6_seq_fops))
+		return -ENOMEM;
+	return 0;
 }
 
 static void __net_init ping_v6_proc_exit_net(struct net *net)
 {
-	return ping_proc_unregister(net, &ping_v6_seq_afinfo);
+	remove_proc_entry("icmp6", net->proc_net);
 }
 
 static struct pernet_operations ping_v6_net_ops = {
-- 
2.17.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

  parent reply	other threads:[~2018-04-19 12:41 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-19 12:41 simplify procfs code for seq_file instances Christoph Hellwig
2018-04-19 12:41 ` [PATCH 01/39] net/can: single_open_net needs to be paired with single_release_net Christoph Hellwig
2018-04-19 12:41 ` [PATCH 02/39] proc: introduce proc_create_seq{,_data} Christoph Hellwig
2018-04-19 18:41   ` Alexey Dobriyan
2018-04-24 14:29     ` Christoph Hellwig
2018-04-19 12:41 ` [PATCH 03/39] proc: introduce proc_create_seq_private Christoph Hellwig
2018-04-19 14:18   ` Dan Carpenter
2018-04-24 14:19     ` Christoph Hellwig
2018-04-19 18:50   ` Alexey Dobriyan
2018-04-24 14:29     ` Christoph Hellwig
2018-04-19 12:41 ` [PATCH 04/39] proc: introduce proc_create_single{,_data} Christoph Hellwig
2018-04-19 12:41 ` [PATCH 05/39] ipv{4, 6}/udp{, lite}: simplify proc registration Christoph Hellwig
2018-04-19 12:41 ` [PATCH 06/39] ipv{4, 6}/tcp: simplify procfs registration Christoph Hellwig
2018-04-19 12:41 ` Christoph Hellwig [this message]
2018-04-19 12:41 ` [PATCH 08/39] ipv{4,6}/raw: simplify ѕeq_file code Christoph Hellwig
2018-04-19 12:41 ` [PATCH 09/39] ipv6/flowlabel: simplify pid namespace lookup Christoph Hellwig
2018-04-19 12:41 ` [PATCH 10/39] net/kcm: simplify proc registration Christoph Hellwig
2018-04-19 12:41 ` [PATCH 11/39] netfilter/x_tables: simplify ѕeq_file code Christoph Hellwig
2018-04-19 12:41 ` [PATCH 12/39] net: move seq_file_single_net to <linux/seq_file_net.h> Christoph Hellwig
2018-04-19 12:41 ` [PATCH 13/39] proc: introduce proc_create_net{,_data} Christoph Hellwig
2018-04-19 12:41 ` [PATCH 14/39] proc: introduce proc_create_net_single Christoph Hellwig
2018-04-19 18:44   ` Alexey Dobriyan
2018-04-19 12:41 ` [PATCH 15/39] acpi/battery: simplify procfs code Christoph Hellwig
2018-04-22  9:42   ` Rafael J. Wysocki
2018-04-19 12:41 ` [PATCH 16/39] ipmi: " Christoph Hellwig
2018-04-19 15:29   ` Corey Minyard
2018-04-24 14:16     ` Christoph Hellwig
2018-04-19 12:41 ` [PATCH 17/39] sgi-gru: " Christoph Hellwig
2018-04-19 12:41 ` [PATCH 18/39] megaraid: " Christoph Hellwig
2018-04-19 12:41 ` [PATCH 19/39] sg: " Christoph Hellwig
2018-04-19 12:41 ` [PATCH 20/39] afs: " Christoph Hellwig
2018-04-19 12:41 ` [PATCH 21/39] ext4: " Christoph Hellwig
2018-04-19 12:41 ` [PATCH 22/39] jfs: " Christoph Hellwig
2018-04-19 12:41 ` [PATCH 23/39] staging/rtl8192u: " Christoph Hellwig
2018-04-19 12:41 ` [PATCH 24/39] resource: switch to proc_create_seq_data Christoph Hellwig
2018-04-19 12:41 ` [PATCH 25/39] drbd: switch to proc_create_single Christoph Hellwig
2018-04-19 12:41 ` [PATCH 26/39] rtc/proc: switch to proc_create_single_data Christoph Hellwig
2018-04-19 13:10   ` Alexandre Belloni
2018-04-24 14:15     ` Christoph Hellwig
2018-04-19 12:41 ` [PATCH 27/39] bonding: switch to proc_create_seq_data Christoph Hellwig
2018-04-19 12:41 ` [PATCH 28/39] hostap: switch to proc_create_{seq,single}_data Christoph Hellwig
2018-04-19 12:41 ` [PATCH 29/39] neigh: switch to proc_create_seq_data Christoph Hellwig
2018-04-19 12:41 ` [PATCH 30/39] netfilter/xt_hashlimit: switch to proc_create_{seq,single}_data Christoph Hellwig
2018-04-19 12:41 ` [PATCH 31/39] netfilter/x_tables: switch to proc_create_seq_private Christoph Hellwig
2018-04-19 12:41 ` [PATCH 32/39] bluetooth: switch to proc_create_seq_data Christoph Hellwig
2018-04-19 12:41 ` [PATCH 33/39] atm: simplify procfs code Christoph Hellwig
2018-04-19 12:41 ` [PATCH 34/39] atm: switch to proc_create_seq_private Christoph Hellwig
2018-04-19 12:41 ` [PATCH 35/39] isdn: replace ->proc_fops with ->proc_show Christoph Hellwig
2018-04-19 12:41 ` [PATCH 36/39] proc: don't detour through seq->private to get the inode Christoph Hellwig
2018-04-19 12:41 ` [PATCH 37/39] ide: remove ide_driver_proc_write Christoph Hellwig
2018-04-19 12:41 ` [PATCH 38/39] ide: replace ->proc_fops with ->proc_show Christoph Hellwig
2018-04-19 12:41 ` [PATCH 39/39] tty: " Christoph Hellwig
2018-04-19 13:00 ` [PATCH 20/39] afs: simplify procfs code David Howells
2018-04-19 18:57 ` simplify procfs code for seq_file instances Alexey Dobriyan
2018-04-24 14:23   ` Christoph Hellwig
2018-04-24 15:19     ` Andrew Morton
     [not found]       ` <20180424081916.e94ca8463fb3c39ebc082bdd-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2018-04-24 16:06         ` Christoph Hellwig
2018-04-25 21:24           ` Alexey Dobriyan

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=20180419124140.9309-8-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=minyard@acm.org \
    --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).