]>
Commit | Line | Data |
---|---|---|
a31b1d3d BF |
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" | |
baff4e44 BF |
21 | #include "xfs_log_format.h" |
22 | #include "xfs_log.h" | |
23 | #include "xfs_log_priv.h" | |
bb230c12 | 24 | #include "xfs_stats.h" |
a31b1d3d BF |
25 | |
26 | struct xfs_sysfs_attr { | |
27 | struct attribute attr; | |
a27c2640 BD |
28 | ssize_t (*show)(struct kobject *kobject, char *buf); |
29 | ssize_t (*store)(struct kobject *kobject, const char *buf, | |
30 | size_t count); | |
a31b1d3d BF |
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) | |
bb230c12 BD |
43 | #define XFS_SYSFS_ATTR_WO(name) \ |
44 | static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_WO(name) | |
a31b1d3d BF |
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 | }; | |
baff4e44 | 57 | |
a27c2640 BD |
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 | ||
65b65735 BF |
86 | #ifdef DEBUG |
87 | /* debug */ | |
88 | ||
2e227178 BF |
89 | STATIC ssize_t |
90 | log_recovery_delay_store( | |
a27c2640 | 91 | struct kobject *kobject, |
2e227178 | 92 | const char *buf, |
a27c2640 | 93 | size_t count) |
2e227178 BF |
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( | |
a27c2640 BD |
112 | struct kobject *kobject, |
113 | char *buf) | |
2e227178 BF |
114 | { |
115 | return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.log_recovery_delay); | |
116 | } | |
117 | XFS_SYSFS_ATTR_RW(log_recovery_delay); | |
118 | ||
65b65735 | 119 | static struct attribute *xfs_dbg_attrs[] = { |
2e227178 | 120 | ATTR_LIST(log_recovery_delay), |
65b65735 BF |
121 | NULL, |
122 | }; | |
123 | ||
65b65735 BF |
124 | struct kobj_type xfs_dbg_ktype = { |
125 | .release = xfs_sysfs_release, | |
a27c2640 | 126 | .sysfs_ops = &xfs_sysfs_ops, |
65b65735 BF |
127 | .default_attrs = xfs_dbg_attrs, |
128 | }; | |
129 | ||
130 | #endif /* DEBUG */ | |
131 | ||
bb230c12 BD |
132 | /* stats */ |
133 | ||
80529c45 BD |
134 | static inline struct xstats * |
135 | to_xstats(struct kobject *kobject) | |
136 | { | |
137 | struct xfs_kobj *kobj = to_kobj(kobject); | |
138 | ||
139 | return container_of(kobj, struct xstats, xs_kobj); | |
140 | } | |
141 | ||
bb230c12 BD |
142 | STATIC ssize_t |
143 | stats_show( | |
a27c2640 BD |
144 | struct kobject *kobject, |
145 | char *buf) | |
bb230c12 | 146 | { |
80529c45 BD |
147 | struct xstats *stats = to_xstats(kobject); |
148 | ||
149 | return xfs_stats_format(stats->xs_stats, buf); | |
bb230c12 BD |
150 | } |
151 | XFS_SYSFS_ATTR_RO(stats); | |
152 | ||
153 | STATIC ssize_t | |
154 | stats_clear_store( | |
a27c2640 | 155 | struct kobject *kobject, |
bb230c12 | 156 | const char *buf, |
a27c2640 | 157 | size_t count) |
bb230c12 BD |
158 | { |
159 | int ret; | |
160 | int val; | |
80529c45 | 161 | struct xstats *stats = to_xstats(kobject); |
bb230c12 BD |
162 | |
163 | ret = kstrtoint(buf, 0, &val); | |
164 | if (ret) | |
165 | return ret; | |
166 | ||
167 | if (val != 1) | |
168 | return -EINVAL; | |
80529c45 BD |
169 | |
170 | xfs_stats_clearall(stats->xs_stats); | |
bb230c12 BD |
171 | return count; |
172 | } | |
173 | XFS_SYSFS_ATTR_WO(stats_clear); | |
174 | ||
175 | static struct attribute *xfs_stats_attrs[] = { | |
176 | ATTR_LIST(stats), | |
177 | ATTR_LIST(stats_clear), | |
178 | NULL, | |
179 | }; | |
180 | ||
bb230c12 BD |
181 | struct kobj_type xfs_stats_ktype = { |
182 | .release = xfs_sysfs_release, | |
a27c2640 | 183 | .sysfs_ops = &xfs_sysfs_ops, |
bb230c12 BD |
184 | .default_attrs = xfs_stats_attrs, |
185 | }; | |
186 | ||
baff4e44 BF |
187 | /* xlog */ |
188 | ||
a27c2640 BD |
189 | static inline struct xlog * |
190 | to_xlog(struct kobject *kobject) | |
191 | { | |
192 | struct xfs_kobj *kobj = to_kobj(kobject); | |
193 | ||
194 | return container_of(kobj, struct xlog, l_kobj); | |
195 | } | |
196 | ||
80d6d698 BF |
197 | STATIC ssize_t |
198 | log_head_lsn_show( | |
a27c2640 BD |
199 | struct kobject *kobject, |
200 | char *buf) | |
80d6d698 | 201 | { |
80d6d698 BF |
202 | int cycle; |
203 | int block; | |
a27c2640 | 204 | struct xlog *log = to_xlog(kobject); |
80d6d698 BF |
205 | |
206 | spin_lock(&log->l_icloglock); | |
207 | cycle = log->l_curr_cycle; | |
208 | block = log->l_curr_block; | |
209 | spin_unlock(&log->l_icloglock); | |
210 | ||
211 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block); | |
212 | } | |
213 | XFS_SYSFS_ATTR_RO(log_head_lsn); | |
214 | ||
215 | STATIC ssize_t | |
216 | log_tail_lsn_show( | |
a27c2640 BD |
217 | struct kobject *kobject, |
218 | char *buf) | |
80d6d698 | 219 | { |
80d6d698 BF |
220 | int cycle; |
221 | int block; | |
a27c2640 | 222 | struct xlog *log = to_xlog(kobject); |
80d6d698 BF |
223 | |
224 | xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block); | |
225 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block); | |
226 | } | |
227 | XFS_SYSFS_ATTR_RO(log_tail_lsn); | |
228 | ||
229 | STATIC ssize_t | |
230 | reserve_grant_head_show( | |
a27c2640 BD |
231 | struct kobject *kobject, |
232 | char *buf) | |
233 | ||
80d6d698 | 234 | { |
80d6d698 BF |
235 | int cycle; |
236 | int bytes; | |
a27c2640 | 237 | struct xlog *log = to_xlog(kobject); |
80d6d698 BF |
238 | |
239 | xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes); | |
240 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes); | |
241 | } | |
242 | XFS_SYSFS_ATTR_RO(reserve_grant_head); | |
243 | ||
244 | STATIC ssize_t | |
245 | write_grant_head_show( | |
a27c2640 BD |
246 | struct kobject *kobject, |
247 | char *buf) | |
80d6d698 | 248 | { |
80d6d698 BF |
249 | int cycle; |
250 | int bytes; | |
a27c2640 | 251 | struct xlog *log = to_xlog(kobject); |
80d6d698 BF |
252 | |
253 | xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes); | |
254 | return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes); | |
255 | } | |
256 | XFS_SYSFS_ATTR_RO(write_grant_head); | |
257 | ||
baff4e44 | 258 | static struct attribute *xfs_log_attrs[] = { |
80d6d698 BF |
259 | ATTR_LIST(log_head_lsn), |
260 | ATTR_LIST(log_tail_lsn), | |
261 | ATTR_LIST(reserve_grant_head), | |
262 | ATTR_LIST(write_grant_head), | |
baff4e44 BF |
263 | NULL, |
264 | }; | |
265 | ||
baff4e44 BF |
266 | struct kobj_type xfs_log_ktype = { |
267 | .release = xfs_sysfs_release, | |
a27c2640 | 268 | .sysfs_ops = &xfs_sysfs_ops, |
baff4e44 BF |
269 | .default_attrs = xfs_log_attrs, |
270 | }; |