blob: 641d625eb334c3230191dce12ecacad4e41d6e4b [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"
Bill O'Donnellbb230c12015-10-12 05:15:45 +110024#include "xfs_stats.h"
Brian Fostera31b1d32014-07-15 08:07:01 +100025
26struct xfs_sysfs_attr {
27 struct attribute attr;
Bill O'Donnella27c2642015-10-12 05:18:45 +110028 ssize_t (*show)(struct kobject *kobject, char *buf);
29 ssize_t (*store)(struct kobject *kobject, const char *buf,
30 size_t count);
Brian Fostera31b1d32014-07-15 08:07:01 +100031};
32
33static inline struct xfs_sysfs_attr *
34to_attr(struct attribute *attr)
35{
36 return container_of(attr, struct xfs_sysfs_attr, attr);
37}
38
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)
Bill O'Donnellbb230c12015-10-12 05:15:45 +110043#define XFS_SYSFS_ATTR_WO(name) \
44 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_WO(name)
Brian Fostera31b1d32014-07-15 08:07:01 +100045
46#define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr
47
48/*
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.
52 */
53
54struct kobj_type xfs_mp_ktype = {
55 .release = xfs_sysfs_release,
56};
Brian Fosterbaff4e42014-07-15 08:07:29 +100057
Bill O'Donnella27c2642015-10-12 05:18:45 +110058STATIC ssize_t
59xfs_sysfs_object_show(
60 struct kobject *kobject,
61 struct attribute *attr,
62 char *buf)
63{
64 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
65
66 return xfs_attr->show ? xfs_attr->show(kobject, buf) : 0;
67}
68
69STATIC ssize_t
70xfs_sysfs_object_store(
71 struct kobject *kobject,
72 struct attribute *attr,
73 const char *buf,
74 size_t count)
75{
76 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
77
78 return xfs_attr->store ? xfs_attr->store(kobject, buf, count) : 0;
79}
80
81static const struct sysfs_ops xfs_sysfs_ops = {
82 .show = xfs_sysfs_object_show,
83 .store = xfs_sysfs_object_store,
84};
85
Brian Foster65b65732014-09-09 11:52:42 +100086#ifdef DEBUG
87/* debug */
88
Brian Foster2e227172014-09-09 11:56:13 +100089STATIC ssize_t
90log_recovery_delay_store(
Bill O'Donnella27c2642015-10-12 05:18:45 +110091 struct kobject *kobject,
Brian Foster2e227172014-09-09 11:56:13 +100092 const char *buf,
Bill O'Donnella27c2642015-10-12 05:18:45 +110093 size_t count)
Brian Foster2e227172014-09-09 11:56:13 +100094{
95 int ret;
96 int val;
97
98 ret = kstrtoint(buf, 0, &val);
99 if (ret)
100 return ret;
101
102 if (val < 0 || val > 60)
103 return -EINVAL;
104
105 xfs_globals.log_recovery_delay = val;
106
107 return count;
108}
109
110STATIC ssize_t
111log_recovery_delay_show(
Bill O'Donnella27c2642015-10-12 05:18:45 +1100112 struct kobject *kobject,
113 char *buf)
Brian Foster2e227172014-09-09 11:56:13 +1000114{
115 return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.log_recovery_delay);
116}
117XFS_SYSFS_ATTR_RW(log_recovery_delay);
118
Brian Foster65b65732014-09-09 11:52:42 +1000119static struct attribute *xfs_dbg_attrs[] = {
Brian Foster2e227172014-09-09 11:56:13 +1000120 ATTR_LIST(log_recovery_delay),
Brian Foster65b65732014-09-09 11:52:42 +1000121 NULL,
122};
123
Brian Foster65b65732014-09-09 11:52:42 +1000124struct kobj_type xfs_dbg_ktype = {
125 .release = xfs_sysfs_release,
Bill O'Donnella27c2642015-10-12 05:18:45 +1100126 .sysfs_ops = &xfs_sysfs_ops,
Brian Foster65b65732014-09-09 11:52:42 +1000127 .default_attrs = xfs_dbg_attrs,
128};
129
130#endif /* DEBUG */
131
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100132/* stats */
133
Bill O'Donnell80529c42015-10-12 05:19:45 +1100134static inline struct xstats *
135to_xstats(struct kobject *kobject)
136{
137 struct xfs_kobj *kobj = to_kobj(kobject);
138
139 return container_of(kobj, struct xstats, xs_kobj);
140}
141
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100142STATIC ssize_t
143stats_show(
Bill O'Donnella27c2642015-10-12 05:18:45 +1100144 struct kobject *kobject,
145 char *buf)
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100146{
Bill O'Donnell80529c42015-10-12 05:19:45 +1100147 struct xstats *stats = to_xstats(kobject);
148
149 return xfs_stats_format(stats->xs_stats, buf);
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100150}
151XFS_SYSFS_ATTR_RO(stats);
152
153STATIC ssize_t
154stats_clear_store(
Bill O'Donnella27c2642015-10-12 05:18:45 +1100155 struct kobject *kobject,
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100156 const char *buf,
Bill O'Donnella27c2642015-10-12 05:18:45 +1100157 size_t count)
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100158{
159 int ret;
160 int val;
Bill O'Donnell80529c42015-10-12 05:19:45 +1100161 struct xstats *stats = to_xstats(kobject);
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100162
163 ret = kstrtoint(buf, 0, &val);
164 if (ret)
165 return ret;
166
167 if (val != 1)
168 return -EINVAL;
Bill O'Donnell80529c42015-10-12 05:19:45 +1100169
170 xfs_stats_clearall(stats->xs_stats);
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100171 return count;
172}
173XFS_SYSFS_ATTR_WO(stats_clear);
174
175static struct attribute *xfs_stats_attrs[] = {
176 ATTR_LIST(stats),
177 ATTR_LIST(stats_clear),
178 NULL,
179};
180
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100181struct kobj_type xfs_stats_ktype = {
182 .release = xfs_sysfs_release,
Bill O'Donnella27c2642015-10-12 05:18:45 +1100183 .sysfs_ops = &xfs_sysfs_ops,
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100184 .default_attrs = xfs_stats_attrs,
185};
186
Brian Fosterbaff4e42014-07-15 08:07:29 +1000187/* xlog */
188
Bill O'Donnella27c2642015-10-12 05:18:45 +1100189static inline struct xlog *
190to_xlog(struct kobject *kobject)
191{
192 struct xfs_kobj *kobj = to_kobj(kobject);
193
194 return container_of(kobj, struct xlog, l_kobj);
195}
196
Brian Foster80d6d692014-07-15 08:07:48 +1000197STATIC ssize_t
198log_head_lsn_show(
Bill O'Donnella27c2642015-10-12 05:18:45 +1100199 struct kobject *kobject,
200 char *buf)
Brian Foster80d6d692014-07-15 08:07:48 +1000201{
Brian Foster80d6d692014-07-15 08:07:48 +1000202 int cycle;
203 int block;
Bill O'Donnella27c2642015-10-12 05:18:45 +1100204 struct xlog *log = to_xlog(kobject);
Brian Foster80d6d692014-07-15 08:07:48 +1000205
206 spin_lock(&log->l_icloglock);
207 cycle = log->l_curr_cycle;
208 block = log->l_curr_block;
209 spin_unlock(&log->l_icloglock);
210
211 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
212}
213XFS_SYSFS_ATTR_RO(log_head_lsn);
214
215STATIC ssize_t
216log_tail_lsn_show(
Bill O'Donnella27c2642015-10-12 05:18:45 +1100217 struct kobject *kobject,
218 char *buf)
Brian Foster80d6d692014-07-15 08:07:48 +1000219{
Brian Foster80d6d692014-07-15 08:07:48 +1000220 int cycle;
221 int block;
Bill O'Donnella27c2642015-10-12 05:18:45 +1100222 struct xlog *log = to_xlog(kobject);
Brian Foster80d6d692014-07-15 08:07:48 +1000223
224 xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block);
225 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
226}
227XFS_SYSFS_ATTR_RO(log_tail_lsn);
228
229STATIC ssize_t
230reserve_grant_head_show(
Bill O'Donnella27c2642015-10-12 05:18:45 +1100231 struct kobject *kobject,
232 char *buf)
233
Brian Foster80d6d692014-07-15 08:07:48 +1000234{
Brian Foster80d6d692014-07-15 08:07:48 +1000235 int cycle;
236 int bytes;
Bill O'Donnella27c2642015-10-12 05:18:45 +1100237 struct xlog *log = to_xlog(kobject);
Brian Foster80d6d692014-07-15 08:07:48 +1000238
239 xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes);
240 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
241}
242XFS_SYSFS_ATTR_RO(reserve_grant_head);
243
244STATIC ssize_t
245write_grant_head_show(
Bill O'Donnella27c2642015-10-12 05:18:45 +1100246 struct kobject *kobject,
247 char *buf)
Brian Foster80d6d692014-07-15 08:07:48 +1000248{
Brian Foster80d6d692014-07-15 08:07:48 +1000249 int cycle;
250 int bytes;
Bill O'Donnella27c2642015-10-12 05:18:45 +1100251 struct xlog *log = to_xlog(kobject);
Brian Foster80d6d692014-07-15 08:07:48 +1000252
253 xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes);
254 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
255}
256XFS_SYSFS_ATTR_RO(write_grant_head);
257
Brian Foster609adfc2016-01-05 07:41:16 +1100258#ifdef DEBUG
259STATIC ssize_t
260log_badcrc_factor_store(
261 struct kobject *kobject,
262 const char *buf,
263 size_t count)
264{
265 struct xlog *log = to_xlog(kobject);
266 int ret;
267 uint32_t val;
268
269 ret = kstrtouint(buf, 0, &val);
270 if (ret)
271 return ret;
272
273 log->l_badcrc_factor = val;
274
275 return count;
276}
277
278STATIC ssize_t
279log_badcrc_factor_show(
280 struct kobject *kobject,
281 char *buf)
282{
283 struct xlog *log = to_xlog(kobject);
284
285 return snprintf(buf, PAGE_SIZE, "%d\n", log->l_badcrc_factor);
286}
287
288XFS_SYSFS_ATTR_RW(log_badcrc_factor);
289#endif /* DEBUG */
290
Brian Fosterbaff4e42014-07-15 08:07:29 +1000291static struct attribute *xfs_log_attrs[] = {
Brian Foster80d6d692014-07-15 08:07:48 +1000292 ATTR_LIST(log_head_lsn),
293 ATTR_LIST(log_tail_lsn),
294 ATTR_LIST(reserve_grant_head),
295 ATTR_LIST(write_grant_head),
Brian Foster609adfc2016-01-05 07:41:16 +1100296#ifdef DEBUG
297 ATTR_LIST(log_badcrc_factor),
298#endif
Brian Fosterbaff4e42014-07-15 08:07:29 +1000299 NULL,
300};
301
Brian Fosterbaff4e42014-07-15 08:07:29 +1000302struct kobj_type xfs_log_ktype = {
303 .release = xfs_sysfs_release,
Bill O'Donnella27c2642015-10-12 05:18:45 +1100304 .sysfs_ops = &xfs_sysfs_ops,
Brian Fosterbaff4e42014-07-15 08:07:29 +1000305 .default_attrs = xfs_log_attrs,
306};