xfs_error.c 4.5 KB

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