aboutsummaryrefslogtreecommitdiffstats
path: root/net/sctp/objcnt.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/sctp/objcnt.c')
-rw-r--r--net/sctp/objcnt.c85
1 files changed, 44 insertions, 41 deletions
diff --git a/net/sctp/objcnt.c b/net/sctp/objcnt.c
index 23f53dd23191..14e294e37626 100644
--- a/net/sctp/objcnt.c
+++ b/net/sctp/objcnt.c
@@ -80,61 +80,64 @@ static sctp_dbg_objcnt_entry_t sctp_dbg_objcnt[] = {
80/* Callback from procfs to read out objcount information. 80/* Callback from procfs to read out objcount information.
81 * Walk through the entries in the sctp_dbg_objcnt array, dumping 81 * Walk through the entries in the sctp_dbg_objcnt array, dumping
82 * the raw object counts for each monitored type. 82 * the raw object counts for each monitored type.
83 *
84 * This code was modified from similar code in route.c
85 */ 83 */
86static int sctp_dbg_objcnt_read(char *buffer, char **start, off_t offset, 84static int sctp_objcnt_seq_show(struct seq_file *seq, void *v)
87 int length, int *eof, void *data)
88{ 85{
89 int len = 0;
90 off_t pos = 0;
91 int entries;
92 int i; 86 int i;
93 char temp[128]; 87 char temp[128];
94 88
95 /* How many entries? */ 89 i = (int)*(loff_t *)v;
96 entries = ARRAY_SIZE(sctp_dbg_objcnt); 90 sprintf(temp, "%s: %d", sctp_dbg_objcnt[i].label,
97 91 atomic_read(sctp_dbg_objcnt[i].counter));
98 /* Walk the entries and print out the debug information 92 seq_printf(seq, "%-127s\n", temp);
99 * for proc fs. 93 return 0;
100 */ 94}
101 for (i = 0; i < entries; i++) { 95
102 pos += 128; 96static void *sctp_objcnt_seq_start(struct seq_file *seq, loff_t *pos)
103 97{
104 /* Skip ahead. */ 98 return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos;
105 if (pos <= offset) { 99}
106 len = 0; 100
107 continue; 101static void sctp_objcnt_seq_stop(struct seq_file *seq, void *v)
108 } 102{
109 /* Print out each entry. */ 103}
110 sprintf(temp, "%s: %d", 104
111 sctp_dbg_objcnt[i].label, 105static void * sctp_objcnt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
112 atomic_read(sctp_dbg_objcnt[i].counter)); 106{
113 107 ++*pos;
114 sprintf(buffer + len, "%-127s\n", temp); 108 return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos;
115 len += 128;
116 if (pos >= offset+length)
117 goto done;
118 }
119
120done:
121 *start = buffer + len - (pos - offset);
122 len = pos - offset;
123 if (len > length)
124 len = length;
125
126 return len;
127} 109}
128 110
111static 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
118static int sctp_objcnt_seq_open(struct inode *inode, struct file *file)
119{
120 return seq_open(file, &sctp_objcnt_seq_ops);
121}
122
123static 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};
129
129/* Initialize the objcount in the proc filesystem. */ 130/* Initialize the objcount in the proc filesystem. */
130void sctp_dbg_objcnt_init(void) 131void sctp_dbg_objcnt_init(void)
131{ 132{
132 struct proc_dir_entry *ent; 133 struct proc_dir_entry *ent;
133 ent = create_proc_read_entry("sctp_dbg_objcnt", 0, proc_net_sctp, 134
134 sctp_dbg_objcnt_read, NULL); 135 ent = create_proc_entry("sctp_dbg_objcnt", 0, proc_net_sctp);
135 if (!ent) 136 if (!ent)
136 printk(KERN_WARNING 137 printk(KERN_WARNING
137 "sctp_dbg_objcnt: Unable to create /proc entry.\n"); 138 "sctp_dbg_objcnt: Unable to create /proc entry.\n");
139 else
140 ent->proc_fops = &sctp_objcnt_ops;
138} 141}
139 142
140/* Cleanup the objcount entry in the proc filesystem. */ 143/* Cleanup the objcount entry in the proc filesystem. */