Skip to contentSkip to conversation

ipv4: convert /proc/net/sockstat to seq_file

PATCH New Arnaldo Carvalho de Melo 1 participant 1 message Nov 13, 2002

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv4: convert /proc/net/sockstat to seq_file

Hi David,

Please pull from:

master.kernel.org:/home/acme/BK/net-2.5

Now there are two outstanding changesets.

- Arnaldo

You can import this changeset into BK by piping this whole message to:
'| bk receive [path to repository]' or apply the patch as usual.

===================================================================

[email protected], 2002-11-13 09:38:15-02:00, [email protected]
o ipv4: convert /proc/net/sockstat to seq_file

Also only compile/link socket_seq_show (previously socket_get_info) in net/socket.c if CONFIG_PROC_FS is enabled.

 ipv4/proc.c |   85 ++++++++++++++++++++++++++----------------------------------
 socket.c    |   22 ++++-----------
 2 files changed, 43 insertions(+), 64 deletions(-)
net/ipv4/proc.c +37 -48
diff -Nru a/net/ipv4/proc.c b/net/ipv4/proc.c
@@ -23,7 +23,7 @@
  *		Alan Cox	:	Handle dead sockets properly.
  *	Gerhard Koerting	:	Show both timers
  *		Alan Cox	:	Allow inode to be NULL (kernel socket)
- *	Andi Kleen		:	Add support for open_requests and 
+ *	Andi Kleen		:	Add support for open_requests and
  *					split functions for more readibility.
  *	Andi Kleen		:	Add support for /proc/net/netstat
  *	Arnaldo C. Melo		:	Convert to seq_file
@@ -33,21 +33,11 @@
  *		as published by the Free Software Foundation; either version
  *		2 of the License, or (at your option) any later version.
  */
-#include <asm/system.h>
-#include <linux/sched.h>
-#include <linux/socket.h>
-#include <linux/net.h>
-#include <linux/un.h>
-#include <linux/in.h>
-#include <linux/param.h>
-#include <linux/inet.h>
-#include <linux/netdevice.h>
-#include <net/ip.h>
+#include <linux/types.h>
 #include <net/icmp.h>
 #include <net/protocol.h>
 #include <net/tcp.h>
 #include <net/udp.h>
-#include <linux/skbuff.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <net/sock.h>
@@ -58,7 +48,7 @@
 	int res = 0;
 	int cpu;
 
-	for (cpu=0; cpu<NR_CPUS; cpu++)
+	for (cpu = 0; cpu < NR_CPUS; cpu++)
 		res += proto->stats[cpu].inuse;
 
 	return res;
@@ -67,38 +57,35 @@
 /*
  *	Report socket allocation statistics [[email protected]]
  */
-int afinet_get_info(char *buffer, char **start, off_t offset, int length)
+static int sockstat_seq_show(struct seq_file *seq, void *v)
 {
-	/* From  net/socket.c  */
-	extern int socket_get_info(char *, char **, off_t, int);
+	/* From net/socket.c */
+	extern void socket_seq_show(struct seq_file *seq);
 
-	int len  = socket_get_info(buffer,start,offset,length);
+	socket_seq_show(seq);
+	seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %d\n",
+		   fold_prot_inuse(&tcp_prot), atomic_read(&tcp_orphan_count),
+		   tcp_tw_count, atomic_read(&tcp_sockets_allocated),
+		   atomic_read(&tcp_memory_allocated));
+	seq_printf(seq, "UDP: inuse %d\n", fold_prot_inuse(&udp_prot));
+	seq_printf(seq, "RAW: inuse %d\n", fold_prot_inuse(&raw_prot));
+	seq_printf(seq,  "FRAG: inuse %d memory %d\n", ip_frag_nqueues,
+		   atomic_read(&ip_frag_mem));
+	return 0;
+}
 
-	len += sprintf(buffer+len,"TCP: inuse %d orphan %d tw %d alloc %d mem %d\n",
-		       fold_prot_inuse(&tcp_prot),
-		       atomic_read(&tcp_orphan_count), tcp_tw_count,
-		       atomic_read(&tcp_sockets_allocated),
-		       atomic_read(&tcp_memory_allocated));
-	len += sprintf(buffer+len,"UDP: inuse %d\n",
-		       fold_prot_inuse(&udp_prot));
-	len += sprintf(buffer+len,"RAW: inuse %d\n",
-		       fold_prot_inuse(&raw_prot));
-	len += sprintf(buffer+len, "FRAG: inuse %d memory %d\n",
-		       ip_frag_nqueues, atomic_read(&ip_frag_mem));
-	if (offset >= len)
-	{
-		*start = buffer;
-		return 0;
-	}
-	*start = buffer + offset;
-	len -= offset;
-	if (len > length)
-		len = length;
-	if (len < 0)
-		len = 0;
-	return len;
+static int sockstat_seq_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, sockstat_seq_show, NULL);
 }
 
