debug.c 2.7 KB

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