Loading...
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6#include "xfs.h"
7#include "xfs_shared.h"
8#include "xfs_format.h"
9#include "xfs_fs.h"
10#include "xfs_log_format.h"
11#include "xfs_trans_resv.h"
12#include "xfs_mount.h"
13#include "xfs_errortag.h"
14#include "xfs_error.h"
15#include "xfs_sysfs.h"
16#include "xfs_inode.h"
17
18#ifdef DEBUG
19
20static unsigned int xfs_errortag_random_default[] = {
21 XFS_RANDOM_DEFAULT,
22 XFS_RANDOM_IFLUSH_1,
23 XFS_RANDOM_IFLUSH_2,
24 XFS_RANDOM_IFLUSH_3,
25 XFS_RANDOM_IFLUSH_4,
26 XFS_RANDOM_IFLUSH_5,
27 XFS_RANDOM_IFLUSH_6,
28 XFS_RANDOM_DA_READ_BUF,
29 XFS_RANDOM_BTREE_CHECK_LBLOCK,
30 XFS_RANDOM_BTREE_CHECK_SBLOCK,
31 XFS_RANDOM_ALLOC_READ_AGF,
32 XFS_RANDOM_IALLOC_READ_AGI,
33 XFS_RANDOM_ITOBP_INOTOBP,
34 XFS_RANDOM_IUNLINK,
35 XFS_RANDOM_IUNLINK_REMOVE,
36 XFS_RANDOM_DIR_INO_VALIDATE,
37 XFS_RANDOM_BULKSTAT_READ_CHUNK,
38 XFS_RANDOM_IODONE_IOERR,
39 XFS_RANDOM_STRATREAD_IOERR,
40 XFS_RANDOM_STRATCMPL_IOERR,
41 XFS_RANDOM_DIOWRITE_IOERR,
42 XFS_RANDOM_BMAPIFORMAT,
43 XFS_RANDOM_FREE_EXTENT,
44 XFS_RANDOM_RMAP_FINISH_ONE,
45 XFS_RANDOM_REFCOUNT_CONTINUE_UPDATE,
46 XFS_RANDOM_REFCOUNT_FINISH_ONE,
47 XFS_RANDOM_BMAP_FINISH_ONE,
48 XFS_RANDOM_AG_RESV_CRITICAL,
49 XFS_RANDOM_DROP_WRITES,
50 XFS_RANDOM_LOG_BAD_CRC,
51 XFS_RANDOM_LOG_ITEM_PIN,
52 XFS_RANDOM_BUF_LRU_REF,
53 XFS_RANDOM_FORCE_SCRUB_REPAIR,
54 XFS_RANDOM_FORCE_SUMMARY_RECALC,
55 XFS_RANDOM_IUNLINK_FALLBACK,
56 XFS_RANDOM_BUF_IOERROR,
57};
58
59struct xfs_errortag_attr {
60 struct attribute attr;
61 unsigned int tag;
62};
63
64static inline struct xfs_errortag_attr *
65to_attr(struct attribute *attr)
66{
67 return container_of(attr, struct xfs_errortag_attr, attr);
68}
69
70static inline struct xfs_mount *
71to_mp(struct kobject *kobject)
72{
73 struct xfs_kobj *kobj = to_kobj(kobject);
74
75 return container_of(kobj, struct xfs_mount, m_errortag_kobj);
76}
77
78STATIC ssize_t
79xfs_errortag_attr_store(
80 struct kobject *kobject,
81 struct attribute *attr,
82 const char *buf,
83 size_t count)
84{
85 struct xfs_mount *mp = to_mp(kobject);
86 struct xfs_errortag_attr *xfs_attr = to_attr(attr);
87 int ret;
88 unsigned int val;
89
90 if (strcmp(buf, "default") == 0) {
91 val = xfs_errortag_random_default[xfs_attr->tag];
92 } else {
93 ret = kstrtouint(buf, 0, &val);
94 if (ret)
95 return ret;
96 }
97
98 ret = xfs_errortag_set(mp, xfs_attr->tag, val);
99 if (ret)
100 return ret;
101 return count;
102}
103
104STATIC ssize_t
105xfs_errortag_attr_show(
106 struct kobject *kobject,
107 struct attribute *attr,
108 char *buf)
109{
110 struct xfs_mount *mp = to_mp(kobject);
111 struct xfs_errortag_attr *xfs_attr = to_attr(attr);
112
113 return snprintf(buf, PAGE_SIZE, "%u\n",
114 xfs_errortag_get(mp, xfs_attr->tag));
115}
116
117static const struct sysfs_ops xfs_errortag_sysfs_ops = {
118 .show = xfs_errortag_attr_show,
119 .store = xfs_errortag_attr_store,
120};
121
122#define XFS_ERRORTAG_ATTR_RW(_name, _tag) \
123static struct xfs_errortag_attr xfs_errortag_attr_##_name = { \
124 .attr = {.name = __stringify(_name), \
125 .mode = VERIFY_OCTAL_PERMISSIONS(S_IWUSR | S_IRUGO) }, \
126 .tag = (_tag), \
127}
128
129#define XFS_ERRORTAG_ATTR_LIST(_name) &xfs_errortag_attr_##_name.attr
130
131XFS_ERRORTAG_ATTR_RW(noerror, XFS_ERRTAG_NOERROR);
132XFS_ERRORTAG_ATTR_RW(iflush1, XFS_ERRTAG_IFLUSH_1);
133XFS_ERRORTAG_ATTR_RW(iflush2, XFS_ERRTAG_IFLUSH_2);
134XFS_ERRORTAG_ATTR_RW(iflush3, XFS_ERRTAG_IFLUSH_3);
135XFS_ERRORTAG_ATTR_RW(iflush4, XFS_ERRTAG_IFLUSH_4);
136XFS_ERRORTAG_ATTR_RW(iflush5, XFS_ERRTAG_IFLUSH_5);
137XFS_ERRORTAG_ATTR_RW(iflush6, XFS_ERRTAG_IFLUSH_6);
138XFS_ERRORTAG_ATTR_RW(dareadbuf, XFS_ERRTAG_DA_READ_BUF);
139XFS_ERRORTAG_ATTR_RW(btree_chk_lblk, XFS_ERRTAG_BTREE_CHECK_LBLOCK);
140XFS_ERRORTAG_ATTR_RW(btree_chk_sblk, XFS_ERRTAG_BTREE_CHECK_SBLOCK);
141XFS_ERRORTAG_ATTR_RW(readagf, XFS_ERRTAG_ALLOC_READ_AGF);
142XFS_ERRORTAG_ATTR_RW(readagi, XFS_ERRTAG_IALLOC_READ_AGI);
143XFS_ERRORTAG_ATTR_RW(itobp, XFS_ERRTAG_ITOBP_INOTOBP);
144XFS_ERRORTAG_ATTR_RW(iunlink, XFS_ERRTAG_IUNLINK);
145XFS_ERRORTAG_ATTR_RW(iunlinkrm, XFS_ERRTAG_IUNLINK_REMOVE);
146XFS_ERRORTAG_ATTR_RW(dirinovalid, XFS_ERRTAG_DIR_INO_VALIDATE);
147XFS_ERRORTAG_ATTR_RW(bulkstat, XFS_ERRTAG_BULKSTAT_READ_CHUNK);
148XFS_ERRORTAG_ATTR_RW(logiodone, XFS_ERRTAG_IODONE_IOERR);
149XFS_ERRORTAG_ATTR_RW(stratread, XFS_ERRTAG_STRATREAD_IOERR);
150XFS_ERRORTAG_ATTR_RW(stratcmpl, XFS_ERRTAG_STRATCMPL_IOERR);
151XFS_ERRORTAG_ATTR_RW(diowrite, XFS_ERRTAG_DIOWRITE_IOERR);
152XFS_ERRORTAG_ATTR_RW(bmapifmt, XFS_ERRTAG_BMAPIFORMAT);
153XFS_ERRORTAG_ATTR_RW(free_extent, XFS_ERRTAG_FREE_EXTENT);
154XFS_ERRORTAG_ATTR_RW(rmap_finish_one, XFS_ERRTAG_RMAP_FINISH_ONE);
155XFS_ERRORTAG_ATTR_RW(refcount_continue_update, XFS_ERRTAG_REFCOUNT_CONTINUE_UPDATE);
156XFS_ERRORTAG_ATTR_RW(refcount_finish_one, XFS_ERRTAG_REFCOUNT_FINISH_ONE);
157XFS_ERRORTAG_ATTR_RW(bmap_finish_one, XFS_ERRTAG_BMAP_FINISH_ONE);
158XFS_ERRORTAG_ATTR_RW(ag_resv_critical, XFS_ERRTAG_AG_RESV_CRITICAL);
159XFS_ERRORTAG_ATTR_RW(drop_writes, XFS_ERRTAG_DROP_WRITES);
160XFS_ERRORTAG_ATTR_RW(log_bad_crc, XFS_ERRTAG_LOG_BAD_CRC);
161XFS_ERRORTAG_ATTR_RW(log_item_pin, XFS_ERRTAG_LOG_ITEM_PIN);
162XFS_ERRORTAG_ATTR_RW(buf_lru_ref, XFS_ERRTAG_BUF_LRU_REF);
163XFS_ERRORTAG_ATTR_RW(force_repair, XFS_ERRTAG_FORCE_SCRUB_REPAIR);
164XFS_ERRORTAG_ATTR_RW(bad_summary, XFS_ERRTAG_FORCE_SUMMARY_RECALC);
165XFS_ERRORTAG_ATTR_RW(iunlink_fallback, XFS_ERRTAG_IUNLINK_FALLBACK);
166XFS_ERRORTAG_ATTR_RW(buf_ioerror, XFS_ERRTAG_BUF_IOERROR);
167
168static struct attribute *xfs_errortag_attrs[] = {
169 XFS_ERRORTAG_ATTR_LIST(noerror),
170 XFS_ERRORTAG_ATTR_LIST(iflush1),
171 XFS_ERRORTAG_ATTR_LIST(iflush2),
172 XFS_ERRORTAG_ATTR_LIST(iflush3),
173 XFS_ERRORTAG_ATTR_LIST(iflush4),
174 XFS_ERRORTAG_ATTR_LIST(iflush5),
175 XFS_ERRORTAG_ATTR_LIST(iflush6),
176 XFS_ERRORTAG_ATTR_LIST(dareadbuf),
177 XFS_ERRORTAG_ATTR_LIST(btree_chk_lblk),
178 XFS_ERRORTAG_ATTR_LIST(btree_chk_sblk),
179 XFS_ERRORTAG_ATTR_LIST(readagf),
180 XFS_ERRORTAG_ATTR_LIST(readagi),
181 XFS_ERRORTAG_ATTR_LIST(itobp),
182 XFS_ERRORTAG_ATTR_LIST(iunlink),
183 XFS_ERRORTAG_ATTR_LIST(iunlinkrm),
184 XFS_ERRORTAG_ATTR_LIST(dirinovalid),
185 XFS_ERRORTAG_ATTR_LIST(bulkstat),
186 XFS_ERRORTAG_ATTR_LIST(logiodone),
187 XFS_ERRORTAG_ATTR_LIST(stratread),
188 XFS_ERRORTAG_ATTR_LIST(stratcmpl),
189 XFS_ERRORTAG_ATTR_LIST(diowrite),
190 XFS_ERRORTAG_ATTR_LIST(bmapifmt),
191 XFS_ERRORTAG_ATTR_LIST(free_extent),
192 XFS_ERRORTAG_ATTR_LIST(rmap_finish_one),
193 XFS_ERRORTAG_ATTR_LIST(refcount_continue_update),
194 XFS_ERRORTAG_ATTR_LIST(refcount_finish_one),
195 XFS_ERRORTAG_ATTR_LIST(bmap_finish_one),
196 XFS_ERRORTAG_ATTR_LIST(ag_resv_critical),
197 XFS_ERRORTAG_ATTR_LIST(drop_writes),
198 XFS_ERRORTAG_ATTR_LIST(log_bad_crc),
199 XFS_ERRORTAG_ATTR_LIST(log_item_pin),
200 XFS_ERRORTAG_ATTR_LIST(buf_lru_ref),
201 XFS_ERRORTAG_ATTR_LIST(force_repair),
202 XFS_ERRORTAG_ATTR_LIST(bad_summary),
203 XFS_ERRORTAG_ATTR_LIST(iunlink_fallback),
204 XFS_ERRORTAG_ATTR_LIST(buf_ioerror),
205 NULL,
206};
207
208static struct kobj_type xfs_errortag_ktype = {
209 .release = xfs_sysfs_release,
210 .sysfs_ops = &xfs_errortag_sysfs_ops,
211 .default_attrs = xfs_errortag_attrs,
212};
213
214int
215xfs_errortag_init(
216 struct xfs_mount *mp)
217{
218 mp->m_errortag = kmem_zalloc(sizeof(unsigned int) * XFS_ERRTAG_MAX,
219 KM_MAYFAIL);
220 if (!mp->m_errortag)
221 return -ENOMEM;
222
223 return xfs_sysfs_init(&mp->m_errortag_kobj, &xfs_errortag_ktype,
224 &mp->m_kobj, "errortag");
225}
226
227void
228xfs_errortag_del(
229 struct xfs_mount *mp)
230{
231 xfs_sysfs_del(&mp->m_errortag_kobj);
232 kmem_free(mp->m_errortag);
233}
234
235bool
236xfs_errortag_test(
237 struct xfs_mount *mp,
238 const char *expression,
239 const char *file,
240 int line,
241 unsigned int error_tag)
242{
243 unsigned int randfactor;
244
245 /*
246 * To be able to use error injection anywhere, we need to ensure error
247 * injection mechanism is already initialized.
248 *
249 * Code paths like I/O completion can be called before the
250 * initialization is complete, but be able to inject errors in such
251 * places is still useful.
252 */
253 if (!mp->m_errortag)
254 return false;
255
256 ASSERT(error_tag < XFS_ERRTAG_MAX);
257 randfactor = mp->m_errortag[error_tag];
258 if (!randfactor || prandom_u32() % randfactor)
259 return false;
260
261 xfs_warn_ratelimited(mp,
262"Injecting error (%s) at file %s, line %d, on filesystem \"%s\"",
263 expression, file, line, mp->m_super->s_id);
264 return true;
265}
266
267int
268xfs_errortag_get(
269 struct xfs_mount *mp,
270 unsigned int error_tag)
271{
272 if (error_tag >= XFS_ERRTAG_MAX)
273 return -EINVAL;
274
275 return mp->m_errortag[error_tag];
276}
277
278int
279xfs_errortag_set(
280 struct xfs_mount *mp,
281 unsigned int error_tag,
282 unsigned int tag_value)
283{
284 if (error_tag >= XFS_ERRTAG_MAX)
285 return -EINVAL;
286
287 mp->m_errortag[error_tag] = tag_value;
288 return 0;
289}
290
291int
292xfs_errortag_add(
293 struct xfs_mount *mp,
294 unsigned int error_tag)
295{
296 if (error_tag >= XFS_ERRTAG_MAX)
297 return -EINVAL;
298
299 return xfs_errortag_set(mp, error_tag,
300 xfs_errortag_random_default[error_tag]);
301}
302
303int
304xfs_errortag_clearall(
305 struct xfs_mount *mp)
306{
307 memset(mp->m_errortag, 0, sizeof(unsigned int) * XFS_ERRTAG_MAX);
308 return 0;
309}
310#endif /* DEBUG */
311
312void
313xfs_error_report(
314 const char *tag,
315 int level,
316 struct xfs_mount *mp,
317 const char *filename,
318 int linenum,
319 xfs_failaddr_t failaddr)
320{
321 if (level <= xfs_error_level) {
322 xfs_alert_tag(mp, XFS_PTAG_ERROR_REPORT,
323 "Internal error %s at line %d of file %s. Caller %pS",
324 tag, linenum, filename, failaddr);
325
326 xfs_stack_trace();
327 }
328}
329
330void
331xfs_corruption_error(
332 const char *tag,
333 int level,
334 struct xfs_mount *mp,
335 const void *buf,
336 size_t bufsize,
337 const char *filename,
338 int linenum,
339 xfs_failaddr_t failaddr)
340{
341 if (buf && level <= xfs_error_level)
342 xfs_hex_dump(buf, bufsize);
343 xfs_error_report(tag, level, mp, filename, linenum, failaddr);
344 xfs_alert(mp, "Corruption detected. Unmount and run xfs_repair");
345}
346
347/*
348 * Complain about the kinds of metadata corruption that we can't detect from a
349 * verifier, such as incorrect inter-block relationship data. Does not set
350 * bp->b_error.
351 *
352 * Call xfs_buf_mark_corrupt, not this function.
353 */
354void
355xfs_buf_corruption_error(
356 struct xfs_buf *bp,
357 xfs_failaddr_t fa)
358{
359 struct xfs_mount *mp = bp->b_mount;
360
361 xfs_alert_tag(mp, XFS_PTAG_VERIFIER_ERROR,
362 "Metadata corruption detected at %pS, %s block 0x%llx",
363 fa, bp->b_ops->name, bp->b_bn);
364
365 xfs_alert(mp, "Unmount and run xfs_repair");
366
367 if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
368 xfs_stack_trace();
369}
370
371/*
372 * Warnings specifically for verifier errors. Differentiate CRC vs. invalid
373 * values, and omit the stack trace unless the error level is tuned high.
374 */
375void
376xfs_buf_verifier_error(
377 struct xfs_buf *bp,
378 int error,
379 const char *name,
380 const void *buf,
381 size_t bufsz,
382 xfs_failaddr_t failaddr)
383{
384 struct xfs_mount *mp = bp->b_mount;
385 xfs_failaddr_t fa;
386 int sz;
387
388 fa = failaddr ? failaddr : __return_address;
389 __xfs_buf_ioerror(bp, error, fa);
390
391 xfs_alert_tag(mp, XFS_PTAG_VERIFIER_ERROR,
392 "Metadata %s detected at %pS, %s block 0x%llx %s",
393 bp->b_error == -EFSBADCRC ? "CRC error" : "corruption",
394 fa, bp->b_ops->name, bp->b_bn, name);
395
396 xfs_alert(mp, "Unmount and run xfs_repair");
397
398 if (xfs_error_level >= XFS_ERRLEVEL_LOW) {
399 sz = min_t(size_t, XFS_CORRUPTION_DUMP_LEN, bufsz);
400 xfs_alert(mp, "First %d bytes of corrupted metadata buffer:",
401 sz);
402 xfs_hex_dump(buf, sz);
403 }
404
405 if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
406 xfs_stack_trace();
407}
408
409/*
410 * Warnings specifically for verifier errors. Differentiate CRC vs. invalid
411 * values, and omit the stack trace unless the error level is tuned high.
412 */
413void
414xfs_verifier_error(
415 struct xfs_buf *bp,
416 int error,
417 xfs_failaddr_t failaddr)
418{
419 return xfs_buf_verifier_error(bp, error, "", xfs_buf_offset(bp, 0),
420 XFS_CORRUPTION_DUMP_LEN, failaddr);
421}
422
423/*
424 * Warnings for inode corruption problems. Don't bother with the stack
425 * trace unless the error level is turned up high.
426 */
427void
428xfs_inode_verifier_error(
429 struct xfs_inode *ip,
430 int error,
431 const char *name,
432 const void *buf,
433 size_t bufsz,
434 xfs_failaddr_t failaddr)
435{
436 struct xfs_mount *mp = ip->i_mount;
437 xfs_failaddr_t fa;
438 int sz;
439
440 fa = failaddr ? failaddr : __return_address;
441
442 xfs_alert(mp, "Metadata %s detected at %pS, inode 0x%llx %s",
443 error == -EFSBADCRC ? "CRC error" : "corruption",
444 fa, ip->i_ino, name);
445
446 xfs_alert(mp, "Unmount and run xfs_repair");
447
448 if (buf && xfs_error_level >= XFS_ERRLEVEL_LOW) {
449 sz = min_t(size_t, XFS_CORRUPTION_DUMP_LEN, bufsz);
450 xfs_alert(mp, "First %d bytes of corrupted metadata buffer:",
451 sz);
452 xfs_hex_dump(buf, sz);
453 }
454
455 if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
456 xfs_stack_trace();
457}
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_format.h"
20#include "xfs_fs.h"
21#include "xfs_log_format.h"
22#include "xfs_trans_resv.h"
23#include "xfs_mount.h"
24#include "xfs_error.h"
25
26#ifdef DEBUG
27
28int xfs_etest[XFS_NUM_INJECT_ERROR];
29int64_t xfs_etest_fsid[XFS_NUM_INJECT_ERROR];
30char * xfs_etest_fsname[XFS_NUM_INJECT_ERROR];
31int xfs_error_test_active;
32
33int
34xfs_error_test(int error_tag, int *fsidp, char *expression,
35 int line, char *file, unsigned long randfactor)
36{
37 int i;
38 int64_t fsid;
39
40 if (prandom_u32() % randfactor)
41 return 0;
42
43 memcpy(&fsid, fsidp, sizeof(xfs_fsid_t));
44
45 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
46 if (xfs_etest[i] == error_tag && xfs_etest_fsid[i] == fsid) {
47 xfs_warn(NULL,
48 "Injecting error (%s) at file %s, line %d, on filesystem \"%s\"",
49 expression, file, line, xfs_etest_fsname[i]);
50 return 1;
51 }
52 }
53
54 return 0;
55}
56
57int
58xfs_errortag_add(unsigned int error_tag, xfs_mount_t *mp)
59{
60 int i;
61 int len;
62 int64_t fsid;
63
64 if (error_tag >= XFS_ERRTAG_MAX)
65 return -EINVAL;
66
67 memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
68
69 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
70 if (xfs_etest_fsid[i] == fsid && xfs_etest[i] == error_tag) {
71 xfs_warn(mp, "error tag #%d on", error_tag);
72 return 0;
73 }
74 }
75
76 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
77 if (xfs_etest[i] == 0) {
78 xfs_warn(mp, "Turned on XFS error tag #%d",
79 error_tag);
80 xfs_etest[i] = error_tag;
81 xfs_etest_fsid[i] = fsid;
82 len = strlen(mp->m_fsname);
83 xfs_etest_fsname[i] = kmem_alloc(len + 1, KM_SLEEP);
84 strcpy(xfs_etest_fsname[i], mp->m_fsname);
85 xfs_error_test_active++;
86 return 0;
87 }
88 }
89
90 xfs_warn(mp, "error tag overflow, too many turned on");
91
92 return 1;
93}
94
95int
96xfs_errortag_clearall(xfs_mount_t *mp, int loud)
97{
98 int64_t fsid;
99 int cleared = 0;
100 int i;
101
102 memcpy(&fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t));
103
104
105 for (i = 0; i < XFS_NUM_INJECT_ERROR; i++) {
106 if ((fsid == 0LL || xfs_etest_fsid[i] == fsid) &&
107 xfs_etest[i] != 0) {
108 cleared = 1;
109 xfs_warn(mp, "Clearing XFS error tag #%d",
110 xfs_etest[i]);
111 xfs_etest[i] = 0;
112 xfs_etest_fsid[i] = 0LL;
113 kmem_free(xfs_etest_fsname[i]);
114 xfs_etest_fsname[i] = NULL;
115 xfs_error_test_active--;
116 }
117 }
118
119 if (loud || cleared)
120 xfs_warn(mp, "Cleared all XFS error tags for filesystem");
121
122 return 0;
123}
124#endif /* DEBUG */
125
126void
127xfs_error_report(
128 const char *tag,
129 int level,
130 struct xfs_mount *mp,
131 const char *filename,
132 int linenum,
133 void *ra)
134{
135 if (level <= xfs_error_level) {
136 xfs_alert_tag(mp, XFS_PTAG_ERROR_REPORT,
137 "Internal error %s at line %d of file %s. Caller %pS",
138 tag, linenum, filename, ra);
139
140 xfs_stack_trace();
141 }
142}
143
144void
145xfs_corruption_error(
146 const char *tag,
147 int level,
148 struct xfs_mount *mp,
149 void *p,
150 const char *filename,
151 int linenum,
152 void *ra)
153{
154 if (level <= xfs_error_level)
155 xfs_hex_dump(p, 64);
156 xfs_error_report(tag, level, mp, filename, linenum, ra);
157 xfs_alert(mp, "Corruption detected. Unmount and run xfs_repair");
158}
159
160/*
161 * Warnings specifically for verifier errors. Differentiate CRC vs. invalid
162 * values, and omit the stack trace unless the error level is tuned high.
163 */
164void
165xfs_verifier_error(
166 struct xfs_buf *bp)
167{
168 struct xfs_mount *mp = bp->b_target->bt_mount;
169
170 xfs_alert(mp, "Metadata %s detected at %pF, %s block 0x%llx",
171 bp->b_error == -EFSBADCRC ? "CRC error" : "corruption",
172 __return_address, bp->b_ops->name, bp->b_bn);
173
174 xfs_alert(mp, "Unmount and run xfs_repair");
175
176 if (xfs_error_level >= XFS_ERRLEVEL_LOW) {
177 xfs_alert(mp, "First 64 bytes of corrupted metadata buffer:");
178 xfs_hex_dump(xfs_buf_offset(bp, 0), 64);
179 }
180
181 if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
182 xfs_stack_trace();
183}