debug.c 2.9 KB

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