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_format.h"
22 #include "xfs_log_format.h"
23 #include "xfs_trans_resv.h"
25 #include "xfs_log_priv.h"
26 #include "xfs_stats.h"
27 #include "xfs_mount.h"
29 struct xfs_sysfs_attr
{
30 struct attribute attr
;
31 ssize_t (*show
)(struct kobject
*kobject
, char *buf
);
32 ssize_t (*store
)(struct kobject
*kobject
, const char *buf
,
36 static inline struct xfs_sysfs_attr
*
37 to_attr(struct attribute
*attr
)
39 return container_of(attr
, struct xfs_sysfs_attr
, attr
);
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)
46 #define XFS_SYSFS_ATTR_WO(name) \
47 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_WO(name)
49 #define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr
52 xfs_sysfs_object_show(
53 struct kobject
*kobject
,
54 struct attribute
*attr
,
57 struct xfs_sysfs_attr
*xfs_attr
= to_attr(attr
);
59 return xfs_attr
->show
? xfs_attr
->show(kobject
, buf
) : 0;
63 xfs_sysfs_object_store(
64 struct kobject
*kobject
,
65 struct attribute
*attr
,
69 struct xfs_sysfs_attr
*xfs_attr
= to_attr(attr
);
71 return xfs_attr
->store
? xfs_attr
->store(kobject
, buf
, count
) : 0;
74 static const struct sysfs_ops xfs_sysfs_ops
= {
75 .show
= xfs_sysfs_object_show
,
76 .store
= xfs_sysfs_object_store
,
80 * xfs_mount kobject. The mp kobject also serves as the per-mount parent object
81 * that is identified by the fsname under sysfs.
84 static inline struct xfs_mount
*
85 to_mp(struct kobject
*kobject
)
87 struct xfs_kobj
*kobj
= to_kobj(kobject
);
89 return container_of(kobj
, struct xfs_mount
, m_kobj
);
96 struct kobject
*kobject
,
100 struct xfs_mount
*mp
= to_mp(kobject
);
104 ret
= kstrtoint(buf
, 0, &val
);
109 mp
->m_fail_writes
= true;
111 mp
->m_fail_writes
= false;
120 struct kobject
*kobject
,
123 struct xfs_mount
*mp
= to_mp(kobject
);
125 return snprintf(buf
, PAGE_SIZE
, "%d\n", mp
->m_fail_writes
? 1 : 0);
127 XFS_SYSFS_ATTR_RW(fail_writes
);
131 static struct attribute
*xfs_mp_attrs
[] = {
133 ATTR_LIST(fail_writes
),
138 struct kobj_type xfs_mp_ktype
= {
139 .release
= xfs_sysfs_release
,
140 .sysfs_ops
= &xfs_sysfs_ops
,
141 .default_attrs
= xfs_mp_attrs
,
148 log_recovery_delay_store(
149 struct kobject
*kobject
,
156 ret
= kstrtoint(buf
, 0, &val
);
160 if (val
< 0 || val
> 60)
163 xfs_globals
.log_recovery_delay
= val
;
169 log_recovery_delay_show(
170 struct kobject
*kobject
,
173 return snprintf(buf
, PAGE_SIZE
, "%d\n", xfs_globals
.log_recovery_delay
);
175 XFS_SYSFS_ATTR_RW(log_recovery_delay
);
177 static struct attribute
*xfs_dbg_attrs
[] = {
178 ATTR_LIST(log_recovery_delay
),
182 struct kobj_type xfs_dbg_ktype
= {
183 .release
= xfs_sysfs_release
,
184 .sysfs_ops
= &xfs_sysfs_ops
,
185 .default_attrs
= xfs_dbg_attrs
,
192 static inline struct xstats
*
193 to_xstats(struct kobject
*kobject
)
195 struct xfs_kobj
*kobj
= to_kobj(kobject
);
197 return container_of(kobj
, struct xstats
, xs_kobj
);
202 struct kobject
*kobject
,
205 struct xstats
*stats
= to_xstats(kobject
);
207 return xfs_stats_format(stats
->xs_stats
, buf
);
209 XFS_SYSFS_ATTR_RO(stats
);
213 struct kobject
*kobject
,
219 struct xstats
*stats
= to_xstats(kobject
);
221 ret
= kstrtoint(buf
, 0, &val
);
228 xfs_stats_clearall(stats
->xs_stats
);
231 XFS_SYSFS_ATTR_WO(stats_clear
);
233 static struct attribute
*xfs_stats_attrs
[] = {
235 ATTR_LIST(stats_clear
),
239 struct kobj_type xfs_stats_ktype
= {
240 .release
= xfs_sysfs_release
,
241 .sysfs_ops
= &xfs_sysfs_ops
,
242 .default_attrs
= xfs_stats_attrs
,
247 static inline struct xlog
*
248 to_xlog(struct kobject
*kobject
)
250 struct xfs_kobj
*kobj
= to_kobj(kobject
);
252 return container_of(kobj
, struct xlog
, l_kobj
);
257 struct kobject
*kobject
,
262 struct xlog
*log
= to_xlog(kobject
);
264 spin_lock(&log
->l_icloglock
);
265 cycle
= log
->l_curr_cycle
;
266 block
= log
->l_curr_block
;
267 spin_unlock(&log
->l_icloglock
);
269 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, block
);
271 XFS_SYSFS_ATTR_RO(log_head_lsn
);
275 struct kobject
*kobject
,
280 struct xlog
*log
= to_xlog(kobject
);
282 xlog_crack_atomic_lsn(&log
->l_tail_lsn
, &cycle
, &block
);
283 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, block
);
285 XFS_SYSFS_ATTR_RO(log_tail_lsn
);
288 reserve_grant_head_show(
289 struct kobject
*kobject
,
295 struct xlog
*log
= to_xlog(kobject
);
297 xlog_crack_grant_head(&log
->l_reserve_head
.grant
, &cycle
, &bytes
);
298 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, bytes
);
300 XFS_SYSFS_ATTR_RO(reserve_grant_head
);
303 write_grant_head_show(
304 struct kobject
*kobject
,
309 struct xlog
*log
= to_xlog(kobject
);
311 xlog_crack_grant_head(&log
->l_write_head
.grant
, &cycle
, &bytes
);
312 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, bytes
);
314 XFS_SYSFS_ATTR_RO(write_grant_head
);
318 log_badcrc_factor_store(
319 struct kobject
*kobject
,
323 struct xlog
*log
= to_xlog(kobject
);
327 ret
= kstrtouint(buf
, 0, &val
);
331 log
->l_badcrc_factor
= val
;
337 log_badcrc_factor_show(
338 struct kobject
*kobject
,
341 struct xlog
*log
= to_xlog(kobject
);
343 return snprintf(buf
, PAGE_SIZE
, "%d\n", log
->l_badcrc_factor
);
346 XFS_SYSFS_ATTR_RW(log_badcrc_factor
);
349 static struct attribute
*xfs_log_attrs
[] = {
350 ATTR_LIST(log_head_lsn
),
351 ATTR_LIST(log_tail_lsn
),
352 ATTR_LIST(reserve_grant_head
),
353 ATTR_LIST(write_grant_head
),
355 ATTR_LIST(log_badcrc_factor
),
360 struct kobj_type xfs_log_ktype
= {
361 .release
= xfs_sysfs_release
,
362 .sysfs_ops
= &xfs_sysfs_ops
,
363 .default_attrs
= xfs_log_attrs
,