[PATCH 3/16] mib: put tcp statistics on struct net

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: David Miller <davem@...>
Cc: Linux Netdev List <netdev@...>
Date: Thursday, July 17, 2008 - 9:25 am

Proc temporary uses stats from init_net.

BTW, TCP_XXX_STATS are beautiful (w/o do { } while (0) facing) again :)

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
---
 include/net/netns/mib.h |    1 +
 include/net/tcp.h       |    9 ++++-----
 net/ipv4/af_inet.c      |   16 +++++++++-------
 net/ipv4/proc.c         |    4 ++--
 net/ipv4/tcp.c          |    3 ---
 5 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/include/net/netns/mib.h b/include/net/netns/mib.h
index 9f4b31e..8f96079 100644
--- a/include/net/netns/mib.h
+++ b/include/net/netns/mib.h
@@ -4,6 +4,7 @@
 #include <net/snmp.h>
 
 struct netns_mib {
+	DEFINE_SNMP_STAT(struct tcp_mib, tcp_statistics);
 };
 
 #endif
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 60e5be8..92d7b55 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -265,11 +265,10 @@ static inline int tcp_too_many_orphans(struct sock *sk, int num)
 
 extern struct proto tcp_prot;
 
-DECLARE_SNMP_STAT(struct tcp_mib, tcp_statistics);
-#define TCP_INC_STATS(net, field)	do { (void)net; SNMP_INC_STATS(tcp_statistics, field); } while (0)
-#define TCP_INC_STATS_BH(net, field)	do { (void)net; SNMP_INC_STATS_BH(tcp_statistics, field); } while (0)
-#define TCP_DEC_STATS(net, field)	do { (void)net; SNMP_DEC_STATS(tcp_statistics, field); } while (0)
-#define TCP_ADD_STATS_USER(net, field, val) do { (void)net; SNMP_ADD_STATS_USER(tcp_statistics, field, val); } while (0)
+#define TCP_INC_STATS(net, field)	SNMP_INC_STATS((net)->mib.tcp_statistics, field)
+#define TCP_INC_STATS_BH(net, field)	SNMP_INC_STATS_BH((net)->mib.tcp_statistics, field)
+#define TCP_DEC_STATS(net, field)	SNMP_DEC_STATS((net)->mib.tcp_statistics, field)
+#define TCP_ADD_STATS_USER(net, field, val) SNMP_ADD_STATS_USER((net)->mib.tcp_statistics, field, val)
 
 extern void			tcp_v4_err(struct sk_buff *skb, u32);
 
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index b4b77aa..c1a3e98 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1342,11 +1342,20 @@ static struct net_protocol icmp_protocol = {
 
 static __net_init int ipv4_mib_init_net(struct net *net)
 {
+	if (snmp_mib_init((void **)net->mib.tcp_statistics,
+			  sizeof(struct tcp_mib)) < 0)
+		goto err_tcp_mib;
+
+	tcp_mib_init(net);
 	return 0;
+
+err_tcp_mib:
+	return -ENOMEM;
 }
 
 static __net_exit void ipv4_mib_exit_net(struct net *net)
 {
+	snmp_mib_free((void **)net->mib.tcp_statistics);
 }
 
 static __net_initdata struct pernet_operations ipv4_mib_ops = {
@@ -1368,9 +1377,6 @@ static int __init init_ipv4_mibs(void)
 	if (snmp_mib_init((void **)icmpmsg_statistics,
 			  sizeof(struct icmpmsg_mib)) < 0)
 		goto err_icmpmsg_mib;
-	if (snmp_mib_init((void **)tcp_statistics,
-			  sizeof(struct tcp_mib)) < 0)
-		goto err_tcp_mib;
 	if (snmp_mib_init((void **)udp_statistics,
 			  sizeof(struct udp_mib)) < 0)
 		goto err_udp_mib;
@@ -1378,8 +1384,6 @@ static int __init init_ipv4_mibs(void)
 			  sizeof(struct udp_mib)) < 0)
 		goto err_udplite_mib;
 
-	tcp_mib_init(&init_net);
-
 	if (register_pernet_subsys(&ipv4_mib_ops))
 		goto err_net;
 
