jfs_debug.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 <linux/seq_file.h>
  24. #include <asm/uaccess.h>
  25. #include "jfs_incore.h"
  26. #include "jfs_filsys.h"
  27. #include "jfs_debug.h"
  28. #ifdef PROC_FS_JFS /* see jfs_debug.h */
  29. static struct proc_dir_entry *base;
  30. #ifdef CONFIG_JFS_DEBUG
  31. static int jfs_loglevel_proc_show(struct seq_file *m, void *v)
  32. {
  33. seq_printf(m, "%d\n", jfsloglevel);
  34. return 0;
  35. }
  36. static int jfs_loglevel_proc_open(struct inode *inode, struct file *file)
  37. {
  38. return single_open(file, jfs_loglevel_proc_show, NULL);
  39. }
  40. static ssize_t jfs_loglevel_proc_write(struct file *file,
  41. const char __user *buffer, size_t count, loff_t *ppos)
  42. {
  43. char c;
  44. if (get_user(c, buffer))
  45. return -EFAULT;
  46. /* yes, I know this is an ASCIIism. --hch */
  47. if (c < '0' || c > '9')
  48. return -EINVAL;
  49. jfsloglevel = c - '0';
  50. return count;
  51. }
  52. static const struct file_operations jfs_loglevel_proc_fops = {
  53. .open = jfs_loglevel_proc_open,
  54. .read = seq_read,
  55. .llseek = seq_lseek,
  56. .release = single_release,
  57. .write = jfs_loglevel_proc_write,
  58. };
  59. #endif
  60. static struct {
  61. const char *name;
  62. const struct file_operations *proc_fops;
  63. } Entries[] = {
  64. #ifdef CONFIG_JFS_STATISTICS
  65. { "lmstats", &jfs_lmstats_proc_fops, },
  66. { "txstats", &jfs_txstats_proc_fops, },
  67. { "xtstat", &jfs_xtstat_proc_fops, },
  68. { "mpstat", &jfs_mpstat_proc_fops, },
  69. #endif
  70. #ifdef CONFIG_JFS_DEBUG
  71. { "TxAnchor", &jfs_txanchor_proc_fops, },
  72. { "loglevel", &jfs_loglevel_proc_fops }
  73. #endif
  74. };
  75. #define NPROCENT ARRAY_SIZE(Entries)
  76. void jfs_proc_init(void)
  77. {
  78. int i;
  79. if (!(base = proc_mkdir("fs/jfs", NULL)))
  80. return;
  81. for (i = 0; i < NPROCENT; i++)
  82. proc_create(Entries[i].name, 0, base, Entries[i].proc_fops);
  83. }
  84. void jfs_proc_clean(void)
  85. {
  86. int i;
  87. if (base) {
  88. for (i = 0; i < NPROCENT; i++)
  89. remove_proc_entry(Entries[i].name, base);
  90. remove_proc_entry("fs/jfs", NULL);
  91. }
  92. }
  93. #endif /* PROC_FS_JFS */