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"
25 struct xfs_sysfs_attr
{
26 struct attribute attr
;
27 ssize_t (*show
)(char *buf
, void *data
);
28 ssize_t (*store
)(const char *buf
, size_t count
, void *data
);
31 static inline struct xfs_sysfs_attr
*
32 to_attr(struct attribute
*attr
)
34 return container_of(attr
, struct xfs_sysfs_attr
, attr
);
37 #define XFS_SYSFS_ATTR_RW(name) \
38 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RW(name)
39 #define XFS_SYSFS_ATTR_RO(name) \
40 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RO(name)
42 #define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr
45 * xfs_mount kobject. This currently has no attributes and thus no need for show
46 * and store helpers. The mp kobject serves as the per-mount parent object that
47 * is identified by the fsname under sysfs.
50 struct kobj_type xfs_mp_ktype
= {
51 .release
= xfs_sysfs_release
,
58 log_recovery_delay_store(
66 ret
= kstrtoint(buf
, 0, &val
);
70 if (val
< 0 || val
> 60)
73 xfs_globals
.log_recovery_delay
= val
;
79 log_recovery_delay_show(
83 return snprintf(buf
, PAGE_SIZE
, "%d\n", xfs_globals
.log_recovery_delay
);
85 XFS_SYSFS_ATTR_RW(log_recovery_delay
);
87 static struct attribute
*xfs_dbg_attrs
[] = {
88 ATTR_LIST(log_recovery_delay
),
94 struct kobject
*kobject
,
95 struct attribute
*attr
,
98 struct xfs_sysfs_attr
*xfs_attr
= to_attr(attr
);
100 return xfs_attr
->show
? xfs_attr
->show(buf
, NULL
) : 0;
105 struct kobject
*kobject
,
106 struct attribute
*attr
,
110 struct xfs_sysfs_attr
*xfs_attr
= to_attr(attr
);
112 return xfs_attr
->store
? xfs_attr
->store(buf
, count
, NULL
) : 0;
115 static struct sysfs_ops xfs_dbg_ops
= {
116 .show
= xfs_dbg_show
,
117 .store
= xfs_dbg_store
,
120 struct kobj_type xfs_dbg_ktype
= {
121 .release
= xfs_sysfs_release
,
122 .sysfs_ops
= &xfs_dbg_ops
,
123 .default_attrs
= xfs_dbg_attrs
,
135 struct xlog
*log
= data
;
139 spin_lock(&log
->l_icloglock
);
140 cycle
= log
->l_curr_cycle
;
141 block
= log
->l_curr_block
;
142 spin_unlock(&log
->l_icloglock
);
144 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, block
);
146 XFS_SYSFS_ATTR_RO(log_head_lsn
);
153 struct xlog
*log
= data
;
157 xlog_crack_atomic_lsn(&log
->l_tail_lsn
, &cycle
, &block
);
158 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, block
);
160 XFS_SYSFS_ATTR_RO(log_tail_lsn
);
163 reserve_grant_head_show(
167 struct xlog
*log
= data
;
171 xlog_crack_grant_head(&log
->l_reserve_head
.grant
, &cycle
, &bytes
);
172 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, bytes
);
174 XFS_SYSFS_ATTR_RO(reserve_grant_head
);
177 write_grant_head_show(
181 struct xlog
*log
= data
;
185 xlog_crack_grant_head(&log
->l_write_head
.grant
, &cycle
, &bytes
);
186 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, bytes
);
188 XFS_SYSFS_ATTR_RO(write_grant_head
);
190 static struct attribute
*xfs_log_attrs
[] = {
191 ATTR_LIST(log_head_lsn
),
192 ATTR_LIST(log_tail_lsn
),
193 ATTR_LIST(reserve_grant_head
),
194 ATTR_LIST(write_grant_head
),
198 static inline struct xlog
*
199 to_xlog(struct kobject
*kobject
)
201 struct xfs_kobj
*kobj
= to_kobj(kobject
);
202 return container_of(kobj
, struct xlog
, l_kobj
);
207 struct kobject
*kobject
,
208 struct attribute
*attr
,
211 struct xlog
*log
= to_xlog(kobject
);
212 struct xfs_sysfs_attr
*xfs_attr
= to_attr(attr
);
214 return xfs_attr
->show
? xfs_attr
->show(buf
, log
) : 0;
219 struct kobject
*kobject
,
220 struct attribute
*attr
,
224 struct xlog
*log
= to_xlog(kobject
);
225 struct xfs_sysfs_attr
*xfs_attr
= to_attr(attr
);
227 return xfs_attr
->store
? xfs_attr
->store(buf
, count
, log
) : 0;
230 static struct sysfs_ops xfs_log_ops
= {
231 .show
= xfs_log_show
,
232 .store
= xfs_log_store
,
235 struct kobj_type xfs_log_ktype
= {
236 .release
= xfs_sysfs_release
,
237 .sysfs_ops
= &xfs_log_ops
,
238 .default_attrs
= xfs_log_attrs
,