blob: 51dd1f43d12f6726e3151ddeac9d83baf2b6a4d5 [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"
Darrick J. Wong5467b342019-06-28 19:25:35 -07007#include "xfs_shared.h"
Dave Chinnera4fbe6a2013-10-23 10:51:50 +11008#include "xfs_format.h"
Nathan Scotta844f452005-11-02 14:38:42 +11009#include "xfs_fs.h"
Dave Chinner239880e2013-10-23 10:50:10 +110010#include "xfs_log_format.h"
11#include "xfs_trans_resv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include "xfs_mount.h"
Darrick J. Wonge9e899a2017-10-31 12:04:49 -070013#include "xfs_errortag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include "xfs_error.h"
Darrick J. Wongc6840102017-06-20 17:54:47 -070015#include "xfs_sysfs.h"
Darrick J. Wong22431bf2018-01-22 18:09:48 -080016#include "xfs_inode.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#ifdef DEBUG
19
Darrick J. Wong31965ef2017-06-20 17:54:46 -070020static 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,
Darrick J. Wongf8c47252017-06-20 17:54:48 -070049 XFS_RANDOM_DROP_WRITES,
Brian Foster3e88a002017-06-27 09:52:32 -070050 XFS_RANDOM_LOG_BAD_CRC,
Brian Foster7f4d01f2017-08-08 18:21:52 -070051 XFS_RANDOM_LOG_ITEM_PIN,
Brian Foster7561d272017-10-17 14:16:29 -070052 XFS_RANDOM_BUF_LRU_REF,
Darrick J. Wong84d42ea2018-05-14 06:34:36 -070053 XFS_RANDOM_FORCE_SCRUB_REPAIR,
Darrick J. Wongf467cad2018-07-20 09:28:40 -070054 XFS_RANDOM_FORCE_SUMMARY_RECALC,
Darrick J. Wong9b247172019-02-07 10:37:16 -080055 XFS_RANDOM_IUNLINK_FALLBACK,
Darrick J. Wong31965ef2017-06-20 17:54:46 -070056};
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Darrick J. Wongc6840102017-06-20 17:54:47 -070058struct xfs_errortag_attr {
59 struct attribute attr;
60 unsigned int tag;
61};
62
63static inline struct xfs_errortag_attr *
64to_attr(struct attribute *attr)
65{
66 return container_of(attr, struct xfs_errortag_attr, attr);
67}
68
69static inline struct xfs_mount *
70to_mp(struct kobject *kobject)
71{
72 struct xfs_kobj *kobj = to_kobj(kobject);
73
74 return container_of(kobj, struct xfs_mount, m_errortag_kobj);
75}
76
77STATIC ssize_t
78xfs_errortag_attr_store(
79 struct kobject *kobject,
80 struct attribute *attr,
81 const char *buf,
82 size_t count)
83{
84 struct xfs_mount *mp = to_mp(kobject);
85 struct xfs_errortag_attr *xfs_attr = to_attr(attr);
86 int ret;
87 unsigned int val;
88
89 if (strcmp(buf, "default") == 0) {
90 val = xfs_errortag_random_default[xfs_attr->tag];
91 } else {
92 ret = kstrtouint(buf, 0, &val);
93 if (ret)
94 return ret;
95 }
96
97 ret = xfs_errortag_set(mp, xfs_attr->tag, val);
98 if (ret)
99 return ret;
100 return count;
101}
102
103STATIC ssize_t
104xfs_errortag_attr_show(
105 struct kobject *kobject,
106 struct attribute *attr,
107 char *buf)
108{
109 struct xfs_mount *mp = to_mp(kobject);
110 struct xfs_errortag_attr *xfs_attr = to_attr(attr);
111
112 return snprintf(buf, PAGE_SIZE, "%u\n",
113 xfs_errortag_get(mp, xfs_attr->tag));
114}
115
116static const struct sysfs_ops xfs_errortag_sysfs_ops = {
117 .show = xfs_errortag_attr_show,
118 .store = xfs_errortag_attr_store,
119};
120
121#define XFS_ERRORTAG_ATTR_RW(_name, _tag) \
122static struct xfs_errortag_attr xfs_errortag_attr_##_name = { \
123 .attr = {.name = __stringify(_name), \
124 .mode = VERIFY_OCTAL_PERMISSIONS(S_IWUSR | S_IRUGO) }, \
125 .tag = (_tag), \
126}
127
128#define XFS_ERRORTAG_ATTR_LIST(_name) &xfs_errortag_attr_##_name.attr
129
130XFS_ERRORTAG_ATTR_RW(noerror, XFS_ERRTAG_NOERROR);
131XFS_ERRORTAG_ATTR_RW(iflush1, XFS_ERRTAG_IFLUSH_1);
132XFS_ERRORTAG_ATTR_RW(iflush2, XFS_ERRTAG_IFLUSH_2);
133XFS_ERRORTAG_ATTR_RW(iflush3, XFS_ERRTAG_IFLUSH_3);
134XFS_ERRORTAG_ATTR_RW(iflush4, XFS_ERRTAG_IFLUSH_4);
135XFS_ERRORTAG_ATTR_RW(iflush5, XFS_ERRTAG_IFLUSH_5);
136XFS_ERRORTAG_ATTR_RW(iflush6, XFS_ERRTAG_IFLUSH_6);
137XFS_ERRORTAG_ATTR_RW(dareadbuf, XFS_ERRTAG_DA_READ_BUF);
138XFS_ERRORTAG_ATTR_RW(btree_chk_lblk, XFS_ERRTAG_BTREE_CHECK_LBLOCK);
139XFS_ERRORTAG_ATTR_RW(btree_chk_sblk, XFS_ERRTAG_BTREE_CHECK_SBLOCK);
140XFS_ERRORTAG_ATTR_RW(readagf, XFS_ERRTAG_ALLOC_READ_AGF);
141XFS_ERRORTAG_ATTR_RW(readagi, XFS_ERRTAG_IALLOC_READ_AGI);
142XFS_ERRORTAG_ATTR_RW(itobp, XFS_ERRTAG_ITOBP_INOTOBP);
143XFS_ERRORTAG_ATTR_RW(iunlink, XFS_ERRTAG_IUNLINK);
144XFS_ERRORTAG_ATTR_RW(iunlinkrm, XFS_ERRTAG_IUNLINK_REMOVE);
145XFS_ERRORTAG_ATTR_RW(dirinovalid, XFS_ERRTAG_DIR_INO_VALIDATE);
146XFS_ERRORTAG_ATTR_RW(bulkstat, XFS_ERRTAG_BULKSTAT_READ_CHUNK);
147XFS_ERRORTAG_ATTR_RW(logiodone, XFS_ERRTAG_IODONE_IOERR);
148XFS_ERRORTAG_ATTR_RW(stratread, XFS_ERRTAG_STRATREAD_IOERR);
149XFS_ERRORTAG_ATTR_RW(stratcmpl, XFS_ERRTAG_STRATCMPL_IOERR);
150XFS_ERRORTAG_ATTR_RW(diowrite, XFS_ERRTAG_DIOWRITE_IOERR);
151XFS_ERRORTAG_ATTR_RW(bmapifmt, XFS_ERRTAG_BMAPIFORMAT);
152XFS_ERRORTAG_ATTR_RW(free_extent, XFS_ERRTAG_FREE_EXTENT);
153XFS_ERRORTAG_ATTR_RW(rmap_finish_one, XFS_ERRTAG_RMAP_FINISH_ONE);
154XFS_ERRORTAG_ATTR_RW(refcount_continue_update, XFS_ERRTAG_REFCOUNT_CONTINUE_UPDATE);
155XFS_ERRORTAG_ATTR_RW(refcount_finish_one, XFS_ERRTAG_REFCOUNT_FINISH_ONE);
156XFS_ERRORTAG_ATTR_RW(bmap_finish_one, XFS_ERRTAG_BMAP_FINISH_ONE);
157XFS_ERRORTAG_ATTR_RW(ag_resv_critical, XFS_ERRTAG_AG_RESV_CRITICAL);
Darrick J. Wongf8c47252017-06-20 17:54:48 -0700158XFS_ERRORTAG_ATTR_RW(drop_writes, XFS_ERRTAG_DROP_WRITES);
Brian Foster3e88a002017-06-27 09:52:32 -0700159XFS_ERRORTAG_ATTR_RW(log_bad_crc, XFS_ERRTAG_LOG_BAD_CRC);
Brian Foster7f4d01f2017-08-08 18:21:52 -0700160XFS_ERRORTAG_ATTR_RW(log_item_pin, XFS_ERRTAG_LOG_ITEM_PIN);
Brian Foster7561d272017-10-17 14:16:29 -0700161XFS_ERRORTAG_ATTR_RW(buf_lru_ref, XFS_ERRTAG_BUF_LRU_REF);
Darrick J. Wong84d42ea2018-05-14 06:34:36 -0700162XFS_ERRORTAG_ATTR_RW(force_repair, XFS_ERRTAG_FORCE_SCRUB_REPAIR);
Darrick J. Wongf467cad2018-07-20 09:28:40 -0700163XFS_ERRORTAG_ATTR_RW(bad_summary, XFS_ERRTAG_FORCE_SUMMARY_RECALC);
Darrick J. Wong9b247172019-02-07 10:37:16 -0800164XFS_ERRORTAG_ATTR_RW(iunlink_fallback, XFS_ERRTAG_IUNLINK_FALLBACK);
Darrick J. Wongc6840102017-06-20 17:54:47 -0700165
166static struct attribute *xfs_errortag_attrs[] = {
167 XFS_ERRORTAG_ATTR_LIST(noerror),
168 XFS_ERRORTAG_ATTR_LIST(iflush1),
169 XFS_ERRORTAG_ATTR_LIST(iflush2),
170 XFS_ERRORTAG_ATTR_LIST(iflush3),
171 XFS_ERRORTAG_ATTR_LIST(iflush4),
172 XFS_ERRORTAG_ATTR_LIST(iflush5),
173 XFS_ERRORTAG_ATTR_LIST(iflush6),
174 XFS_ERRORTAG_ATTR_LIST(dareadbuf),
175 XFS_ERRORTAG_ATTR_LIST(btree_chk_lblk),
176 XFS_ERRORTAG_ATTR_LIST(btree_chk_sblk),
177 XFS_ERRORTAG_ATTR_LIST(readagf),
178 XFS_ERRORTAG_ATTR_LIST(readagi),
179 XFS_ERRORTAG_ATTR_LIST(itobp),
180 XFS_ERRORTAG_ATTR_LIST(iunlink),
181 XFS_ERRORTAG_ATTR_LIST(iunlinkrm),
182 XFS_ERRORTAG_ATTR_LIST(dirinovalid),
183 XFS_ERRORTAG_ATTR_LIST(bulkstat),
184 XFS_ERRORTAG_ATTR_LIST(logiodone),
185 XFS_ERRORTAG_ATTR_LIST(stratread),
186 XFS_ERRORTAG_ATTR_LIST(stratcmpl),
187 XFS_ERRORTAG_ATTR_LIST(diowrite),
188 XFS_ERRORTAG_ATTR_LIST(bmapifmt),
189 XFS_ERRORTAG_ATTR_LIST(free_extent),
190 XFS_ERRORTAG_ATTR_LIST(rmap_finish_one),
191 XFS_ERRORTAG_ATTR_LIST(refcount_continue_update),
192 XFS_ERRORTAG_ATTR_LIST(refcount_finish_one),
193 XFS_ERRORTAG_ATTR_LIST(bmap_finish_one),
194 XFS_ERRORTAG_ATTR_LIST(ag_resv_critical),
Darrick J. Wongf8c47252017-06-20 17:54:48 -0700195 XFS_ERRORTAG_ATTR_LIST(drop_writes),
Brian Foster3e88a002017-06-27 09:52:32 -0700196 XFS_ERRORTAG_ATTR_LIST(log_bad_crc),
Brian Foster7f4d01f2017-08-08 18:21:52 -0700197 XFS_ERRORTAG_ATTR_LIST(log_item_pin),
Brian Foster7561d272017-10-17 14:16:29 -0700198 XFS_ERRORTAG_ATTR_LIST(buf_lru_ref),
Darrick J. Wong84d42ea2018-05-14 06:34:36 -0700199 XFS_ERRORTAG_ATTR_LIST(force_repair),
Darrick J. Wongf467cad2018-07-20 09:28:40 -0700200 XFS_ERRORTAG_ATTR_LIST(bad_summary),
Darrick J. Wong9b247172019-02-07 10:37:16 -0800201 XFS_ERRORTAG_ATTR_LIST(iunlink_fallback),
Darrick J. Wongc6840102017-06-20 17:54:47 -0700202 NULL,
203};
204
Christoph Hellwig43711552017-11-06 11:53:59 -0800205static struct kobj_type xfs_errortag_ktype = {
Darrick J. Wongc6840102017-06-20 17:54:47 -0700206 .release = xfs_sysfs_release,
207 .sysfs_ops = &xfs_errortag_sysfs_ops,
208 .default_attrs = xfs_errortag_attrs,
209};
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211int
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700212xfs_errortag_init(
213 struct xfs_mount *mp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700215 mp->m_errortag = kmem_zalloc(sizeof(unsigned int) * XFS_ERRTAG_MAX,
Tetsuo Handa707e0dd2019-08-26 12:06:22 -0700216 KM_MAYFAIL);
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700217 if (!mp->m_errortag)
218 return -ENOMEM;
Darrick J. Wongc6840102017-06-20 17:54:47 -0700219
220 return xfs_sysfs_init(&mp->m_errortag_kobj, &xfs_errortag_ktype,
221 &mp->m_kobj, "errortag");
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700222}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700224void
225xfs_errortag_del(
226 struct xfs_mount *mp)
227{
Darrick J. Wongc6840102017-06-20 17:54:47 -0700228 xfs_sysfs_del(&mp->m_errortag_kobj);
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700229 kmem_free(mp->m_errortag);
230}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700232bool
233xfs_errortag_test(
234 struct xfs_mount *mp,
235 const char *expression,
236 const char *file,
237 int line,
238 unsigned int error_tag)
239{
240 unsigned int randfactor;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Carlos Maiolinod04c2412017-06-30 09:46:07 -0700242 /*
243 * To be able to use error injection anywhere, we need to ensure error
244 * injection mechanism is already initialized.
245 *
246 * Code paths like I/O completion can be called before the
247 * initialization is complete, but be able to inject errors in such
248 * places is still useful.
249 */
250 if (!mp->m_errortag)
251 return false;
252
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700253 ASSERT(error_tag < XFS_ERRTAG_MAX);
254 randfactor = mp->m_errortag[error_tag];
255 if (!randfactor || prandom_u32() % randfactor)
256 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700258 xfs_warn_ratelimited(mp,
259"Injecting error (%s) at file %s, line %d, on filesystem \"%s\"",
Ian Kente1d3d212019-11-04 13:58:40 -0800260 expression, file, line, mp->m_super->s_id);
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700261 return true;
262}
263
264int
Darrick J. Wongc6840102017-06-20 17:54:47 -0700265xfs_errortag_get(
266 struct xfs_mount *mp,
267 unsigned int error_tag)
268{
269 if (error_tag >= XFS_ERRTAG_MAX)
270 return -EINVAL;
271
272 return mp->m_errortag[error_tag];
273}
274
275int
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700276xfs_errortag_set(
277 struct xfs_mount *mp,
278 unsigned int error_tag,
279 unsigned int tag_value)
280{
281 if (error_tag >= XFS_ERRTAG_MAX)
282 return -EINVAL;
283
284 mp->m_errortag[error_tag] = tag_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 return 0;
286}
287
288int
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700289xfs_errortag_add(
290 struct xfs_mount *mp,
291 unsigned int error_tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
Darrick J. Wong128f24d2016-06-21 11:53:28 +1000293 if (error_tag >= XFS_ERRTAG_MAX)
294 return -EINVAL;
295
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700296 return xfs_errortag_set(mp, error_tag,
297 xfs_errortag_random_default[error_tag]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
300int
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700301xfs_errortag_clearall(
302 struct xfs_mount *mp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
Darrick J. Wong31965ef2017-06-20 17:54:46 -0700304 memset(mp->m_errortag, 0, sizeof(unsigned int) * XFS_ERRTAG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 return 0;
306}
Christoph Hellwig1550d0b2008-08-13 16:17:37 +1000307#endif /* DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309void
310xfs_error_report(
Alex Eldera0e856b2010-04-13 15:22:08 +1000311 const char *tag,
312 int level,
313 struct xfs_mount *mp,
314 const char *filename,
315 int linenum,
Darrick J. Wongd9418ed2018-01-08 10:51:25 -0800316 xfs_failaddr_t failaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
318 if (level <= xfs_error_level) {
Dave Chinner6a19d932011-03-07 10:02:35 +1100319 xfs_alert_tag(mp, XFS_PTAG_ERROR_REPORT,
Scott Wood65dd2972015-03-25 14:56:21 +1100320 "Internal error %s at line %d of file %s. Caller %pS",
Darrick J. Wongd9418ed2018-01-08 10:51:25 -0800321 tag, linenum, filename, failaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323 xfs_stack_trace();
324 }
325}
326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327void
328xfs_corruption_error(
Alex Eldera0e856b2010-04-13 15:22:08 +1000329 const char *tag,
330 int level,
331 struct xfs_mount *mp,
Darrick J. Wongd243b892019-11-02 09:40:36 -0700332 const void *buf,
Darrick J. Wong2551a532018-06-04 10:23:54 -0700333 size_t bufsize,
Alex Eldera0e856b2010-04-13 15:22:08 +1000334 const char *filename,
335 int linenum,
Darrick J. Wongd9418ed2018-01-08 10:51:25 -0800336 xfs_failaddr_t failaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
338 if (level <= xfs_error_level)
Darrick J. Wong2551a532018-06-04 10:23:54 -0700339 xfs_hex_dump(buf, bufsize);
Darrick J. Wongd9418ed2018-01-08 10:51:25 -0800340 xfs_error_report(tag, level, mp, filename, linenum, failaddr);
Dave Chinner65333b42011-03-07 10:03:35 +1100341 xfs_alert(mp, "Corruption detected. Unmount and run xfs_repair");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}
Eric Sandeenca23f8f2014-02-27 15:21:07 +1100343
344/*
Darrick J. Wonga5155b82019-11-02 09:40:53 -0700345 * Complain about the kinds of metadata corruption that we can't detect from a
346 * verifier, such as incorrect inter-block relationship data. Does not set
347 * bp->b_error.
348 */
349void
350xfs_buf_corruption_error(
351 struct xfs_buf *bp)
352{
353 struct xfs_mount *mp = bp->b_mount;
354
355 xfs_alert_tag(mp, XFS_PTAG_VERIFIER_ERROR,
356 "Metadata corruption detected at %pS, %s block 0x%llx",
357 __return_address, bp->b_ops->name, bp->b_bn);
358
359 xfs_alert(mp, "Unmount and run xfs_repair");
360
361 if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
362 xfs_stack_trace();
363}
364
365/*
Eric Sandeenca23f8f2014-02-27 15:21:07 +1100366 * Warnings specifically for verifier errors. Differentiate CRC vs. invalid
367 * values, and omit the stack trace unless the error level is tuned high.
368 */
369void
Darrick J. Wong6edb1812018-03-23 10:06:53 -0700370xfs_buf_verifier_error(
371 struct xfs_buf *bp,
372 int error,
373 const char *name,
Darrick J. Wongd243b892019-11-02 09:40:36 -0700374 const void *buf,
Darrick J. Wong6edb1812018-03-23 10:06:53 -0700375 size_t bufsz,
376 xfs_failaddr_t failaddr)
377{
Christoph Hellwigdbd329f12019-06-28 19:27:29 -0700378 struct xfs_mount *mp = bp->b_mount;
Darrick J. Wong6edb1812018-03-23 10:06:53 -0700379 xfs_failaddr_t fa;
380 int sz;
381
382 fa = failaddr ? failaddr : __return_address;
383 __xfs_buf_ioerror(bp, error, fa);
384
Marco Benattod519da42019-02-01 09:12:20 -0800385 xfs_alert_tag(mp, XFS_PTAG_VERIFIER_ERROR,
386 "Metadata %s detected at %pS, %s block 0x%llx %s",
Darrick J. Wong6edb1812018-03-23 10:06:53 -0700387 bp->b_error == -EFSBADCRC ? "CRC error" : "corruption",
388 fa, bp->b_ops->name, bp->b_bn, name);
389
390 xfs_alert(mp, "Unmount and run xfs_repair");
391
392 if (xfs_error_level >= XFS_ERRLEVEL_LOW) {
393 sz = min_t(size_t, XFS_CORRUPTION_DUMP_LEN, bufsz);
394 xfs_alert(mp, "First %d bytes of corrupted metadata buffer:",
395 sz);
396 xfs_hex_dump(buf, sz);
397 }
398
399 if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
400 xfs_stack_trace();
401}
402
403/*
404 * Warnings specifically for verifier errors. Differentiate CRC vs. invalid
405 * values, and omit the stack trace unless the error level is tuned high.
406 */
407void
Eric Sandeenca23f8f2014-02-27 15:21:07 +1100408xfs_verifier_error(
Darrick J. Wong31ca03c2018-01-08 10:51:02 -0800409 struct xfs_buf *bp,
Darrick J. Wongbc1a09b2018-01-08 10:51:03 -0800410 int error,
411 xfs_failaddr_t failaddr)
Eric Sandeenca23f8f2014-02-27 15:21:07 +1100412{
Darrick J. Wong6edb1812018-03-23 10:06:53 -0700413 return xfs_buf_verifier_error(bp, error, "", xfs_buf_offset(bp, 0),
414 XFS_CORRUPTION_DUMP_LEN, failaddr);
Eric Sandeenca23f8f2014-02-27 15:21:07 +1100415}
Darrick J. Wong22431bf2018-01-22 18:09:48 -0800416
417/*
418 * Warnings for inode corruption problems. Don't bother with the stack
419 * trace unless the error level is turned up high.
420 */
421void
422xfs_inode_verifier_error(
423 struct xfs_inode *ip,
424 int error,
425 const char *name,
Darrick J. Wongd243b892019-11-02 09:40:36 -0700426 const void *buf,
Darrick J. Wong22431bf2018-01-22 18:09:48 -0800427 size_t bufsz,
428 xfs_failaddr_t failaddr)
429{
430 struct xfs_mount *mp = ip->i_mount;
431 xfs_failaddr_t fa;
432 int sz;
433
434 fa = failaddr ? failaddr : __return_address;
435
436 xfs_alert(mp, "Metadata %s detected at %pS, inode 0x%llx %s",
437 error == -EFSBADCRC ? "CRC error" : "corruption",
438 fa, ip->i_ino, name);
439
440 xfs_alert(mp, "Unmount and run xfs_repair");
441
442 if (buf && xfs_error_level >= XFS_ERRLEVEL_LOW) {
443 sz = min_t(size_t, XFS_CORRUPTION_DUMP_LEN, bufsz);
444 xfs_alert(mp, "First %d bytes of corrupted metadata buffer:",
445 sz);
446 xfs_hex_dump(buf, sz);
447 }
448
449 if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
450 xfs_stack_trace();
451}