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 | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 21 | #include "xfs_log_format.h" |
| 22 | #include "xfs_log.h" |
| 23 | #include "xfs_log_priv.h" |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 24 | #include "xfs_stats.h" |
Brian Foster | a31b1d3 | 2014-07-15 08:07:01 +1000 | [diff] [blame] | 25 | |
| 26 | struct xfs_sysfs_attr { |
| 27 | struct attribute attr; |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 28 | ssize_t (*show)(struct kobject *kobject, char *buf); |
| 29 | ssize_t (*store)(struct kobject *kobject, const char *buf, |
| 30 | size_t count); |
Brian Foster | a31b1d3 | 2014-07-15 08:07:01 +1000 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | static inline struct xfs_sysfs_attr * |
| 34 | to_attr(struct attribute *attr) |
| 35 | { |
| 36 | return container_of(attr, struct xfs_sysfs_attr, attr); |
| 37 | } |
| 38 | |
| 39 | #define XFS_SYSFS_ATTR_RW(name) \ |
| 40 | static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RW(name) |
| 41 | #define XFS_SYSFS_ATTR_RO(name) \ |
| 42 | 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] | 43 | #define XFS_SYSFS_ATTR_WO(name) \ |
| 44 | static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_WO(name) |
Brian Foster | a31b1d3 | 2014-07-15 08:07:01 +1000 | [diff] [blame] | 45 | |
| 46 | #define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr |
| 47 | |
| 48 | /* |
| 49 | * xfs_mount kobject. This currently has no attributes and thus no need for show |
| 50 | * and store helpers. The mp kobject serves as the per-mount parent object that |
| 51 | * is identified by the fsname under sysfs. |
| 52 | */ |
| 53 | |
| 54 | struct kobj_type xfs_mp_ktype = { |
| 55 | .release = xfs_sysfs_release, |
| 56 | }; |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 57 | |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 58 | STATIC ssize_t |
| 59 | xfs_sysfs_object_show( |
| 60 | struct kobject *kobject, |
| 61 | struct attribute *attr, |
| 62 | char *buf) |
| 63 | { |
| 64 | struct xfs_sysfs_attr *xfs_attr = to_attr(attr); |
| 65 | |
| 66 | return xfs_attr->show ? xfs_attr->show(kobject, buf) : 0; |
| 67 | } |
| 68 | |
| 69 | STATIC ssize_t |
| 70 | xfs_sysfs_object_store( |
| 71 | struct kobject *kobject, |
| 72 | struct attribute *attr, |
| 73 | const char *buf, |
| 74 | size_t count) |
| 75 | { |
| 76 | struct xfs_sysfs_attr *xfs_attr = to_attr(attr); |
| 77 | |
| 78 | return xfs_attr->store ? xfs_attr->store(kobject, buf, count) : 0; |
| 79 | } |
| 80 | |
| 81 | static const struct sysfs_ops xfs_sysfs_ops = { |
| 82 | .show = xfs_sysfs_object_show, |
| 83 | .store = xfs_sysfs_object_store, |
| 84 | }; |
| 85 | |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 86 | #ifdef DEBUG |
| 87 | /* debug */ |
| 88 | |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 89 | STATIC ssize_t |
| 90 | log_recovery_delay_store( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 91 | struct kobject *kobject, |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 92 | const char *buf, |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 93 | size_t count) |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 94 | { |
| 95 | int ret; |
| 96 | int val; |
| 97 | |
| 98 | ret = kstrtoint(buf, 0, &val); |
| 99 | if (ret) |
| 100 | return ret; |
| 101 | |
| 102 | if (val < 0 || val > 60) |
| 103 | return -EINVAL; |
| 104 | |
| 105 | xfs_globals.log_recovery_delay = val; |
| 106 | |
| 107 | return count; |
| 108 | } |
| 109 | |
| 110 | STATIC ssize_t |
| 111 | log_recovery_delay_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 112 | struct kobject *kobject, |
| 113 | char *buf) |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 114 | { |
| 115 | return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.log_recovery_delay); |
| 116 | } |
| 117 | XFS_SYSFS_ATTR_RW(log_recovery_delay); |
| 118 | |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 119 | static struct attribute *xfs_dbg_attrs[] = { |
Brian Foster | 2e22717 | 2014-09-09 11:56:13 +1000 | [diff] [blame] | 120 | ATTR_LIST(log_recovery_delay), |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 121 | NULL, |
| 122 | }; |
| 123 | |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 124 | struct kobj_type xfs_dbg_ktype = { |
| 125 | .release = xfs_sysfs_release, |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 126 | .sysfs_ops = &xfs_sysfs_ops, |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 127 | .default_attrs = xfs_dbg_attrs, |
| 128 | }; |
| 129 | |
| 130 | #endif /* DEBUG */ |
| 131 | |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 132 | /* stats */ |
| 133 | |
| 134 | STATIC ssize_t |
| 135 | stats_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 136 | struct kobject *kobject, |
| 137 | char *buf) |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 138 | { |
| 139 | return xfs_stats_format(buf); |
| 140 | } |
| 141 | XFS_SYSFS_ATTR_RO(stats); |
| 142 | |
| 143 | STATIC ssize_t |
| 144 | stats_clear_store( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 145 | struct kobject *kobject, |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 146 | const char *buf, |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 147 | size_t count) |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 148 | { |
| 149 | int ret; |
| 150 | int val; |
| 151 | |
| 152 | ret = kstrtoint(buf, 0, &val); |
| 153 | if (ret) |
| 154 | return ret; |
| 155 | |
| 156 | if (val != 1) |
| 157 | return -EINVAL; |
| 158 | xfs_stats_clearall(); |
| 159 | return count; |
| 160 | } |
| 161 | XFS_SYSFS_ATTR_WO(stats_clear); |
| 162 | |
| 163 | static struct attribute *xfs_stats_attrs[] = { |
| 164 | ATTR_LIST(stats), |
| 165 | ATTR_LIST(stats_clear), |
| 166 | NULL, |
| 167 | }; |
| 168 | |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 169 | struct kobj_type xfs_stats_ktype = { |
| 170 | .release = xfs_sysfs_release, |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 171 | .sysfs_ops = &xfs_sysfs_ops, |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 172 | .default_attrs = xfs_stats_attrs, |
| 173 | }; |
| 174 | |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 175 | /* xlog */ |
| 176 | |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 177 | static inline struct xlog * |
| 178 | to_xlog(struct kobject *kobject) |
| 179 | { |
| 180 | struct xfs_kobj *kobj = to_kobj(kobject); |
| 181 | |
| 182 | return container_of(kobj, struct xlog, l_kobj); |
| 183 | } |
| 184 | |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 185 | STATIC ssize_t |
| 186 | log_head_lsn_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 187 | struct kobject *kobject, |
| 188 | char *buf) |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 189 | { |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 190 | int cycle; |
| 191 | int block; |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 192 | struct xlog *log = to_xlog(kobject); |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 193 | |
| 194 | spin_lock(&log->l_icloglock); |
| 195 | cycle = log->l_curr_cycle; |
| 196 | block = log->l_curr_block; |
| 197 | spin_unlock(&log->l_icloglock); |
| 198 | |
| 199 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block); |
| 200 | } |
| 201 | XFS_SYSFS_ATTR_RO(log_head_lsn); |
| 202 | |
| 203 | STATIC ssize_t |
| 204 | log_tail_lsn_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 205 | struct kobject *kobject, |
| 206 | char *buf) |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 207 | { |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 208 | int cycle; |
| 209 | int block; |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 210 | struct xlog *log = to_xlog(kobject); |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 211 | |
| 212 | xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block); |
| 213 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block); |
| 214 | } |
| 215 | XFS_SYSFS_ATTR_RO(log_tail_lsn); |
| 216 | |
| 217 | STATIC ssize_t |
| 218 | reserve_grant_head_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 219 | struct kobject *kobject, |
| 220 | char *buf) |
| 221 | |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 222 | { |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 223 | int cycle; |
| 224 | int bytes; |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 225 | struct xlog *log = to_xlog(kobject); |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 226 | |
| 227 | xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes); |
| 228 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes); |
| 229 | } |
| 230 | XFS_SYSFS_ATTR_RO(reserve_grant_head); |
| 231 | |
| 232 | STATIC ssize_t |
| 233 | write_grant_head_show( |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 234 | struct kobject *kobject, |
| 235 | char *buf) |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 236 | { |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 237 | int cycle; |
| 238 | int bytes; |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 239 | struct xlog *log = to_xlog(kobject); |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 240 | |
| 241 | xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes); |
| 242 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes); |
| 243 | } |
| 244 | XFS_SYSFS_ATTR_RO(write_grant_head); |
| 245 | |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 246 | static struct attribute *xfs_log_attrs[] = { |
Brian Foster | 80d6d69 | 2014-07-15 08:07:48 +1000 | [diff] [blame] | 247 | ATTR_LIST(log_head_lsn), |
| 248 | ATTR_LIST(log_tail_lsn), |
| 249 | ATTR_LIST(reserve_grant_head), |
| 250 | ATTR_LIST(write_grant_head), |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 251 | NULL, |
| 252 | }; |
| 253 | |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 254 | struct kobj_type xfs_log_ktype = { |
| 255 | .release = xfs_sysfs_release, |
Bill O'Donnell | a27c2640 | 2015-10-12 05:18:45 +1100 | [diff] [blame^] | 256 | .sysfs_ops = &xfs_sysfs_ops, |
Brian Foster | baff4e4 | 2014-07-15 08:07:29 +1000 | [diff] [blame] | 257 | .default_attrs = xfs_log_attrs, |
| 258 | }; |