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