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" |
| 20 | #include "xfs_sysfs.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" |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 24 | #include "xfs_log.h" |
| 25 | #include "xfs_log_priv.h" |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 26 | #include "xfs_stats.h" |
Brian Foster | 801cc4e | 2016-03-15 11:42:44 +1100 | [diff] [blame] | 27 | #include "xfs_mount.h" |
Brian Foster | a31b1d3 | 2014-07-15 08:07:01 +1000 | [diff] [blame] | 28 | |
| 29 | struct xfs_sysfs_attr { |
| 30 | struct attribute attr; |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 31 | ssize_t (*show)(struct kobject *kobject, char *buf); |
| 32 | ssize_t (*store)(struct kobject *kobject, const char *buf, |
| 33 | size_t count); |
Brian Foster | a31b1d3 | 2014-07-15 08:07:01 +1000 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | static inline struct xfs_sysfs_attr * |
| 37 | to_attr(struct attribute *attr) |
| 38 | { |
| 39 | return container_of(attr, struct xfs_sysfs_attr, attr); |
| 40 | } |
| 41 | |
| 42 | #define XFS_SYSFS_ATTR_RW(name) \ |
| 43 | static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RW(name) |
| 44 | #define XFS_SYSFS_ATTR_RO(name) \ |
| 45 | 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] | 46 | #define XFS_SYSFS_ATTR_WO(name) \ |
| 47 | static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_WO(name) |
Brian Foster | a31b1d3 | 2014-07-15 08:07:01 +1000 | [diff] [blame] | 48 | |
| 49 | #define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr |
| 50 | |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 51 | STATIC ssize_t |
| 52 | xfs_sysfs_object_show( |
| 53 | struct kobject *kobject, |
| 54 | struct attribute *attr, |
| 55 | char *buf) |
| 56 | { |
| 57 | struct xfs_sysfs_attr *xfs_attr = to_attr(attr); |
| 58 | |
| 59 | return xfs_attr->show ? xfs_attr->show(kobject, buf) : 0; |
| 60 | } |
| 61 | |
| 62 | STATIC ssize_t |
| 63 | xfs_sysfs_object_store( |
| 64 | struct kobject *kobject, |
| 65 | struct attribute *attr, |
| 66 | const char *buf, |
| 67 | size_t count) |
| 68 | { |
| 69 | struct xfs_sysfs_attr *xfs_attr = to_attr(attr); |
| 70 | |
| 71 | return xfs_attr->store ? xfs_attr->store(kobject, buf, count) : 0; |
| 72 | } |
| 73 | |
| 74 | static const struct sysfs_ops xfs_sysfs_ops = { |
| 75 | .show = xfs_sysfs_object_show, |
| 76 | .store = xfs_sysfs_object_store, |
| 77 | }; |
| 78 | |
Brian Foster | 801cc4e | 2016-03-15 11:42:44 +1100 | [diff] [blame] | 79 | /* |
| 80 | * xfs_mount kobject. The mp kobject also serves as the per-mount parent object |
| 81 | * that is identified by the fsname under sysfs. |
| 82 | */ |
| 83 | |
| 84 | static inline struct xfs_mount * |
| 85 | to_mp(struct kobject *kobject) |
| 86 | { |
| 87 | struct xfs_kobj *kobj = to_kobj(kobject); |
| 88 | |
| 89 | return container_of(kobj, struct xfs_mount, m_kobj); |
| 90 | } |
| 91 | |
| 92 | #ifdef DEBUG |
| 93 | |
| 94 | STATIC ssize_t |
| 95 | fail_writes_store( |
| 96 | struct kobject *kobject, |
| 97 | const char *buf, |
| 98 | size_t count) |
| 99 | { |
| 100 | struct xfs_mount *mp = to_mp(kobject); |
| 101 | int ret; |
| 102 | int val; |
| 103 | |
| 104 | ret = kstrtoint(buf, 0, &val); |
| 105 | if (ret) |
| 106 | return ret; |
| 107 | |
| 108 | if (val == 1) |
| 109 | mp->m_fail_writes = true; |
| 110 | else if (val == 0) |
| 111 | mp->m_fail_writes = false; |
| 112 | else |
| 113 | return -EINVAL; |
| 114 | |
| 115 | return count; |
| 116 | } |
| 117 | |
| 118 | STATIC ssize_t |
| 119 | fail_writes_show( |
| 120 | struct kobject *kobject, |
| 121 | char *buf) |
| 122 | { |
| 123 | struct xfs_mount *mp = to_mp(kobject); |
| 124 | |
| 125 | return snprintf(buf, PAGE_SIZE, "%d\n", mp->m_fail_writes ? 1 : 0); |
| 126 | } |
| 127 | XFS_SYSFS_ATTR_RW(fail_writes); |
| 128 | |
| 129 | #endif /* DEBUG */ |
| 130 | |
| 131 | static struct attribute *xfs_mp_attrs[] = { |
| 132 | #ifdef DEBUG |
| 133 | ATTR_LIST(fail_writes), |
| 134 | #endif |
| 135 | NULL, |
| 136 | }; |
| 137 | |
| 138 | struct kobj_type xfs_mp_ktype = { |
| 139 | .release = xfs_sysfs_release, |
| 140 | .sysfs_ops = &xfs_sysfs_ops, |
| 141 | .default_attrs = xfs_mp_attrs, |
| 142 | }; |
| 143 | |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 144 | #ifdef DEBUG |
| 145 | /* debug */ |
| 146 | |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 147 | STATIC ssize_t |
| 148 | log_recovery_delay_store( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 149 | struct kobject *kobject, |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 150 | const char *buf, |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 151 | size_t count) |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 152 | { |
| 153 | int ret; |
| 154 | int val; |
| 155 | |
| 156 | ret = kstrtoint(buf, 0, &val); |
| 157 | if (ret) |
| 158 | return ret; |
| 159 | |
| 160 | if (val < 0 || val > 60) |
| 161 | return -EINVAL; |
| 162 | |
| 163 | xfs_globals.log_recovery_delay = val; |
| 164 | |
| 165 | return count; |
| 166 | } |
| 167 | |
| 168 | STATIC ssize_t |
| 169 | log_recovery_delay_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 170 | struct kobject *kobject, |
| 171 | char *buf) |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 172 | { |
| 173 | return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.log_recovery_delay); |
| 174 | } |
| 175 | XFS_SYSFS_ATTR_RW(log_recovery_delay); |
| 176 | |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 177 | static struct attribute *xfs_dbg_attrs[] = { |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 178 | ATTR_LIST(log_recovery_delay), |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 179 | NULL, |
| 180 | }; |
| 181 | |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 182 | struct kobj_type xfs_dbg_ktype = { |
| 183 | .release = xfs_sysfs_release, |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 184 | .sysfs_ops = &xfs_sysfs_ops, |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 185 | .default_attrs = xfs_dbg_attrs, |
| 186 | }; |
| 187 | |
| 188 | #endif /* DEBUG */ |
| 189 | |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 190 | /* stats */ |
| 191 | |
Bill O'Donnell | 80529c4 | 2015-10-12 05:19:45 +1100 | [diff] [blame] | 192 | static inline struct xstats * |
| 193 | to_xstats(struct kobject *kobject) |
| 194 | { |
| 195 | struct xfs_kobj *kobj = to_kobj(kobject); |
| 196 | |
| 197 | return container_of(kobj, struct xstats, xs_kobj); |
| 198 | } |
| 199 | |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 200 | STATIC ssize_t |
| 201 | stats_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 202 | struct kobject *kobject, |
| 203 | char *buf) |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 204 | { |
Bill O'Donnell | 80529c4 | 2015-10-12 05:19:45 +1100 | [diff] [blame] | 205 | struct xstats *stats = to_xstats(kobject); |
| 206 | |
| 207 | return xfs_stats_format(stats->xs_stats, buf); |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 208 | } |
| 209 | XFS_SYSFS_ATTR_RO(stats); |
| 210 | |
| 211 | STATIC ssize_t |
| 212 | stats_clear_store( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 213 | struct kobject *kobject, |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 214 | const char *buf, |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 215 | size_t count) |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 216 | { |
| 217 | int ret; |
| 218 | int val; |
Bill O'Donnell | 80529c4 | 2015-10-12 05:19:45 +1100 | [diff] [blame] | 219 | struct xstats *stats = to_xstats(kobject); |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 220 | |
| 221 | ret = kstrtoint(buf, 0, &val); |
| 222 | if (ret) |
| 223 | return ret; |
| 224 | |
| 225 | if (val != 1) |
| 226 | return -EINVAL; |
Bill O'Donnell | 80529c4 | 2015-10-12 05:19:45 +1100 | [diff] [blame] | 227 | |
| 228 | xfs_stats_clearall(stats->xs_stats); |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 229 | return count; |
| 230 | } |
| 231 | XFS_SYSFS_ATTR_WO(stats_clear); |
| 232 | |
| 233 | static struct attribute *xfs_stats_attrs[] = { |
| 234 | ATTR_LIST(stats), |
| 235 | ATTR_LIST(stats_clear), |
| 236 | NULL, |
| 237 | }; |
| 238 | |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 239 | struct kobj_type xfs_stats_ktype = { |
| 240 | .release = xfs_sysfs_release, |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 241 | .sysfs_ops = &xfs_sysfs_ops, |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 242 | .default_attrs = xfs_stats_attrs, |
| 243 | }; |
| 244 | |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 245 | /* xlog */ |
| 246 | |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 247 | static inline struct xlog * |
| 248 | to_xlog(struct kobject *kobject) |
| 249 | { |
| 250 | struct xfs_kobj *kobj = to_kobj(kobject); |
| 251 | |
| 252 | return container_of(kobj, struct xlog, l_kobj); |
| 253 | } |
| 254 | |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 255 | STATIC ssize_t |
| 256 | log_head_lsn_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 257 | struct kobject *kobject, |
| 258 | char *buf) |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 259 | { |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 260 | int cycle; |
| 261 | int block; |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 262 | struct xlog *log = to_xlog(kobject); |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 263 | |
| 264 | spin_lock(&log->l_icloglock); |
| 265 | cycle = log->l_curr_cycle; |
| 266 | block = log->l_curr_block; |
| 267 | spin_unlock(&log->l_icloglock); |
| 268 | |
| 269 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block); |
| 270 | } |
| 271 | XFS_SYSFS_ATTR_RO(log_head_lsn); |
| 272 | |
| 273 | STATIC ssize_t |
| 274 | log_tail_lsn_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 275 | struct kobject *kobject, |
| 276 | char *buf) |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 277 | { |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 278 | int cycle; |
| 279 | int block; |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 280 | struct xlog *log = to_xlog(kobject); |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 281 | |
| 282 | xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block); |
| 283 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block); |
| 284 | } |
| 285 | XFS_SYSFS_ATTR_RO(log_tail_lsn); |
| 286 | |
| 287 | STATIC ssize_t |
| 288 | reserve_grant_head_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 289 | struct kobject *kobject, |
| 290 | char *buf) |
| 291 | |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 292 | { |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 293 | int cycle; |
| 294 | int bytes; |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 295 | struct xlog *log = to_xlog(kobject); |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 296 | |
| 297 | xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes); |
| 298 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes); |
| 299 | } |
| 300 | XFS_SYSFS_ATTR_RO(reserve_grant_head); |
| 301 | |
| 302 | STATIC ssize_t |
| 303 | write_grant_head_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 304 | struct kobject *kobject, |
| 305 | char *buf) |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 306 | { |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 307 | int cycle; |
| 308 | int bytes; |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 309 | struct xlog *log = to_xlog(kobject); |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 310 | |
| 311 | xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes); |
| 312 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes); |
| 313 | } |
| 314 | XFS_SYSFS_ATTR_RO(write_grant_head); |
| 315 | |
Brian Foster | 609adfc | 2016-01-05 07:41:16 +1100 | [diff] [blame] | 316 | #ifdef DEBUG |
| 317 | STATIC ssize_t |
| 318 | log_badcrc_factor_store( |
| 319 | struct kobject *kobject, |
| 320 | const char *buf, |
| 321 | size_t count) |
| 322 | { |
| 323 | struct xlog *log = to_xlog(kobject); |
| 324 | int ret; |
| 325 | uint32_t val; |
| 326 | |
| 327 | ret = kstrtouint(buf, 0, &val); |
| 328 | if (ret) |
| 329 | return ret; |
| 330 | |
| 331 | log->l_badcrc_factor = val; |
| 332 | |
| 333 | return count; |
| 334 | } |
| 335 | |
| 336 | STATIC ssize_t |
| 337 | log_badcrc_factor_show( |
| 338 | struct kobject *kobject, |
| 339 | char *buf) |
| 340 | { |
| 341 | struct xlog *log = to_xlog(kobject); |
| 342 | |
| 343 | return snprintf(buf, PAGE_SIZE, "%d\n", log->l_badcrc_factor); |
| 344 | } |
| 345 | |
| 346 | XFS_SYSFS_ATTR_RW(log_badcrc_factor); |
| 347 | #endif /* DEBUG */ |
| 348 | |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 349 | static struct attribute *xfs_log_attrs[] = { |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 350 | ATTR_LIST(log_head_lsn), |
| 351 | ATTR_LIST(log_tail_lsn), |
| 352 | ATTR_LIST(reserve_grant_head), |
| 353 | ATTR_LIST(write_grant_head), |
Brian Foster | 609adfc | 2016-01-05 07:41:16 +1100 | [diff] [blame] | 354 | #ifdef DEBUG |
| 355 | ATTR_LIST(log_badcrc_factor), |
| 356 | #endif |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 357 | NULL, |
| 358 | }; |
| 359 | |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 360 | struct kobj_type xfs_log_ktype = { |
| 361 | .release = xfs_sysfs_release, |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame] | 362 | .sysfs_ops = &xfs_sysfs_ops, |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 363 | .default_attrs = xfs_log_attrs, |
| 364 | }; |