xfs_error.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * Copyright (c) 2000-2001,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 "xfs_fs.h"
  20. #include "xfs_types.h"
  21. #include "xfs_log.h"
  22. #include "xfs_inum.h"
  23. #include "xfs_trans.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_ag.h"
  26. #include "xfs_mount.h"
  27. #include "xfs_bmap_btree.h"
  28. #include "xfs_dinode.h"
  29. #include "xfs_inode.h"
  30. #include "xfs_utils.h"
  31. #include "xfs_error.h"
  32. #ifdef DEBUG
  33. int xfs_etrap[XFS_ERROR_NTRAP] = {
  34. 0,
  35. };
  36. int
  37. xfs_error_trap(int e)
  38. {
  39. int i;
  40. if (!e)
  41. return 0;
  42. for (i = 0; i < XFS_ERROR_NTRAP; i++) {
  43. if (xfs_etrap[i] == 0)
  44. break;
  45. if (e != xfs_etrap[i])
  46. continue;
  47. cmn_err(CE_NOTE, "xfs_error_trap: error %d", e);
  48. BUG();
  49. break;
  50. }
  51. return e;
  52. }
  53. int xfs_etest[XFS_NUM_INJECT_ERROR];
  54. int64_t xfs_etest_fsid[XFS_NUM_INJECT_ERROR];
  55. char * xfs_etest_fsname[XFS_NUM_INJECT_ERROR];
  56. int
  57. xfs_error_test(int error_tag, int *fsidp, char *expression,
  58. int line, char *file, unsigned long randfactor)
  59. {
  60. int i;
  61. int64_t fsid;
  62. if (random32() % randfactor)
  63. return 0;
  64. memcpy(&fsid, fsidp, sizeof(xfs_fsid_t));
  65. for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
  66. if (xfs_etest[i] == error_tag && xfs_etest_fsid[i] == fsid) {
  67. cmn_err(CE_WARN,
  68. "Injecting error (%s) at file %s, line %d, on filesystem \"%s\"",
  69. expression, file, line, xfs_etest_fsname[i]);
  70. return 1;
  71. }
  72. }
  73. return 0;
  74. }
  75. int
  76. xfs_errortag_add(int error_tag, xfs_mount_t *mp)
  77. {
  78. int i;
  79. int len;
  80. int64_t fsid;
  81. memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
  82. for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
  83. if (xfs_etest_fsid[i] == fsid && xfs_etest[i] == error_tag) {
  84. cmn_err(CE_WARN, "XFS error tag #%d on", error_tag);
  85. return 0;
  86. }
  87. }
  88. for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
  89. if (xfs_etest[i] == 0) {
  90. cmn_err(CE_WARN, "Turned on XFS error tag #%d",
  91. error_tag);
  92. xfs_etest[i] = error_tag;
  93. xfs_etest_fsid[i] = fsid;
  94. len = strlen(mp->m_fsname);
  95. xfs_etest_fsname[i] = kmem_alloc(len + 1, KM_SLEEP);
  96. strcpy(xfs_etest_fsname[i], mp->m_fsname);
  97. return 0;
  98. }
  99. }
  100. cmn_err(CE_WARN, "error tag overflow, too many turned on");
  101. return 1;
  102. }
  103. int
  104. xfs_errortag_clearall(xfs_mount_t *mp, int loud)
  105. {
  106. int64_t fsid;
  107. int cleared = 0;
  108. int i;
  109. memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
  110. for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
  111. if ((fsid == 0LL || xfs_etest_fsid[i] == fsid) &&
  112. xfs_etest[i] != 0) {
  113. cleared = 1;
  114. cmn_err(CE_WARN, "Clearing XFS error tag #%d",
  115. xfs_etest[i]);
  116. xfs_etest[i] = 0;
  117. xfs_etest_fsid[i] = 0LL;
  118. kmem_free(xfs_etest_fsname[i]);
  119. xfs_etest_fsname[i] = NULL;
  120. }
  121. }
  122. if (loud || cleared)
  123. cmn_err(CE_WARN,
  124. "Cleared all XFS error tags for filesystem \"%s\"",
  125. mp->m_fsname);
  126. return 0;
  127. }
  128. #endif /* DEBUG */
  129. void
  130. xfs_fs_cmn_err(int level, xfs_mount_t *mp, char *fmt, ...)
  131. {
  132. va_list ap;
  133. va_start(ap, fmt);
  134. xfs_fs_vcmn_err(level, mp, fmt, ap);
  135. va_end(ap);
  136. }
  137. void
  138. xfs_cmn_err(int panic_tag, int level, xfs_mount_t *mp, char *fmt, ...)
  139. {
  140. va_list ap;
  141. #ifdef DEBUG
  142. xfs_panic_mask |= (XFS_PTAG_SHUTDOWN_CORRUPT | XFS_PTAG_LOGRES);
  143. #endif
  144. if (xfs_panic_mask && (xfs_panic_mask & panic_tag)
  145. && (level & CE_ALERT)) {
  146. level &= ~CE_ALERT;
  147. level |= CE_PANIC;
  148. cmn_err(CE_ALERT, "XFS: Transforming an alert into a BUG.");
  149. }
  150. va_start(ap, fmt);
  151. xfs_fs_vcmn_err(level, mp, fmt, ap);
  152. va_end(ap);
  153. }
  154. void
  155. xfs_error_report(
  156. const char *tag,
  157. int level,
  158. struct xfs_mount *mp,
  159. const char *filename,
  160. int linenum,
  161. inst_t *ra)
  162. {
  163. if (level <= xfs_error_level) {
  164. xfs_cmn_err(XFS_PTAG_ERROR_REPORT,
  165. CE_ALERT, mp,
  166. "XFS internal error %s at line %d of file %s. Caller 0x%p\n",
  167. tag, linenum, filename, ra);
  168. xfs_stack_trace();
  169. }
  170. }
  171. void
  172. xfs_corruption_error(
  173. const char *tag,
  174. int level,
  175. struct xfs_mount *mp,
  176. void *p,
  177. const char *filename,
  178. int linenum,
  179. inst_t *ra)
  180. {
  181. if (level <= xfs_error_level)
  182. xfs_hex_dump(p, 16);
  183. xfs_error_report(tag, level, mp, filename, linenum, ra);
  184. }