xfs_message.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2011 Red Hat, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms 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,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write the Free Software Foundation,
  15. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. #include "xfs.h"
  18. #include "xfs_fs.h"
  19. #include "xfs_error.h"
  20. #include "xfs_format.h"
  21. #include "xfs_log_format.h"
  22. #include "xfs_trans_resv.h"
  23. #include "xfs_mount.h"
  24. /*
  25. * XFS logging functions
  26. */
  27. static void
  28. __xfs_printk(
  29. const char *level,
  30. const struct xfs_mount *mp,
  31. struct va_format *vaf)
  32. {
  33. if (mp && mp->m_fsname) {
  34. printk("%sXFS (%s): %pV\n", level, mp->m_fsname, vaf);
  35. return;
  36. }
  37. printk("%sXFS: %pV\n", level, vaf);
  38. }
  39. #define define_xfs_printk_level(func, kern_level) \
  40. void func(const struct xfs_mount *mp, const char *fmt, ...) \
  41. { \
  42. struct va_format vaf; \
  43. va_list args; \
  44. int level; \
  45. \
  46. va_start(args, fmt); \
  47. \
  48. vaf.fmt = fmt; \
  49. vaf.va = &args; \
  50. \
  51. __xfs_printk(kern_level, mp, &vaf); \
  52. va_end(args); \
  53. \
  54. if (!kstrtoint(kern_level, 0, &level) && \
  55. level <= LOGLEVEL_ERR && \
  56. xfs_error_level >= XFS_ERRLEVEL_HIGH) \
  57. xfs_stack_trace(); \
  58. } \
  59. define_xfs_printk_level(xfs_emerg, KERN_EMERG);
  60. define_xfs_printk_level(xfs_alert, KERN_ALERT);
  61. define_xfs_printk_level(xfs_crit, KERN_CRIT);
  62. define_xfs_printk_level(xfs_err, KERN_ERR);
  63. define_xfs_printk_level(xfs_warn, KERN_WARNING);
  64. define_xfs_printk_level(xfs_notice, KERN_NOTICE);
  65. define_xfs_printk_level(xfs_info, KERN_INFO);
  66. #ifdef DEBUG
  67. define_xfs_printk_level(xfs_debug, KERN_DEBUG);
  68. #endif
  69. void
  70. xfs_alert_tag(
  71. const struct xfs_mount *mp,
  72. int panic_tag,
  73. const char *fmt, ...)
  74. {
  75. struct va_format vaf;
  76. va_list args;
  77. int do_panic = 0;
  78. if (xfs_panic_mask && (xfs_panic_mask & panic_tag)) {
  79. xfs_alert(mp, "Transforming an alert into a BUG.");
  80. do_panic = 1;
  81. }
  82. va_start(args, fmt);
  83. vaf.fmt = fmt;
  84. vaf.va = &args;
  85. __xfs_printk(KERN_ALERT, mp, &vaf);
  86. va_end(args);
  87. BUG_ON(do_panic);
  88. }
  89. void
  90. asswarn(char *expr, char *file, int line)
  91. {
  92. xfs_warn(NULL, "Assertion failed: %s, file: %s, line: %d",
  93. expr, file, line);
  94. WARN_ON(1);
  95. }
  96. void
  97. assfail(char *expr, char *file, int line)
  98. {
  99. xfs_emerg(NULL, "Assertion failed: %s, file: %s, line: %d",
  100. expr, file, line);
  101. BUG();
  102. }
  103. void
  104. xfs_hex_dump(void *p, int length)
  105. {
  106. print_hex_dump(KERN_ALERT, "", DUMP_PREFIX_ADDRESS, 16, 1, p, length, 1);
  107. }