blob: a1e177f66404d28184fd99a5711d2c6f0b5005c2 [file] [log] [blame]
Dave Chinner0b61f8a2018-06-05 19:42:14 -07001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Nathan Scott7b718762005-11-02 14:58:39 +11003 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include "xfs.h"
Dave Chinnera4fbe6a2013-10-23 10:51:50 +11007#include "xfs_format.h"
Nathan Scotta844f452005-11-02 14:38:42 +11008#include "xfs_fs.h"
Dave Chinner239880e2013-10-23 10:50:10 +11009#include "xfs_log_format.h"
10#include "xfs_trans_resv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include "xfs_mount.h"
Darrick J. Wonge9e899a2017-10-31 12:04:49 -070012#include "xfs_errortag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "xfs_error.h"
Darrick J. Wongc6840102017-06-20 17:54:47 -070014#include "xfs_sysfs.h"
Darrick J. Wong22431bf2018-01-22 18:09:48 -080015#include "xfs_inode.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#ifdef DEBUG
18
Darrick J. Wong31965ef2017-06-20 17:54:46 -070019static unsigned int xfs_errortag_random_default[] = {
20 XFS_RANDOM_DEFAULT,
21 XFS_RANDOM_IFLUSH_1,
22 XFS_RANDOM_IFLUSH_2,
23 XFS_RANDOM_IFLUSH_3,
24 XFS_RANDOM_IFLUSH_4,
25 XFS_RANDOM_IFLUSH_5,
26 XFS_RANDOM_IFLUSH_6,
27 XFS_RANDOM_DA_READ_BUF,
28 XFS_RANDOM_BTREE_CHECK_LBLOCK,
29 XFS_RANDOM_BTREE_CHECK_SBLOCK,
30 XFS_RANDOM_ALLOC_READ_AGF,
31 XFS_RANDOM_IALLOC_READ_AGI,
32 XFS_RANDOM_ITOBP_INOTOBP,
33 XFS_RANDOM_IUNLINK,
34 XFS_RANDOM_IUNLINK_REMOVE,
35 XFS_RANDOM_DIR_INO_VALIDATE,
36 XFS_RANDOM_BULKSTAT_READ_CHUNK,
37 XFS_RANDOM_IODONE_IOERR,
38 XFS_RANDOM_STRATREAD_IOERR,
39 XFS_RANDOM_STRATCMPL_IOERR,
40 XFS_RANDOM_DIOWRITE_IOERR,
41 XFS_RANDOM_BMAPIFORMAT,
42 XFS_RANDOM_FREE_EXTENT,
43 XFS_RANDOM_RMAP_FINISH_ONE,
44 XFS_RANDOM_REFCOUNT_CONTINUE_UPDATE,
45 XFS_RANDOM_REFCOUNT_FINISH_ONE,
46 XFS_RANDOM_BMAP_FINISH_ONE,
47 XFS_RANDOM_AG_RESV_CRITICAL,
Darrick J. Wongf8c47252017-06-20 17:54:48 -070048 XFS_RANDOM_DROP_WRITES,
Brian Foster3e88a002017-06-27 09:52:32 -070049 XFS_RANDOM_LOG_BAD_CRC,
Brian Foster7f4d01f2017-08-08 18:21:52 -070050 XFS_RANDOM_LOG_ITEM_PIN,
Brian Foster7561d272017-10-17 14:16:29 -070051 XFS_RANDOM_BUF_LRU_REF,
Darrick J. Wong84d42ea2018-05-14 06:34:36 -070052 XFS_RANDOM_FORCE_SCRUB_REPAIR,
Darrick J. Wongf467cad2018-07-20 09:28:40 -070053 XFS_RANDOM_FORCE_SUMMARY_RECALC,
Darrick J. Wong9b247172019-02-07 10:37:16 -080054 XFS_RANDOM_IUNLINK_FALLBACK,
Darrick J. Wong31965ef2017-06-20 17:54:46 -070055};
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Darrick J. Wongc6840102017-06-20 17:54:47 -070057struct xfs_errortag_attr {
58 struct attribute attr;
59 unsigned int tag;
60};
61
62static inline struct xfs_errortag_attr *
63to_attr(struct attribute *attr)
64{
65 return container_of(attr, struct xfs_errortag_attr, attr);
66}
67
68static inline struct xfs_mount *
69to_mp(struct kobject *kobject)
70{
71 struct xfs_kobj *kobj = to_kobj(kobject);
72
73 return container_of(kobj, struct xfs_mount, m_errortag_kobj);
74}
75
76STATIC ssize_t
77xfs_errortag_attr_store(
78 struct kobject *kobject,
79 struct attribute *attr,
80 const char *buf,
81 size_t count)
82{
83 struct xfs_mount *mp = to_mp(kobject);
84 struct xfs_errortag_attr *xfs_attr = to_attr(attr);
85 int ret;
86 unsigned int val;
87
88 if (strcmp(buf, "default") == 0) {
89 val = xfs_errortag_random_default[xfs_attr->tag];
90 } else {
91 ret = kstrtouint(buf, 0, &val);
92 if (ret)
93 return ret;
94 }
95
96 ret = xfs_errortag_set(mp, xfs_attr->tag, val);
97 if (ret)
98 return ret;
99 return count;
100}
101
102STATIC ssize_t
103xfs_errortag_attr_show(
104 struct kobject *kobject,
105 struct attribute *attr,
106 char *buf)
107{
108 struct xfs_mount *mp = to_mp(kobject);
109 struct xfs_errortag_attr *xfs_attr = to_attr(attr);
110
111 return snprintf(buf, PAGE_SIZE, "%u\n",
112 xfs_errortag_get(mp, xfs_attr->tag));
113}
114
115static const struct sysfs_ops xfs_errortag_sysfs_ops = {
116 .show = xfs_errortag_attr_show,
117 .store = xfs_errortag_attr_store,
118};
119
120#define XFS_ERRORTAG_ATTR_RW(_name, _tag) \
121static struct xfs_errortag_attr xfs_errortag_attr_##_name = { \
122 .attr = {.name = __stringify(_name), \
123 .mode = VERIFY_OCTAL_PERMISSIONS(S_IWUSR | S_IRUGO) }, \
124 .tag = (_tag), \
125}
126
127#define XFS_ERRORTAG_ATTR_LIST(_name) &xfs_errortag_attr_##_name.attr
128
129XFS_ERRORTAG_ATTR_RW(noerror, XFS_ERRTAG_NOERROR);
130XFS_ERRORTAG_ATTR_RW(iflush1, XFS_ERRTAG_IFLUSH_1);
131XFS_ERRORTAG_ATTR_RW(iflush2, XFS_ERRTAG_IFLUSH_2);
132XFS_ERRORTAG_ATTR_RW(iflush3, XFS_ERRTAG_IFLUSH_3);
133XFS_ERRORTAG_ATTR_RW(iflush4, XFS_ERRTAG_IFLUSH_4);
134XFS_ERRORTAG_ATTR_RW(iflush5, XFS_ERRTAG_IFLUSH_5);
135XFS_ERRORTAG_ATTR_RW(iflush6, XFS_ERRTAG_IFLUSH_6);
136XFS_ERRORTAG_ATTR_RW(dareadbuf, XFS_ERRTAG_DA_READ_BUF);
137XFS_ERRORTAG_ATTR_RW(btree_chk_lblk, XFS_ERRTAG_BTREE_CHECK_LBLOCK);
138XFS_ERRORTAG_ATTR_RW(btree_chk_sblk, XFS_ERRTAG_BTREE_CHECK_SBLOCK);
139XFS_ERRORTAG_ATTR_RW(readagf, XFS_ERRTAG_ALLOC_READ_AGF);
140XFS_ERRORTAG_ATTR_RW(readagi, XFS_ERRTAG_IALLOC_READ_AGI);
141XFS_ERRORTAG_ATTR_RW(itobp, XFS_ERRTAG_ITOBP_INOTOBP);
142XFS_ERRORTAG_ATTR_RW(iunlink, XFS_ERRTAG_IUNLINK);
143XFS_ERRORTAG_ATTR_RW(iunlinkrm, XFS_ERRTAG_IUNLINK_REMOVE);
144XFS_ERRORTAG_ATTR_RW(dirinovalid, XFS_ERRTAG_DIR_INO_VALIDATE);
145XFS_ERRORTAG_ATTR_RW(bulkstat, XFS_ERRTAG_BULKSTAT_READ_CHUNK);
146XFS_ERRORTAG_ATTR_RW(logiodone, XFS_ERRTAG_IODONE_IOERR);
147XFS_ERRORTAG_ATTR_RW(stratread, XFS_ERRTAG_STRATREAD_IOERR);
148XFS_ERRORTAG_ATTR_RW(stratcmpl, XFS_ERRTAG_STRATCMPL_IOERR);
149XFS_ERRORTAG_ATTR_RW(diowrite, XFS_ERRTAG_DIOWRITE_IOERR);
150XFS_ERRORTAG_ATTR_RW(bmapifmt, XFS_ERRTAG_BMAPIFORMAT);
151XFS_ERRORTAG_ATTR_RW(free_extent, XFS_ERRTAG_FREE_EXTENT);
152XFS_ERRORTAG_ATTR_RW(rmap_finish_one, XFS_ERRTAG_RMAP_FINISH_ONE);
153XFS_ERRORTAG_ATTR_RW(refcount_continue_update, XFS_ERRTAG_REFCOUNT_CONTINUE_UPDATE);
154XFS_ERRORTAG_ATTR_RW(refcount_finish_one, XFS_ERRTAG_REFCOUNT_FINISH_ONE);
155XFS_ERRORTAG_ATTR_RW(bmap_finish_one, XFS_ERRTAG_BMAP_FINISH_ONE);
156XFS_ERRORTAG_ATTR_RW(ag_resv_critical, XFS_ERRTAG_AG_RESV_CRITICAL);
Darrick J. Wongf8c47252017-06-20 17:54:48 -0700157XFS_ERRORTAG_ATTR_RW(drop_writes, XFS_ERRTAG_DROP_WRITES);
Brian Foster3e88a002017-06-27 09:52:32 -0700158XFS_ERRORTAG_ATTR_RW(log_bad_crc, XFS_ERRTAG_LOG_BAD_CRC);
Brian Foster7f4d01f2017-08-08 18:21:52 -0700159XFS_ERRORTAG_ATTR_RW(log_item_pin, XFS_ERRTAG_LOG_ITEM_PIN);
Brian Foster7561d272017-10-17 14:16:29 -0700160XFS_ERRORTAG_ATTR_RW(buf_lru_ref, XFS_ERRTAG_BUF_LRU_REF);
Darrick J. Wong84d42ea2018-05-14 06:34:36 -0700161XFS_ERRORTAG_ATTR_RW(force_repair, XFS_ERRTAG_FORCE_SCRUB_REPAIR);
Darrick J. Wongf467cad2018-07-20 09:28:40 -0700162XFS_ERRORTAG_ATTR_RW(bad_summary, XFS_ERRTAG_FORCE_SUMMARY_RECALC);
Darrick J. Wong9b247172019-02-07 10:37:16 -0800163XFS_ERRORTAG_ATTR_RW(iunlink_fallback, XFS_ERRTAG_IUNLINK_FALLBACK);
Darrick J. Wongc6840102017-06-20 17:54:47 -0700164
165static struct attribute *xfs_errortag_attrs[] = {
166 XFS_ERRORTAG_ATTR_LIST(noerror),
167 XFS_ERRORTAG_ATTR_LIST(iflush1),
168 XFS_ERRORTAG_ATTR_LIST(iflush2),
169 XFS_ERRORTAG_ATTR_LIST(iflush3),
170 XFS_ERRORTAG_ATTR_LIST(iflush4),
171 XFS_ERRORTAG_ATTR_LIST(iflush5),
172 XFS_ERRORTAG_ATTR_LIST(iflush6),
173 XFS_ERRORTAG_ATTR_LIST(dareadbuf),
174 XFS_ERRORTAG_ATTR_LIST(btree_chk_lblk),
175 XFS_ERRORTAG_ATTR_LIST(btree_chk_sblk),
176 XFS_ERRORTAG_ATTR_LIST(readagf),
177 XFS_ERRORTAG_ATTR_LIST(readagi),
178 XFS_ERRORTAG_ATTR_LIST(itobp),
179 XFS_ERRORTAG_ATTR_LIST(iunlink),
180 XFS_ERRORTAG_ATTR_LIST(iunlinkrm),
181 XFS_ERRORTAG_ATTR_LIST(dirinovalid),
182 XFS_ERRORTAG_ATTR_LIST(bulkstat),
183 XFS_ERRORTAG_ATTR_LIST(logiodone),
184 XFS_ERRORTAG_ATTR_LIST(stratread),
185 XFS_ERRORTAG_ATTR_LIST(stratcmpl),
186 XFS_ERRORTAG_ATTR_LIST(diowrite),
187 XFS_ERRORTAG_ATTR_LIST(bmapifmt),
188 XFS_ERRORTAG_ATTR_LIST(free_extent),
189 XFS_ERRORTAG_ATTR_LIST(rmap_finish_one),
190 XFS_ERRORTAG_ATTR_LIST(refcount_continue_update),
191 XFS_ERRORTAG_ATTR_LIST(refcount_finish_one),
192 XFS_ERRORTAG_ATTR_LIST(bmap_finish_one),
193 XFS_ERRORTAG_ATTR_LIST(ag_resv_critical),
Darrick J. Wongf8c47252017-06-20 17:54:48 -0700194 XFS_ERRORTAG_ATTR_LIST(drop_writes),
Brian Foster3e88a002017-06-27 09:52:32 -0700195 XFS_ERRORTAG_ATTR_LIST(log_bad_crc),
Brian Foster7f4d01f2017-08-08 18:21:52 -0700196 XFS_ERRORTAG_ATTR_LIST(log_item_pin),
Brian Foster7561d272017-10-17 14:16:29 -0700197 XFS_ERRORTAG_ATTR_LIST(buf_lru_ref),
Darrick J. Wong84d42ea2018-05-14 06:34:36 -0700198 XFS_ERRORTAG_ATTR_LIST(force_repair),
Darrick J. Wongf467cad2018-07-20 09:28:40 -0700199 XFS_ERRORTAG_ATTR_LIST(bad_summary),
Darrick J. Wong9b247172019-02-07 10:37:16 -0800200 XFS_ERRORTAG_ATTR_LIST(iunlink_fallback),
Darrick J. Wongc6840102017-06-20 17:54:47 -0700201 NULL,
202};
203
Christoph Hellwig43711552017-11-06 11:53:59 -0800204static struct kobj_type xfs_errortag_ktype = {
Darrick J. Wongc6840102017-06-20 17:54:47 -0700205 .release = xfs_sysfs_release,
206 .sysfs_ops = &xfs_errortag_sysfs_ops,
207 .default_attrs = xfs_errortag_attrs,
208};
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210int
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700211xfs_errortag_init(
212 struct xfs_mount *mp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700214 mp->m_errortag = kmem_zalloc(sizeof(unsigned int) * XFS_ERRTAG_MAX,
215 KM_SLEEP | KM_MAYFAIL);
216 if (!mp->m_errortag)
217 return -ENOMEM;
Darrick J. Wongc6840102017-06-20 17:54:47 -0700218
219 return xfs_sysfs_init(&mp->m_errortag_kobj, &xfs_errortag_ktype,
220 &mp->m_kobj, "errortag");
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700221}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700223void
224xfs_errortag_del(
225 struct xfs_mount *mp)
226{
Darrick J. Wongc6840102017-06-20 17:54:47 -0700227 xfs_sysfs_del(&mp->m_errortag_kobj);
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700228 kmem_free(mp->m_errortag);
229}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700231bool
232xfs_errortag_test(
233 struct xfs_mount *mp,
234 const char *expression,
235 const char *file,
236 int line,
237 unsigned int error_tag)
238{
239 unsigned int randfactor;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Carlos Maiolinod04c2412017-06-30 09:46:07 -0700241 /*
242 * To be able to use error injection anywhere, we need to ensure error
243 * injection mechanism is already initialized.
244 *
245 * Code paths like I/O completion can be called before the
246 * initialization is complete, but be able to inject errors in such
247 * places is still useful.
248 */
249 if (!mp->m_errortag)
250 return false;
251
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700252 ASSERT(error_tag < XFS_ERRTAG_MAX);
253 randfactor = mp->m_errortag[error_tag];
254 if (!randfactor || prandom_u32() % randfactor)
255 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700257 xfs_warn_ratelimited(mp,
258"Injecting error (%s) at file %s, line %d, on filesystem \"%s\"",
259 expression, file, line, mp->m_fsname);
260 return true;
261}
262
263int
Darrick J. Wongc6840102017-06-20 17:54:47 -0700264xfs_errortag_get(
265 struct xfs_mount *mp,
266 unsigned int error_tag)
267{
268 if (error_tag >= XFS_ERRTAG_MAX)
269 return -EINVAL;
270
271 return mp->m_errortag[error_tag];
272}
273
274int
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700275xfs_errortag_set(
276 struct xfs_mount *mp,
277 unsigned int error_tag,
278 unsigned int tag_value)
279{
280 if (error_tag >= XFS_ERRTAG_MAX)
281 return -EINVAL;
282
283 mp->m_errortag[error_tag] = tag_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 return 0;
285}
286
287int
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700288xfs_errortag_add(
289 struct xfs_mount *mp,
290 unsigned int error_tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
Darrick J. Wong128f24d2016-06-21 11:53:28 +1000292 if (error_tag >= XFS_ERRTAG_MAX)
293 return -EINVAL;
294
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700295 return xfs_errortag_set(mp, error_tag,
296 xfs_errortag_random_default[error_tag]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297}
298
299int
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700300xfs_errortag_clearall(
301 struct xfs_mount *mp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700303 memset(mp->m_errortag, 0, sizeof(unsigned int) * XFS_ERRTAG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 return 0;
305}
Christoph Hellwig1550d0b2008-08-13 16:17:37 +1000306#endif /* DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308void
309xfs_error_report(
Alex Eldera0e856b2010-04-13 15:22:08 +1000310 const char *tag,
311 int level,
312 struct xfs_mount *mp,
313 const char *filename,
314 int linenum,
Darrick J. Wongd9418ed2018-01-08 10:51:25 -0800315 xfs_failaddr_t failaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
317 if (level <= xfs_error_level) {
Dave Chinner6a19d932011-03-07 10:02:35 +1100318 xfs_alert_tag(mp, XFS_PTAG_ERROR_REPORT,
Scott Wood65dd2972015-03-25 14:56:21 +1100319 "Internal error %s at line %d of file %s. Caller %pS",
Darrick J. Wongd9418ed2018-01-08 10:51:25 -0800320 tag, linenum, filename, failaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 xfs_stack_trace();
323 }
324}
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326void
327xfs_corruption_error(
Alex Eldera0e856b2010-04-13 15:22:08 +1000328 const char *tag,
329 int level,
330 struct xfs_mount *mp,
Darrick J. Wong2551a532018-06-04 10:23:54 -0700331 void *buf,
332 size_t bufsize,
Alex Eldera0e856b2010-04-13 15:22:08 +1000333 const char *filename,
334 int linenum,
Darrick J. Wongd9418ed2018-01-08 10:51:25 -0800335 xfs_failaddr_t failaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336{
337 if (level <= xfs_error_level)
Darrick J. Wong2551a532018-06-04 10:23:54 -0700338 xfs_hex_dump(buf, bufsize);
Darrick J. Wongd9418ed2018-01-08 10:51:25 -0800339 xfs_error_report(tag, level, mp, filename, linenum, failaddr);
Dave Chinner65333b42011-03-07 10:03:35 +1100340 xfs_alert(mp, "Corruption detected. Unmount and run xfs_repair");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341}
Eric Sandeenca23f8f2014-02-27 15:21:07 +1100342
343/*
344 * Warnings specifically for verifier errors. Differentiate CRC vs. invalid
345 * values, and omit the stack trace unless the error level is tuned high.
346 */
347void
Darrick J. Wong6edb1812018-03-23 10:06:53 -0700348xfs_buf_verifier_error(
349 struct xfs_buf *bp,
350 int error,
351 const char *name,
352 void *buf,
353 size_t bufsz,
354 xfs_failaddr_t failaddr)
355{
356 struct xfs_mount *mp = bp->b_target->bt_mount;
357 xfs_failaddr_t fa;
358 int sz;
359
360 fa = failaddr ? failaddr : __return_address;
361 __xfs_buf_ioerror(bp, error, fa);
362
Marco Benattod519da42019-02-01 09:12:20 -0800363 xfs_alert_tag(mp, XFS_PTAG_VERIFIER_ERROR,
364 "Metadata %s detected at %pS, %s block 0x%llx %s",
Darrick J. Wong6edb1812018-03-23 10:06:53 -0700365 bp->b_error == -EFSBADCRC ? "CRC error" : "corruption",
366 fa, bp->b_ops->name, bp->b_bn, name);
367
368 xfs_alert(mp, "Unmount and run xfs_repair");
369
370 if (xfs_error_level >= XFS_ERRLEVEL_LOW) {
371 sz = min_t(size_t, XFS_CORRUPTION_DUMP_LEN, bufsz);
372 xfs_alert(mp, "First %d bytes of corrupted metadata buffer:",
373 sz);
374 xfs_hex_dump(buf, sz);
375 }
376
377 if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
378 xfs_stack_trace();
379}
380
381/*
382 * Warnings specifically for verifier errors. Differentiate CRC vs. invalid
383 * values, and omit the stack trace unless the error level is tuned high.
384 */
385void
Eric Sandeenca23f8f2014-02-27 15:21:07 +1100386xfs_verifier_error(
Darrick J. Wong31ca03c2018-01-08 10:51:02 -0800387 struct xfs_buf *bp,
Darrick J. Wongbc1a09b2018-01-08 10:51:03 -0800388 int error,
389 xfs_failaddr_t failaddr)
Eric Sandeenca23f8f2014-02-27 15:21:07 +1100390{
Darrick J. Wong6edb1812018-03-23 10:06:53 -0700391 return xfs_buf_verifier_error(bp, error, "", xfs_buf_offset(bp, 0),
392 XFS_CORRUPTION_DUMP_LEN, failaddr);
Eric Sandeenca23f8f2014-02-27 15:21:07 +1100393}
Darrick J. Wong22431bf2018-01-22 18:09:48 -0800394
395/*
396 * Warnings for inode corruption problems. Don't bother with the stack
397 * trace unless the error level is turned up high.
398 */
399void
400xfs_inode_verifier_error(
401 struct xfs_inode *ip,
402 int error,
403 const char *name,
404 void *buf,
405 size_t bufsz,
406 xfs_failaddr_t failaddr)
407{
408 struct xfs_mount *mp = ip->i_mount;
409 xfs_failaddr_t fa;
410 int sz;
411
412 fa = failaddr ? failaddr : __return_address;
413
414 xfs_alert(mp, "Metadata %s detected at %pS, inode 0x%llx %s",
415 error == -EFSBADCRC ? "CRC error" : "corruption",
416 fa, ip->i_ino, name);
417
418 xfs_alert(mp, "Unmount and run xfs_repair");
419
420 if (buf && xfs_error_level >= XFS_ERRLEVEL_LOW) {
421 sz = min_t(size_t, XFS_CORRUPTION_DUMP_LEN, bufsz);
422 xfs_alert(mp, "First %d bytes of corrupted metadata buffer:",
423 sz);
424 xfs_hex_dump(buf, sz);
425 }
426
427 if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
428 xfs_stack_trace();
429}