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
,
61 struct xlog
*log
= data
;
65 spin_lock(&log
->l_icloglock
);
66 cycle
= log
->l_curr_cycle
;
67 block
= log
->l_curr_block
;
68 spin_unlock(&log
->l_icloglock
);
70 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, block
);
72 XFS_SYSFS_ATTR_RO(log_head_lsn
);
79 struct xlog
*log
= data
;
83 xlog_crack_atomic_lsn(&log
->l_tail_lsn
, &cycle
, &block
);
84 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, block
);
86 XFS_SYSFS_ATTR_RO(log_tail_lsn
);
89 reserve_grant_head_show(
93 struct xlog
*log
= data
;
97 xlog_crack_grant_head(&log
->l_reserve_head
.grant
, &cycle
, &bytes
);
98 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, bytes
);
100 XFS_SYSFS_ATTR_RO(reserve_grant_head
);
103 write_grant_head_show(
107 struct xlog
*log
= data
;
111 xlog_crack_grant_head(&log
->l_write_head
.grant
, &cycle
, &bytes
);
112 return snprintf(buf
, PAGE_SIZE
, "%d:%d\n", cycle
, bytes
);
114 XFS_SYSFS_ATTR_RO(write_grant_head
);
116 static struct attribute
*xfs_log_attrs
[] = {
117 ATTR_LIST(log_head_lsn
),
118 ATTR_LIST(log_tail_lsn
),
119 ATTR_LIST(reserve_grant_head
),
120 ATTR_LIST(write_grant_head
),
124 static inline struct xlog
*
125 to_xlog(struct kobject
*kobject
)
127 struct xfs_kobj
*kobj
= to_kobj(kobject
);
128 return container_of(kobj
, struct xlog
, l_kobj
);
133 struct kobject
*kobject
,
134 struct attribute
*attr
,
137 struct xlog
*log
= to_xlog(kobject
);
138 struct xfs_sysfs_attr
*xfs_attr
= to_attr(attr
);
140 return xfs_attr
->show
? xfs_attr
->show(buf
, log
) : 0;
145 struct kobject
*kobject
,
146 struct attribute
*attr
,
150 struct xlog
*log
= to_xlog(kobject
);
151 struct xfs_sysfs_attr
*xfs_attr
= to_attr(attr
);
153 return xfs_attr
->store
? xfs_attr
->store(buf
, count
, log
) : 0;
156 static struct sysfs_ops xfs_log_ops
= {
157 .show
= xfs_log_show
,
158 .store
= xfs_log_store
,
161 struct kobj_type xfs_log_ktype
= {
162 .release
= xfs_sysfs_release
,
163 .sysfs_ops
= &xfs_log_ops
,
164 .default_attrs
= xfs_log_attrs
,