xfs_message.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2011 Red Hat, Inc. All Rights Reserved.
  4. */
  5. #include "xfs.h"
  6. #include "xfs_fs.h"
  7. #include "xfs_error.h"
  8. #include "xfs_shared.h"
  9. #include "xfs_format.h"
  10. #include "xfs_trans_resv.h"
  11. #include "xfs_mount.h"
  12. /*
  13. * XFS logging functions
  14. */
  15. static void
  16. __xfs_printk(
  17. const char *level,
  18. const struct xfs_mount *mp,
  19. struct va_format *vaf)
  20. {
  21. if (mp && mp->m_super) {
  22. printk("%sXFS (%s): %pV\n", level, mp->m_super->s_id, vaf);
  23. return;
  24. }
  25. printk("%sXFS: %pV\n", level, vaf);
  26. }
  27. #define define_xfs_printk_level(func, kern_level) \
  28. void func(const struct xfs_mount *mp, const char *fmt, ...) \
  29. { \
  30. struct va_format vaf; \
  31. va_list args; \
  32. int level; \
  33. \
  34. va_start(args, fmt); \
  35. \
  36. vaf.fmt = fmt; \
  37. vaf.va = &args; \
  38. \
  39. __xfs_printk(kern_level, mp, &vaf); \
  40. va_end(args); \
  41. \
  42. if (!kstrtoint(kern_level, 0, &level) && \
  43. level <= LOGLEVEL_ERR && \
  44. xfs_error_level >= XFS_ERRLEVEL_HIGH) \
  45. xfs_stack_trace(); \
  46. } \
  47. define_xfs_printk_level(xfs_emerg, KERN_EMERG);
  48. define_xfs_printk_level(xfs_alert, KERN_ALERT);
  49. define_xfs_printk_level(xfs_crit, KERN_CRIT);
  50. define_xfs_printk_level(xfs_err, KERN_ERR);
  51. define_xfs_printk_level(xfs_warn, KERN_WARNING);
  52. define_xfs_printk_level(xfs_notice, KERN_NOTICE);
  53. define_xfs_printk_level(xfs_info, KERN_INFO);
  54. #ifdef DEBUG
  55. define_xfs_printk_level(xfs_debug, KERN_DEBUG);
  56. #endif
  57. void
  58. xfs_alert_tag(
  59. const struct xfs_mount *mp,
  60. int panic_tag,
  61. const char *fmt, ...)
  62. {
  63. struct va_format vaf;
  64. va_list args;
  65. int do_panic = 0;
  66. if (xfs_panic_mask && (xfs_panic_mask & panic_tag)) {
  67. xfs_alert(mp, "Transforming an alert into a BUG.");
  68. do_panic = 1;
  69. }
  70. va_start(args, fmt);
  71. vaf.fmt = fmt;
  72. vaf.va = &args;
  73. __xfs_printk(KERN_ALERT, mp, &vaf);
  74. va_end(args);
  75. BUG_ON(do_panic);
  76. }
  77. void
  78. asswarn(
  79. struct xfs_mount *mp,
  80. char *expr,
  81. char *file,
  82. int line)
  83. {
  84. xfs_warn(mp, "Assertion failed: %s, file: %s, line: %d",
  85. expr, file, line);
  86. WARN_ON(1);
  87. }
  88. void
  89. assfail(
  90. struct xfs_mount *mp,
  91. char *expr,
  92. char *file,
  93. int line)
  94. {
  95. xfs_emerg(mp, "Assertion failed: %s, file: %s, line: %d",
  96. expr, file, line);
  97. if (xfs_globals.bug_on_assert)
  98. BUG();
  99. else
  100. WARN_ON(1);
  101. }
  102. void
  103. xfs_hex_dump(const void *p, int length)
  104. {
  105. print_hex_dump(KERN_ALERT, "", DUMP_PREFIX_OFFSET, 16, 1, p, length, 1);
  106. }
  107. void
  108. xfs_buf_alert_ratelimited(
  109. struct xfs_buf *bp,
  110. const char *rlmsg,
  111. const char *fmt,
  112. ...)
  113. {
  114. struct xfs_mount *mp = bp->b_mount;
  115. struct va_format vaf;
  116. va_list args;
  117. /* use the more aggressive per-target rate limit for buffers */
  118. if (!___ratelimit(&bp->b_target->bt_ioerror_rl, rlmsg))
  119. return;
  120. va_start(args, fmt);
  121. vaf.fmt = fmt;
  122. vaf.va = &args;
  123. __xfs_printk(KERN_ALERT, mp, &vaf);
  124. va_end(args);
  125. }