jfs_debug.c 2.8 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. .owner = THIS_MODULE,
  54. .open = jfs_loglevel_proc_open,
  55. .read = seq_read,
  56. .llseek = seq_lseek,
  57. .release = single_release,
  58. .write = jfs_loglevel_proc_write,
  59. };
  60. #endif
  61. static struct {
  62. const char *name;
  63. const struct file_operations *proc_fops;
  64. } Entries[] = {
  65. #ifdef CONFIG_JFS_STATISTICS
  66. { "lmstats", &jfs_lmstats_proc_fops, },
  67. { "txstats", &jfs_txstats_proc_fops, },
  68. { "xtstat", &jfs_xtstat_proc_fops, },
  69. { "mpstat", &jfs_mpstat_proc_fops, },
  70. #endif
  71. #ifdef CONFIG_JFS_DEBUG
  72. { "TxAnchor", &jfs_txanchor_proc_fops, },
  73. { "loglevel", &jfs_loglevel_proc_fops }
  74. #endif
  75. };
  76. #define NPROCENT ARRAY_SIZE(Entries)
  77. void jfs_proc_init(void)
  78. {
  79. int i;
  80. if (!(base = proc_mkdir("fs/jfs", NULL)))
  81. return;
  82. for (i = 0; i < NPROCENT; i++)
  83. proc_create(Entries[i].name, 0, base, Entries[i].proc_fops);
  84. }
  85. void jfs_proc_clean(void)
  86. {
  87. int i;
  88. if (base) {
  89. for (i = 0; i < NPROCENT; i++)
  90. remove_proc_entry(Entries[i].name, base);
  91. remove_proc_entry("fs/jfs", NULL);
  92. }
  93. }
  94. #endif /* PROC_FS_JFS */