Brian Foster | a31b1d3 | 2014-07-15 08:07:01 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 Red Hat, Inc. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 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 |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 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. |
| 13 | * |
| 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 |
| 17 | */ |
| 18 | |
| 19 | #include "xfs.h" |
Carlos Maiolino | 192852b | 2016-05-18 10:58:51 +1000 | [diff] [blame] | 20 | #include "xfs_shared.h" |
Brian Foster | 801cc4e | 2016-03-15 11:42:44 +1100 | [diff] [blame] | 21 | #include "xfs_format.h" |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 22 | #include "xfs_log_format.h" |
Brian Foster | 801cc4e | 2016-03-15 11:42:44 +1100 | [diff] [blame] | 23 | #include "xfs_trans_resv.h" |
Carlos Maiolino | 192852b | 2016-05-18 10:58:51 +1000 | [diff] [blame] | 24 | #include "xfs_sysfs.h" |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 25 | #include "xfs_log.h" |
| 26 | #include "xfs_log_priv.h" |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 27 | #include "xfs_stats.h" |
Brian Foster | 801cc4e | 2016-03-15 11:42:44 +1100 | [diff] [blame] | 28 | #include "xfs_mount.h" |
Brian Foster | a31b1d3 | 2014-07-15 08:07:01 +1000 | [diff] [blame] | 29 | |
| 30 | struct xfs_sysfs_attr { |
| 31 | struct attribute attr; |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 32 | ssize_t (*show)(struct kobject *kobject, char *buf); |
| 33 | ssize_t (*store)(struct kobject *kobject, const char *buf, |
| 34 | size_t count); |
Brian Foster | a31b1d3 | 2014-07-15 08:07:01 +1000 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | static inline struct xfs_sysfs_attr * |
| 38 | to_attr(struct attribute *attr) |
| 39 | { |
| 40 | return container_of(attr, struct xfs_sysfs_attr, attr); |
| 41 | } |
| 42 | |
| 43 | #define XFS_SYSFS_ATTR_RW(name) \ |
| 44 | static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RW(name) |
| 45 | #define XFS_SYSFS_ATTR_RO(name) \ |
| 46 | static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RO(name) |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 47 | #define XFS_SYSFS_ATTR_WO(name) \ |
| 48 | static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_WO(name) |
Brian Foster | a31b1d3 | 2014-07-15 08:07:01 +1000 | [diff] [blame] | 49 | |
| 50 | #define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr |
| 51 | |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 52 | STATIC ssize_t |
| 53 | xfs_sysfs_object_show( |
| 54 | struct kobject *kobject, |
| 55 | struct attribute *attr, |
| 56 | char *buf) |
| 57 | { |
| 58 | struct xfs_sysfs_attr *xfs_attr = to_attr(attr); |
| 59 | |
| 60 | return xfs_attr->show ? xfs_attr->show(kobject, buf) : 0; |
| 61 | } |
| 62 | |
| 63 | STATIC ssize_t |
| 64 | xfs_sysfs_object_store( |
| 65 | struct kobject *kobject, |
| 66 | struct attribute *attr, |
| 67 | const char *buf, |
| 68 | size_t count) |
| 69 | { |
| 70 | struct xfs_sysfs_attr *xfs_attr = to_attr(attr); |
| 71 | |
| 72 | return xfs_attr->store ? xfs_attr->store(kobject, buf, count) : 0; |
| 73 | } |
| 74 | |
| 75 | static const struct sysfs_ops xfs_sysfs_ops = { |
| 76 | .show = xfs_sysfs_object_show, |
| 77 | .store = xfs_sysfs_object_store, |
| 78 | }; |
| 79 | |
Brian Foster | 801cc4e | 2016-03-15 11:42:44 +1100 | [diff] [blame] | 80 | /* |
| 81 | * xfs_mount kobject. The mp kobject also serves as the per-mount parent object |
| 82 | * that is identified by the fsname under sysfs. |
| 83 | */ |
| 84 | |
| 85 | static inline struct xfs_mount * |
| 86 | to_mp(struct kobject *kobject) |
| 87 | { |
| 88 | struct xfs_kobj *kobj = to_kobj(kobject); |
| 89 | |
| 90 | return container_of(kobj, struct xfs_mount, m_kobj); |
| 91 | } |
| 92 | |
Brian Foster | 801cc4e | 2016-03-15 11:42:44 +1100 | [diff] [blame] | 93 | static struct attribute *xfs_mp_attrs[] = { |
Brian Foster | 801cc4e | 2016-03-15 11:42:44 +1100 | [diff] [blame] | 94 | NULL, |
| 95 | }; |
| 96 | |
| 97 | struct kobj_type xfs_mp_ktype = { |
| 98 | .release = xfs_sysfs_release, |
| 99 | .sysfs_ops = &xfs_sysfs_ops, |
| 100 | .default_attrs = xfs_mp_attrs, |
| 101 | }; |
| 102 | |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 103 | #ifdef DEBUG |
| 104 | /* debug */ |
| 105 | |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 106 | STATIC ssize_t |
Brian Foster | ccdab3d | 2017-06-14 21:29:12 -0700 | [diff] [blame] | 107 | bug_on_assert_store( |
| 108 | struct kobject *kobject, |
| 109 | const char *buf, |
| 110 | size_t count) |
| 111 | { |
| 112 | int ret; |
| 113 | int val; |
| 114 | |
| 115 | ret = kstrtoint(buf, 0, &val); |
| 116 | if (ret) |
| 117 | return ret; |
| 118 | |
| 119 | if (val == 1) |
| 120 | xfs_globals.bug_on_assert = true; |
| 121 | else if (val == 0) |
| 122 | xfs_globals.bug_on_assert = false; |
| 123 | else |
| 124 | return -EINVAL; |
| 125 | |
| 126 | return count; |
| 127 | } |
| 128 | |
| 129 | STATIC ssize_t |
| 130 | bug_on_assert_show( |
| 131 | struct kobject *kobject, |
| 132 | char *buf) |
| 133 | { |
| 134 | return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.bug_on_assert ? 1 : 0); |
| 135 | } |
| 136 | XFS_SYSFS_ATTR_RW(bug_on_assert); |
| 137 | |
| 138 | STATIC ssize_t |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 139 | log_recovery_delay_store( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 140 | struct kobject *kobject, |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 141 | const char *buf, |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 142 | size_t count) |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 143 | { |
| 144 | int ret; |
| 145 | int val; |
| 146 | |
| 147 | ret = kstrtoint(buf, 0, &val); |
| 148 | if (ret) |
| 149 | return ret; |
| 150 | |
| 151 | if (val < 0 || val > 60) |
| 152 | return -EINVAL; |
| 153 | |
| 154 | xfs_globals.log_recovery_delay = val; |
| 155 | |
| 156 | return count; |
| 157 | } |
| 158 | |
| 159 | STATIC ssize_t |
| 160 | log_recovery_delay_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 161 | struct kobject *kobject, |
| 162 | char *buf) |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 163 | { |
| 164 | return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.log_recovery_delay); |
| 165 | } |
| 166 | XFS_SYSFS_ATTR_RW(log_recovery_delay); |
| 167 | |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 168 | static struct attribute *xfs_dbg_attrs[] = { |
Brian Foster | ccdab3d | 2017-06-14 21:29:12 -0700 | [diff] [blame] | 169 | ATTR_LIST(bug_on_assert), |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 170 | ATTR_LIST(log_recovery_delay), |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 171 | NULL, |
| 172 | }; |
| 173 | |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 174 | struct kobj_type xfs_dbg_ktype = { |
| 175 | .release = xfs_sysfs_release, |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 176 | .sysfs_ops = &xfs_sysfs_ops, |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 177 | .default_attrs = xfs_dbg_attrs, |
| 178 | }; |
| 179 | |
| 180 | #endif /* DEBUG */ |
| 181 | |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 182 | /* stats */ |
| 183 | |
Bill O'Donnell | 80529c4 | 2015-10-12 05:19:45 +1100 | [diff] [blame] | 184 | static inline struct xstats * |
| 185 | to_xstats(struct kobject *kobject) |
| 186 | { |
| 187 | struct xfs_kobj *kobj = to_kobj(kobject); |
| 188 | |
| 189 | return container_of(kobj, struct xstats, xs_kobj); |
| 190 | } |
| 191 | |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 192 | STATIC ssize_t |
| 193 | stats_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 194 | struct kobject *kobject, |
| 195 | char *buf) |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 196 | { |
Bill O'Donnell | 80529c4 | 2015-10-12 05:19:45 +1100 | [diff] [blame] | 197 | struct xstats *stats = to_xstats(kobject); |
| 198 | |
| 199 | return xfs_stats_format(stats->xs_stats, buf); |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 200 | } |
| 201 | XFS_SYSFS_ATTR_RO(stats); |
| 202 | |
| 203 | STATIC ssize_t |
| 204 | stats_clear_store( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 205 | struct kobject *kobject, |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 206 | const char *buf, |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 207 | size_t count) |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 208 | { |
| 209 | int ret; |
| 210 | int val; |
Bill O'Donnell | 80529c4 | 2015-10-12 05:19:45 +1100 | [diff] [blame] | 211 | struct xstats *stats = to_xstats(kobject); |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 212 | |
| 213 | ret = kstrtoint(buf, 0, &val); |
| 214 | if (ret) |
| 215 | return ret; |
| 216 | |
| 217 | if (val != 1) |
| 218 | return -EINVAL; |
Bill O'Donnell | 80529c4 | 2015-10-12 05:19:45 +1100 | [diff] [blame] | 219 | |
| 220 | xfs_stats_clearall(stats->xs_stats); |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 221 | return count; |
| 222 | } |
| 223 | XFS_SYSFS_ATTR_WO(stats_clear); |
| 224 | |
| 225 | static struct attribute *xfs_stats_attrs[] = { |
| 226 | ATTR_LIST(stats), |
| 227 | ATTR_LIST(stats_clear), |
| 228 | NULL, |
| 229 | }; |
| 230 | |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 231 | struct kobj_type xfs_stats_ktype = { |
| 232 | .release = xfs_sysfs_release, |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 233 | .sysfs_ops = &xfs_sysfs_ops, |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 234 | .default_attrs = xfs_stats_attrs, |
| 235 | }; |
| 236 | |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 237 | /* xlog */ |
| 238 | |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 239 | static inline struct xlog * |
| 240 | to_xlog(struct kobject *kobject) |
| 241 | { |
| 242 | struct xfs_kobj *kobj = to_kobj(kobject); |
| 243 | |
| 244 | return container_of(kobj, struct xlog, l_kobj); |
| 245 | } |
| 246 | |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 247 | STATIC ssize_t |
| 248 | log_head_lsn_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 249 | struct kobject *kobject, |
| 250 | char *buf) |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 251 | { |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 252 | int cycle; |
| 253 | int block; |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 254 | struct xlog *log = to_xlog(kobject); |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 255 | |
| 256 | spin_lock(&log->l_icloglock); |
| 257 | cycle = log->l_curr_cycle; |
| 258 | block = log->l_curr_block; |
| 259 | spin_unlock(&log->l_icloglock); |
| 260 | |
| 261 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block); |
| 262 | } |
| 263 | XFS_SYSFS_ATTR_RO(log_head_lsn); |
| 264 | |
| 265 | STATIC ssize_t |
| 266 | log_tail_lsn_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 267 | struct kobject *kobject, |
| 268 | char *buf) |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 269 | { |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 270 | int cycle; |
| 271 | int block; |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 272 | struct xlog *log = to_xlog(kobject); |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 273 | |
| 274 | xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block); |
| 275 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block); |
| 276 | } |
| 277 | XFS_SYSFS_ATTR_RO(log_tail_lsn); |
| 278 | |
| 279 | STATIC ssize_t |
| 280 | reserve_grant_head_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 281 | struct kobject *kobject, |
| 282 | char *buf) |
| 283 | |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 284 | { |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 285 | int cycle; |
| 286 | int bytes; |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 287 | struct xlog *log = to_xlog(kobject); |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 288 | |
| 289 | xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes); |
| 290 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes); |
| 291 | } |
| 292 | XFS_SYSFS_ATTR_RO(reserve_grant_head); |
| 293 | |
| 294 | STATIC ssize_t |
| 295 | write_grant_head_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 296 | struct kobject *kobject, |
| 297 | char *buf) |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 298 | { |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 299 | int cycle; |
| 300 | int bytes; |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 301 | struct xlog *log = to_xlog(kobject); |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 302 | |
| 303 | xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes); |
| 304 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes); |
| 305 | } |
| 306 | XFS_SYSFS_ATTR_RO(write_grant_head); |
| 307 | |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 308 | static struct attribute *xfs_log_attrs[] = { |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 309 | ATTR_LIST(log_head_lsn), |
| 310 | ATTR_LIST(log_tail_lsn), |
| 311 | ATTR_LIST(reserve_grant_head), |
| 312 | ATTR_LIST(write_grant_head), |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 313 | NULL, |
| 314 | }; |
| 315 | |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 316 | struct kobj_type xfs_log_ktype = { |
| 317 | .release = xfs_sysfs_release, |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 318 | .sysfs_ops = &xfs_sysfs_ops, |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 319 | .default_attrs = xfs_log_attrs, |
| 320 | }; |
Carlos Maiolino | 192852b | 2016-05-18 10:58:51 +1000 | [diff] [blame] | 321 | |
| 322 | /* |
| 323 | * Metadata IO error configuration |
| 324 | * |
| 325 | * The sysfs structure here is: |
| 326 | * ...xfs/<dev>/error/<class>/<errno>/<error_attrs> |
| 327 | * |
| 328 | * where <class> allows us to discriminate between data IO and metadata IO, |
| 329 | * and any other future type of IO (e.g. special inode or directory error |
| 330 | * handling) we care to support. |
| 331 | */ |
Carlos Maiolino | 192852b | 2016-05-18 10:58:51 +1000 | [diff] [blame] | 332 | static inline struct xfs_error_cfg * |
| 333 | to_error_cfg(struct kobject *kobject) |
| 334 | { |
| 335 | struct xfs_kobj *kobj = to_kobj(kobject); |
| 336 | return container_of(kobj, struct xfs_error_cfg, kobj); |
| 337 | } |
| 338 | |
Carlos Maiolino | e6b3bb7 | 2016-05-18 11:11:27 +1000 | [diff] [blame] | 339 | static inline struct xfs_mount * |
| 340 | err_to_mp(struct kobject *kobject) |
| 341 | { |
| 342 | struct xfs_kobj *kobj = to_kobj(kobject); |
| 343 | return container_of(kobj, struct xfs_mount, m_error_kobj); |
| 344 | } |
| 345 | |
Carlos Maiolino | a5ea70d | 2016-05-18 11:08:15 +1000 | [diff] [blame] | 346 | static ssize_t |
| 347 | max_retries_show( |
| 348 | struct kobject *kobject, |
| 349 | char *buf) |
| 350 | { |
Eric Sandeen | 7716981 | 2016-09-14 07:51:30 +1000 | [diff] [blame] | 351 | int retries; |
Carlos Maiolino | a5ea70d | 2016-05-18 11:08:15 +1000 | [diff] [blame] | 352 | struct xfs_error_cfg *cfg = to_error_cfg(kobject); |
| 353 | |
Carlos Maiolino | ff97f23 | 2017-01-03 20:34:17 -0800 | [diff] [blame] | 354 | if (cfg->max_retries == XFS_ERR_RETRY_FOREVER) |
Eric Sandeen | 7716981 | 2016-09-14 07:51:30 +1000 | [diff] [blame] | 355 | retries = -1; |
| 356 | else |
| 357 | retries = cfg->max_retries; |
| 358 | |
| 359 | return snprintf(buf, PAGE_SIZE, "%d\n", retries); |
Carlos Maiolino | a5ea70d | 2016-05-18 11:08:15 +1000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | static ssize_t |
| 363 | max_retries_store( |
| 364 | struct kobject *kobject, |
| 365 | const char *buf, |
| 366 | size_t count) |
| 367 | { |
| 368 | struct xfs_error_cfg *cfg = to_error_cfg(kobject); |
| 369 | int ret; |
| 370 | int val; |
| 371 | |
| 372 | ret = kstrtoint(buf, 0, &val); |
| 373 | if (ret) |
| 374 | return ret; |
| 375 | |
| 376 | if (val < -1) |
| 377 | return -EINVAL; |
| 378 | |
Eric Sandeen | 7716981 | 2016-09-14 07:51:30 +1000 | [diff] [blame] | 379 | if (val == -1) |
Carlos Maiolino | ff97f23 | 2017-01-03 20:34:17 -0800 | [diff] [blame] | 380 | cfg->max_retries = XFS_ERR_RETRY_FOREVER; |
Eric Sandeen | 7716981 | 2016-09-14 07:51:30 +1000 | [diff] [blame] | 381 | else |
| 382 | cfg->max_retries = val; |
Carlos Maiolino | a5ea70d | 2016-05-18 11:08:15 +1000 | [diff] [blame] | 383 | return count; |
| 384 | } |
| 385 | XFS_SYSFS_ATTR_RW(max_retries); |
| 386 | |
| 387 | static ssize_t |
| 388 | retry_timeout_seconds_show( |
| 389 | struct kobject *kobject, |
| 390 | char *buf) |
| 391 | { |
Eric Sandeen | 7716981 | 2016-09-14 07:51:30 +1000 | [diff] [blame] | 392 | int timeout; |
Carlos Maiolino | a5ea70d | 2016-05-18 11:08:15 +1000 | [diff] [blame] | 393 | struct xfs_error_cfg *cfg = to_error_cfg(kobject); |
| 394 | |
Eric Sandeen | 7716981 | 2016-09-14 07:51:30 +1000 | [diff] [blame] | 395 | if (cfg->retry_timeout == XFS_ERR_RETRY_FOREVER) |
| 396 | timeout = -1; |
| 397 | else |
| 398 | timeout = jiffies_to_msecs(cfg->retry_timeout) / MSEC_PER_SEC; |
| 399 | |
| 400 | return snprintf(buf, PAGE_SIZE, "%d\n", timeout); |
Carlos Maiolino | a5ea70d | 2016-05-18 11:08:15 +1000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | static ssize_t |
| 404 | retry_timeout_seconds_store( |
| 405 | struct kobject *kobject, |
| 406 | const char *buf, |
| 407 | size_t count) |
| 408 | { |
| 409 | struct xfs_error_cfg *cfg = to_error_cfg(kobject); |
| 410 | int ret; |
| 411 | int val; |
| 412 | |
| 413 | ret = kstrtoint(buf, 0, &val); |
| 414 | if (ret) |
| 415 | return ret; |
| 416 | |
Eric Sandeen | 7716981 | 2016-09-14 07:51:30 +1000 | [diff] [blame] | 417 | /* 1 day timeout maximum, -1 means infinite */ |
| 418 | if (val < -1 || val > 86400) |
Carlos Maiolino | a5ea70d | 2016-05-18 11:08:15 +1000 | [diff] [blame] | 419 | return -EINVAL; |
| 420 | |
Eric Sandeen | 7716981 | 2016-09-14 07:51:30 +1000 | [diff] [blame] | 421 | if (val == -1) |
| 422 | cfg->retry_timeout = XFS_ERR_RETRY_FOREVER; |
| 423 | else { |
| 424 | cfg->retry_timeout = msecs_to_jiffies(val * MSEC_PER_SEC); |
| 425 | ASSERT(msecs_to_jiffies(val * MSEC_PER_SEC) < LONG_MAX); |
| 426 | } |
Carlos Maiolino | a5ea70d | 2016-05-18 11:08:15 +1000 | [diff] [blame] | 427 | return count; |
| 428 | } |
| 429 | XFS_SYSFS_ATTR_RW(retry_timeout_seconds); |
| 430 | |
Carlos Maiolino | e6b3bb7 | 2016-05-18 11:11:27 +1000 | [diff] [blame] | 431 | static ssize_t |
| 432 | fail_at_unmount_show( |
| 433 | struct kobject *kobject, |
| 434 | char *buf) |
| 435 | { |
| 436 | struct xfs_mount *mp = err_to_mp(kobject); |
| 437 | |
| 438 | return snprintf(buf, PAGE_SIZE, "%d\n", mp->m_fail_unmount); |
| 439 | } |
| 440 | |
| 441 | static ssize_t |
| 442 | fail_at_unmount_store( |
| 443 | struct kobject *kobject, |
| 444 | const char *buf, |
| 445 | size_t count) |
| 446 | { |
| 447 | struct xfs_mount *mp = err_to_mp(kobject); |
| 448 | int ret; |
| 449 | int val; |
| 450 | |
| 451 | ret = kstrtoint(buf, 0, &val); |
| 452 | if (ret) |
| 453 | return ret; |
| 454 | |
| 455 | if (val < 0 || val > 1) |
| 456 | return -EINVAL; |
| 457 | |
| 458 | mp->m_fail_unmount = val; |
| 459 | return count; |
| 460 | } |
| 461 | XFS_SYSFS_ATTR_RW(fail_at_unmount); |
| 462 | |
Carlos Maiolino | a5ea70d | 2016-05-18 11:08:15 +1000 | [diff] [blame] | 463 | static struct attribute *xfs_error_attrs[] = { |
| 464 | ATTR_LIST(max_retries), |
| 465 | ATTR_LIST(retry_timeout_seconds), |
| 466 | NULL, |
| 467 | }; |
| 468 | |
| 469 | |
Eric Biggers | f1b8243 | 2016-10-20 15:42:30 +1100 | [diff] [blame] | 470 | static struct kobj_type xfs_error_cfg_ktype = { |
Carlos Maiolino | 192852b | 2016-05-18 10:58:51 +1000 | [diff] [blame] | 471 | .release = xfs_sysfs_release, |
| 472 | .sysfs_ops = &xfs_sysfs_ops, |
| 473 | .default_attrs = xfs_error_attrs, |
| 474 | }; |
| 475 | |
Eric Biggers | f1b8243 | 2016-10-20 15:42:30 +1100 | [diff] [blame] | 476 | static struct kobj_type xfs_error_ktype = { |
Carlos Maiolino | 192852b | 2016-05-18 10:58:51 +1000 | [diff] [blame] | 477 | .release = xfs_sysfs_release, |
Carlos Maiolino | e6b3bb7 | 2016-05-18 11:11:27 +1000 | [diff] [blame] | 478 | .sysfs_ops = &xfs_sysfs_ops, |
Carlos Maiolino | 192852b | 2016-05-18 10:58:51 +1000 | [diff] [blame] | 479 | }; |
| 480 | |
Carlos Maiolino | ef6a50f | 2016-05-18 11:06:44 +1000 | [diff] [blame] | 481 | /* |
| 482 | * Error initialization tables. These need to be ordered in the same |
| 483 | * order as the enums used to index the array. All class init tables need to |
| 484 | * define a "default" behaviour as the first entry, all other entries can be |
| 485 | * empty. |
| 486 | */ |
| 487 | struct xfs_error_init { |
| 488 | char *name; |
| 489 | int max_retries; |
Carlos Maiolino | a5ea70d | 2016-05-18 11:08:15 +1000 | [diff] [blame] | 490 | int retry_timeout; /* in seconds */ |
Carlos Maiolino | ef6a50f | 2016-05-18 11:06:44 +1000 | [diff] [blame] | 491 | }; |
| 492 | |
| 493 | static const struct xfs_error_init xfs_error_meta_init[XFS_ERR_ERRNO_MAX] = { |
| 494 | { .name = "default", |
Carlos Maiolino | e0a431b3 | 2016-05-18 11:09:28 +1000 | [diff] [blame] | 495 | .max_retries = XFS_ERR_RETRY_FOREVER, |
Eric Sandeen | 7716981 | 2016-09-14 07:51:30 +1000 | [diff] [blame] | 496 | .retry_timeout = XFS_ERR_RETRY_FOREVER, |
Carlos Maiolino | ef6a50f | 2016-05-18 11:06:44 +1000 | [diff] [blame] | 497 | }, |
Carlos Maiolino | e0a431b3 | 2016-05-18 11:09:28 +1000 | [diff] [blame] | 498 | { .name = "EIO", |
| 499 | .max_retries = XFS_ERR_RETRY_FOREVER, |
Eric Sandeen | 7716981 | 2016-09-14 07:51:30 +1000 | [diff] [blame] | 500 | .retry_timeout = XFS_ERR_RETRY_FOREVER, |
Carlos Maiolino | e0a431b3 | 2016-05-18 11:09:28 +1000 | [diff] [blame] | 501 | }, |
| 502 | { .name = "ENOSPC", |
| 503 | .max_retries = XFS_ERR_RETRY_FOREVER, |
Eric Sandeen | 7716981 | 2016-09-14 07:51:30 +1000 | [diff] [blame] | 504 | .retry_timeout = XFS_ERR_RETRY_FOREVER, |
Carlos Maiolino | e0a431b3 | 2016-05-18 11:09:28 +1000 | [diff] [blame] | 505 | }, |
| 506 | { .name = "ENODEV", |
Eric Sandeen | 7716981 | 2016-09-14 07:51:30 +1000 | [diff] [blame] | 507 | .max_retries = 0, /* We can't recover from devices disappearing */ |
| 508 | .retry_timeout = 0, |
Carlos Maiolino | e0a431b3 | 2016-05-18 11:09:28 +1000 | [diff] [blame] | 509 | }, |
Carlos Maiolino | ef6a50f | 2016-05-18 11:06:44 +1000 | [diff] [blame] | 510 | }; |
| 511 | |
| 512 | static int |
| 513 | xfs_error_sysfs_init_class( |
| 514 | struct xfs_mount *mp, |
| 515 | int class, |
| 516 | const char *parent_name, |
| 517 | struct xfs_kobj *parent_kobj, |
| 518 | const struct xfs_error_init init[]) |
| 519 | { |
| 520 | struct xfs_error_cfg *cfg; |
| 521 | int error; |
| 522 | int i; |
| 523 | |
| 524 | ASSERT(class < XFS_ERR_CLASS_MAX); |
| 525 | |
| 526 | error = xfs_sysfs_init(parent_kobj, &xfs_error_ktype, |
| 527 | &mp->m_error_kobj, parent_name); |
| 528 | if (error) |
| 529 | return error; |
| 530 | |
| 531 | for (i = 0; i < XFS_ERR_ERRNO_MAX; i++) { |
| 532 | cfg = &mp->m_error_cfg[class][i]; |
| 533 | error = xfs_sysfs_init(&cfg->kobj, &xfs_error_cfg_ktype, |
| 534 | parent_kobj, init[i].name); |
| 535 | if (error) |
| 536 | goto out_error; |
| 537 | |
| 538 | cfg->max_retries = init[i].max_retries; |
Eric Sandeen | 7716981 | 2016-09-14 07:51:30 +1000 | [diff] [blame] | 539 | if (init[i].retry_timeout == XFS_ERR_RETRY_FOREVER) |
| 540 | cfg->retry_timeout = XFS_ERR_RETRY_FOREVER; |
| 541 | else |
| 542 | cfg->retry_timeout = msecs_to_jiffies( |
Carlos Maiolino | a5ea70d | 2016-05-18 11:08:15 +1000 | [diff] [blame] | 543 | init[i].retry_timeout * MSEC_PER_SEC); |
Carlos Maiolino | ef6a50f | 2016-05-18 11:06:44 +1000 | [diff] [blame] | 544 | } |
| 545 | return 0; |
| 546 | |
| 547 | out_error: |
| 548 | /* unwind the entries that succeeded */ |
| 549 | for (i--; i >= 0; i--) { |
| 550 | cfg = &mp->m_error_cfg[class][i]; |
| 551 | xfs_sysfs_del(&cfg->kobj); |
| 552 | } |
| 553 | xfs_sysfs_del(parent_kobj); |
| 554 | return error; |
| 555 | } |
| 556 | |
Carlos Maiolino | 192852b | 2016-05-18 10:58:51 +1000 | [diff] [blame] | 557 | int |
| 558 | xfs_error_sysfs_init( |
| 559 | struct xfs_mount *mp) |
| 560 | { |
| 561 | int error; |
| 562 | |
| 563 | /* .../xfs/<dev>/error/ */ |
| 564 | error = xfs_sysfs_init(&mp->m_error_kobj, &xfs_error_ktype, |
| 565 | &mp->m_kobj, "error"); |
Carlos Maiolino | ffd40ef | 2016-05-18 11:01:00 +1000 | [diff] [blame] | 566 | if (error) |
| 567 | return error; |
| 568 | |
Carlos Maiolino | e6b3bb7 | 2016-05-18 11:11:27 +1000 | [diff] [blame] | 569 | error = sysfs_create_file(&mp->m_error_kobj.kobject, |
| 570 | ATTR_LIST(fail_at_unmount)); |
| 571 | |
| 572 | if (error) |
| 573 | goto out_error; |
| 574 | |
Carlos Maiolino | ffd40ef | 2016-05-18 11:01:00 +1000 | [diff] [blame] | 575 | /* .../xfs/<dev>/error/metadata/ */ |
Carlos Maiolino | ef6a50f | 2016-05-18 11:06:44 +1000 | [diff] [blame] | 576 | error = xfs_error_sysfs_init_class(mp, XFS_ERR_METADATA, |
| 577 | "metadata", &mp->m_error_meta_kobj, |
| 578 | xfs_error_meta_init); |
Carlos Maiolino | ffd40ef | 2016-05-18 11:01:00 +1000 | [diff] [blame] | 579 | if (error) |
| 580 | goto out_error; |
| 581 | |
Carlos Maiolino | ffd40ef | 2016-05-18 11:01:00 +1000 | [diff] [blame] | 582 | return 0; |
| 583 | |
Carlos Maiolino | ffd40ef | 2016-05-18 11:01:00 +1000 | [diff] [blame] | 584 | out_error: |
| 585 | xfs_sysfs_del(&mp->m_error_kobj); |
Carlos Maiolino | 192852b | 2016-05-18 10:58:51 +1000 | [diff] [blame] | 586 | return error; |
| 587 | } |
| 588 | |
| 589 | void |
| 590 | xfs_error_sysfs_del( |
| 591 | struct xfs_mount *mp) |
| 592 | { |
Carlos Maiolino | ffd40ef | 2016-05-18 11:01:00 +1000 | [diff] [blame] | 593 | struct xfs_error_cfg *cfg; |
| 594 | int i, j; |
| 595 | |
| 596 | for (i = 0; i < XFS_ERR_CLASS_MAX; i++) { |
| 597 | for (j = 0; j < XFS_ERR_ERRNO_MAX; j++) { |
| 598 | cfg = &mp->m_error_cfg[i][j]; |
| 599 | |
| 600 | xfs_sysfs_del(&cfg->kobj); |
| 601 | } |
| 602 | } |
| 603 | xfs_sysfs_del(&mp->m_error_meta_kobj); |
Carlos Maiolino | 192852b | 2016-05-18 10:58:51 +1000 | [diff] [blame] | 604 | xfs_sysfs_del(&mp->m_error_kobj); |
| 605 | } |
Carlos Maiolino | df30939 | 2016-05-18 11:05:33 +1000 | [diff] [blame] | 606 | |
| 607 | struct xfs_error_cfg * |
| 608 | xfs_error_get_cfg( |
| 609 | struct xfs_mount *mp, |
| 610 | int error_class, |
| 611 | int error) |
| 612 | { |
| 613 | struct xfs_error_cfg *cfg; |
| 614 | |
Eric Sandeen | e97f6c5 | 2016-07-20 10:48:51 +1000 | [diff] [blame] | 615 | if (error < 0) |
| 616 | error = -error; |
| 617 | |
Carlos Maiolino | df30939 | 2016-05-18 11:05:33 +1000 | [diff] [blame] | 618 | switch (error) { |
Carlos Maiolino | e0a431b3 | 2016-05-18 11:09:28 +1000 | [diff] [blame] | 619 | case EIO: |
| 620 | cfg = &mp->m_error_cfg[error_class][XFS_ERR_EIO]; |
| 621 | break; |
| 622 | case ENOSPC: |
| 623 | cfg = &mp->m_error_cfg[error_class][XFS_ERR_ENOSPC]; |
| 624 | break; |
| 625 | case ENODEV: |
| 626 | cfg = &mp->m_error_cfg[error_class][XFS_ERR_ENODEV]; |
| 627 | break; |
Carlos Maiolino | df30939 | 2016-05-18 11:05:33 +1000 | [diff] [blame] | 628 | default: |
| 629 | cfg = &mp->m_error_cfg[error_class][XFS_ERR_DEFAULT]; |
| 630 | break; |
| 631 | } |
| 632 | |
| 633 | return cfg; |
| 634 | } |