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