debug.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <xfs.h>
  19. #include "debug.h"
  20. static char message[1024]; /* keep it off the stack */
  21. static DEFINE_SPINLOCK(xfs_err_lock);
  22. /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */
  23. #define XFS_MAX_ERR_LEVEL 7
  24. #define XFS_ERR_MASK ((1 << 3) - 1)
  25. static const char * const err_level[XFS_MAX_ERR_LEVEL+1] =
  26. {KERN_EMERG, KERN_ALERT, KERN_CRIT,
  27. KERN_ERR, KERN_WARNING, KERN_NOTICE,
  28. KERN_INFO, KERN_DEBUG};
  29. void
  30. cmn_err(register int level, char *fmt, ...)
  31. {
  32. char *fp = fmt;
  33. int len;
  34. ulong flags;
  35. va_list ap;
  36. level &= XFS_ERR_MASK;
  37. if (level > XFS_MAX_ERR_LEVEL)
  38. level = XFS_MAX_ERR_LEVEL;
  39. spin_lock_irqsave(&xfs_err_lock,flags);
  40. va_start(ap, fmt);
  41. if (*fmt == '!') fp++;
  42. len = vsnprintf(message, sizeof(message), fp, ap);
  43. if (len >= sizeof(message))
  44. len = sizeof(message) - 1;
  45. if (message[len-1] == '\n')
  46. message[len-1] = 0;
  47. printk("%s%s\n", err_level[level], message);
  48. va_end(ap);
  49. spin_unlock_irqrestore(&xfs_err_lock,flags);
  50. BUG_ON(level == CE_PANIC);
  51. }
  52. void
  53. icmn_err(register int level, char *fmt, va_list ap)
  54. {
  55. ulong flags;
  56. int len;
  57. level &= XFS_ERR_MASK;
  58. if(level > XFS_MAX_ERR_LEVEL)
  59. level = XFS_MAX_ERR_LEVEL;
  60. spin_lock_irqsave(&xfs_err_lock,flags);
  61. len = vsnprintf(message, sizeof(message), fmt, ap);
  62. if (len >= sizeof(message))
  63. len = sizeof(message) - 1;
  64. if (message[len-1] == '\n')
  65. message[len-1] = 0;
  66. printk("%s%s\n", err_level[level], message);
  67. spin_unlock_irqrestore(&xfs_err_lock,flags);
  68. BUG_ON(level == CE_PANIC);
  69. }
  70. void
  71. assfail(char *expr, char *file, int line)
  72. {
  73. printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line);
  74. BUG();
  75. }
  76. void
  77. xfs_hex_dump(void *p, int length)
  78. {
  79. print_hex_dump(KERN_ALERT, "", DUMP_PREFIX_OFFSET, 16, 1, p, length, 1);
  80. }