[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>

authored by Pavel Emelyanov and committed by David S. Miller bd2f7476 61145aa1

+63 -41
+63 -41
net/key/af_key.c
··· 3734 }; 3735 3736 #ifdef CONFIG_PROC_FS 3737 - static int pfkey_read_proc(char *buffer, char **start, off_t offset, 3738 - int length, int *eof, void *data) 3739 { 3740 - off_t pos = 0; 3741 - off_t begin = 0; 3742 - int len = 0; 3743 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 - 3750 - sk_for_each(s, node, &pfkey_table) { 3751 - len += sprintf(buffer+len,"%p %-6d %-6u %-6u %-6u %-6lu", 3752 s, 3753 atomic_read(&s->sk_refcnt), 3754 atomic_read(&s->sk_rmem_alloc), ··· 3750 sock_i_uid(s), 3751 sock_i_ino(s) 3752 ); 3753 - 3754 - buffer[len++] = '\n'; 3755 - 3756 - pos = begin + len; 3757 - if (pos < offset) { 3758 - len = 0; 3759 - begin = pos; 3760 - } 3761 - if(pos > offset + length) 3762 - goto done; 3763 - } 3764 - *eof = 1; 3765 - 3766 - done: 3767 - read_unlock(&pfkey_table_lock); 3768 - 3769 - *start = buffer + (offset - begin); 3770 - len -= (offset - begin); 3771 - 3772 - if (len > length) 3773 - len = length; 3774 - if (len < 0) 3775 - len = 0; 3776 - 3777 - return len; 3778 } 3779 3780 static int pfkey_init_proc(void) 3781 { 3782 - if (create_proc_read_entry("pfkey", 0, init_net.proc_net, 3783 - pfkey_read_proc, NULL) == NULL) 3784 return -ENOMEM; 3785 - else 3786 - return 0; 3787 } 3788 3789 static void pfkey_exit_proc(void)
··· 3734 }; 3735 3736 #ifdef CONFIG_PROC_FS 3737 + static int pfkey_seq_show(struct seq_file *f, void *v) 3738 { 3739 struct sock *s; 3740 3741 + s = (struct sock *)v; 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", 3746 s, 3747 atomic_read(&s->sk_refcnt), 3748 atomic_read(&s->sk_rmem_alloc), ··· 3756 sock_i_uid(s), 3757 sock_i_ino(s) 3758 ); 3759 + return 0; 3760 } 3761 + 3762 + static void *pfkey_seq_start(struct seq_file *f, loff_t *ppos) 3763 + { 3764 + struct sock *s; 3765 + struct hlist_node *node; 3766 + loff_t pos = *ppos; 3767 + 3768 + read_lock(&pfkey_table_lock); 3769 + if (pos == 0) 3770 + return SEQ_START_TOKEN; 3771 + 3772 + sk_for_each(s, node, &pfkey_table) 3773 + if (pos-- == 1) 3774 + return s; 3775 + 3776 + return NULL; 3777 + } 3778 + 3779 + static void *pfkey_seq_next(struct seq_file *f, void *v, loff_t *ppos) 3780 + { 3781 + ++*ppos; 3782 + return (v == SEQ_START_TOKEN) ? 3783 + sk_head(&pfkey_table) : 3784 + sk_next((struct sock *)v); 3785 + } 3786 + 3787 + static void pfkey_seq_stop(struct seq_file *f, void *v) 3788 + { 3789 + read_unlock(&pfkey_table_lock); 3790 + } 3791 + 3792 + static struct seq_operations pfkey_seq_ops = { 3793 + .start = pfkey_seq_start, 3794 + .next = pfkey_seq_next, 3795 + .stop = pfkey_seq_stop, 3796 + .show = pfkey_seq_show, 3797 + }; 3798 + 3799 + static int pfkey_seq_open(struct inode *inode, struct file *file) 3800 + { 3801 + return seq_open(file, &pfkey_seq_ops); 3802 + } 3803 + 3804 + static struct file_operations pfkey_proc_ops = { 3805 + .open = pfkey_seq_open, 3806 + .read = seq_read, 3807 + .llseek = seq_lseek, 3808 + .release = seq_release, 3809 + }; 3810 3811 static int pfkey_init_proc(void) 3812 { 3813 + struct proc_dir_entry *e; 3814 + 3815 + e = create_proc_entry("pfkey", 0, init_net.proc_net); 3816 + if (e == NULL) 3817 return -ENOMEM; 3818 + 3819 + e->proc_fops = &pfkey_proc_ops; 3820 + return 0; 3821 } 3822 3823 static void pfkey_exit_proc(void)