@@ -1390,8 +1394,6 @@ err_net:
 err_udplite_mib:
 	snmp_mib_free((void **)udp_statistics);
 err_udp_mib:
-	snmp_mib_free((void **)tcp_statistics);
-err_tcp_mib:
 	snmp_mib_free((void **)icmpmsg_statistics);
 err_icmpmsg_mib:
 	snmp_mib_free((void **)icmp_statistics);
diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
index eb5cee2..19e1d8e 100644
--- a/net/ipv4/proc.c
+++ b/net/ipv4/proc.c
@@ -359,11 +359,11 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
 		/* MaxConn field is signed, RFC 2012 */
 		if (snmp4_tcp_list[i].entry == TCP_MIB_MAXCONN)
 			seq_printf(seq, " %ld",
-				   snmp_fold_field((void **)tcp_statistics,
+				   snmp_fold_field((void **)init_net.mib.tcp_statistics,
 						   snmp4_tcp_list[i].entry));
 		else
 			seq_printf(seq, " %lu",
-				   snmp_fold_field((void **)tcp_statistics,
+				   snmp_fold_field((void **)init_net.mib.tcp_statistics,
 						   snmp4_tcp_list[i].entry));
 	}
 
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index e00ef15..21136aa 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -277,8 +277,6 @@
 
 int sysctl_tcp_fin_timeout __read_mostly = TCP_FIN_TIMEOUT;
 
-DEFINE_SNMP_STAT(struct tcp_mib, tcp_statistics) __read_mostly;
-
 atomic_t tcp_orphan_count = ATOMIC_INIT(0);
 
 EXPORT_SYMBOL_GPL(tcp_orphan_count);
@@ -2802,4 +2800,3 @@ EXPORT_SYMBOL(tcp_splice_read);
 EXPORT_SYMBOL(tcp_sendpage);
 EXPORT_SYMBOL(tcp_setsockopt);
 EXPORT_SYMBOL(tcp_shutdown);
-EXPORT_SYMBOL(tcp_statistics);
-- 
1.5.5.1

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/16] mib: finish with ipv4 mibs netnsization, Pavel Emelyanov, (Thu Jul 17, 9:19 am)
Re: [PATCH 0/16] mib: finish with ipv4 mibs netnsization, Pavel Emelyanov, (Mon Jul 21, 1:38 pm)
Re: [PATCH 0/16] mib: finish with ipv4 mibs netnsization, Eric W. Biederman, (Mon Jul 21, 8:24 pm)
[PATCH 15/16] proc: consolidate per-net single_open callers, Pavel Emelyanov, (Thu Jul 17, 9:41 am)
[PATCH 12/16] proc: create /proc/net/snmp file in each net, Pavel Emelyanov, (Thu Jul 17, 9:36 am)
[PATCH 10/16] ipvs: clean the init_ipv4_mibs error paths, Pavel Emelyanov, (Thu Jul 17, 9:33 am)
[PATCH 9/16] mib: put icmpmsg statistics on struct net, Pavel Emelyanov, (Thu Jul 17, 9:32 am)
[PATCH 8/16] mib: put icmp statistics on struct net, Pavel Emelyanov, (Thu Jul 17, 9:31 am)
[PATCH 7/16] mib: put udplite statistics on struct net, Pavel Emelyanov, (Thu Jul 17, 9:30 am)
[PATCH 6/16] mib: put udp statistics on struct net, Pavel Emelyanov, (Thu Jul 17, 9:29 am)
[PATCH 5/16] mib: put net statistics on struct net, Pavel Emelyanov, (Thu Jul 17, 9:28 am)
[PATCH 4/16] mib: put ip statistics on struct net, Pavel Emelyanov, (Thu Jul 17, 9:26 am)
[PATCH 3/16] mib: put tcp statistics on struct net, Pavel Emelyanov, (Thu Jul 17, 9:25 am)
[PATCH 2/16] ipv4: add pernet mib operations, Pavel Emelyanov, (Thu Jul 17, 9:23 am)
[PATCH 1/16] mib: add netns/mib.h file, Pavel Emelyanov, (Thu Jul 17, 9:21 am)