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.
parent 01daf811
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* Alan Cox : Handle dead sockets properly. * Alan Cox : Handle dead sockets properly.
* Gerhard Koerting : Show both timers * Gerhard Koerting : Show both timers
* Alan Cox : Allow inode to be NULL (kernel socket) * 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. * split functions for more readibility.
* Andi Kleen : Add support for /proc/net/netstat * Andi Kleen : Add support for /proc/net/netstat
* Arnaldo C. Melo : Convert to seq_file * Arnaldo C. Melo : Convert to seq_file
...@@ -33,21 +33,11 @@ ...@@ -33,21 +33,11 @@
* as published by the Free Software Foundation; either version * as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version. * 2 of the License, or (at your option) any later version.
*/ */
#include <asm/system.h> #include <linux/types.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 <net/icmp.h> #include <net/icmp.h>
#include <net/protocol.h> #include <net/protocol.h>
#include <net/tcp.h> #include <net/tcp.h>
#include <net/udp.h> #include <net/udp.h>
#include <linux/skbuff.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <net/sock.h> #include <net/sock.h>
...@@ -58,7 +48,7 @@ static int fold_prot_inuse(struct proto *proto) ...@@ -58,7 +48,7 @@ static int fold_prot_inuse(struct proto *proto)
int res = 0; int res = 0;
int cpu; int cpu;
for (cpu=0; cpu<NR_CPUS; cpu++) for (cpu = 0; cpu < NR_CPUS; cpu++)
res += proto->stats[cpu].inuse; res += proto->stats[cpu].inuse;
return res; return res;
...@@ -67,38 +57,35 @@ static int fold_prot_inuse(struct proto *proto) ...@@ -67,38 +57,35 @@ static int fold_prot_inuse(struct proto *proto)
/* /*
* Report socket allocation statistics [mea@utu.fi] * Report socket allocation statistics [mea@utu.fi]
*/ */
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 */ /* From net/socket.c */
extern int socket_get_info(char *, char **, off_t, int); 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",
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),
fold_prot_inuse(&tcp_prot), tcp_tw_count, atomic_read(&tcp_sockets_allocated),
atomic_read(&tcp_orphan_count), tcp_tw_count, atomic_read(&tcp_memory_allocated));
atomic_read(&tcp_sockets_allocated), seq_printf(seq, "UDP: inuse %d\n", fold_prot_inuse(&udp_prot));
atomic_read(&tcp_memory_allocated)); seq_printf(seq, "RAW: inuse %d\n", fold_prot_inuse(&raw_prot));
len += sprintf(buffer+len,"UDP: inuse %d\n", seq_printf(seq, "FRAG: inuse %d memory %d\n", ip_frag_nqueues,
fold_prot_inuse(&udp_prot)); atomic_read(&ip_frag_mem));
len += sprintf(buffer+len,"RAW: inuse %d\n", return 0;
fold_prot_inuse(&raw_prot)); }
len += sprintf(buffer+len, "FRAG: inuse %d memory %d\n",
ip_frag_nqueues, atomic_read(&ip_frag_mem)); static int sockstat_seq_open(struct inode *inode, struct file *file)
if (offset >= len) {
{ return single_open(file, sockstat_seq_show, NULL);
*start = buffer;
return 0;
}
*start = buffer + offset;
len -= offset;
if (len > length)
len = length;
if (len < 0)
len = 0;
return len;
} }
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) static unsigned long fold_field(unsigned long *begin, int sz, int nr)
{ {
unsigned long res = 0; unsigned long res = 0;
...@@ -106,14 +93,14 @@ static unsigned long fold_field(unsigned long *begin, int sz, int nr) ...@@ -106,14 +93,14 @@ static unsigned long fold_field(unsigned long *begin, int sz, int nr)
sz /= sizeof(unsigned long); sz /= sizeof(unsigned long);
for (i=0; i<NR_CPUS; i++) { for (i = 0; i < NR_CPUS; i++) {
res += begin[2*i*sz + nr]; res += begin[2 * i * sz + nr];
res += begin[(2*i+1)*sz + nr]; res += begin[(2 * i + 1) * sz + nr];
} }
return res; return res;
} }
/* /*
* Called from the PROCfs module. This outputs /proc/net/snmp. * Called from the PROCfs module. This outputs /proc/net/snmp.
*/ */
static int snmp_seq_show(struct seq_file *seq, void *v) static int snmp_seq_show(struct seq_file *seq, void *v)
...@@ -160,7 +147,7 @@ static int snmp_seq_show(struct seq_file *seq, void *v) ...@@ -160,7 +147,7 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
seq_printf(seq, "\nUdp: InDatagrams NoPorts InErrors OutDatagrams\n" seq_printf(seq, "\nUdp: InDatagrams NoPorts InErrors OutDatagrams\n"
"Udp:"); "Udp:");
for (i = 0; for (i = 0;
i < offsetof(struct udp_mib, __pad) / sizeof(unsigned long); i++) i < offsetof(struct udp_mib, __pad) / sizeof(unsigned long); i++)
seq_printf(seq, " %lu", seq_printf(seq, " %lu",
...@@ -183,7 +170,7 @@ static struct file_operations snmp_seq_fops = { ...@@ -183,7 +170,7 @@ static struct file_operations snmp_seq_fops = {
.release = single_release, .release = single_release,
}; };
/* /*
* Output /proc/net/netstat * Output /proc/net/netstat
*/ */
static int netstat_seq_show(struct seq_file *seq, void *v) static int netstat_seq_show(struct seq_file *seq, void *v)
...@@ -243,7 +230,7 @@ int __init ip_misc_proc_init(void) ...@@ -243,7 +230,7 @@ int __init ip_misc_proc_init(void)
{ {
int rc = 0; int rc = 0;
struct proc_dir_entry *p; struct proc_dir_entry *p;
p = create_proc_entry("netstat", S_IRUGO, proc_net); p = create_proc_entry("netstat", S_IRUGO, proc_net);
if (!p) if (!p)
goto out_netstat; goto out_netstat;
...@@ -254,8 +241,10 @@ int __init ip_misc_proc_init(void) ...@@ -254,8 +241,10 @@ int __init ip_misc_proc_init(void)
goto out_snmp; goto out_snmp;
p->proc_fops = &snmp_seq_fops; 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; goto out_sockstat;
p->proc_fops = &sockstat_seq_fops;
out: out:
return rc; return rc;
out_sockstat: out_sockstat:
......
...@@ -1839,29 +1839,19 @@ void __init sock_init(void) ...@@ -1839,29 +1839,19 @@ void __init sock_init(void)
#endif #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; int counter = 0;
for (cpu=0; cpu<NR_CPUS; cpu++) for (cpu = 0; cpu < NR_CPUS; cpu++)
counter += sockets_in_use[cpu].counter; counter += sockets_in_use[cpu].counter;
/* It can be negative, by the way. 8) */ /* It can be negative, by the way. 8) */
if (counter < 0) if (counter < 0)
counter = 0; counter = 0;
len = sprintf(buffer, "sockets: used %d\n", counter); seq_printf(seq, "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;
} }
#endif /* CONFIG_PROC_FS */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment