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
)(struct kobject
*kobject
, char *buf
);
29 ssize_t (*store
)(struct kobject
*kobject
, const char *buf
,
33 static inline struct xfs_sysfs_attr
*
34 to_attr(struct attribute
*attr
)
36 return container_of(attr
, struct xfs_sysfs_attr
, attr
);
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)
43 #define XFS_SYSFS_ATTR_WO(name) \
44 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_WO(name)
46 #define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr
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.
54 struct kobj_type xfs_mp_ktype
= {
55 .release
= xfs_sysfs_release
,
59 xfs_sysfs_object_show(
60 struct kobject
*kobject
,
61 struct attribute
*attr
,
64 struct xfs_sysfs_attr
*xfs_attr
= to_attr(attr
);
66 return xfs_attr
->show
? xfs_attr
->show(kobject
, buf
) : 0;
70 xfs_sysfs_object_store(
71 struct kobject
*kobject
,
72 struct attribute
*attr
,
76 struct xfs_sysfs_attr
*xfs_attr
= to_attr(attr
);
78 return xfs_attr
->store
? xfs_attr
->store(kobject
, buf
, count
) : 0;
81 static const struct sysfs_ops xfs_sysfs_ops
= {
82 .show
= xfs_sysfs_object_show
,
83 .store
= xfs_sysfs_object_store
,
90 log_recovery_delay_store(
91 struct kobject
*kobject
,
98 ret
= kstrtoint(buf
, 0, &val
);
102 if (val
< 0 || val
> 60)
105 xfs_globals
.log_recovery_delay
= val
;
111 log_recovery_delay_show(
112 struct kobject
*kobject
,
115 return snprintf(buf
, PAGE_SIZE
, "%d\n", xfs_globals
.log_recovery_delay
);
117 XFS_SYSFS_ATTR_RW(log_recovery_delay
);
119 static struct attribute
*xfs_dbg_attrs
[] = {
120 ATTR_LIST(log_recovery_delay
),
124 struct kobj_type xfs_dbg_ktype
= {
125 .release
= xfs_sysfs_release
,
126 .sysfs_ops
= &xfs_sysfs_ops
,
127 .default_attrs
= xfs_dbg_attrs
,
134 static inline struct xstats
*
135 to_xstats(struct kobject
*kobject
)
137 struct xfs_kobj
*kobj
= to_kobj(kobject
);
139 return container_of(kobj
, struct xstats
, xs_kobj
);
144 struct kobject
*kobject
,
147 struct xstats
*stats
= to_xstats(kobject
);
149 return xfs_stats_format(stats
->xs_stats
, buf
);
151 XFS_SYSFS_ATTR_RO(stats
);
155 struct kobject
*kobject
,
161 struct xstats
*stats
= to_xstats(kobject
);
163 ret
= kstrtoint(buf
, 0, &val
);
170 xfs_stats_clearall(stats
->xs_stats
);
173 XFS_SYSFS_ATTR_WO(stats_clear
);
175 static struct attribute
*xfs_stats_attrs
[] = {
177 ATTR_LIST(stats_clear
),
181 struct kobj_type xfs_stats_ktype
= {
182 .release
= xfs_sysfs_release
,
183 .sysfs_ops
= &xfs_sysfs_ops
,
184 .default_attrs
= xfs_stats_attrs
,
189 static inline struct xlog
*
190 to_xlog(struct kobject
*kobject
)
192 struct xfs_kobj
*kobj
= to_kobj(kobject
);
194 return container_of(kobj
, struct xlog
, l_kobj
);
199 struct kobject
*kobject
,
204 struct xlog
*log
= to_xlog(kobject
);
206 spin_lock(&log
->l_icloglock
);
207 cycle
= log
->l_curr_cycle
;
208 block
= log
->l_curr_block
;
209 spin_unlock(&log
->l_icloglock
);
211 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, block
);
213 XFS_SYSFS_ATTR_RO(log_head_lsn
);
217 struct kobject
*kobject
,
222 struct xlog
*log
= to_xlog(kobject
);
224 xlog_crack_atomic_lsn(&log
->l_tail_lsn
, &cycle
, &block
);
225 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, block
);
227 XFS_SYSFS_ATTR_RO(log_tail_lsn
);
230 reserve_grant_head_show(
231 struct kobject
*kobject
,
237 struct xlog
*log
= to_xlog(kobject
);
239 xlog_crack_grant_head(&log
->l_reserve_head
.grant
, &cycle
, &bytes
);
240 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, bytes
);
242 XFS_SYSFS_ATTR_RO(reserve_grant_head
);
245 write_grant_head_show(
246 struct kobject
*kobject
,
251 struct xlog
*log
= to_xlog(kobject
);
253 xlog_crack_grant_head(&log
->l_write_head
.grant
, &cycle
, &bytes
);
254 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, bytes
);
256 XFS_SYSFS_ATTR_RO(write_grant_head
);
260 log_badcrc_factor_store(
261 struct kobject
*kobject
,
265 struct xlog
*log
= to_xlog(kobject
);
269 ret
= kstrtouint(buf
, 0, &val
);
273 log
->l_badcrc_factor
= val
;
279 log_badcrc_factor_show(
280 struct kobject
*kobject
,
283 struct xlog
*log
= to_xlog(kobject
);
285 return snprintf(buf
, PAGE_SIZE
, "%d\n", log
->l_badcrc_factor
);
288 XFS_SYSFS_ATTR_RW(log_badcrc_factor
);
291 static struct attribute
*xfs_log_attrs
[] = {
292 ATTR_LIST(log_head_lsn
),
293 ATTR_LIST(log_tail_lsn
),
294 ATTR_LIST(reserve_grant_head
),
295 ATTR_LIST(write_grant_head
),
297 ATTR_LIST(log_badcrc_factor
),
302 struct kobj_type xfs_log_ktype
= {
303 .release
= xfs_sysfs_release
,
304 .sysfs_ops
= &xfs_sysfs_ops
,
305 .default_attrs
= xfs_log_attrs
,