Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
7b718769 NS |
2 | * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
1da177e4 | 4 | * |
7b718769 NS |
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 | |
1da177e4 LT |
7 | * published by the Free Software Foundation. |
8 | * | |
7b718769 NS |
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. | |
1da177e4 | 13 | * |
7b718769 NS |
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 | |
1da177e4 | 17 | */ |
1da177e4 | 18 | #include "xfs.h" |
a844f451 | 19 | #include "xfs_fs.h" |
1da177e4 | 20 | #include "xfs_types.h" |
1da177e4 | 21 | #include "xfs_log.h" |
1da177e4 | 22 | #include "xfs_trans.h" |
a844f451 | 23 | #include "xfs_sb.h" |
da353b0d | 24 | #include "xfs_ag.h" |
1da177e4 LT |
25 | #include "xfs_mount.h" |
26 | #include "xfs_bmap_btree.h" | |
1da177e4 LT |
27 | #include "xfs_dinode.h" |
28 | #include "xfs_inode.h" | |
1da177e4 LT |
29 | #include "xfs_error.h" |
30 | ||
31 | #ifdef DEBUG | |
32 | ||
33 | int xfs_etrap[XFS_ERROR_NTRAP] = { | |
34 | 0, | |
35 | }; | |
36 | ||
37 | int | |
38 | xfs_error_trap(int e) | |
39 | { | |
40 | int i; | |
41 | ||
42 | if (!e) | |
43 | return 0; | |
44 | for (i = 0; i < XFS_ERROR_NTRAP; i++) { | |
45 | if (xfs_etrap[i] == 0) | |
46 | break; | |
47 | if (e != xfs_etrap[i]) | |
48 | continue; | |
0b932ccc | 49 | xfs_notice(NULL, "%s: error %d", __func__, e); |
1da177e4 LT |
50 | BUG(); |
51 | break; | |
52 | } | |
53 | return e; | |
54 | } | |
1da177e4 LT |
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]; | |
c76febef | 59 | int xfs_error_test_active; |
1da177e4 | 60 | |
1da177e4 LT |
61 | int |
62 | xfs_error_test(int error_tag, int *fsidp, char *expression, | |
63 | int line, char *file, unsigned long randfactor) | |
64 | { | |
65 | int i; | |
66 | int64_t fsid; | |
67 | ||
ecb3403d | 68 | if (prandom_u32() % randfactor) |
1da177e4 LT |
69 | return 0; |
70 | ||
71 | memcpy(&fsid, fsidp, sizeof(xfs_fsid_t)); | |
72 | ||
73 | for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) { | |
74 | if (xfs_etest[i] == error_tag && xfs_etest_fsid[i] == fsid) { | |
0b932ccc | 75 | xfs_warn(NULL, |
1da177e4 LT |
76 | "Injecting error (%s) at file %s, line %d, on filesystem \"%s\"", |
77 | expression, file, line, xfs_etest_fsname[i]); | |
78 | return 1; | |
79 | } | |
80 | } | |
81 | ||
82 | return 0; | |
83 | } | |
84 | ||
85 | int | |
86 | xfs_errortag_add(int error_tag, xfs_mount_t *mp) | |
87 | { | |
88 | int i; | |
89 | int len; | |
90 | int64_t fsid; | |
91 | ||
92 | memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t)); | |
93 | ||
94 | for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) { | |
95 | if (xfs_etest_fsid[i] == fsid && xfs_etest[i] == error_tag) { | |
0b932ccc | 96 | xfs_warn(mp, "error tag #%d on", error_tag); |
1da177e4 LT |
97 | return 0; |
98 | } | |
99 | } | |
100 | ||
101 | for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) { | |
102 | if (xfs_etest[i] == 0) { | |
0b932ccc | 103 | xfs_warn(mp, "Turned on XFS error tag #%d", |
1da177e4 LT |
104 | error_tag); |
105 | xfs_etest[i] = error_tag; | |
106 | xfs_etest_fsid[i] = fsid; | |
107 | len = strlen(mp->m_fsname); | |
108 | xfs_etest_fsname[i] = kmem_alloc(len + 1, KM_SLEEP); | |
109 | strcpy(xfs_etest_fsname[i], mp->m_fsname); | |
c76febef | 110 | xfs_error_test_active++; |
1da177e4 LT |
111 | return 0; |
112 | } | |
113 | } | |
114 | ||
0b932ccc | 115 | xfs_warn(mp, "error tag overflow, too many turned on"); |
1da177e4 LT |
116 | |
117 | return 1; | |
118 | } | |
119 | ||
1da177e4 | 120 | int |
0ce4cfd4 | 121 | xfs_errortag_clearall(xfs_mount_t *mp, int loud) |
1da177e4 | 122 | { |
0ce4cfd4 | 123 | int64_t fsid; |
1da177e4 | 124 | int cleared = 0; |
0ce4cfd4 CH |
125 | int i; |
126 | ||
127 | memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t)); | |
128 | ||
1da177e4 LT |
129 | |
130 | for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) { | |
131 | if ((fsid == 0LL || xfs_etest_fsid[i] == fsid) && | |
132 | xfs_etest[i] != 0) { | |
133 | cleared = 1; | |
0b932ccc | 134 | xfs_warn(mp, "Clearing XFS error tag #%d", |
1da177e4 LT |
135 | xfs_etest[i]); |
136 | xfs_etest[i] = 0; | |
137 | xfs_etest_fsid[i] = 0LL; | |
f0e2d93c | 138 | kmem_free(xfs_etest_fsname[i]); |
1da177e4 | 139 | xfs_etest_fsname[i] = NULL; |
c76febef | 140 | xfs_error_test_active--; |
1da177e4 LT |
141 | } |
142 | } | |
143 | ||
144 | if (loud || cleared) | |
0b932ccc | 145 | xfs_warn(mp, "Cleared all XFS error tags for filesystem"); |
1da177e4 LT |
146 | |
147 | return 0; | |
148 | } | |
1550d0b0 | 149 | #endif /* DEBUG */ |
1da177e4 | 150 | |
1da177e4 LT |
151 | void |
152 | xfs_error_report( | |
a0e856b0 AE |
153 | const char *tag, |
154 | int level, | |
155 | struct xfs_mount *mp, | |
156 | const char *filename, | |
157 | int linenum, | |
158 | inst_t *ra) | |
1da177e4 LT |
159 | { |
160 | if (level <= xfs_error_level) { | |
6a19d939 | 161 | xfs_alert_tag(mp, XFS_PTAG_ERROR_REPORT, |
08e96e1a | 162 | "Internal error %s at line %d of file %s. Caller 0x%p", |
a0e856b0 | 163 | tag, linenum, filename, ra); |
1da177e4 LT |
164 | |
165 | xfs_stack_trace(); | |
166 | } | |
167 | } | |
168 | ||
1da177e4 LT |
169 | void |
170 | xfs_corruption_error( | |
a0e856b0 AE |
171 | const char *tag, |
172 | int level, | |
173 | struct xfs_mount *mp, | |
174 | void *p, | |
175 | const char *filename, | |
176 | int linenum, | |
177 | inst_t *ra) | |
1da177e4 LT |
178 | { |
179 | if (level <= xfs_error_level) | |
a2050646 | 180 | xfs_hex_dump(p, 64); |
a0e856b0 | 181 | xfs_error_report(tag, level, mp, filename, linenum, ra); |
65333b4c | 182 | xfs_alert(mp, "Corruption detected. Unmount and run xfs_repair"); |
1da177e4 | 183 | } |