diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2009-08-28 05:57:21 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-08-29 03:19:38 -0400 |
commit | ea00b8e2223170a842bee06e0f27754ccdf2a217 (patch) | |
tree | d167e267a05de6a1f422d805b0290047af313981 /net/can/proc.c | |
parent | 4923576b8ac5bfd36ab2beb176aeb747aaab7e41 (diff) |
can: switch to seq_file
create_proc_read_entry() is going to be removed soon.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/can/proc.c')
-rw-r--r-- | net/can/proc.c | 281 |
1 files changed, 131 insertions, 150 deletions
diff --git a/net/can/proc.c b/net/can/proc.c index 1463653dbe34..9b9ad29be567 100644 --- a/net/can/proc.c +++ b/net/can/proc.c | |||
@@ -196,8 +196,8 @@ void can_stat_update(unsigned long data) | |||
196 | * | 196 | * |
197 | */ | 197 | */ |
198 | 198 | ||
199 | static int can_print_rcvlist(char *page, int len, struct hlist_head *rx_list, | 199 | static void can_print_rcvlist(struct seq_file *m, struct hlist_head *rx_list, |
200 | struct net_device *dev) | 200 | struct net_device *dev) |
201 | { | 201 | { |
202 | struct receiver *r; | 202 | struct receiver *r; |
203 | struct hlist_node *n; | 203 | struct hlist_node *n; |
@@ -208,199 +208,188 @@ static int can_print_rcvlist(char *page, int len, struct hlist_head *rx_list, | |||
208 | " %-5s %08X %08x %08x %08x %8ld %s\n" : | 208 | " %-5s %08X %08x %08x %08x %8ld %s\n" : |
209 | " %-5s %03X %08x %08lx %08lx %8ld %s\n"; | 209 | " %-5s %03X %08x %08lx %08lx %8ld %s\n"; |
210 | 210 | ||
211 | len += snprintf(page + len, PAGE_SIZE - len, fmt, | 211 | seq_printf(m, fmt, DNAME(dev), r->can_id, r->mask, |
212 | DNAME(dev), r->can_id, r->mask, | ||
213 | (unsigned long)r->func, (unsigned long)r->data, | 212 | (unsigned long)r->func, (unsigned long)r->data, |
214 | r->matches, r->ident); | 213 | r->matches, r->ident); |
215 | |||
216 | /* does a typical line fit into the current buffer? */ | ||
217 | |||
218 | /* 100 Bytes before end of buffer */ | ||
219 | if (len > PAGE_SIZE - 100) { | ||
220 | /* mark output cut off */ | ||
221 | len += snprintf(page + len, PAGE_SIZE - len, | ||
222 | " (..)\n"); | ||
223 | break; | ||
224 | } | ||
225 | } | 214 | } |
226 | rcu_read_unlock(); | 215 | rcu_read_unlock(); |
227 | |||
228 | return len; | ||
229 | } | 216 | } |
230 | 217 | ||
231 | static int can_print_recv_banner(char *page, int len) | 218 | static void can_print_recv_banner(struct seq_file *m) |
232 | { | 219 | { |
233 | /* | 220 | /* |
234 | * can1. 00000000 00000000 00000000 | 221 | * can1. 00000000 00000000 00000000 |
235 | * ....... 0 tp20 | 222 | * ....... 0 tp20 |
236 | */ | 223 | */ |
237 | len += snprintf(page + len, PAGE_SIZE - len, | 224 | seq_puts(m, " device can_id can_mask function" |
238 | " device can_id can_mask function" | ||
239 | " userdata matches ident\n"); | 225 | " userdata matches ident\n"); |
240 | |||
241 | return len; | ||
242 | } | 226 | } |
243 | 227 | ||
244 | static int can_proc_read_stats(char *page, char **start, off_t off, | 228 | static int can_stats_proc_show(struct seq_file *m, void *v) |
245 | int count, int *eof, void *data) | ||
246 | { | 229 | { |
247 | int len = 0; | 230 | seq_putc(m, '\n'); |
231 | seq_printf(m, " %8ld transmitted frames (TXF)\n", can_stats.tx_frames); | ||
232 | seq_printf(m, " %8ld received frames (RXF)\n", can_stats.rx_frames); | ||
233 | seq_printf(m, " %8ld matched frames (RXMF)\n", can_stats.matches); | ||
248 | 234 | ||
249 | len += snprintf(page + len, PAGE_SIZE - len, "\n"); | 235 | seq_putc(m, '\n'); |
250 | len += snprintf(page + len, PAGE_SIZE - len, | ||
251 | " %8ld transmitted frames (TXF)\n", | ||
252 | can_stats.tx_frames); | ||
253 | len += snprintf(page + len, PAGE_SIZE - len, | ||
254 | " %8ld received frames (RXF)\n", can_stats.rx_frames); | ||
255 | len += snprintf(page + len, PAGE_SIZE - len, | ||
256 | " %8ld matched frames (RXMF)\n", can_stats.matches); | ||
257 | |||
258 | len += snprintf(page + len, PAGE_SIZE - len, "\n"); | ||
259 | 236 | ||
260 | if (can_stattimer.function == can_stat_update) { | 237 | if (can_stattimer.function == can_stat_update) { |
261 | len += snprintf(page + len, PAGE_SIZE - len, | 238 | seq_printf(m, " %8ld %% total match ratio (RXMR)\n", |
262 | " %8ld %% total match ratio (RXMR)\n", | ||
263 | can_stats.total_rx_match_ratio); | 239 | can_stats.total_rx_match_ratio); |
264 | 240 | ||
265 | len += snprintf(page + len, PAGE_SIZE - len, | 241 | seq_printf(m, " %8ld frames/s total tx rate (TXR)\n", |
266 | " %8ld frames/s total tx rate (TXR)\n", | ||
267 | can_stats.total_tx_rate); | 242 | can_stats.total_tx_rate); |
268 | len += snprintf(page + len, PAGE_SIZE - len, | 243 | seq_printf(m, " %8ld frames/s total rx rate (RXR)\n", |
269 | " %8ld frames/s total rx rate (RXR)\n", | ||
270 | can_stats.total_rx_rate); | 244 | can_stats.total_rx_rate); |
271 | 245 | ||
272 | len += snprintf(page + len, PAGE_SIZE - len, "\n"); | 246 | seq_putc(m, '\n'); |
273 | 247 | ||
274 | len += snprintf(page + len, PAGE_SIZE - len, | 248 | seq_printf(m, " %8ld %% current match ratio (CRXMR)\n", |
275 | " %8ld %% current match ratio (CRXMR)\n", | ||
276 | can_stats.current_rx_match_ratio); | 249 | can_stats.current_rx_match_ratio); |
277 | 250 | ||
278 | len += snprintf(page + len, PAGE_SIZE - len, | 251 | seq_printf(m, " %8ld frames/s current tx rate (CTXR)\n", |
279 | " %8ld frames/s current tx rate (CTXR)\n", | ||
280 | can_stats.current_tx_rate); | 252 | can_stats.current_tx_rate); |
281 | len += snprintf(page + len, PAGE_SIZE - len, | 253 | seq_printf(m, " %8ld frames/s current rx rate (CRXR)\n", |
282 | " %8ld frames/s current rx rate (CRXR)\n", | ||
283 | can_stats.current_rx_rate); | 254 | can_stats.current_rx_rate); |
284 | 255 | ||
285 | len += snprintf(page + len, PAGE_SIZE - len, "\n"); | 256 | seq_putc(m, '\n'); |
286 | 257 | ||
287 | len += snprintf(page + len, PAGE_SIZE - len, | 258 | seq_printf(m, " %8ld %% max match ratio (MRXMR)\n", |
288 | " %8ld %% max match ratio (MRXMR)\n", | ||
289 | can_stats.max_rx_match_ratio); | 259 | can_stats.max_rx_match_ratio); |
290 | 260 | ||
291 | len += snprintf(page + len, PAGE_SIZE - len, | 261 | seq_printf(m, " %8ld frames/s max tx rate (MTXR)\n", |
292 | " %8ld frames/s max tx rate (MTXR)\n", | ||
293 | can_stats.max_tx_rate); | 262 | can_stats.max_tx_rate); |
294 | len += snprintf(page + len, PAGE_SIZE - len, | 263 | seq_printf(m, " %8ld frames/s max rx rate (MRXR)\n", |
295 | " %8ld frames/s max rx rate (MRXR)\n", | ||
296 | can_stats.max_rx_rate); | 264 | can_stats.max_rx_rate); |
297 | 265 | ||
298 | len += snprintf(page + len, PAGE_SIZE - len, "\n"); | 266 | seq_putc(m, '\n'); |
299 | } | 267 | } |
300 | 268 | ||
301 | len += snprintf(page + len, PAGE_SIZE - len, | 269 | seq_printf(m, " %8ld current receive list entries (CRCV)\n", |
302 | " %8ld current receive list entries (CRCV)\n", | ||
303 | can_pstats.rcv_entries); | 270 | can_pstats.rcv_entries); |
304 | len += snprintf(page + len, PAGE_SIZE - len, | 271 | seq_printf(m, " %8ld maximum receive list entries (MRCV)\n", |
305 | " %8ld maximum receive list entries (MRCV)\n", | ||
306 | can_pstats.rcv_entries_max); | 272 | can_pstats.rcv_entries_max); |
307 | 273 | ||
308 | if (can_pstats.stats_reset) | 274 | if (can_pstats.stats_reset) |
309 | len += snprintf(page + len, PAGE_SIZE - len, | 275 | seq_printf(m, "\n %8ld statistic resets (STR)\n", |
310 | "\n %8ld statistic resets (STR)\n", | ||
311 | can_pstats.stats_reset); | 276 | can_pstats.stats_reset); |
312 | 277 | ||
313 | if (can_pstats.user_reset) | 278 | if (can_pstats.user_reset) |
314 | len += snprintf(page + len, PAGE_SIZE - len, | 279 | seq_printf(m, " %8ld user statistic resets (USTR)\n", |
315 | " %8ld user statistic resets (USTR)\n", | ||
316 | can_pstats.user_reset); | 280 | can_pstats.user_reset); |
317 | 281 | ||
318 | len += snprintf(page + len, PAGE_SIZE - len, "\n"); | 282 | seq_putc(m, '\n'); |
319 | 283 | return 0; | |
320 | *eof = 1; | ||
321 | return len; | ||
322 | } | 284 | } |
323 | 285 | ||
324 | static int can_proc_read_reset_stats(char *page, char **start, off_t off, | 286 | static int can_stats_proc_open(struct inode *inode, struct file *file) |
325 | int count, int *eof, void *data) | ||
326 | { | 287 | { |
327 | int len = 0; | 288 | return single_open(file, can_stats_proc_show, NULL); |
289 | } | ||
290 | |||
291 | static const struct file_operations can_stats_proc_fops = { | ||
292 | .owner = THIS_MODULE, | ||
293 | .open = can_stats_proc_open, | ||
294 | .read = seq_read, | ||
295 | .llseek = seq_lseek, | ||
296 | .release = single_release, | ||
297 | }; | ||
328 | 298 | ||
299 | static int can_reset_stats_proc_show(struct seq_file *m, void *v) | ||
300 | { | ||
329 | user_reset = 1; | 301 | user_reset = 1; |
330 | 302 | ||
331 | if (can_stattimer.function == can_stat_update) { | 303 | if (can_stattimer.function == can_stat_update) { |
332 | len += snprintf(page + len, PAGE_SIZE - len, | 304 | seq_printf(m, "Scheduled statistic reset #%ld.\n", |
333 | "Scheduled statistic reset #%ld.\n", | ||
334 | can_pstats.stats_reset + 1); | 305 | can_pstats.stats_reset + 1); |
335 | 306 | ||
336 | } else { | 307 | } else { |
337 | if (can_stats.jiffies_init != jiffies) | 308 | if (can_stats.jiffies_init != jiffies) |
338 | can_init_stats(); | 309 | can_init_stats(); |
339 | 310 | ||
340 | len += snprintf(page + len, PAGE_SIZE - len, | 311 | seq_printf(m, "Performed statistic reset #%ld.\n", |
341 | "Performed statistic reset #%ld.\n", | ||
342 | can_pstats.stats_reset); | 312 | can_pstats.stats_reset); |
343 | } | 313 | } |
314 | return 0; | ||
315 | } | ||
344 | 316 | ||
345 | *eof = 1; | 317 | static int can_reset_stats_proc_open(struct inode *inode, struct file *file) |
346 | return len; | 318 | { |
319 | return single_open(file, can_reset_stats_proc_show, NULL); | ||
347 | } | 320 | } |
348 | 321 | ||
349 | static int can_proc_read_version(char *page, char **start, off_t off, | 322 | static const struct file_operations can_reset_stats_proc_fops = { |
350 | int count, int *eof, void *data) | 323 | .owner = THIS_MODULE, |
324 | .open = can_reset_stats_proc_open, | ||
325 | .read = seq_read, | ||
326 | .llseek = seq_lseek, | ||
327 | .release = single_release, | ||
328 | }; | ||
329 | |||
330 | static int can_version_proc_show(struct seq_file *m, void *v) | ||
351 | { | 331 | { |
352 | int len = 0; | 332 | seq_printf(m, "%s\n", CAN_VERSION_STRING); |
333 | return 0; | ||
334 | } | ||
353 | 335 | ||
354 | len += snprintf(page + len, PAGE_SIZE - len, "%s\n", | 336 | static int can_version_proc_open(struct inode *inode, struct file *file) |
355 | CAN_VERSION_STRING); | 337 | { |
356 | *eof = 1; | 338 | return single_open(file, can_version_proc_show, NULL); |
357 | return len; | ||
358 | } | 339 | } |
359 | 340 | ||
360 | static int can_proc_read_rcvlist(char *page, char **start, off_t off, | 341 | static const struct file_operations can_version_proc_fops = { |
361 | int count, int *eof, void *data) | 342 | .owner = THIS_MODULE, |
343 | .open = can_version_proc_open, | ||
344 | .read = seq_read, | ||
345 | .llseek = seq_lseek, | ||
346 | .release = single_release, | ||
347 | }; | ||
348 | |||
349 | static int can_rcvlist_proc_show(struct seq_file *m, void *v) | ||
362 | { | 350 | { |
363 | /* double cast to prevent GCC warning */ | 351 | /* double cast to prevent GCC warning */ |
364 | int idx = (int)(long)data; | 352 | int idx = (int)(long)m->private; |
365 | int len = 0; | ||
366 | struct dev_rcv_lists *d; | 353 | struct dev_rcv_lists *d; |
367 | struct hlist_node *n; | 354 | struct hlist_node *n; |
368 | 355 | ||
369 | len += snprintf(page + len, PAGE_SIZE - len, | 356 | seq_printf(m, "\nreceive list '%s':\n", rx_list_name[idx]); |
370 | "\nreceive list '%s':\n", rx_list_name[idx]); | ||
371 | 357 | ||
372 | rcu_read_lock(); | 358 | rcu_read_lock(); |
373 | hlist_for_each_entry_rcu(d, n, &can_rx_dev_list, list) { | 359 | hlist_for_each_entry_rcu(d, n, &can_rx_dev_list, list) { |
374 | 360 | ||
375 | if (!hlist_empty(&d->rx[idx])) { | 361 | if (!hlist_empty(&d->rx[idx])) { |
376 | len = can_print_recv_banner(page, len); | 362 | can_print_recv_banner(m); |
377 | len = can_print_rcvlist(page, len, &d->rx[idx], d->dev); | 363 | can_print_rcvlist(m, &d->rx[idx], d->dev); |
378 | } else | 364 | } else |
379 | len += snprintf(page + len, PAGE_SIZE - len, | 365 | seq_printf(m, " (%s: no entry)\n", DNAME(d->dev)); |
380 | " (%s: no entry)\n", DNAME(d->dev)); | ||
381 | |||
382 | /* exit on end of buffer? */ | ||
383 | if (len > PAGE_SIZE - 100) | ||
384 | break; | ||
385 | } | 366 | } |
386 | rcu_read_unlock(); | 367 | rcu_read_unlock(); |
387 | 368 | ||
388 | len += snprintf(page + len, PAGE_SIZE - len, "\n"); | 369 | seq_putc(m, '\n'); |
370 | return 0; | ||
371 | } | ||
389 | 372 | ||
390 | *eof = 1; | 373 | static int can_rcvlist_proc_open(struct inode *inode, struct file *file) |
391 | return len; | 374 | { |
375 | return single_open(file, can_rcvlist_proc_show, PDE(inode)->data); | ||
392 | } | 376 | } |
393 | 377 | ||
394 | static int can_proc_read_rcvlist_sff(char *page, char **start, off_t off, | 378 | static const struct file_operations can_rcvlist_proc_fops = { |
395 | int count, int *eof, void *data) | 379 | .owner = THIS_MODULE, |
380 | .open = can_rcvlist_proc_open, | ||
381 | .read = seq_read, | ||
382 | .llseek = seq_lseek, | ||
383 | .release = single_release, | ||
384 | }; | ||
385 | |||
386 | static int can_rcvlist_sff_proc_show(struct seq_file *m, void *v) | ||
396 | { | 387 | { |
397 | int len = 0; | ||
398 | struct dev_rcv_lists *d; | 388 | struct dev_rcv_lists *d; |
399 | struct hlist_node *n; | 389 | struct hlist_node *n; |
400 | 390 | ||
401 | /* RX_SFF */ | 391 | /* RX_SFF */ |
402 | len += snprintf(page + len, PAGE_SIZE - len, | 392 | seq_puts(m, "\nreceive list 'rx_sff':\n"); |
403 | "\nreceive list 'rx_sff':\n"); | ||
404 | 393 | ||
405 | rcu_read_lock(); | 394 | rcu_read_lock(); |
406 | hlist_for_each_entry_rcu(d, n, &can_rx_dev_list, list) { | 395 | hlist_for_each_entry_rcu(d, n, &can_rx_dev_list, list) { |
@@ -413,46 +402,38 @@ static int can_proc_read_rcvlist_sff(char *page, char **start, off_t off, | |||
413 | } | 402 | } |
414 | 403 | ||
415 | if (!all_empty) { | 404 | if (!all_empty) { |
416 | len = can_print_recv_banner(page, len); | 405 | can_print_recv_banner(m); |
417 | for (i = 0; i < 0x800; i++) { | 406 | for (i = 0; i < 0x800; i++) { |
418 | if (!hlist_empty(&d->rx_sff[i]) && | 407 | if (!hlist_empty(&d->rx_sff[i])) |
419 | len < PAGE_SIZE - 100) | 408 | can_print_rcvlist(m, &d->rx_sff[i], |
420 | len = can_print_rcvlist(page, len, | 409 | d->dev); |
421 | &d->rx_sff[i], | ||
422 | d->dev); | ||
423 | } | 410 | } |
424 | } else | 411 | } else |
425 | len += snprintf(page + len, PAGE_SIZE - len, | 412 | seq_printf(m, " (%s: no entry)\n", DNAME(d->dev)); |
426 | " (%s: no entry)\n", DNAME(d->dev)); | ||
427 | |||
428 | /* exit on end of buffer? */ | ||
429 | if (len > PAGE_SIZE - 100) | ||
430 | break; | ||
431 | } | 413 | } |
432 | rcu_read_unlock(); | 414 | rcu_read_unlock(); |
433 | 415 | ||
434 | len += snprintf(page + len, PAGE_SIZE - len, "\n"); | 416 | seq_putc(m, '\n'); |
417 | return 0; | ||
418 | } | ||
435 | 419 | ||
436 | *eof = 1; | 420 | static int can_rcvlist_sff_proc_open(struct inode *inode, struct file *file) |
437 | return len; | 421 | { |
422 | return single_open(file, can_rcvlist_sff_proc_show, NULL); | ||
438 | } | 423 | } |
439 | 424 | ||
425 | static const struct file_operations can_rcvlist_sff_proc_fops = { | ||
426 | .owner = THIS_MODULE, | ||
427 | .open = can_rcvlist_sff_proc_open, | ||
428 | .read = seq_read, | ||
429 | .llseek = seq_lseek, | ||
430 | .release = single_release, | ||
431 | }; | ||
432 | |||
440 | /* | 433 | /* |
441 | * proc utility functions | 434 | * proc utility functions |
442 | */ | 435 | */ |
443 | 436 | ||
444 | static struct proc_dir_entry *can_create_proc_readentry(const char *name, | ||
445 | mode_t mode, | ||
446 | read_proc_t *read_proc, | ||
447 | void *data) | ||
448 | { | ||
449 | if (can_dir) | ||
450 | return create_proc_read_entry(name, mode, can_dir, read_proc, | ||
451 | data); | ||
452 | else | ||
453 | return NULL; | ||
454 | } | ||
455 | |||
456 | static void can_remove_proc_readentry(const char *name) | 437 | static void can_remove_proc_readentry(const char *name) |
457 | { | 438 | { |
458 | if (can_dir) | 439 | if (can_dir) |
@@ -474,24 +455,24 @@ void can_init_proc(void) | |||
474 | } | 455 | } |
475 | 456 | ||
476 | /* own procfs entries from the AF_CAN core */ | 457 | /* own procfs entries from the AF_CAN core */ |
477 | pde_version = can_create_proc_readentry(CAN_PROC_VERSION, 0644, | 458 | pde_version = proc_create(CAN_PROC_VERSION, 0644, can_dir, |
478 | can_proc_read_version, NULL); | 459 | &can_version_proc_fops); |
479 | pde_stats = can_create_proc_readentry(CAN_PROC_STATS, 0644, | 460 | pde_stats = proc_create(CAN_PROC_STATS, 0644, can_dir, |
480 | can_proc_read_stats, NULL); | 461 | &can_stats_proc_fops); |
481 | pde_reset_stats = can_create_proc_readentry(CAN_PROC_RESET_STATS, 0644, | 462 | pde_reset_stats = proc_create(CAN_PROC_RESET_STATS, 0644, can_dir, |
482 | can_proc_read_reset_stats, NULL); | 463 | &can_reset_stats_proc_fops); |
483 | pde_rcvlist_err = can_create_proc_readentry(CAN_PROC_RCVLIST_ERR, 0644, | 464 | pde_rcvlist_err = proc_create_data(CAN_PROC_RCVLIST_ERR, 0644, can_dir, |
484 | can_proc_read_rcvlist, (void *)RX_ERR); | 465 | &can_rcvlist_proc_fops, (void *)RX_ERR); |
485 | pde_rcvlist_all = can_create_proc_readentry(CAN_PROC_RCVLIST_ALL, 0644, | 466 | pde_rcvlist_all = proc_create_data(CAN_PROC_RCVLIST_ALL, 0644, can_dir, |
486 | can_proc_read_rcvlist, (void *)RX_ALL); | 467 | &can_rcvlist_proc_fops, (void *)RX_ALL); |
487 | pde_rcvlist_fil = can_create_proc_readentry(CAN_PROC_RCVLIST_FIL, 0644, | 468 | pde_rcvlist_fil = proc_create_data(CAN_PROC_RCVLIST_FIL, 0644, can_dir, |
488 | can_proc_read_rcvlist, (void *)RX_FIL); | 469 | &can_rcvlist_proc_fops, (void *)RX_FIL); |
489 | pde_rcvlist_inv = can_create_proc_readentry(CAN_PROC_RCVLIST_INV, 0644, | 470 | pde_rcvlist_inv = proc_create_data(CAN_PROC_RCVLIST_INV, 0644, can_dir, |
490 | can_proc_read_rcvlist, (void *)RX_INV); | 471 | &can_rcvlist_proc_fops, (void *)RX_INV); |
491 | pde_rcvlist_eff = can_create_proc_readentry(CAN_PROC_RCVLIST_EFF, 0644, | 472 | pde_rcvlist_eff = proc_create_data(CAN_PROC_RCVLIST_EFF, 0644, can_dir, |
492 | can_proc_read_rcvlist, (void *)RX_EFF); | 473 | &can_rcvlist_proc_fops, (void *)RX_EFF); |
493 | pde_rcvlist_sff = can_create_proc_readentry(CAN_PROC_RCVLIST_SFF, 0644, | 474 | pde_rcvlist_sff = proc_create(CAN_PROC_RCVLIST_SFF, 0644, can_dir, |
494 | can_proc_read_rcvlist_sff, NULL); | 475 | &can_rcvlist_sff_proc_fops); |
495 | } | 476 | } |
496 | 477 | ||
497 | /* | 478 | /* |