[SCTP]: Convert sctp_dbg_objcnt to seq files.

This makes the code use a good proc API and the text ~50 bytes shorter.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Acked-by: Vlad Yasevich <vladislav.yasevich@hp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by Pavel Emelyanov and committed by David S. Miller 8ff65b46 3f5340a6

+44 -41
+44 -41
net/sctp/objcnt.c
··· 80 80 /* Callback from procfs to read out objcount information. 81 81 * Walk through the entries in the sctp_dbg_objcnt array, dumping 82 82 * the raw object counts for each monitored type. 83 - * 84 - * This code was modified from similar code in route.c 85 83 */ 86 - static int sctp_dbg_objcnt_read(char *buffer, char **start, off_t offset, 87 - int length, int *eof, void *data) 84 + static int sctp_objcnt_seq_show(struct seq_file *seq, void *v) 88 85 { 89 - int len = 0; 90 - off_t pos = 0; 91 - int entries; 92 86 int i; 93 87 char temp[128]; 94 88 95 - /* How many entries? */ 96 - entries = ARRAY_SIZE(sctp_dbg_objcnt); 97 - 98 - /* Walk the entries and print out the debug information 99 - * for proc fs. 100 - */ 101 - for (i = 0; i < entries; i++) { 102 - pos += 128; 103 - 104 - /* Skip ahead. */ 105 - if (pos <= offset) { 106 - len = 0; 107 - continue; 108 - } 109 - /* Print out each entry. */ 110 - sprintf(temp, "%s: %d", 111 - sctp_dbg_objcnt[i].label, 112 - atomic_read(sctp_dbg_objcnt[i].counter)); 113 - 114 - sprintf(buffer + len, "%-127s\n", temp); 115 - len += 128; 116 - if (pos >= offset+length) 117 - goto done; 118 - } 119 - 120 - done: 121 - *start = buffer + len - (pos - offset); 122 - len = pos - offset; 123 - if (len > length) 124 - len = length; 125 - 126 - return len; 89 + i = (int)*(loff_t *)v; 90 + sprintf(temp, "%s: %d", sctp_dbg_objcnt[i].label, 91 + atomic_read(sctp_dbg_objcnt[i].counter)); 92 + seq_printf(seq, "%-127s\n", temp); 93 + return 0; 127 94 } 95 + 96 + static void *sctp_objcnt_seq_start(struct seq_file *seq, loff_t *pos) 97 + { 98 + return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos; 99 + } 100 + 101 + static void sctp_objcnt_seq_stop(struct seq_file *seq, void *v) 102 + { 103 + } 104 + 105 + static void * sctp_objcnt_seq_next(struct seq_file *seq, void *v, loff_t *pos) 106 + { 107 + ++*pos; 108 + return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos; 109 + } 110 + 111 + static const struct seq_operations sctp_objcnt_seq_ops = { 112 + .start = sctp_objcnt_seq_start, 113 + .next = sctp_objcnt_seq_next, 114 + .stop = sctp_objcnt_seq_stop, 115 + .show = sctp_objcnt_seq_show, 116 + }; 117 + 118 + static int sctp_objcnt_seq_open(struct inode *inode, struct file *file) 119 + { 120 + return seq_open(file, &sctp_objcnt_seq_ops); 121 + } 122 + 123 + static const struct file_operations sctp_objcnt_ops = { 124 + .open = sctp_objcnt_seq_open, 125 + .read = seq_read, 126 + .llseek = seq_lseek, 127 + .release = seq_release, 128 + }; 128 129 129 130 /* Initialize the objcount in the proc filesystem. */ 130 131 void sctp_dbg_objcnt_init(void) 131 132 { 132 133 struct proc_dir_entry *ent; 133 - ent = create_proc_read_entry("sctp_dbg_objcnt", 0, proc_net_sctp, 134 - sctp_dbg_objcnt_read, NULL); 134 + 135 + ent = create_proc_entry("sctp_dbg_objcnt", 0, proc_net_sctp); 135 136 if (!ent) 136 137 printk(KERN_WARNING 137 138 "sctp_dbg_objcnt: Unable to create /proc entry.\n"); 139 + else 140 + ent->proc_fops = &sctp_objcnt_ops; 138 141 } 139 142 140 143 /* Cleanup the objcount entry in the proc filesystem. */