From: Pavel Emelyanov <xemul@openvz.org>
To: David Miller <davem@davemloft.net>
Cc: Linux Netdev List <netdev@vger.kernel.org>
Subject: [PATCH 11/16] proc: create /proc/net/netstat file in each net
Date: Thu, 17 Jul 2008 17:35:22 +0400 [thread overview]
Message-ID: <487F4A9A.4070500@openvz.org> (raw)
In-Reply-To: <487F46CD.7090103@openvz.org>
Now all the shown in it statistics is netnsizated, time to
show it in appropriate net.
The appropriate net init/exit ops already exist - they make
the sockstat file per net - so just extend them.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
---
net/ipv4/proc.c | 47 ++++++++++++++++++++++++++++++++++++++---------
1 files changed, 38 insertions(+), 9 deletions(-)
diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
index e11144b..df8c4af 100644
--- a/net/ipv4/proc.c
+++ b/net/ipv4/proc.c
@@ -413,6 +413,7 @@ static const struct file_operations snmp_seq_fops = {
static int netstat_seq_show(struct seq_file *seq, void *v)
{
int i;
+ struct net *net = seq->private;
seq_puts(seq, "TcpExt:");
for (i = 0; snmp4_net_list[i].name != NULL; i++)
@@ -421,7 +422,7 @@ static int netstat_seq_show(struct seq_file *seq, void *v)
seq_puts(seq, "\nTcpExt:");
for (i = 0; snmp4_net_list[i].name != NULL; i++)
seq_printf(seq, " %lu",
- snmp_fold_field((void **)init_net.mib.net_statistics,
+ snmp_fold_field((void **)net->mib.net_statistics,
snmp4_net_list[i].entry));
seq_puts(seq, "\nIpExt:");
@@ -431,7 +432,7 @@ static int netstat_seq_show(struct seq_file *seq, void *v)
seq_puts(seq, "\nIpExt:");
for (i = 0; snmp4_ipextstats_list[i].name != NULL; i++)
seq_printf(seq, " %lu",
- snmp_fold_field((void **)init_net.mib.ip_statistics,
+ snmp_fold_field((void **)net->mib.ip_statistics,
snmp4_ipextstats_list[i].entry));
seq_putc(seq, '\n');
@@ -440,7 +441,32 @@ static int netstat_seq_show(struct seq_file *seq, void *v)
static int netstat_seq_open(struct inode *inode, struct file *file)
{
- return single_open(file, netstat_seq_show, NULL);
+ int err;
+ struct net *net;
+
+ err = -ENXIO;
+ net = get_proc_net(inode);
+ if (net == NULL)
+ goto err_net;
+
+ err = single_open(file, netstat_seq_show, net);
+ if (err < 0)
+ goto err_open;
+
+ return 0;
+
+err_open:
+ put_net(net);
+err_net:
+ return err;
+}
+
+static int netstat_seq_release(struct inode *inode, struct file *file)
+{
+ struct net *net = ((struct seq_file *)file->private_data)->private;
+
+ put_net(net);
+ return single_release(inode, file);
}
static const struct file_operations netstat_seq_fops = {
@@ -448,18 +474,26 @@ static const struct file_operations netstat_seq_fops = {
.open = netstat_seq_open,
.read = seq_read,
.llseek = seq_lseek,
- .release = single_release,
+ .release = netstat_seq_release,
};
static __net_init int ip_proc_init_net(struct net *net)
{
if (!proc_net_fops_create(net, "sockstat", S_IRUGO, &sockstat_seq_fops))
return -ENOMEM;
+ if (!proc_net_fops_create(net, "netstat", S_IRUGO, &netstat_seq_fops))
+ goto out_netstat;
+
return 0;
+
+out_netstat:
+ proc_net_remove(net, "sockstat");
+ return -ENOMEM;
}
static __net_exit void ip_proc_exit_net(struct net *net)
{
+ proc_net_remove(net, "netstat");
proc_net_remove(net, "sockstat");
}
@@ -475,16 +509,11 @@ int __init ip_misc_proc_init(void)
if (register_pernet_subsys(&ip_proc_ops))
goto out_pernet;
- if (!proc_net_fops_create(&init_net, "netstat", S_IRUGO, &netstat_seq_fops))
- goto out_netstat;
-
if (!proc_net_fops_create(&init_net, "snmp", S_IRUGO, &snmp_seq_fops))
goto out_snmp;
out:
return rc;
out_snmp:
- proc_net_remove(&init_net, "netstat");
-out_netstat:
unregister_pernet_subsys(&ip_proc_ops);
out_pernet:
rc = -ENOMEM;
--
1.5.5.1
next prev parent reply other threads:[~2008-07-17 13:35 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-17 13:19 [PATCH 0/16] mib: finish with ipv4 mibs netnsization Pavel Emelyanov
2008-07-17 13:21 ` [PATCH 1/16] mib: add netns/mib.h file Pavel Emelyanov
2008-07-17 13:23 ` [PATCH 2/16] ipv4: add pernet mib operations Pavel Emelyanov
2008-07-17 13:25 ` [PATCH 3/16] mib: put tcp statistics on struct net Pavel Emelyanov
2008-07-17 13:26 ` [PATCH 4/16] mib: put ip " Pavel Emelyanov
2008-07-17 13:28 ` [PATCH 5/16] mib: put net " Pavel Emelyanov
2008-07-17 13:29 ` [PATCH 6/16] mib: put udp " Pavel Emelyanov
2008-07-17 13:30 ` [PATCH 7/16] mib: put udplite " Pavel Emelyanov
2008-07-17 13:31 ` [PATCH 8/16] mib: put icmp " Pavel Emelyanov
2008-07-17 13:32 ` [PATCH 9/16] mib: put icmpmsg " Pavel Emelyanov
2008-07-17 13:33 ` [PATCH 10/16] ipvs: clean the init_ipv4_mibs error paths Pavel Emelyanov
2008-07-17 13:35 ` Pavel Emelyanov [this message]
2008-07-17 13:36 ` [PATCH 12/16] proc: create /proc/net/snmp file in each net Pavel Emelyanov
2008-07-17 13:38 ` [PATCH 13/16] proc: show per-net ip_devconf.forwarding in /proc/net/snmp Pavel Emelyanov
2008-07-17 13:40 ` [PATCH 14/16] proc: clean the ip_misc_proc_init and ip_proc_init_net error paths Pavel Emelyanov
2008-07-17 13:41 ` [PATCH 15/16] proc: consolidate per-net single_open callers Pavel Emelyanov
2008-07-17 13:43 ` [PATCH 16/16] proc: consolidate per-net single-release callers Pavel Emelyanov
2008-07-18 11:09 ` [PATCH 0/16] mib: finish with ipv4 mibs netnsization David Miller
2008-07-21 17:38 ` Pavel Emelyanov
2008-07-22 0:24 ` Eric W. Biederman
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=487F4A9A.4070500@openvz.org \
--to=xemul@openvz.org \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/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).