debug.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. cmn_err(register int level, char *fmt, ...)
  34. {
  35. char *fp = fmt;
  36. int len;
  37. ulong flags;
  38. va_list ap;
  39. level &= XFS_ERR_MASK;
  40. if (level > XFS_MAX_ERR_LEVEL)
  41. level = XFS_MAX_ERR_LEVEL;
  42. spin_lock_irqsave(&xfs_err_lock,flags);
  43. va_start(ap, fmt);
  44. if (*fmt == '!') fp++;
  45. len = vsprintf(message, fp, ap);
  46. if (level != CE_DEBUG && message[len-1] != '\n')
  47. strcat(message, "\n");
  48. printk("%s%s", err_level[level], message);
  49. va_end(ap);
  50. spin_unlock_irqrestore(&xfs_err_lock,flags);
  51. if (level == CE_PANIC)
  52. BUG();
  53. }
  54. void
  55. icmn_err(register int level, char *fmt, va_list ap)
  56. {
  57. ulong flags;
  58. int len;
  59. level &= XFS_ERR_MASK;
  60. if(level > XFS_MAX_ERR_LEVEL)
  61. level = XFS_MAX_ERR_LEVEL;
  62. spin_lock_irqsave(&xfs_err_lock,flags);
  63. len = vsprintf(message, fmt, ap);
  64. if (level != CE_DEBUG && message[len-1] != '\n')
  65. strcat(message, "\n");
  66. spin_unlock_irqrestore(&xfs_err_lock,flags);
  67. printk("%s%s", err_level[level], message);
  68. if (level == CE_PANIC)
  69. BUG();
  70. }
  71. void
  72. assfail(char *expr, char *file, int line)
  73. {
  74. printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line);
  75. BUG();
  76. }
  77. #if ((defined(DEBUG) || defined(INDUCE_IO_ERRROR)) && !defined(NO_WANT_RANDOM))
  78. unsigned long random(void)
  79. {
  80. static unsigned long RandomValue = 1;
  81. /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */
  82. register long rv = RandomValue;
  83. register long lo;
  84. register long hi;
  85. hi = rv / 127773;
  86. lo = rv % 127773;
  87. rv = 16807 * lo - 2836 * hi;
  88. if (rv <= 0) rv += 2147483647;
  89. return RandomValue = rv;
  90. }
  91. #endif /* DEBUG || INDUCE_IO_ERRROR || !NO_WANT_RANDOM */