Commit a661c419 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by David S. Miller

net: convert /proc/net/rt_acct to seq_file

Rewrite statistics accumulation to be in terms of structure fields,
not raw u32 additions. Keep them in same order, though.

This is the last user of create_proc_read_entry() in net/,
please NAK all new ones as well as all new ->write_proc, ->read_proc and
create_proc_entry() users. Cc me if there are problems. :-)
Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 09ad9bc7
...@@ -513,43 +513,42 @@ static const struct file_operations rt_cpu_seq_fops = { ...@@ -513,43 +513,42 @@ static const struct file_operations rt_cpu_seq_fops = {
}; };
#ifdef CONFIG_NET_CLS_ROUTE #ifdef CONFIG_NET_CLS_ROUTE
static int ip_rt_acct_read(char *buffer, char **start, off_t offset, static int rt_acct_proc_show(struct seq_file *m, void *v)
int length, int *eof, void *data)
{ {
unsigned int i; struct ip_rt_acct *dst, *src;
unsigned int i, j;
if ((offset & 3) || (length & 3)) dst = kcalloc(256, sizeof(struct ip_rt_acct), GFP_KERNEL);
return -EIO; if (!dst)
return -ENOMEM;
if (offset >= sizeof(struct ip_rt_acct) * 256) { for_each_possible_cpu(i) {
*eof = 1; src = (struct ip_rt_acct *)per_cpu_ptr(ip_rt_acct, i);
return 0; for (j = 0; j < 256; j++) {
dst[j].o_bytes += src[j].o_bytes;
dst[j].o_packets += src[j].o_packets;
dst[j].i_bytes += src[j].i_bytes;
dst[j].i_packets += src[j].i_packets;
} }
if (offset + length >= sizeof(struct ip_rt_acct) * 256) {
length = sizeof(struct ip_rt_acct) * 256 - offset;
*eof = 1;
} }
offset /= sizeof(u32); seq_write(m, dst, 256 * sizeof(struct ip_rt_acct));
kfree(dst);
if (length > 0) { return 0;
u32 *dst = (u32 *) buffer; }
*start = buffer;
memset(dst, 0, length);
for_each_possible_cpu(i) {
unsigned int j;
u32 *src;
src = ((u32 *) per_cpu_ptr(ip_rt_acct, i)) + offset; static int rt_acct_proc_open(struct inode *inode, struct file *file)
for (j = 0; j < length/4; j++) {
dst[j] += src[j]; return single_open(file, rt_acct_proc_show, NULL);
}
}
return length;
} }
static const struct file_operations rt_acct_proc_fops = {
.owner = THIS_MODULE,
.open = rt_acct_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
#endif #endif
static int __net_init ip_rt_do_proc_init(struct net *net) static int __net_init ip_rt_do_proc_init(struct net *net)
...@@ -567,8 +566,7 @@ static int __net_init ip_rt_do_proc_init(struct net *net) ...@@ -567,8 +566,7 @@ static int __net_init ip_rt_do_proc_init(struct net *net)
goto err2; goto err2;
#ifdef CONFIG_NET_CLS_ROUTE #ifdef CONFIG_NET_CLS_ROUTE
pde = create_proc_read_entry("rt_acct", 0, net->proc_net, pde = proc_create("rt_acct", 0, net->proc_net, &rt_acct_proc_fops);
ip_rt_acct_read, NULL);
if (!pde) if (!pde)
goto err3; goto err3;
#endif #endif
......
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