xfs_error.c 4.6 KB

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