debug.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #include "debug.h"
  33. #include "spin.h"
  34. #include <asm/page.h>
  35. #include <linux/sched.h>
  36. #include <linux/kernel.h>
  37. static char message[256]; /* keep it off the stack */
  38. static DEFINE_SPINLOCK(xfs_err_lock);
  39. /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */
  40. #define XFS_MAX_ERR_LEVEL 7
  41. #define XFS_ERR_MASK ((1 << 3) - 1)
  42. static char *err_level[XFS_MAX_ERR_LEVEL+1] =
  43. {KERN_EMERG, KERN_ALERT, KERN_CRIT,
  44. KERN_ERR, KERN_WARNING, KERN_NOTICE,
  45. KERN_INFO, KERN_DEBUG};
  46. void
  47. assfail(char *a, char *f, int l)
  48. {
  49. printk("XFS assertion failed: %s, file: %s, line: %d\n", a, f, l);
  50. BUG();
  51. }
  52. #if ((defined(DEBUG) || defined(INDUCE_IO_ERRROR)) && !defined(NO_WANT_RANDOM))
  53. unsigned long
  54. random(void)
  55. {
  56. static unsigned long RandomValue = 1;
  57. /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */
  58. register long rv = RandomValue;
  59. register long lo;
  60. register long hi;
  61. hi = rv / 127773;
  62. lo = rv % 127773;
  63. rv = 16807 * lo - 2836 * hi;
  64. if( rv <= 0 ) rv += 2147483647;
  65. return( RandomValue = rv );
  66. }
  67. int
  68. get_thread_id(void)
  69. {
  70. return current->pid;
  71. }
  72. #endif /* DEBUG || INDUCE_IO_ERRROR || !NO_WANT_RANDOM */
  73. void
  74. cmn_err(register int level, char *fmt, ...)
  75. {
  76. char *fp = fmt;
  77. int len;
  78. ulong flags;
  79. va_list ap;
  80. level &= XFS_ERR_MASK;
  81. if (level > XFS_MAX_ERR_LEVEL)
  82. level = XFS_MAX_ERR_LEVEL;
  83. spin_lock_irqsave(&xfs_err_lock,flags);
  84. va_start(ap, fmt);
  85. if (*fmt == '!') fp++;
  86. len = vsprintf(message, fp, ap);
  87. if (message[len-1] != '\n')
  88. strcat(message, "\n");
  89. printk("%s%s", err_level[level], message);
  90. va_end(ap);
  91. spin_unlock_irqrestore(&xfs_err_lock,flags);
  92. if (level == CE_PANIC)
  93. BUG();
  94. }
  95. void
  96. icmn_err(register int level, char *fmt, va_list ap)
  97. {
  98. ulong flags;
  99. int len;
  100. level &= XFS_ERR_MASK;
  101. if(level > XFS_MAX_ERR_LEVEL)
  102. level = XFS_MAX_ERR_LEVEL;
  103. spin_lock_irqsave(&xfs_err_lock,flags);
  104. len = vsprintf(message, fmt, ap);
  105. if (message[len-1] != '\n')
  106. strcat(message, "\n");
  107. spin_unlock_irqrestore(&xfs_err_lock,flags);
  108. printk("%s%s", err_level[level], message);
  109. if (level == CE_PANIC)
  110. BUG();
  111. }