Commit bd2f7476 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by David S. Miller

[KEY]: Convert net/pfkey to use seq files.

The seq files API disposes the caller of the difficulty of
checking file position, the length of data to produce and
the size of provided buffer.
Signed-off-by: default avatarPavel Emelyanov <xemul@openvz.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 61145aa1
...@@ -3734,21 +3734,15 @@ static struct net_proto_family pfkey_family_ops = { ...@@ -3734,21 +3734,15 @@ static struct net_proto_family pfkey_family_ops = {
}; };
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
static int pfkey_read_proc(char *buffer, char **start, off_t offset, static int pfkey_seq_show(struct seq_file *f, void *v)
int length, int *eof, void *data)
{ {
off_t pos = 0;
off_t begin = 0;
int len = 0;
struct sock *s; struct sock *s;
struct hlist_node *node;
len += sprintf(buffer,"sk RefCnt Rmem Wmem User Inode\n");
read_lock(&pfkey_table_lock);
sk_for_each(s, node, &pfkey_table) { s = (struct sock *)v;
len += sprintf(buffer+len,"%p %-6d %-6u %-6u %-6u %-6lu", if (v == SEQ_START_TOKEN)
seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
else
seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
s, s,
atomic_read(&s->sk_refcnt), atomic_read(&s->sk_refcnt),
atomic_read(&s->sk_rmem_alloc), atomic_read(&s->sk_rmem_alloc),
...@@ -3756,39 +3750,67 @@ static int pfkey_read_proc(char *buffer, char **start, off_t offset, ...@@ -3756,39 +3750,67 @@ static int pfkey_read_proc(char *buffer, char **start, off_t offset,
sock_i_uid(s), sock_i_uid(s),
sock_i_ino(s) sock_i_ino(s)
); );
return 0;
}
buffer[len++] = '\n'; static void *pfkey_seq_start(struct seq_file *f, loff_t *ppos)
{
struct sock *s;
struct hlist_node *node;
loff_t pos = *ppos;
pos = begin + len; read_lock(&pfkey_table_lock);
if (pos < offset) { if (pos == 0)
len = 0; return SEQ_START_TOKEN;
begin = pos;
}
if(pos > offset + length)
goto done;
}
*eof = 1;
done: sk_for_each(s, node, &pfkey_table)
read_unlock(&pfkey_table_lock); if (pos-- == 1)
return s;
return NULL;
}
*start = buffer + (offset - begin); static void *pfkey_seq_next(struct seq_file *f, void *v, loff_t *ppos)
len -= (offset - begin); {
++*ppos;
return (v == SEQ_START_TOKEN) ?
sk_head(&pfkey_table) :
sk_next((struct sock *)v);
}
if (len > length) static void pfkey_seq_stop(struct seq_file *f, void *v)
len = length; {
if (len < 0) read_unlock(&pfkey_table_lock);
len = 0; }
return len; static struct seq_operations pfkey_seq_ops = {
.start = pfkey_seq_start,
.next = pfkey_seq_next,
.stop = pfkey_seq_stop,
.show = pfkey_seq_show,
};
static int pfkey_seq_open(struct inode *inode, struct file *file)
{
return seq_open(file, &pfkey_seq_ops);
} }
static struct file_operations pfkey_proc_ops = {
.open = pfkey_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
static int pfkey_init_proc(void) static int pfkey_init_proc(void)
{ {
if (create_proc_read_entry("pfkey", 0, init_net.proc_net, struct proc_dir_entry *e;
pfkey_read_proc, NULL) == NULL)
e = create_proc_entry("pfkey", 0, init_net.proc_net);
if (e == NULL)
return -ENOMEM; return -ENOMEM;
else
e->proc_fops = &pfkey_proc_ops;
return 0; return 0;
} }
......
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