+static struct file_operations sockstat_seq_fops = {
+	.open	 = sockstat_seq_open,
+	.read	 = seq_read,
+	.llseek	 = seq_lseek,
+	.release = single_release,
+};
+
 static unsigned long fold_field(unsigned long *begin, int sz, int nr)
 {
 	unsigned long res = 0;
@@ -106,14 +93,14 @@
 
 	sz /= sizeof(unsigned long);
 
-	for (i=0; i<NR_CPUS; i++) {
-		res += begin[2*i*sz + nr];
-		res += begin[(2*i+1)*sz + nr];
+	for (i = 0; i < NR_CPUS; i++) {
+		res += begin[2 * i * sz + nr];
+		res += begin[(2 * i + 1) * sz + nr];
 	}
 	return res;
 }
 
-/* 
+/*
  *	Called from the PROCfs module. This outputs /proc/net/snmp.
  */
 static int snmp_seq_show(struct seq_file *seq, void *v)
@@ -160,7 +147,7 @@
 
 	seq_printf(seq, "\nUdp: InDatagrams NoPorts InErrors OutDatagrams\n"
 			"Udp:");
-	
+
 	for (i = 0;
 	     i < offsetof(struct udp_mib, __pad) / sizeof(unsigned long); i++)
 		seq_printf(seq, " %lu",
@@ -183,7 +170,7 @@
 	.release = single_release,
 };
 
-/* 
+/*
  *	Output /proc/net/netstat
  */
 static int netstat_seq_show(struct seq_file *seq, void *v)
@@ -243,7 +230,7 @@
 {
 	int rc = 0;
 	struct proc_dir_entry *p;
-		
+
 	p = create_proc_entry("netstat", S_IRUGO, proc_net);
 	if (!p)
 		goto out_netstat;
@@ -254,8 +241,10 @@
 		goto out_snmp;
 	p->proc_fops = &snmp_seq_fops;
 
-	if (!proc_net_create("sockstat", 0, afinet_get_info))
+	p = create_proc_entry("sockstat", S_IRUGO, proc_net);
+	if (!p)
 		goto out_sockstat;
+	p->proc_fops = &sockstat_seq_fops;
 out:
 	return rc;
 out_sockstat:
net/socket.c +6 -16
diff -Nru a/net/socket.c b/net/socket.c
@@ -1839,29 +1839,19 @@
 #endif
 }
 
-int socket_get_info(char *buffer, char **start, off_t offset, int length)
+#ifdef CONFIG_PROC_FS
+void socket_seq_show(struct seq_file *seq)
 {
-	int len, cpu;
+	int cpu;
 	int counter = 0;
 
-	for (cpu=0; cpu<NR_CPUS; cpu++)
+	for (cpu = 0; cpu < NR_CPUS; cpu++)
 		counter += sockets_in_use[cpu].counter;
 
 	/* It can be negative, by the way. 8) */
 	if (counter < 0)
 		counter = 0;
 
-	len = sprintf(buffer, "sockets: used %d\n", counter);
-	if (offset >= len)
-	{
-		*start = buffer;
-		return 0;
-	}
-	*start = buffer + offset;
-	len -= offset;
-	if (len > length)
-		len = length;
-	if (len < 0)
-		len = 0;
-	return len;
+	seq_printf(seq, "sockets: used %d\n", counter);
 }
+#endif /* CONFIG_PROC_FS */

===================================================================

This BitKeeper patch contains the following changesets:
1.826
## Wrapped with gzip_uu ##

begin 664 bkpatch15114 M'XL(`!$[TCT``^57;6_;-A#^+/Z*6X(5MN,74N]VZJ)IW&1&BR9P%NS#.AB* M1"="95*5:*?9W/^^(V5[KNVT:;%O3122.MX=']ZK<@C7)2]Z5A1/.3F$WV2I M>E8L!8]5.H_:L9RV;PK<&$F)&YT[.>6=5V\Z@JN6W?8([EQ&*KZ#.2_*GL7:
MSIJB'G+>LT:OSZ_?GHP(Z??A]"X2M_R**^CWB9+%/,J2\F6D[C(IVJJ(1#GE MRIRY6+,N;$IM_/58X%#/7S"?NL$B9@ECD<MX0FTW]%VBX;_<AKVEA3'F4.IY M-EW8H>,S,@#6#FT?J-UAK,,<H-V>$_:8UZ)VCU+8JQ2.;&A1\@K^WPN<DA@D MI/G<[0$>B>94T,D+&6M3=TH9?RA5I/!0*/G'\23-.K@<Y*5$J3('E!JFB.Y MDZ7BV@!KL::M[R3]U#+"SY/Y:Q$QN7>+?ZE8B+KD`I4M#J&JW8,Z01.+]Z= M#<_'EZ.+T_'9%:0E<!'=9#QIDS=@AR[MDLO_/$I:W_E#"(TH>?$-*VZ"VC1D MUPL6OAL$WB*FD\#VHXGG!9,;NQOO=]JN(AT,^(2,H:(N#9X$1;O'.&4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