xfs_error.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. #endif
  58. #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
  59. int xfs_etest[XFS_NUM_INJECT_ERROR];
  60. int64_t xfs_etest_fsid[XFS_NUM_INJECT_ERROR];
  61. char * xfs_etest_fsname[XFS_NUM_INJECT_ERROR];
  62. int
  63. xfs_error_test(int error_tag, int *fsidp, char *expression,
  64. int line, char *file, unsigned long randfactor)
  65. {
  66. int i;
  67. int64_t fsid;
  68. if (random32() % randfactor)
  69. return 0;
  70. memcpy(&fsid, fsidp, sizeof(xfs_fsid_t));
  71. for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
  72. if (xfs_etest[i] == error_tag && xfs_etest_fsid[i] == fsid) {
  73. cmn_err(CE_WARN,
  74. "Injecting error (%s) at file %s, line %d, on filesystem \"%s\"",
  75. expression, file, line, xfs_etest_fsname[i]);
  76. return 1;
  77. }
  78. }
  79. return 0;
  80. }
  81. int
  82. xfs_errortag_add(int error_tag, xfs_mount_t *mp)
  83. {
  84. int i;
  85. int len;
  86. int64_t fsid;
  87. memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
  88. for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
  89. if (xfs_etest_fsid[i] == fsid && xfs_etest[i] == error_tag) {
  90. cmn_err(CE_WARN, "XFS error tag #%d on", error_tag);
  91. return 0;
  92. }
  93. }
  94. for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
  95. if (xfs_etest[i] == 0) {
  96. cmn_err(CE_WARN, "Turned on XFS error tag #%d",
  97. error_tag);
  98. xfs_etest[i] = error_tag;
  99. xfs_etest_fsid[i] = fsid;
  100. len = strlen(mp->m_fsname);
  101. xfs_etest_fsname[i] = kmem_alloc(len + 1, KM_SLEEP);
  102. strcpy(xfs_etest_fsname[i], mp->m_fsname);
  103. return 0;
  104. }
  105. }
  106. cmn_err(CE_WARN, "error tag overflow, too many turned on");
  107. return 1;
  108. }
  109. int
  110. xfs_errortag_clearall(xfs_mount_t *mp, int loud)
  111. {
  112. int64_t fsid;
  113. int cleared = 0;
  114. int i;
  115. memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
  116. for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
  117. if ((fsid == 0LL || xfs_etest_fsid[i] == fsid) &&
  118. xfs_etest[i] != 0) {
  119. cleared = 1;
  120. cmn_err(CE_WARN, "Clearing XFS error tag #%d",
  121. xfs_etest[i]);
  122. xfs_etest[i] = 0;
  123. xfs_etest_fsid[i] = 0LL;
  124. kmem_free(xfs_etest_fsname[i]);
  125. xfs_etest_fsname[i] = NULL;
  126. }
  127. }
  128. if (loud || cleared)
  129. cmn_err(CE_WARN,
  130. "Cleared all XFS error tags for filesystem \"%s\"",
  131. mp->m_fsname);
  132. return 0;
  133. }
  134. #endif /* DEBUG || INDUCE_IO_ERROR */
  135. static void
  136. xfs_fs_vcmn_err(int level, xfs_mount_t *mp, char *fmt, va_list ap)
  137. {
  138. if (mp != NULL) {
  139. char *newfmt;
  140. int len = 16 + mp->m_fsname_len + strlen(fmt);
  141. newfmt = kmem_alloc(len, KM_SLEEP);
  142. sprintf(newfmt, "Filesystem \"%s\": %s", mp->m_fsname, fmt);
  143. icmn_err(level, newfmt, ap);
  144. kmem_free(newfmt);
  145. } else {
  146. icmn_err(level, fmt, ap);
  147. }
  148. }
  149. void
  150. xfs_fs_cmn_err(int level, xfs_mount_t *mp, char *fmt, ...)
  151. {
  152. va_list ap;
  153. va_start(ap, fmt);
  154. xfs_fs_vcmn_err(level, mp, fmt, ap);
  155. va_end(ap);
  156. }
  157. void
  158. xfs_cmn_err(int panic_tag, int level, xfs_mount_t *mp, char *fmt, ...)
  159. {
  160. va_list ap;
  161. #ifdef DEBUG
  162. xfs_panic_mask |= XFS_PTAG_SHUTDOWN_CORRUPT;
  163. #endif
  164. if (xfs_panic_mask && (xfs_panic_mask & panic_tag)
  165. && (level & CE_ALERT)) {
  166. level &= ~CE_ALERT;
  167. level |= CE_PANIC;
  168. cmn_err(CE_ALERT, "XFS: Transforming an alert into a BUG.");
  169. }
  170. va_start(ap, fmt);
  171. xfs_fs_vcmn_err(level, mp, fmt, ap);
  172. va_end(ap);
  173. }
  174. void
  175. xfs_error_report(
  176. char *tag,
  177. int level,
  178. xfs_mount_t *mp,
  179. char *fname,
  180. int linenum,
  181. inst_t *ra)
  182. {
  183. if (level <= xfs_error_level) {
  184. xfs_cmn_err(XFS_PTAG_ERROR_REPORT,
  185. CE_ALERT, mp,
  186. "XFS internal error %s at line %d of file %s. Caller 0x%p\n",
  187. tag, linenum, fname, ra);
  188. xfs_stack_trace();
  189. }
  190. }
  191. void
  192. xfs_corruption_error(
  193. char *tag,
  194. int level,
  195. xfs_mount_t *mp,
  196. void *p,
  197. char *fname,
  198. int linenum,
  199. inst_t *ra)
  200. {
  201. if (level <= xfs_error_level)
  202. xfs_hex_dump(p, 16);
  203. xfs_error_report(tag, level, mp, fname, linenum, ra);
  204. }