Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 3 | * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. |
| 4 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include "xfs.h" |
Darrick J. Wong | 5467b34 | 2019-06-28 19:25:35 -0700 | [diff] [blame] | 7 | #include "xfs_shared.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 8 | #include "xfs_format.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 9 | #include "xfs_fs.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 10 | #include "xfs_log_format.h" |
| 11 | #include "xfs_trans_resv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include "xfs_mount.h" |
Darrick J. Wong | e9e899a | 2017-10-31 12:04:49 -0700 | [diff] [blame] | 13 | #include "xfs_errortag.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include "xfs_error.h" |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 15 | #include "xfs_sysfs.h" |
Darrick J. Wong | 22431bf | 2018-01-22 18:09:48 -0800 | [diff] [blame] | 16 | #include "xfs_inode.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #ifdef DEBUG |
| 19 | |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 20 | static 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. Wong | f8c4725 | 2017-06-20 17:54:48 -0700 | [diff] [blame] | 49 | XFS_RANDOM_DROP_WRITES, |
Brian Foster | 3e88a00 | 2017-06-27 09:52:32 -0700 | [diff] [blame] | 50 | XFS_RANDOM_LOG_BAD_CRC, |
Brian Foster | 7f4d01f | 2017-08-08 18:21:52 -0700 | [diff] [blame] | 51 | XFS_RANDOM_LOG_ITEM_PIN, |
Brian Foster | 7561d27 | 2017-10-17 14:16:29 -0700 | [diff] [blame] | 52 | XFS_RANDOM_BUF_LRU_REF, |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 53 | XFS_RANDOM_FORCE_SCRUB_REPAIR, |
Darrick J. Wong | f467cad | 2018-07-20 09:28:40 -0700 | [diff] [blame] | 54 | XFS_RANDOM_FORCE_SUMMARY_RECALC, |
Darrick J. Wong | 9b24717 | 2019-02-07 10:37:16 -0800 | [diff] [blame] | 55 | XFS_RANDOM_IUNLINK_FALLBACK, |
Brian Foster | 7376d74 | 2020-05-06 13:29:19 -0700 | [diff] [blame] | 56 | XFS_RANDOM_BUF_IOERROR, |
Chandan Babu R | f9fa871 | 2021-01-22 16:48:15 -0800 | [diff] [blame] | 57 | XFS_RANDOM_REDUCE_MAX_IEXTENTS, |
Chandan Babu R | 3015196 | 2021-01-22 16:48:17 -0800 | [diff] [blame] | 58 | XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT, |
Gao Xiang | 2b92fae | 2021-03-23 19:05:39 -0700 | [diff] [blame] | 59 | XFS_RANDOM_AG_RESV_FAIL, |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 60 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 62 | struct xfs_errortag_attr { |
| 63 | struct attribute attr; |
| 64 | unsigned int tag; |
| 65 | }; |
| 66 | |
| 67 | static inline struct xfs_errortag_attr * |
| 68 | to_attr(struct attribute *attr) |
| 69 | { |
| 70 | return container_of(attr, struct xfs_errortag_attr, attr); |
| 71 | } |
| 72 | |
| 73 | static inline struct xfs_mount * |
| 74 | to_mp(struct kobject *kobject) |
| 75 | { |
| 76 | struct xfs_kobj *kobj = to_kobj(kobject); |
| 77 | |
| 78 | return container_of(kobj, struct xfs_mount, m_errortag_kobj); |
| 79 | } |
| 80 | |
| 81 | STATIC ssize_t |
| 82 | xfs_errortag_attr_store( |
| 83 | struct kobject *kobject, |
| 84 | struct attribute *attr, |
| 85 | const char *buf, |
| 86 | size_t count) |
| 87 | { |
| 88 | struct xfs_mount *mp = to_mp(kobject); |
| 89 | struct xfs_errortag_attr *xfs_attr = to_attr(attr); |
| 90 | int ret; |
| 91 | unsigned int val; |
| 92 | |
| 93 | if (strcmp(buf, "default") == 0) { |
| 94 | val = xfs_errortag_random_default[xfs_attr->tag]; |
| 95 | } else { |
| 96 | ret = kstrtouint(buf, 0, &val); |
| 97 | if (ret) |
| 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | ret = xfs_errortag_set(mp, xfs_attr->tag, val); |
| 102 | if (ret) |
| 103 | return ret; |
| 104 | return count; |
| 105 | } |
| 106 | |
| 107 | STATIC ssize_t |
| 108 | xfs_errortag_attr_show( |
| 109 | struct kobject *kobject, |
| 110 | struct attribute *attr, |
| 111 | char *buf) |
| 112 | { |
| 113 | struct xfs_mount *mp = to_mp(kobject); |
| 114 | struct xfs_errortag_attr *xfs_attr = to_attr(attr); |
| 115 | |
| 116 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 117 | xfs_errortag_get(mp, xfs_attr->tag)); |
| 118 | } |
| 119 | |
| 120 | static const struct sysfs_ops xfs_errortag_sysfs_ops = { |
| 121 | .show = xfs_errortag_attr_show, |
| 122 | .store = xfs_errortag_attr_store, |
| 123 | }; |
| 124 | |
| 125 | #define XFS_ERRORTAG_ATTR_RW(_name, _tag) \ |
| 126 | static struct xfs_errortag_attr xfs_errortag_attr_##_name = { \ |
| 127 | .attr = {.name = __stringify(_name), \ |
| 128 | .mode = VERIFY_OCTAL_PERMISSIONS(S_IWUSR | S_IRUGO) }, \ |
| 129 | .tag = (_tag), \ |
| 130 | } |
| 131 | |
| 132 | #define XFS_ERRORTAG_ATTR_LIST(_name) &xfs_errortag_attr_##_name.attr |
| 133 | |
| 134 | XFS_ERRORTAG_ATTR_RW(noerror, XFS_ERRTAG_NOERROR); |
| 135 | XFS_ERRORTAG_ATTR_RW(iflush1, XFS_ERRTAG_IFLUSH_1); |
| 136 | XFS_ERRORTAG_ATTR_RW(iflush2, XFS_ERRTAG_IFLUSH_2); |
| 137 | XFS_ERRORTAG_ATTR_RW(iflush3, XFS_ERRTAG_IFLUSH_3); |
| 138 | XFS_ERRORTAG_ATTR_RW(iflush4, XFS_ERRTAG_IFLUSH_4); |
| 139 | XFS_ERRORTAG_ATTR_RW(iflush5, XFS_ERRTAG_IFLUSH_5); |
| 140 | XFS_ERRORTAG_ATTR_RW(iflush6, XFS_ERRTAG_IFLUSH_6); |
| 141 | XFS_ERRORTAG_ATTR_RW(dareadbuf, XFS_ERRTAG_DA_READ_BUF); |
| 142 | XFS_ERRORTAG_ATTR_RW(btree_chk_lblk, XFS_ERRTAG_BTREE_CHECK_LBLOCK); |
| 143 | XFS_ERRORTAG_ATTR_RW(btree_chk_sblk, XFS_ERRTAG_BTREE_CHECK_SBLOCK); |
| 144 | XFS_ERRORTAG_ATTR_RW(readagf, XFS_ERRTAG_ALLOC_READ_AGF); |
| 145 | XFS_ERRORTAG_ATTR_RW(readagi, XFS_ERRTAG_IALLOC_READ_AGI); |
| 146 | XFS_ERRORTAG_ATTR_RW(itobp, XFS_ERRTAG_ITOBP_INOTOBP); |
| 147 | XFS_ERRORTAG_ATTR_RW(iunlink, XFS_ERRTAG_IUNLINK); |
| 148 | XFS_ERRORTAG_ATTR_RW(iunlinkrm, XFS_ERRTAG_IUNLINK_REMOVE); |
| 149 | XFS_ERRORTAG_ATTR_RW(dirinovalid, XFS_ERRTAG_DIR_INO_VALIDATE); |
| 150 | XFS_ERRORTAG_ATTR_RW(bulkstat, XFS_ERRTAG_BULKSTAT_READ_CHUNK); |
| 151 | XFS_ERRORTAG_ATTR_RW(logiodone, XFS_ERRTAG_IODONE_IOERR); |
| 152 | XFS_ERRORTAG_ATTR_RW(stratread, XFS_ERRTAG_STRATREAD_IOERR); |
| 153 | XFS_ERRORTAG_ATTR_RW(stratcmpl, XFS_ERRTAG_STRATCMPL_IOERR); |
| 154 | XFS_ERRORTAG_ATTR_RW(diowrite, XFS_ERRTAG_DIOWRITE_IOERR); |
| 155 | XFS_ERRORTAG_ATTR_RW(bmapifmt, XFS_ERRTAG_BMAPIFORMAT); |
| 156 | XFS_ERRORTAG_ATTR_RW(free_extent, XFS_ERRTAG_FREE_EXTENT); |
| 157 | XFS_ERRORTAG_ATTR_RW(rmap_finish_one, XFS_ERRTAG_RMAP_FINISH_ONE); |
| 158 | XFS_ERRORTAG_ATTR_RW(refcount_continue_update, XFS_ERRTAG_REFCOUNT_CONTINUE_UPDATE); |
| 159 | XFS_ERRORTAG_ATTR_RW(refcount_finish_one, XFS_ERRTAG_REFCOUNT_FINISH_ONE); |
| 160 | XFS_ERRORTAG_ATTR_RW(bmap_finish_one, XFS_ERRTAG_BMAP_FINISH_ONE); |
| 161 | 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] | 162 | XFS_ERRORTAG_ATTR_RW(drop_writes, XFS_ERRTAG_DROP_WRITES); |
Brian Foster | 3e88a00 | 2017-06-27 09:52:32 -0700 | [diff] [blame] | 163 | XFS_ERRORTAG_ATTR_RW(log_bad_crc, XFS_ERRTAG_LOG_BAD_CRC); |
Brian Foster | 7f4d01f | 2017-08-08 18:21:52 -0700 | [diff] [blame] | 164 | XFS_ERRORTAG_ATTR_RW(log_item_pin, XFS_ERRTAG_LOG_ITEM_PIN); |
Brian Foster | 7561d27 | 2017-10-17 14:16:29 -0700 | [diff] [blame] | 165 | XFS_ERRORTAG_ATTR_RW(buf_lru_ref, XFS_ERRTAG_BUF_LRU_REF); |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 166 | XFS_ERRORTAG_ATTR_RW(force_repair, XFS_ERRTAG_FORCE_SCRUB_REPAIR); |
Darrick J. Wong | f467cad | 2018-07-20 09:28:40 -0700 | [diff] [blame] | 167 | XFS_ERRORTAG_ATTR_RW(bad_summary, XFS_ERRTAG_FORCE_SUMMARY_RECALC); |
Darrick J. Wong | 9b24717 | 2019-02-07 10:37:16 -0800 | [diff] [blame] | 168 | XFS_ERRORTAG_ATTR_RW(iunlink_fallback, XFS_ERRTAG_IUNLINK_FALLBACK); |
Brian Foster | 7376d74 | 2020-05-06 13:29:19 -0700 | [diff] [blame] | 169 | XFS_ERRORTAG_ATTR_RW(buf_ioerror, XFS_ERRTAG_BUF_IOERROR); |
Chandan Babu R | f9fa871 | 2021-01-22 16:48:15 -0800 | [diff] [blame] | 170 | XFS_ERRORTAG_ATTR_RW(reduce_max_iextents, XFS_ERRTAG_REDUCE_MAX_IEXTENTS); |
Chandan Babu R | 3015196 | 2021-01-22 16:48:17 -0800 | [diff] [blame] | 171 | XFS_ERRORTAG_ATTR_RW(bmap_alloc_minlen_extent, XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT); |
Gao Xiang | 2b92fae | 2021-03-23 19:05:39 -0700 | [diff] [blame] | 172 | XFS_ERRORTAG_ATTR_RW(ag_resv_fail, XFS_ERRTAG_AG_RESV_FAIL); |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 173 | |
| 174 | static struct attribute *xfs_errortag_attrs[] = { |
| 175 | XFS_ERRORTAG_ATTR_LIST(noerror), |
| 176 | XFS_ERRORTAG_ATTR_LIST(iflush1), |
| 177 | XFS_ERRORTAG_ATTR_LIST(iflush2), |
| 178 | XFS_ERRORTAG_ATTR_LIST(iflush3), |
| 179 | XFS_ERRORTAG_ATTR_LIST(iflush4), |
| 180 | XFS_ERRORTAG_ATTR_LIST(iflush5), |
| 181 | XFS_ERRORTAG_ATTR_LIST(iflush6), |
| 182 | XFS_ERRORTAG_ATTR_LIST(dareadbuf), |
| 183 | XFS_ERRORTAG_ATTR_LIST(btree_chk_lblk), |
| 184 | XFS_ERRORTAG_ATTR_LIST(btree_chk_sblk), |
| 185 | XFS_ERRORTAG_ATTR_LIST(readagf), |
| 186 | XFS_ERRORTAG_ATTR_LIST(readagi), |
| 187 | XFS_ERRORTAG_ATTR_LIST(itobp), |
| 188 | XFS_ERRORTAG_ATTR_LIST(iunlink), |
| 189 | XFS_ERRORTAG_ATTR_LIST(iunlinkrm), |
| 190 | XFS_ERRORTAG_ATTR_LIST(dirinovalid), |
| 191 | XFS_ERRORTAG_ATTR_LIST(bulkstat), |
| 192 | XFS_ERRORTAG_ATTR_LIST(logiodone), |
| 193 | XFS_ERRORTAG_ATTR_LIST(stratread), |
| 194 | XFS_ERRORTAG_ATTR_LIST(stratcmpl), |
| 195 | XFS_ERRORTAG_ATTR_LIST(diowrite), |
| 196 | XFS_ERRORTAG_ATTR_LIST(bmapifmt), |
| 197 | XFS_ERRORTAG_ATTR_LIST(free_extent), |
| 198 | XFS_ERRORTAG_ATTR_LIST(rmap_finish_one), |
| 199 | XFS_ERRORTAG_ATTR_LIST(refcount_continue_update), |
| 200 | XFS_ERRORTAG_ATTR_LIST(refcount_finish_one), |
| 201 | XFS_ERRORTAG_ATTR_LIST(bmap_finish_one), |
| 202 | XFS_ERRORTAG_ATTR_LIST(ag_resv_critical), |
Darrick J. Wong | f8c4725 | 2017-06-20 17:54:48 -0700 | [diff] [blame] | 203 | XFS_ERRORTAG_ATTR_LIST(drop_writes), |
Brian Foster | 3e88a00 | 2017-06-27 09:52:32 -0700 | [diff] [blame] | 204 | XFS_ERRORTAG_ATTR_LIST(log_bad_crc), |
Brian Foster | 7f4d01f | 2017-08-08 18:21:52 -0700 | [diff] [blame] | 205 | XFS_ERRORTAG_ATTR_LIST(log_item_pin), |
Brian Foster | 7561d27 | 2017-10-17 14:16:29 -0700 | [diff] [blame] | 206 | XFS_ERRORTAG_ATTR_LIST(buf_lru_ref), |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 207 | XFS_ERRORTAG_ATTR_LIST(force_repair), |
Darrick J. Wong | f467cad | 2018-07-20 09:28:40 -0700 | [diff] [blame] | 208 | XFS_ERRORTAG_ATTR_LIST(bad_summary), |
Darrick J. Wong | 9b24717 | 2019-02-07 10:37:16 -0800 | [diff] [blame] | 209 | XFS_ERRORTAG_ATTR_LIST(iunlink_fallback), |
Brian Foster | 7376d74 | 2020-05-06 13:29:19 -0700 | [diff] [blame] | 210 | XFS_ERRORTAG_ATTR_LIST(buf_ioerror), |
Chandan Babu R | f9fa871 | 2021-01-22 16:48:15 -0800 | [diff] [blame] | 211 | XFS_ERRORTAG_ATTR_LIST(reduce_max_iextents), |
Chandan Babu R | 3015196 | 2021-01-22 16:48:17 -0800 | [diff] [blame] | 212 | XFS_ERRORTAG_ATTR_LIST(bmap_alloc_minlen_extent), |
Gao Xiang | 2b92fae | 2021-03-23 19:05:39 -0700 | [diff] [blame] | 213 | XFS_ERRORTAG_ATTR_LIST(ag_resv_fail), |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 214 | NULL, |
| 215 | }; |
Greg Kroah-Hartman | 219aac5 | 2022-01-03 11:10:18 -0800 | [diff] [blame] | 216 | ATTRIBUTE_GROUPS(xfs_errortag); |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 217 | |
Christoph Hellwig | 4371155 | 2017-11-06 11:53:59 -0800 | [diff] [blame] | 218 | static struct kobj_type xfs_errortag_ktype = { |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 219 | .release = xfs_sysfs_release, |
| 220 | .sysfs_ops = &xfs_errortag_sysfs_ops, |
Greg Kroah-Hartman | 219aac5 | 2022-01-03 11:10:18 -0800 | [diff] [blame] | 221 | .default_groups = xfs_errortag_groups, |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 222 | }; |
| 223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | int |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 225 | xfs_errortag_init( |
| 226 | struct xfs_mount *mp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 228 | mp->m_errortag = kmem_zalloc(sizeof(unsigned int) * XFS_ERRTAG_MAX, |
Tetsuo Handa | 707e0dd | 2019-08-26 12:06:22 -0700 | [diff] [blame] | 229 | KM_MAYFAIL); |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 230 | if (!mp->m_errortag) |
| 231 | return -ENOMEM; |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 232 | |
| 233 | return xfs_sysfs_init(&mp->m_errortag_kobj, &xfs_errortag_ktype, |
| 234 | &mp->m_kobj, "errortag"); |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 237 | void |
| 238 | xfs_errortag_del( |
| 239 | struct xfs_mount *mp) |
| 240 | { |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 241 | xfs_sysfs_del(&mp->m_errortag_kobj); |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 242 | kmem_free(mp->m_errortag); |
| 243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 245 | bool |
| 246 | xfs_errortag_test( |
| 247 | struct xfs_mount *mp, |
| 248 | const char *expression, |
| 249 | const char *file, |
| 250 | int line, |
| 251 | unsigned int error_tag) |
| 252 | { |
| 253 | unsigned int randfactor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Carlos Maiolino | d04c241 | 2017-06-30 09:46:07 -0700 | [diff] [blame] | 255 | /* |
| 256 | * To be able to use error injection anywhere, we need to ensure error |
| 257 | * injection mechanism is already initialized. |
| 258 | * |
| 259 | * Code paths like I/O completion can be called before the |
| 260 | * initialization is complete, but be able to inject errors in such |
| 261 | * places is still useful. |
| 262 | */ |
| 263 | if (!mp->m_errortag) |
| 264 | return false; |
| 265 | |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 266 | ASSERT(error_tag < XFS_ERRTAG_MAX); |
| 267 | randfactor = mp->m_errortag[error_tag]; |
| 268 | if (!randfactor || prandom_u32() % randfactor) |
| 269 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 271 | xfs_warn_ratelimited(mp, |
| 272 | "Injecting error (%s) at file %s, line %d, on filesystem \"%s\"", |
Ian Kent | e1d3d21 | 2019-11-04 13:58:40 -0800 | [diff] [blame] | 273 | expression, file, line, mp->m_super->s_id); |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 274 | return true; |
| 275 | } |
| 276 | |
| 277 | int |
Darrick J. Wong | c684010 | 2017-06-20 17:54:47 -0700 | [diff] [blame] | 278 | xfs_errortag_get( |
| 279 | struct xfs_mount *mp, |
| 280 | unsigned int error_tag) |
| 281 | { |
| 282 | if (error_tag >= XFS_ERRTAG_MAX) |
| 283 | return -EINVAL; |
| 284 | |
| 285 | return mp->m_errortag[error_tag]; |
| 286 | } |
| 287 | |
| 288 | int |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 289 | xfs_errortag_set( |
| 290 | struct xfs_mount *mp, |
| 291 | unsigned int error_tag, |
| 292 | unsigned int tag_value) |
| 293 | { |
| 294 | if (error_tag >= XFS_ERRTAG_MAX) |
| 295 | return -EINVAL; |
| 296 | |
| 297 | mp->m_errortag[error_tag] = tag_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | int |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 302 | xfs_errortag_add( |
| 303 | struct xfs_mount *mp, |
| 304 | unsigned int error_tag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | { |
Gao Xiang | b2c2974 | 2021-03-22 09:52:02 -0700 | [diff] [blame] | 306 | BUILD_BUG_ON(ARRAY_SIZE(xfs_errortag_random_default) != XFS_ERRTAG_MAX); |
| 307 | |
Darrick J. Wong | 128f24d | 2016-06-21 11:53:28 +1000 | [diff] [blame] | 308 | if (error_tag >= XFS_ERRTAG_MAX) |
| 309 | return -EINVAL; |
| 310 | |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 311 | return xfs_errortag_set(mp, error_tag, |
| 312 | xfs_errortag_random_default[error_tag]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | int |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 316 | xfs_errortag_clearall( |
| 317 | struct xfs_mount *mp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | { |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 319 | memset(mp->m_errortag, 0, sizeof(unsigned int) * XFS_ERRTAG_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | return 0; |
| 321 | } |
Christoph Hellwig | 1550d0b | 2008-08-13 16:17:37 +1000 | [diff] [blame] | 322 | #endif /* DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | void |
| 325 | xfs_error_report( |
Alex Elder | a0e856b | 2010-04-13 15:22:08 +1000 | [diff] [blame] | 326 | const char *tag, |
| 327 | int level, |
| 328 | struct xfs_mount *mp, |
| 329 | const char *filename, |
| 330 | int linenum, |
Darrick J. Wong | d9418ed | 2018-01-08 10:51:25 -0800 | [diff] [blame] | 331 | xfs_failaddr_t failaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | { |
| 333 | if (level <= xfs_error_level) { |
Dave Chinner | 6a19d93 | 2011-03-07 10:02:35 +1100 | [diff] [blame] | 334 | xfs_alert_tag(mp, XFS_PTAG_ERROR_REPORT, |
Scott Wood | 65dd297 | 2015-03-25 14:56:21 +1100 | [diff] [blame] | 335 | "Internal error %s at line %d of file %s. Caller %pS", |
Darrick J. Wong | d9418ed | 2018-01-08 10:51:25 -0800 | [diff] [blame] | 336 | tag, linenum, filename, failaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
| 338 | xfs_stack_trace(); |
| 339 | } |
| 340 | } |
| 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | void |
| 343 | xfs_corruption_error( |
Alex Elder | a0e856b | 2010-04-13 15:22:08 +1000 | [diff] [blame] | 344 | const char *tag, |
| 345 | int level, |
| 346 | struct xfs_mount *mp, |
Darrick J. Wong | d243b89 | 2019-11-02 09:40:36 -0700 | [diff] [blame] | 347 | const void *buf, |
Darrick J. Wong | 2551a53 | 2018-06-04 10:23:54 -0700 | [diff] [blame] | 348 | size_t bufsize, |
Alex Elder | a0e856b | 2010-04-13 15:22:08 +1000 | [diff] [blame] | 349 | const char *filename, |
| 350 | int linenum, |
Darrick J. Wong | d9418ed | 2018-01-08 10:51:25 -0800 | [diff] [blame] | 351 | xfs_failaddr_t failaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | { |
Darrick J. Wong | 6519f70 | 2019-11-17 10:36:52 -0800 | [diff] [blame] | 353 | if (buf && level <= xfs_error_level) |
Darrick J. Wong | 2551a53 | 2018-06-04 10:23:54 -0700 | [diff] [blame] | 354 | xfs_hex_dump(buf, bufsize); |
Darrick J. Wong | d9418ed | 2018-01-08 10:51:25 -0800 | [diff] [blame] | 355 | xfs_error_report(tag, level, mp, filename, linenum, failaddr); |
Dave Chinner | 65333b4 | 2011-03-07 10:03:35 +1100 | [diff] [blame] | 356 | xfs_alert(mp, "Corruption detected. Unmount and run xfs_repair"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
Eric Sandeen | ca23f8f | 2014-02-27 15:21:07 +1100 | [diff] [blame] | 358 | |
| 359 | /* |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 360 | * Complain about the kinds of metadata corruption that we can't detect from a |
| 361 | * verifier, such as incorrect inter-block relationship data. Does not set |
| 362 | * bp->b_error. |
Darrick J. Wong | 8d57c21 | 2020-03-11 10:37:54 -0700 | [diff] [blame] | 363 | * |
| 364 | * Call xfs_buf_mark_corrupt, not this function. |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 365 | */ |
| 366 | void |
| 367 | xfs_buf_corruption_error( |
Darrick J. Wong | e83cf87 | 2020-03-11 10:37:54 -0700 | [diff] [blame] | 368 | struct xfs_buf *bp, |
| 369 | xfs_failaddr_t fa) |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 370 | { |
| 371 | struct xfs_mount *mp = bp->b_mount; |
| 372 | |
| 373 | xfs_alert_tag(mp, XFS_PTAG_VERIFIER_ERROR, |
| 374 | "Metadata corruption detected at %pS, %s block 0x%llx", |
Dave Chinner | 9343ee7 | 2021-08-18 18:47:05 -0700 | [diff] [blame] | 375 | fa, bp->b_ops->name, xfs_buf_daddr(bp)); |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 376 | |
| 377 | xfs_alert(mp, "Unmount and run xfs_repair"); |
| 378 | |
| 379 | if (xfs_error_level >= XFS_ERRLEVEL_HIGH) |
| 380 | xfs_stack_trace(); |
| 381 | } |
| 382 | |
| 383 | /* |
Eric Sandeen | ca23f8f | 2014-02-27 15:21:07 +1100 | [diff] [blame] | 384 | * Warnings specifically for verifier errors. Differentiate CRC vs. invalid |
| 385 | * values, and omit the stack trace unless the error level is tuned high. |
| 386 | */ |
| 387 | void |
Darrick J. Wong | 6edb181 | 2018-03-23 10:06:53 -0700 | [diff] [blame] | 388 | xfs_buf_verifier_error( |
| 389 | struct xfs_buf *bp, |
| 390 | int error, |
| 391 | const char *name, |
Darrick J. Wong | d243b89 | 2019-11-02 09:40:36 -0700 | [diff] [blame] | 392 | const void *buf, |
Darrick J. Wong | 6edb181 | 2018-03-23 10:06:53 -0700 | [diff] [blame] | 393 | size_t bufsz, |
| 394 | xfs_failaddr_t failaddr) |
| 395 | { |
Christoph Hellwig | dbd329f1 | 2019-06-28 19:27:29 -0700 | [diff] [blame] | 396 | struct xfs_mount *mp = bp->b_mount; |
Darrick J. Wong | 6edb181 | 2018-03-23 10:06:53 -0700 | [diff] [blame] | 397 | xfs_failaddr_t fa; |
| 398 | int sz; |
| 399 | |
| 400 | fa = failaddr ? failaddr : __return_address; |
| 401 | __xfs_buf_ioerror(bp, error, fa); |
| 402 | |
Marco Benatto | d519da4 | 2019-02-01 09:12:20 -0800 | [diff] [blame] | 403 | xfs_alert_tag(mp, XFS_PTAG_VERIFIER_ERROR, |
| 404 | "Metadata %s detected at %pS, %s block 0x%llx %s", |
Darrick J. Wong | 6edb181 | 2018-03-23 10:06:53 -0700 | [diff] [blame] | 405 | bp->b_error == -EFSBADCRC ? "CRC error" : "corruption", |
Dave Chinner | 9343ee7 | 2021-08-18 18:47:05 -0700 | [diff] [blame] | 406 | fa, bp->b_ops->name, xfs_buf_daddr(bp), name); |
Darrick J. Wong | 6edb181 | 2018-03-23 10:06:53 -0700 | [diff] [blame] | 407 | |
| 408 | xfs_alert(mp, "Unmount and run xfs_repair"); |
| 409 | |
| 410 | if (xfs_error_level >= XFS_ERRLEVEL_LOW) { |
| 411 | sz = min_t(size_t, XFS_CORRUPTION_DUMP_LEN, bufsz); |
| 412 | xfs_alert(mp, "First %d bytes of corrupted metadata buffer:", |
| 413 | sz); |
| 414 | xfs_hex_dump(buf, sz); |
| 415 | } |
| 416 | |
| 417 | if (xfs_error_level >= XFS_ERRLEVEL_HIGH) |
| 418 | xfs_stack_trace(); |
| 419 | } |
| 420 | |
| 421 | /* |
| 422 | * Warnings specifically for verifier errors. Differentiate CRC vs. invalid |
| 423 | * values, and omit the stack trace unless the error level is tuned high. |
| 424 | */ |
| 425 | void |
Eric Sandeen | ca23f8f | 2014-02-27 15:21:07 +1100 | [diff] [blame] | 426 | xfs_verifier_error( |
Darrick J. Wong | 31ca03c | 2018-01-08 10:51:02 -0800 | [diff] [blame] | 427 | struct xfs_buf *bp, |
Darrick J. Wong | bc1a09b | 2018-01-08 10:51:03 -0800 | [diff] [blame] | 428 | int error, |
| 429 | xfs_failaddr_t failaddr) |
Eric Sandeen | ca23f8f | 2014-02-27 15:21:07 +1100 | [diff] [blame] | 430 | { |
Darrick J. Wong | 6edb181 | 2018-03-23 10:06:53 -0700 | [diff] [blame] | 431 | return xfs_buf_verifier_error(bp, error, "", xfs_buf_offset(bp, 0), |
| 432 | XFS_CORRUPTION_DUMP_LEN, failaddr); |
Eric Sandeen | ca23f8f | 2014-02-27 15:21:07 +1100 | [diff] [blame] | 433 | } |
Darrick J. Wong | 22431bf | 2018-01-22 18:09:48 -0800 | [diff] [blame] | 434 | |
| 435 | /* |
| 436 | * Warnings for inode corruption problems. Don't bother with the stack |
| 437 | * trace unless the error level is turned up high. |
| 438 | */ |
| 439 | void |
| 440 | xfs_inode_verifier_error( |
| 441 | struct xfs_inode *ip, |
| 442 | int error, |
| 443 | const char *name, |
Darrick J. Wong | d243b89 | 2019-11-02 09:40:36 -0700 | [diff] [blame] | 444 | const void *buf, |
Darrick J. Wong | 22431bf | 2018-01-22 18:09:48 -0800 | [diff] [blame] | 445 | size_t bufsz, |
| 446 | xfs_failaddr_t failaddr) |
| 447 | { |
| 448 | struct xfs_mount *mp = ip->i_mount; |
| 449 | xfs_failaddr_t fa; |
| 450 | int sz; |
| 451 | |
| 452 | fa = failaddr ? failaddr : __return_address; |
| 453 | |
| 454 | xfs_alert(mp, "Metadata %s detected at %pS, inode 0x%llx %s", |
| 455 | error == -EFSBADCRC ? "CRC error" : "corruption", |
| 456 | fa, ip->i_ino, name); |
| 457 | |
| 458 | xfs_alert(mp, "Unmount and run xfs_repair"); |
| 459 | |
| 460 | if (buf && xfs_error_level >= XFS_ERRLEVEL_LOW) { |
| 461 | sz = min_t(size_t, XFS_CORRUPTION_DUMP_LEN, bufsz); |
| 462 | xfs_alert(mp, "First %d bytes of corrupted metadata buffer:", |
| 463 | sz); |
| 464 | xfs_hex_dump(buf, sz); |
| 465 | } |
| 466 | |
| 467 | if (xfs_error_level >= XFS_ERRLEVEL_HIGH) |
| 468 | xfs_stack_trace(); |
| 469 | } |