xfs_message.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. void
  28. xfs_printk_level(
  29. const char *kern_level,
  30. const struct xfs_mount *mp,
  31. const char *fmt, ...)
  32. {
  33. struct va_format vaf;
  34. va_list args;
  35. int level;
  36. va_start(args, fmt);
  37. vaf.fmt = fmt;
  38. vaf.va = &args;
  39. __xfs_printk(kern_level, mp, &vaf);
  40. va_end(args);
  41. if (!kstrtoint(kern_level, 0, &level) &&
  42. level <= LOGLEVEL_ERR &&
  43. xfs_error_level >= XFS_ERRLEVEL_HIGH)
  44. xfs_stack_trace();
  45. }
  46. void
  47. _xfs_alert_tag(
  48. const struct xfs_mount *mp,
  49. uint32_t panic_tag,
  50. const char *fmt, ...)
  51. {
  52. struct va_format vaf;
  53. va_list args;
  54. int do_panic = 0;
  55. if (xfs_panic_mask && (xfs_panic_mask & panic_tag)) {
  56. xfs_alert(mp, "Transforming an alert into a BUG.");
  57. do_panic = 1;
  58. }
  59. va_start(args, fmt);
  60. vaf.fmt = fmt;
  61. vaf.va = &args;
  62. __xfs_printk(KERN_ALERT, mp, &vaf);
  63. va_end(args);
  64. BUG_ON(do_panic);
  65. }
  66. void
  67. asswarn(
  68. struct xfs_mount *mp,
  69. char *expr,
  70. char *file,
  71. int line)
  72. {
  73. xfs_warn(mp, "Assertion failed: %s, file: %s, line: %d",
  74. expr, file, line);
  75. WARN_ON(1);
  76. }
  77. void
  78. assfail(
  79. struct xfs_mount *mp,
  80. char *expr,
  81. char *file,
  82. int line)
  83. {
  84. xfs_emerg(mp, "Assertion failed: %s, file: %s, line: %d",
  85. expr, file, line);
  86. if (xfs_globals.bug_on_assert)
  87. BUG();
  88. else
  89. WARN_ON(1);
  90. }
  91. void
  92. xfs_hex_dump(const void *p, int length)
  93. {
  94. print_hex_dump(KERN_ALERT, "", DUMP_PREFIX_OFFSET, 16, 1, p, length, 1);
  95. }
  96. void
  97. xfs_buf_alert_ratelimited(
  98. struct xfs_buf *bp,
  99. const char *rlmsg,
  100. const char *fmt,
  101. ...)
  102. {
  103. struct xfs_mount *mp = bp->b_mount;
  104. struct va_format vaf;
  105. va_list args;
  106. /* use the more aggressive per-target rate limit for buffers */
  107. if (!___ratelimit(&bp->b_target->bt_ioerror_rl, rlmsg))
  108. return;
  109. va_start(args, fmt);
  110. vaf.fmt = fmt;
  111. vaf.va = &args;
  112. __xfs_printk(KERN_ALERT, mp, &vaf);
  113. va_end(args);
  114. }