blob: 9835139ce1ec24cd2e1d5358377bd844d4323ab7 [file] [log] [blame]
Brian Fostera31b1d32014-07-15 08:07:01 +10001/*
2 * Copyright (c) 2014 Red Hat, Inc.
3 * All Rights Reserved.
4 *
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.
8 *
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.
13 *
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
17 */
18
19#include "xfs.h"
20#include "xfs_sysfs.h"
Brian Fosterbaff4e42014-07-15 08:07:29 +100021#include "xfs_log_format.h"
22#include "xfs_log.h"
23#include "xfs_log_priv.h"
Brian Fostera31b1d32014-07-15 08:07:01 +100024
25struct 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);
29};
30
31static inline struct xfs_sysfs_attr *
32to_attr(struct attribute *attr)
33{
34 return container_of(attr, struct xfs_sysfs_attr, attr);
35}
36
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)
41
42#define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr
43
44/*
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.
48 */
49
50struct kobj_type xfs_mp_ktype = {
51 .release = xfs_sysfs_release,
52};
Brian Fosterbaff4e42014-07-15 08:07:29 +100053
54/* xlog */
55
Brian Foster80d6d692014-07-15 08:07:48 +100056STATIC ssize_t
57log_head_lsn_show(
58 char *buf,
59 void *data)
60{
61 struct xlog *log = data;
62 int cycle;
63 int block;
64
65 spin_lock(&log->l_icloglock);
66 cycle = log->l_curr_cycle;
67 block = log->l_curr_block;
68 spin_unlock(&log->l_icloglock);
69
70 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
71}
72XFS_SYSFS_ATTR_RO(log_head_lsn);
73
74STATIC ssize_t
75log_tail_lsn_show(
76 char *buf,
77 void *data)
78{
79 struct xlog *log = data;
80 int cycle;
81 int block;
82
83 xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block);
84 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
85}
86XFS_SYSFS_ATTR_RO(log_tail_lsn);
87
88STATIC ssize_t
89reserve_grant_head_show(
90 char *buf,
91 void *data)
92{
93 struct xlog *log = data;
94 int cycle;
95 int bytes;
96
97 xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes);
98 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
99}
100XFS_SYSFS_ATTR_RO(reserve_grant_head);
101
102STATIC ssize_t
103write_grant_head_show(
104 char *buf,
105 void *data)
106{
107 struct xlog *log = data;
108 int cycle;
109 int bytes;
110
111 xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes);
112 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
113}
114XFS_SYSFS_ATTR_RO(write_grant_head);
115
Brian Fosterbaff4e42014-07-15 08:07:29 +1000116static struct attribute *xfs_log_attrs[] = {
Brian Foster80d6d692014-07-15 08:07:48 +1000117 ATTR_LIST(log_head_lsn),
118 ATTR_LIST(log_tail_lsn),
119 ATTR_LIST(reserve_grant_head),
120 ATTR_LIST(write_grant_head),
Brian Fosterbaff4e42014-07-15 08:07:29 +1000121 NULL,
122};
123
124static inline struct xlog *
125to_xlog(struct kobject *kobject)
126{
127 struct xfs_kobj *kobj = to_kobj(kobject);
128 return container_of(kobj, struct xlog, l_kobj);
129}
130
131STATIC ssize_t
132xfs_log_show(
133 struct kobject *kobject,
134 struct attribute *attr,
135 char *buf)
136{
137 struct xlog *log = to_xlog(kobject);
138 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
139
140 return xfs_attr->show ? xfs_attr->show(buf, log) : 0;
141}
142
143STATIC ssize_t
144xfs_log_store(
145 struct kobject *kobject,
146 struct attribute *attr,
147 const char *buf,
148 size_t count)
149{
150 struct xlog *log = to_xlog(kobject);
151 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
152
153 return xfs_attr->store ? xfs_attr->store(buf, count, log) : 0;
154}
155
156static struct sysfs_ops xfs_log_ops = {
157 .show = xfs_log_show,
158 .store = xfs_log_store,
159};
160
161struct kobj_type xfs_log_ktype = {
162 .release = xfs_sysfs_release,
163 .sysfs_ops = &xfs_log_ops,
164 .default_attrs = xfs_log_attrs,
165};