debug.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "debug.h"
  19. #include "spin.h"
  20. #include <asm/page.h>
  21. #include <linux/sched.h>
  22. #include <linux/kernel.h>
  23. static char message[256]; /* keep it off the stack */
  24. static DEFINE_SPINLOCK(xfs_err_lock);
  25. /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */
  26. #define XFS_MAX_ERR_LEVEL 7
  27. #define XFS_ERR_MASK ((1 << 3) - 1)
  28. static const char * const err_level[XFS_MAX_ERR_LEVEL+1] =
  29. {KERN_EMERG, KERN_ALERT, KERN_CRIT,
  30. KERN_ERR, KERN_WARNING, KERN_NOTICE,
  31. KERN_INFO, KERN_DEBUG};
  32. void
  33. assfail(char *a, char *f, int l)
  34. {
  35. printk("XFS assertion failed: %s, file: %s, line: %d\n", a, f, l);
  36. BUG();
  37. }
  38. #if ((defined(DEBUG) || defined(INDUCE_IO_ERRROR)) && !defined(NO_WANT_RANDOM))
  39. unsigned long
  40. random(void)
  41. {
  42. static unsigned long RandomValue = 1;
  43. /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */
  44. register long rv = RandomValue;
  45. register long lo;
  46. register long hi;
  47. hi = rv / 127773;
  48. lo = rv % 127773;
  49. rv = 16807 * lo - 2836 * hi;
  50. if( rv <= 0 ) rv += 2147483647;
  51. return( RandomValue = rv );
  52. }
  53. int
  54. get_thread_id(void)
  55. {
  56. return current->pid;
  57. }
  58. #endif /* DEBUG || INDUCE_IO_ERRROR || !NO_WANT_RANDOM */
  59. void
  60. cmn_err(register int level, char *fmt, ...)
  61. {
  62. char *fp = fmt;
  63. int len;
  64. ulong flags;
  65. va_list ap;
  66. level &= XFS_ERR_MASK;
  67. if (level > XFS_MAX_ERR_LEVEL)
  68. level = XFS_MAX_ERR_LEVEL;
  69. spin_lock_irqsave(&xfs_err_lock,flags);
  70. va_start(ap, fmt);
  71. if (*fmt == '!') fp++;
  72. len = vsprintf(message, fp, ap);
  73. if (message[len-1] != '\n')
  74. strcat(message, "\n");
  75. printk("%s%s", err_level[level], message);
  76. va_end(ap);
  77. spin_unlock_irqrestore(&xfs_err_lock,flags);
  78. if (level == CE_PANIC)
  79. BUG();
  80. }
  81. void
  82. icmn_err(register int level, char *fmt, va_list ap)
  83. {
  84. ulong flags;
  85. int len;
  86. level &= XFS_ERR_MASK;
  87. if(level > XFS_MAX_ERR_LEVEL)
  88. level = XFS_MAX_ERR_LEVEL;
  89. spin_lock_irqsave(&xfs_err_lock,flags);
  90. len = vsprintf(message, fmt, ap);
  91. if (message[len-1] != '\n')
  92. strcat(message, "\n");
  93. spin_unlock_irqrestore(&xfs_err_lock,flags);
  94. printk("%s%s", err_level[level], message);
  95. if (level == CE_PANIC)
  96. BUG();
  97. }