Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "xfs.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 19 | #include "xfs_format.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 20 | #include "xfs_fs.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 21 | #include "xfs_log_format.h" |
| 22 | #include "xfs_trans_resv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include "xfs_mount.h" |
Darrick J. Wong | e9e899a | 2017-10-31 12:04:49 -0700 | [diff] [blame^] | 24 | #include "xfs_errortag.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include "xfs_error.h" |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 26 | #include "xfs_sysfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | #ifdef DEBUG |
| 29 | |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 30 | static unsigned int xfs_errortag_random_default[] = { |
| 31 | XFS_RANDOM_DEFAULT, |
| 32 | XFS_RANDOM_IFLUSH_1, |
| 33 | XFS_RANDOM_IFLUSH_2, |
| 34 | XFS_RANDOM_IFLUSH_3, |
| 35 | XFS_RANDOM_IFLUSH_4, |
| 36 | XFS_RANDOM_IFLUSH_5, |
| 37 | XFS_RANDOM_IFLUSH_6, |
| 38 | XFS_RANDOM_DA_READ_BUF, |
| 39 | XFS_RANDOM_BTREE_CHECK_LBLOCK, |
| 40 | XFS_RANDOM_BTREE_CHECK_SBLOCK, |
| 41 | XFS_RANDOM_ALLOC_READ_AGF, |
| 42 | XFS_RANDOM_IALLOC_READ_AGI, |
| 43 | XFS_RANDOM_ITOBP_INOTOBP, |
| 44 | XFS_RANDOM_IUNLINK, |
| 45 | XFS_RANDOM_IUNLINK_REMOVE, |
| 46 | XFS_RANDOM_DIR_INO_VALIDATE, |
| 47 | XFS_RANDOM_BULKSTAT_READ_CHUNK, |
| 48 | XFS_RANDOM_IODONE_IOERR, |
| 49 | XFS_RANDOM_STRATREAD_IOERR, |
| 50 | XFS_RANDOM_STRATCMPL_IOERR, |
| 51 | XFS_RANDOM_DIOWRITE_IOERR, |
| 52 | XFS_RANDOM_BMAPIFORMAT, |
| 53 | XFS_RANDOM_FREE_EXTENT, |
| 54 | XFS_RANDOM_RMAP_FINISH_ONE, |
| 55 | XFS_RANDOM_REFCOUNT_CONTINUE_UPDATE, |
| 56 | XFS_RANDOM_REFCOUNT_FINISH_ONE, |
| 57 | XFS_RANDOM_BMAP_FINISH_ONE, |
| 58 | XFS_RANDOM_AG_RESV_CRITICAL, |
Darrick J. Wong | f8c4725 | 2017-06-20 17:54:48 -0700 | [diff] [blame] | 59 | XFS_RANDOM_DROP_WRITES, |
Brian Foster | 3e88a00 | 2017-06-27 09:52:32 -0700 | [diff] [blame] | 60 | XFS_RANDOM_LOG_BAD_CRC, |
Brian Foster | 7f4d01f | 2017-08-08 18:21:52 -0700 | [diff] [blame] | 61 | XFS_RANDOM_LOG_ITEM_PIN, |
Brian Foster | 7561d27 | 2017-10-17 14:16:29 -0700 | [diff] [blame] | 62 | XFS_RANDOM_BUF_LRU_REF, |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 63 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 65 | struct xfs_errortag_attr { |
| 66 | struct attribute attr; |
| 67 | unsigned int tag; |
| 68 | }; |
| 69 | |
| 70 | static inline struct xfs_errortag_attr * |
| 71 | to_attr(struct attribute *attr) |
| 72 | { |
| 73 | return container_of(attr, struct xfs_errortag_attr, attr); |
| 74 | } |
| 75 | |
| 76 | static inline struct xfs_mount * |
| 77 | to_mp(struct kobject *kobject) |
| 78 | { |
| 79 | struct xfs_kobj *kobj = to_kobj(kobject); |
| 80 | |
| 81 | return container_of(kobj, struct xfs_mount, m_errortag_kobj); |
| 82 | } |
| 83 | |
| 84 | STATIC ssize_t |
| 85 | xfs_errortag_attr_store( |
| 86 | struct kobject *kobject, |
| 87 | struct attribute *attr, |
| 88 | const char *buf, |
| 89 | size_t count) |
| 90 | { |
| 91 | struct xfs_mount *mp = to_mp(kobject); |
| 92 | struct xfs_errortag_attr *xfs_attr = to_attr(attr); |
| 93 | int ret; |
| 94 | unsigned int val; |
| 95 | |
| 96 | if (strcmp(buf, "default") == 0) { |
| 97 | val = xfs_errortag_random_default[xfs_attr->tag]; |
| 98 | } else { |
| 99 | ret = kstrtouint(buf, 0, &val); |
| 100 | if (ret) |
| 101 | return ret; |
| 102 | } |
| 103 | |
| 104 | ret = xfs_errortag_set(mp, xfs_attr->tag, val); |
| 105 | if (ret) |
| 106 | return ret; |
| 107 | return count; |
| 108 | } |
| 109 | |
| 110 | STATIC ssize_t |
| 111 | xfs_errortag_attr_show( |
| 112 | struct kobject *kobject, |
| 113 | struct attribute *attr, |
| 114 | char *buf) |
| 115 | { |
| 116 | struct xfs_mount *mp = to_mp(kobject); |
| 117 | struct xfs_errortag_attr *xfs_attr = to_attr(attr); |
| 118 | |
| 119 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 120 | xfs_errortag_get(mp, xfs_attr->tag)); |
| 121 | } |
| 122 | |
| 123 | static const struct sysfs_ops xfs_errortag_sysfs_ops = { |
| 124 | .show = xfs_errortag_attr_show, |
| 125 | .store = xfs_errortag_attr_store, |
| 126 | }; |
| 127 | |
| 128 | #define XFS_ERRORTAG_ATTR_RW(_name, _tag) \ |
| 129 | static struct xfs_errortag_attr xfs_errortag_attr_##_name = { \ |
| 130 | .attr = {.name = __stringify(_name), \ |
| 131 | .mode = VERIFY_OCTAL_PERMISSIONS(S_IWUSR | S_IRUGO) }, \ |
| 132 | .tag = (_tag), \ |
| 133 | } |
| 134 | |
| 135 | #define XFS_ERRORTAG_ATTR_LIST(_name) &xfs_errortag_attr_##_name.attr |
| 136 | |
| 137 | XFS_ERRORTAG_ATTR_RW(noerror, XFS_ERRTAG_NOERROR); |
| 138 | XFS_ERRORTAG_ATTR_RW(iflush1, XFS_ERRTAG_IFLUSH_1); |
| 139 | XFS_ERRORTAG_ATTR_RW(iflush2, XFS_ERRTAG_IFLUSH_2); |
| 140 | XFS_ERRORTAG_ATTR_RW(iflush3, XFS_ERRTAG_IFLUSH_3); |
| 141 | XFS_ERRORTAG_ATTR_RW(iflush4, XFS_ERRTAG_IFLUSH_4); |
| 142 | XFS_ERRORTAG_ATTR_RW(iflush5, XFS_ERRTAG_IFLUSH_5); |
| 143 | XFS_ERRORTAG_ATTR_RW(iflush6, XFS_ERRTAG_IFLUSH_6); |
| 144 | XFS_ERRORTAG_ATTR_RW(dareadbuf, XFS_ERRTAG_DA_READ_BUF); |
| 145 | XFS_ERRORTAG_ATTR_RW(btree_chk_lblk, XFS_ERRTAG_BTREE_CHECK_LBLOCK); |
| 146 | XFS_ERRORTAG_ATTR_RW(btree_chk_sblk, XFS_ERRTAG_BTREE_CHECK_SBLOCK); |
| 147 | XFS_ERRORTAG_ATTR_RW(readagf, XFS_ERRTAG_ALLOC_READ_AGF); |
| 148 | XFS_ERRORTAG_ATTR_RW(readagi, XFS_ERRTAG_IALLOC_READ_AGI); |
| 149 | XFS_ERRORTAG_ATTR_RW(itobp, XFS_ERRTAG_ITOBP_INOTOBP); |
| 150 | XFS_ERRORTAG_ATTR_RW(iunlink, XFS_ERRTAG_IUNLINK); |
| 151 | XFS_ERRORTAG_ATTR_RW(iunlinkrm, XFS_ERRTAG_IUNLINK_REMOVE); |
| 152 | XFS_ERRORTAG_ATTR_RW(dirinovalid, XFS_ERRTAG_DIR_INO_VALIDATE); |
| 153 | XFS_ERRORTAG_ATTR_RW(bulkstat, XFS_ERRTAG_BULKSTAT_READ_CHUNK); |
| 154 | XFS_ERRORTAG_ATTR_RW(logiodone, XFS_ERRTAG_IODONE_IOERR); |
| 155 | XFS_ERRORTAG_ATTR_RW(stratread, XFS_ERRTAG_STRATREAD_IOERR); |
| 156 | XFS_ERRORTAG_ATTR_RW(stratcmpl, XFS_ERRTAG_STRATCMPL_IOERR); |
| 157 | XFS_ERRORTAG_ATTR_RW(diowrite, XFS_ERRTAG_DIOWRITE_IOERR); |
| 158 | XFS_ERRORTAG_ATTR_RW(bmapifmt, XFS_ERRTAG_BMAPIFORMAT); |
| 159 | XFS_ERRORTAG_ATTR_RW(free_extent, XFS_ERRTAG_FREE_EXTENT); |
| 160 | XFS_ERRORTAG_ATTR_RW(rmap_finish_one, XFS_ERRTAG_RMAP_FINISH_ONE); |
| 161 | XFS_ERRORTAG_ATTR_RW(refcount_continue_update, XFS_ERRTAG_REFCOUNT_CONTINUE_UPDATE); |
| 162 | XFS_ERRORTAG_ATTR_RW(refcount_finish_one, XFS_ERRTAG_REFCOUNT_FINISH_ONE); |
| 163 | XFS_ERRORTAG_ATTR_RW(bmap_finish_one, XFS_ERRTAG_BMAP_FINISH_ONE); |
| 164 | XFS_ERRORTAG_ATTR_RW(ag_resv_critical, XFS_ERRTAG_AG_RESV_CRITICAL); |
Darrick J. Wong | f8c4725 | 2017-06-20 17:54:48 -0700 | [diff] [blame] | 165 | XFS_ERRORTAG_ATTR_RW(drop_writes, XFS_ERRTAG_DROP_WRITES); |
Brian Foster | 3e88a00 | 2017-06-27 09:52:32 -0700 | [diff] [blame] | 166 | XFS_ERRORTAG_ATTR_RW(log_bad_crc, XFS_ERRTAG_LOG_BAD_CRC); |
Brian Foster | 7f4d01f | 2017-08-08 18:21:52 -0700 | [diff] [blame] | 167 | XFS_ERRORTAG_ATTR_RW(log_item_pin, XFS_ERRTAG_LOG_ITEM_PIN); |
Brian Foster | 7561d27 | 2017-10-17 14:16:29 -0700 | [diff] [blame] | 168 | XFS_ERRORTAG_ATTR_RW(buf_lru_ref, XFS_ERRTAG_BUF_LRU_REF); |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 169 | |
| 170 | static struct attribute *xfs_errortag_attrs[] = { |
| 171 | XFS_ERRORTAG_ATTR_LIST(noerror), |
| 172 | XFS_ERRORTAG_ATTR_LIST(iflush1), |
| 173 | XFS_ERRORTAG_ATTR_LIST(iflush2), |
| 174 | XFS_ERRORTAG_ATTR_LIST(iflush3), |
| 175 | XFS_ERRORTAG_ATTR_LIST(iflush4), |
| 176 | XFS_ERRORTAG_ATTR_LIST(iflush5), |
| 177 | XFS_ERRORTAG_ATTR_LIST(iflush6), |
| 178 | XFS_ERRORTAG_ATTR_LIST(dareadbuf), |
| 179 | XFS_ERRORTAG_ATTR_LIST(btree_chk_lblk), |
| 180 | XFS_ERRORTAG_ATTR_LIST(btree_chk_sblk), |
| 181 | XFS_ERRORTAG_ATTR_LIST(readagf), |
| 182 | XFS_ERRORTAG_ATTR_LIST(readagi), |
| 183 | XFS_ERRORTAG_ATTR_LIST(itobp), |
| 184 | XFS_ERRORTAG_ATTR_LIST(iunlink), |
| 185 | XFS_ERRORTAG_ATTR_LIST(iunlinkrm), |
| 186 | XFS_ERRORTAG_ATTR_LIST(dirinovalid), |
| 187 | XFS_ERRORTAG_ATTR_LIST(bulkstat), |
| 188 | XFS_ERRORTAG_ATTR_LIST(logiodone), |
| 189 | XFS_ERRORTAG_ATTR_LIST(stratread), |
| 190 | XFS_ERRORTAG_ATTR_LIST(stratcmpl), |
| 191 | XFS_ERRORTAG_ATTR_LIST(diowrite), |
| 192 | XFS_ERRORTAG_ATTR_LIST(bmapifmt), |
| 193 | XFS_ERRORTAG_ATTR_LIST(free_extent), |
| 194 | XFS_ERRORTAG_ATTR_LIST(rmap_finish_one), |
| 195 | XFS_ERRORTAG_ATTR_LIST(refcount_continue_update), |
| 196 | XFS_ERRORTAG_ATTR_LIST(refcount_finish_one), |
| 197 | XFS_ERRORTAG_ATTR_LIST(bmap_finish_one), |
| 198 | XFS_ERRORTAG_ATTR_LIST(ag_resv_critical), |
Darrick J. Wong | f8c4725 | 2017-06-20 17:54:48 -0700 | [diff] [blame] | 199 | XFS_ERRORTAG_ATTR_LIST(drop_writes), |
Brian Foster | 3e88a00 | 2017-06-27 09:52:32 -0700 | [diff] [blame] | 200 | XFS_ERRORTAG_ATTR_LIST(log_bad_crc), |
Brian Foster | 7f4d01f | 2017-08-08 18:21:52 -0700 | [diff] [blame] | 201 | XFS_ERRORTAG_ATTR_LIST(log_item_pin), |
Brian Foster | 7561d27 | 2017-10-17 14:16:29 -0700 | [diff] [blame] | 202 | XFS_ERRORTAG_ATTR_LIST(buf_lru_ref), |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 203 | NULL, |
| 204 | }; |
| 205 | |
| 206 | struct kobj_type xfs_errortag_ktype = { |
| 207 | .release = xfs_sysfs_release, |
| 208 | .sysfs_ops = &xfs_errortag_sysfs_ops, |
| 209 | .default_attrs = xfs_errortag_attrs, |
| 210 | }; |
| 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | int |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 213 | xfs_errortag_init( |
| 214 | struct xfs_mount *mp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 216 | mp->m_errortag = kmem_zalloc(sizeof(unsigned int) * XFS_ERRTAG_MAX, |
| 217 | KM_SLEEP | KM_MAYFAIL); |
| 218 | if (!mp->m_errortag) |
| 219 | return -ENOMEM; |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 220 | |
| 221 | return xfs_sysfs_init(&mp->m_errortag_kobj, &xfs_errortag_ktype, |
| 222 | &mp->m_kobj, "errortag"); |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 223 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 225 | void |
| 226 | xfs_errortag_del( |
| 227 | struct xfs_mount *mp) |
| 228 | { |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 229 | xfs_sysfs_del(&mp->m_errortag_kobj); |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 230 | kmem_free(mp->m_errortag); |
| 231 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 233 | bool |
| 234 | xfs_errortag_test( |
| 235 | struct xfs_mount *mp, |
| 236 | const char *expression, |
| 237 | const char *file, |
| 238 | int line, |
| 239 | unsigned int error_tag) |
| 240 | { |
| 241 | unsigned int randfactor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Carlos Maiolino | d04c241 | 2017-06-30 09:46:07 -0700 | [diff] [blame] | 243 | /* |
| 244 | * To be able to use error injection anywhere, we need to ensure error |
| 245 | * injection mechanism is already initialized. |
| 246 | * |
| 247 | * Code paths like I/O completion can be called before the |
| 248 | * initialization is complete, but be able to inject errors in such |
| 249 | * places is still useful. |
| 250 | */ |
| 251 | if (!mp->m_errortag) |
| 252 | return false; |
| 253 | |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 254 | ASSERT(error_tag < XFS_ERRTAG_MAX); |
| 255 | randfactor = mp->m_errortag[error_tag]; |
| 256 | if (!randfactor || prandom_u32() % randfactor) |
| 257 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 259 | xfs_warn_ratelimited(mp, |
| 260 | "Injecting error (%s) at file %s, line %d, on filesystem \"%s\"", |
| 261 | expression, file, line, mp->m_fsname); |
| 262 | return true; |
| 263 | } |
| 264 | |
| 265 | int |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 266 | xfs_errortag_get( |
| 267 | struct xfs_mount *mp, |
| 268 | unsigned int error_tag) |
| 269 | { |
| 270 | if (error_tag >= XFS_ERRTAG_MAX) |
| 271 | return -EINVAL; |
| 272 | |
| 273 | return mp->m_errortag[error_tag]; |
| 274 | } |
| 275 | |
| 276 | int |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 277 | xfs_errortag_set( |
| 278 | struct xfs_mount *mp, |
| 279 | unsigned int error_tag, |
| 280 | unsigned int tag_value) |
| 281 | { |
| 282 | if (error_tag >= XFS_ERRTAG_MAX) |
| 283 | return -EINVAL; |
| 284 | |
| 285 | mp->m_errortag[error_tag] = tag_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | int |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 290 | xfs_errortag_add( |
| 291 | struct xfs_mount *mp, |
| 292 | unsigned int error_tag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | { |
Darrick J. Wong | 128f24d | 2016-06-21 11:53:28 +1000 | [diff] [blame] | 294 | if (error_tag >= XFS_ERRTAG_MAX) |
| 295 | return -EINVAL; |
| 296 | |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 297 | return xfs_errortag_set(mp, error_tag, |
| 298 | xfs_errortag_random_default[error_tag]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | int |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 302 | xfs_errortag_clearall( |
| 303 | struct xfs_mount *mp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 305 | memset(mp->m_errortag, 0, sizeof(unsigned int) * XFS_ERRTAG_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | return 0; |
| 307 | } |
Christoph Hellwig | 1550d0b | 2008-08-13 16:17:37 +1000 | [diff] [blame] | 308 | #endif /* DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | void |
| 311 | xfs_error_report( |
Alex Elder | a0e856b | 2010-04-13 15:22:08 +1000 | [diff] [blame] | 312 | const char *tag, |
| 313 | int level, |
| 314 | struct xfs_mount *mp, |
| 315 | const char *filename, |
| 316 | int linenum, |
Christoph Hellwig | fc51c2b | 2015-06-22 09:44:02 +1000 | [diff] [blame] | 317 | void *ra) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | { |
| 319 | if (level <= xfs_error_level) { |
Dave Chinner | 6a19d93 | 2011-03-07 10:02:35 +1100 | [diff] [blame] | 320 | xfs_alert_tag(mp, XFS_PTAG_ERROR_REPORT, |
Scott Wood | 65dd297 | 2015-03-25 14:56:21 +1100 | [diff] [blame] | 321 | "Internal error %s at line %d of file %s. Caller %pS", |
Alex Elder | a0e856b | 2010-04-13 15:22:08 +1000 | [diff] [blame] | 322 | tag, linenum, filename, ra); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | xfs_stack_trace(); |
| 325 | } |
| 326 | } |
| 327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | void |
| 329 | xfs_corruption_error( |
Alex Elder | a0e856b | 2010-04-13 15:22:08 +1000 | [diff] [blame] | 330 | const char *tag, |
| 331 | int level, |
| 332 | struct xfs_mount *mp, |
| 333 | void *p, |
| 334 | const char *filename, |
| 335 | int linenum, |
Christoph Hellwig | fc51c2b | 2015-06-22 09:44:02 +1000 | [diff] [blame] | 336 | void *ra) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
| 338 | if (level <= xfs_error_level) |
Dave Chinner | a205064 | 2013-04-03 16:11:11 +1100 | [diff] [blame] | 339 | xfs_hex_dump(p, 64); |
Alex Elder | a0e856b | 2010-04-13 15:22:08 +1000 | [diff] [blame] | 340 | xfs_error_report(tag, level, mp, filename, linenum, ra); |
Dave Chinner | 65333b4 | 2011-03-07 10:03:35 +1100 | [diff] [blame] | 341 | xfs_alert(mp, "Corruption detected. Unmount and run xfs_repair"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
Eric Sandeen | ca23f8f | 2014-02-27 15:21:07 +1100 | [diff] [blame] | 343 | |
| 344 | /* |
| 345 | * Warnings specifically for verifier errors. Differentiate CRC vs. invalid |
| 346 | * values, and omit the stack trace unless the error level is tuned high. |
| 347 | */ |
| 348 | void |
| 349 | xfs_verifier_error( |
| 350 | struct xfs_buf *bp) |
| 351 | { |
| 352 | struct xfs_mount *mp = bp->b_target->bt_mount; |
| 353 | |
Helge Deller | e150dcd | 2017-09-18 11:34:16 -0700 | [diff] [blame] | 354 | xfs_alert(mp, "Metadata %s detected at %pS, %s block 0x%llx", |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 355 | bp->b_error == -EFSBADCRC ? "CRC error" : "corruption", |
Eric Sandeen | 233135b | 2016-01-04 16:10:19 +1100 | [diff] [blame] | 356 | __return_address, bp->b_ops->name, bp->b_bn); |
Eric Sandeen | ca23f8f | 2014-02-27 15:21:07 +1100 | [diff] [blame] | 357 | |
| 358 | xfs_alert(mp, "Unmount and run xfs_repair"); |
| 359 | |
| 360 | if (xfs_error_level >= XFS_ERRLEVEL_LOW) { |
| 361 | xfs_alert(mp, "First 64 bytes of corrupted metadata buffer:"); |
| 362 | xfs_hex_dump(xfs_buf_offset(bp, 0), 64); |
| 363 | } |
| 364 | |
| 365 | if (xfs_error_level >= XFS_ERRLEVEL_HIGH) |
| 366 | xfs_stack_trace(); |
| 367 | } |