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