2 * Copyright (c) 2014 Red Hat, Inc.
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.
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.
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
20 #include "xfs_sysfs.h"
21 #include "xfs_log_format.h"
23 #include "xfs_log_priv.h"
24 #include "xfs_stats.h"
26 struct xfs_sysfs_attr {
27 struct attribute attr;
28 ssize_t (*show)(char *buf, void *data);
29 ssize_t (*store)(const char *buf, size_t count, void *data);
32 static inline struct xfs_sysfs_attr *
33 to_attr(struct attribute *attr)
35 return container_of(attr, struct xfs_sysfs_attr, attr);
38 #define XFS_SYSFS_ATTR_RW(name) \
39 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RW(name)
40 #define XFS_SYSFS_ATTR_RO(name) \
41 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RO(name)
42 #define XFS_SYSFS_ATTR_WO(name) \
43 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_WO(name)
45 #define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr
48 * xfs_mount kobject. This currently has no attributes and thus no need for show
49 * and store helpers. The mp kobject serves as the per-mount parent object that
50 * is identified by the fsname under sysfs.
53 struct kobj_type xfs_mp_ktype = {
54 .release = xfs_sysfs_release,
61 log_recovery_delay_store(
69 ret = kstrtoint(buf, 0, &val);
73 if (val < 0 || val > 60)
76 xfs_globals.log_recovery_delay = val;
82 log_recovery_delay_show(
86 return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.log_recovery_delay);
88 XFS_SYSFS_ATTR_RW(log_recovery_delay);
90 static struct attribute *xfs_dbg_attrs[] = {
91 ATTR_LIST(log_recovery_delay),
97 struct kobject *kobject,
98 struct attribute *attr,
101 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
103 return xfs_attr->show ? xfs_attr->show(buf, NULL) : 0;
108 struct kobject *kobject,
109 struct attribute *attr,
113 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
115 return xfs_attr->store ? xfs_attr->store(buf, count, NULL) : 0;
118 static struct sysfs_ops xfs_dbg_ops = {
119 .show = xfs_dbg_show,
120 .store = xfs_dbg_store,
123 struct kobj_type xfs_dbg_ktype = {
124 .release = xfs_sysfs_release,
125 .sysfs_ops = &xfs_dbg_ops,
126 .default_attrs = xfs_dbg_attrs,
139 return xfs_stats_format(buf);
141 XFS_SYSFS_ATTR_RO(stats);
152 ret = kstrtoint(buf, 0, &val);
158 xfs_stats_clearall();
161 XFS_SYSFS_ATTR_WO(stats_clear);
163 static struct attribute *xfs_stats_attrs[] = {
165 ATTR_LIST(stats_clear),
171 struct kobject *kobject,
172 struct attribute *attr,
175 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
177 return xfs_attr->show ? xfs_attr->show(buf, NULL) : 0;
182 struct kobject *kobject,
183 struct attribute *attr,
187 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
189 return xfs_attr->store ? xfs_attr->store(buf, count, NULL) : 0;
192 static struct sysfs_ops xfs_stats_ops = {
193 .show = xfs_stats_show,
194 .store = xfs_stats_store,
197 struct kobj_type xfs_stats_ktype = {
198 .release = xfs_sysfs_release,
199 .sysfs_ops = &xfs_stats_ops,
200 .default_attrs = xfs_stats_attrs,
210 struct xlog *log = data;
214 spin_lock(&log->l_icloglock);
215 cycle = log->l_curr_cycle;
216 block = log->l_curr_block;
217 spin_unlock(&log->l_icloglock);
219 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
221 XFS_SYSFS_ATTR_RO(log_head_lsn);
228 struct xlog *log = data;
232 xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block);
233 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
235 XFS_SYSFS_ATTR_RO(log_tail_lsn);
238 reserve_grant_head_show(
242 struct xlog *log = data;
246 xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes);
247 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
249 XFS_SYSFS_ATTR_RO(reserve_grant_head);
252 write_grant_head_show(
256 struct xlog *log = data;
260 xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes);
261 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
263 XFS_SYSFS_ATTR_RO(write_grant_head);
265 static struct attribute *xfs_log_attrs[] = {
266 ATTR_LIST(log_head_lsn),
267 ATTR_LIST(log_tail_lsn),
268 ATTR_LIST(reserve_grant_head),
269 ATTR_LIST(write_grant_head),
273 static inline struct xlog *
274 to_xlog(struct kobject *kobject)
276 struct xfs_kobj *kobj = to_kobj(kobject);
277 return container_of(kobj, struct xlog, l_kobj);
282 struct kobject *kobject,
283 struct attribute *attr,
286 struct xlog *log = to_xlog(kobject);
287 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
289 return xfs_attr->show ? xfs_attr->show(buf, log) : 0;
294 struct kobject *kobject,
295 struct attribute *attr,
299 struct xlog *log = to_xlog(kobject);
300 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
302 return xfs_attr->store ? xfs_attr->store(buf, count, log) : 0;
305 static struct sysfs_ops xfs_log_ops = {
306 .show = xfs_log_show,
307 .store = xfs_log_store,
310 struct kobj_type xfs_log_ktype = {
311 .release = xfs_sysfs_release,
312 .sysfs_ops = &xfs_log_ops,
313 .default_attrs = xfs_log_attrs,