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

[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: default avatarPavel Emelyanov <xemul@openvz.org>
Acked-by: default avatarVlad Yasevich <vladislav.yasevich@hp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3f5340a6
...@@ -80,61 +80,64 @@ static sctp_dbg_objcnt_entry_t sctp_dbg_objcnt[] = { ...@@ -80,61 +80,64 @@ static sctp_dbg_objcnt_entry_t sctp_dbg_objcnt[] = {
/* Callback from procfs to read out objcount information. /* Callback from procfs to read out objcount information.
* Walk through the entries in the sctp_dbg_objcnt array, dumping * Walk through the entries in the sctp_dbg_objcnt array, dumping
* the raw object counts for each monitored type. * the raw object counts for each monitored type.
*
* This code was modified from similar code in route.c
*/ */
static int sctp_dbg_objcnt_read(char *buffer, char **start, off_t offset, static int sctp_objcnt_seq_show(struct seq_file *seq, void *v)
int length, int *eof, void *data)
{ {
int len = 0;
off_t pos = 0;
int entries;
int i; int i;
char temp[128]; char temp[128];
/* How many entries? */ i = (int)*(loff_t *)v;
entries = ARRAY_SIZE(sctp_dbg_objcnt); sprintf(temp, "%s: %d", sctp_dbg_objcnt[i].label,
atomic_read(sctp_dbg_objcnt[i].counter));
/* Walk the entries and print out the debug information seq_printf(seq, "%-127s\n", temp);
* for proc fs. return 0;
*/ }
for (i = 0; i < entries; i++) {
pos += 128; static void *sctp_objcnt_seq_start(struct seq_file *seq, loff_t *pos)
{
/* Skip ahead. */ return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos;
if (pos <= offset) { }
len = 0;
continue; static void sctp_objcnt_seq_stop(struct seq_file *seq, void *v)
} {
/* Print out each entry. */ }
sprintf(temp, "%s: %d",
sctp_dbg_objcnt[i].label, static void * sctp_objcnt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
atomic_read(sctp_dbg_objcnt[i].counter)); {
++*pos;
sprintf(buffer + len, "%-127s\n", temp); return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos;
len += 128;
if (pos >= offset+length)
goto done;
}
done:
*start = buffer + len - (pos - offset);
len = pos - offset;
if (len > length)
len = length;
return len;
} }
static const struct seq_operations sctp_objcnt_seq_ops = {
.start = sctp_objcnt_seq_start,
.next = sctp_objcnt_seq_next,
.stop = sctp_objcnt_seq_stop,
.show = sctp_objcnt_seq_show,
};
static int sctp_objcnt_seq_open(struct inode *inode, struct file *file)
{
return seq_open(file, &sctp_objcnt_seq_ops);
}
static const struct file_operations sctp_objcnt_ops = {
.open = sctp_objcnt_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
/* Initialize the objcount in the proc filesystem. */ /* Initialize the objcount in the proc filesystem. */
void sctp_dbg_objcnt_init(void) void sctp_dbg_objcnt_init(void)
{ {
struct proc_dir_entry *ent; struct proc_dir_entry *ent;
ent = create_proc_read_entry("sctp_dbg_objcnt", 0, proc_net_sctp,
sctp_dbg_objcnt_read, NULL); ent = create_proc_entry("sctp_dbg_objcnt", 0, proc_net_sctp);
if (!ent) if (!ent)
printk(KERN_WARNING printk(KERN_WARNING
"sctp_dbg_objcnt: Unable to create /proc entry.\n"); "sctp_dbg_objcnt: Unable to create /proc entry.\n");
else
ent->proc_fops = &sctp_objcnt_ops;
} }
/* Cleanup the objcount entry in the proc filesystem. */ /* Cleanup the objcount entry in the proc filesystem. */
......
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