debug.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 <asm/page.h>
  34. #include <linux/sched.h>
  35. #include <linux/kernel.h>
  36. static char message[256]; /* keep it off the stack */
  37. static DEFINE_SPINLOCK(xfs_err_lock);
  38. /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */
  39. #define XFS_MAX_ERR_LEVEL 7
  40. #define XFS_ERR_MASK ((1 << 3) - 1)
  41. static char *err_level[XFS_MAX_ERR_LEVEL+1] =
  42. {KERN_EMERG, KERN_ALERT, KERN_CRIT,
  43. KERN_ERR, KERN_WARNING, KERN_NOTICE,
  44. KERN_INFO, KERN_DEBUG};
  45. void
  46. assfail(char *a, char *f, int l)
  47. {
  48. printk("XFS assertion failed: %s, file: %s, line: %d\n", a, f, l);
  49. BUG();
  50. }
  51. #if ((defined(DEBUG) || defined(INDUCE_IO_ERRROR)) && !defined(NO_WANT_RANDOM))
  52. unsigned long
  53. random(void)
  54. {
  55. static unsigned long RandomValue = 1;
  56. /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */
  57. register long rv = RandomValue;
  58. register long lo;
  59. register long hi;
  60. hi = rv / 127773;
  61. lo = rv % 127773;
  62. rv = 16807 * lo - 2836 * hi;
  63. if( rv <= 0 ) rv += 2147483647;
  64. return( RandomValue = rv );
  65. }
  66. int
  67. get_thread_id(void)
  68. {
  69. return current->pid;
  70. }
  71. #endif /* DEBUG || INDUCE_IO_ERRROR || !NO_WANT_RANDOM */
  72. void
  73. cmn_err(register int level, char *fmt, ...)
  74. {
  75. char *fp = fmt;
  76. int len;
  77. ulong flags;
  78. va_list ap;
  79. level &= XFS_ERR_MASK;
  80. if (level > XFS_MAX_ERR_LEVEL)
  81. level = XFS_MAX_ERR_LEVEL;
  82. spin_lock_irqsave(&xfs_err_lock,flags);
  83. va_start(ap, fmt);
  84. if (*fmt == '!') fp++;
  85. len = vsprintf(message, fp, ap);
  86. if (message[len-1] != '\n')
  87. strcat(message, "\n");
  88. printk("%s%s", err_level[level], message);
  89. va_end(ap);
  90. spin_unlock_irqrestore(&xfs_err_lock,flags);
  91. if (level == CE_PANIC)
  92. BUG();
  93. }
  94. void
  95. icmn_err(register int level, char *fmt, va_list ap)
  96. {
  97. ulong flags;
  98. int len;
  99. level &= XFS_ERR_MASK;
  100. if(level > XFS_MAX_ERR_LEVEL)
  101. level = XFS_MAX_ERR_LEVEL;
  102. spin_lock_irqsave(&xfs_err_lock,flags);
  103. len = vsprintf(message, fmt, ap);
  104. if (message[len-1] != '\n')
  105. strcat(message, "\n");
  106. spin_unlock_irqrestore(&xfs_err_lock,flags);
  107. printk("%s%s", err_level[level], message);
  108. if (level == CE_PANIC)
  109. BUG();
  110. }