debug.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. /* xfs_mount.h drags a lot of crap in, sorry.. */
  21. #include "xfs_sb.h"
  22. #include "xfs_inum.h"
  23. #include "xfs_ag.h"
  24. #include "xfs_dmapi.h"
  25. #include "xfs_mount.h"
  26. static char message[1024]; /* keep it off the stack */
  27. static DEFINE_SPINLOCK(xfs_err_lock);
  28. /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */
  29. #define XFS_MAX_ERR_LEVEL 7
  30. #define XFS_ERR_MASK ((1 << 3) - 1)
  31. static const char * const err_level[XFS_MAX_ERR_LEVEL+1] =
  32. {KERN_EMERG, KERN_ALERT, KERN_CRIT,
  33. KERN_ERR, KERN_WARNING, KERN_NOTICE,
  34. KERN_INFO, KERN_DEBUG};
  35. void
  36. cmn_err(register int level, char *fmt, ...)
  37. {
  38. char *fp = fmt;
  39. int len;
  40. ulong flags;
  41. va_list ap;
  42. level &= XFS_ERR_MASK;
  43. if (level > XFS_MAX_ERR_LEVEL)
  44. level = XFS_MAX_ERR_LEVEL;
  45. spin_lock_irqsave(&xfs_err_lock,flags);
  46. va_start(ap, fmt);
  47. if (*fmt == '!') fp++;
  48. len = vsnprintf(message, sizeof(message), fp, ap);
  49. if (len >= sizeof(message))
  50. len = sizeof(message) - 1;
  51. if (message[len-1] == '\n')
  52. message[len-1] = 0;
  53. printk("%s%s\n", err_level[level], message);
  54. va_end(ap);
  55. spin_unlock_irqrestore(&xfs_err_lock,flags);
  56. BUG_ON(level == CE_PANIC);
  57. }
  58. void
  59. xfs_fs_vcmn_err(
  60. int level,
  61. struct xfs_mount *mp,
  62. char *fmt,
  63. va_list ap)
  64. {
  65. unsigned long flags;
  66. int len = 0;
  67. level &= XFS_ERR_MASK;
  68. if (level > XFS_MAX_ERR_LEVEL)
  69. level = XFS_MAX_ERR_LEVEL;
  70. spin_lock_irqsave(&xfs_err_lock,flags);
  71. if (mp) {
  72. len = sprintf(message, "Filesystem \"%s\": ", mp->m_fsname);
  73. /*
  74. * Skip the printk if we can't print anything useful
  75. * due to an over-long device name.
  76. */
  77. if (len >= sizeof(message))
  78. goto out;
  79. }
  80. len = vsnprintf(message + len, sizeof(message) - len, fmt, ap);
  81. if (len >= sizeof(message))
  82. len = sizeof(message) - 1;
  83. if (message[len-1] == '\n')
  84. message[len-1] = 0;
  85. printk("%s%s\n", err_level[level], message);
  86. out:
  87. spin_unlock_irqrestore(&xfs_err_lock,flags);
  88. BUG_ON(level == CE_PANIC);
  89. }
  90. void
  91. assfail(char *expr, char *file, int line)
  92. {
  93. printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line);
  94. BUG();
  95. }
  96. void
  97. xfs_hex_dump(void *p, int length)
  98. {
  99. print_hex_dump(KERN_ALERT, "", DUMP_PREFIX_ADDRESS, 16, 1, p, length, 1);
  100. }