jfs_debug.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (C) International Business Machines Corp., 2000-2004
  3. * Portions Copyright (C) Christoph Hellwig, 2001-2002
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. * the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/fs.h>
  20. #include <linux/ctype.h>
  21. #include <linux/module.h>
  22. #include <linux/proc_fs.h>
  23. #include <asm/uaccess.h>
  24. #include "jfs_incore.h"
  25. #include "jfs_filsys.h"
  26. #include "jfs_debug.h"
  27. #ifdef PROC_FS_JFS /* see jfs_debug.h */
  28. static struct proc_dir_entry *base;
  29. #ifdef CONFIG_JFS_DEBUG
  30. static int loglevel_read(char *page, char **start, off_t off,
  31. int count, int *eof, void *data)
  32. {
  33. int len;
  34. len = sprintf(page, "%d\n", jfsloglevel);
  35. len -= off;
  36. *start = page + off;
  37. if (len > count)
  38. len = count;
  39. else
  40. *eof = 1;
  41. if (len < 0)
  42. len = 0;
  43. return len;
  44. }
  45. static int loglevel_write(struct file *file, const char __user *buffer,
  46. unsigned long count, void *data)
  47. {
  48. char c;
  49. if (get_user(c, buffer))
  50. return -EFAULT;
  51. /* yes, I know this is an ASCIIism. --hch */
  52. if (c < '0' || c > '9')
  53. return -EINVAL;
  54. jfsloglevel = c - '0';
  55. return count;
  56. }
  57. #endif
  58. static struct {
  59. const char *name;
  60. read_proc_t *read_fn;
  61. write_proc_t *write_fn;
  62. } Entries[] = {
  63. #ifdef CONFIG_JFS_STATISTICS
  64. { "lmstats", jfs_lmstats_read, },
  65. { "txstats", jfs_txstats_read, },
  66. { "xtstat", jfs_xtstat_read, },
  67. { "mpstat", jfs_mpstat_read, },
  68. #endif
  69. #ifdef CONFIG_JFS_DEBUG
  70. { "TxAnchor", jfs_txanchor_read, },
  71. { "loglevel", loglevel_read, loglevel_write }
  72. #endif
  73. };
  74. #define NPROCENT ARRAY_SIZE(Entries)
  75. void jfs_proc_init(void)
  76. {
  77. int i;
  78. if (!(base = proc_mkdir("jfs", proc_root_fs)))
  79. return;
  80. base->owner = THIS_MODULE;
  81. for (i = 0; i < NPROCENT; i++) {
  82. struct proc_dir_entry *p;
  83. if ((p = create_proc_entry(Entries[i].name, 0, base))) {
  84. p->read_proc = Entries[i].read_fn;
  85. p->write_proc = Entries[i].write_fn;
  86. }
  87. }
  88. }
  89. void jfs_proc_clean(void)
  90. {
  91. int i;
  92. if (base) {
  93. for (i = 0; i < NPROCENT; i++)
  94. remove_proc_entry(Entries[i].name, base);
  95. remove_proc_entry("jfs", proc_root_fs);
  96. }
  97. }
  98. #endif /* PROC_FS_JFS */