aboutsummaryrefslogtreecommitdiffstats
path: root/net/key/af_key.c
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@openvz.org>2008-02-10 02:20:06 -0500
committerDavid S. Miller <davem@davemloft.net>2008-02-10 02:20:06 -0500
commitbd2f747658b303d9b08d2c5bc815022d825a5e3c (patch)
treec04d118379e68c7cb17a967b16dc561dda418dcd /net/key/af_key.c
parent61145aa1a12401ac71bcc450a58c773dd6e2bfb9 (diff)
[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: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/key/af_key.c')
-rw-r--r--net/key/af_key.c92
1 files changed, 57 insertions, 35 deletions
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 162fcea3324c..b3ac85e808ac 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -3734,21 +3734,15 @@ static struct net_proto_family pfkey_family_ops = {
3734}; 3734};
3735 3735
3736#ifdef CONFIG_PROC_FS 3736#ifdef CONFIG_PROC_FS
3737static int pfkey_read_proc(char *buffer, char **start, off_t offset, 3737static int pfkey_seq_show(struct seq_file *f, void *v)
3738 int length, int *eof, void *data)
3739{ 3738{
3740 off_t pos = 0;
3741 off_t begin = 0;
3742 int len = 0;
3743 struct sock *s; 3739 struct sock *s;
3744 struct hlist_node *node;
3745
3746 len += sprintf(buffer,"sk RefCnt Rmem Wmem User Inode\n");
3747
3748 read_lock(&pfkey_table_lock);
3749 3740
3750 sk_for_each(s, node, &pfkey_table) { 3741 s = (struct sock *)v;
3751 len += sprintf(buffer+len,"%p %-6d %-6u %-6u %-6u %-6lu", 3742 if (v == SEQ_START_TOKEN)
3743 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
3744 else
3745 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
3752 s, 3746 s,
3753 atomic_read(&s->sk_refcnt), 3747 atomic_read(&s->sk_refcnt),
3754 atomic_read(&s->sk_rmem_alloc), 3748 atomic_read(&s->sk_rmem_alloc),
@@ -3756,40 +3750,68 @@ static int pfkey_read_proc(char *buffer, char **start, off_t offset,
3756 sock_i_uid(s), 3750 sock_i_uid(s),
3757 sock_i_ino(s) 3751 sock_i_ino(s)
3758 ); 3752 );
3753 return 0;
3754}
3755
3756static void *pfkey_seq_start(struct seq_file *f, loff_t *ppos)
3757{
3758 struct sock *s;
3759 struct hlist_node *node;
3760 loff_t pos = *ppos;
3759 3761
3760 buffer[len++] = '\n'; 3762 read_lock(&pfkey_table_lock);
3763 if (pos == 0)
3764 return SEQ_START_TOKEN;
3761 3765
3762 pos = begin + len; 3766 sk_for_each(s, node, &pfkey_table)
3763 if (pos < offset) { 3767 if (pos-- == 1)
3764 len = 0; 3768 return s;
3765 begin = pos;
3766 }
3767 if(pos > offset + length)
3768 goto done;
3769 }
3770 *eof = 1;
3771 3769
3772done: 3770 return NULL;
3773 read_unlock(&pfkey_table_lock); 3771}
3772
3773static void *pfkey_seq_next(struct seq_file *f, void *v, loff_t *ppos)
3774{
3775 ++*ppos;
3776 return (v == SEQ_START_TOKEN) ?
3777 sk_head(&pfkey_table) :
3778 sk_next((struct sock *)v);
3779}
3774 3780
3775 *start = buffer + (offset - begin); 3781static void pfkey_seq_stop(struct seq_file *f, void *v)
3776 len -= (offset - begin); 3782{
3783 read_unlock(&pfkey_table_lock);
3784}
3777 3785
3778 if (len > length) 3786static struct seq_operations pfkey_seq_ops = {
3779 len = length; 3787 .start = pfkey_seq_start,
3780 if (len < 0) 3788 .next = pfkey_seq_next,
3781 len = 0; 3789 .stop = pfkey_seq_stop,
3790 .show = pfkey_seq_show,
3791};
3782 3792
3783 return len; 3793static int pfkey_seq_open(struct inode *inode, struct file *file)
3794{
3795 return seq_open(file, &pfkey_seq_ops);
3784} 3796}
3785 3797
3798static struct file_operations pfkey_proc_ops = {
3799 .open = pfkey_seq_open,
3800 .read = seq_read,
3801 .llseek = seq_lseek,
3802 .release = seq_release,
3803};
3804
3786static int pfkey_init_proc(void) 3805static int pfkey_init_proc(void)
3787{ 3806{
3788 if (create_proc_read_entry("pfkey", 0, init_net.proc_net, 3807 struct proc_dir_entry *e;
3789 pfkey_read_proc, NULL) == NULL) 3808
3809 e = create_proc_entry("pfkey", 0, init_net.proc_net);
3810 if (e == NULL)
3790 return -ENOMEM; 3811 return -ENOMEM;
3791 else 3812
3792 return 0; 3813 e->proc_fops = &pfkey_proc_ops;
3814 return 0;
3793} 3815}
3794 3816
3795static void pfkey_exit_proc(void) 3817static void pfkey_exit_proc(void)