blob: 6ced4f1434948d3757077c732a93d6fac88ea0cc [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 Foster801cc4e2016-03-15 11:42:44 +110021#include "xfs_format.h"
Brian Fosterbaff4e42014-07-15 08:07:29 +100022#include "xfs_log_format.h"
Brian Foster801cc4e2016-03-15 11:42:44 +110023#include "xfs_trans_resv.h"
Brian Fosterbaff4e42014-07-15 08:07:29 +100024#include "xfs_log.h"
25#include "xfs_log_priv.h"
Bill O'Donnellbb230c12015-10-12 05:15:45 +110026#include "xfs_stats.h"
Brian Foster801cc4e2016-03-15 11:42:44 +110027#include "xfs_mount.h"
Brian Fostera31b1d32014-07-15 08:07:01 +100028
29struct xfs_sysfs_attr {
30 struct attribute attr;
Bill O'Donnella27c2642015-10-12 05:18:45 +110031 ssize_t (*show)(struct kobject *kobject, char *buf);
32 ssize_t (*store)(struct kobject *kobject, const char *buf,
33 size_t count);
Brian Fostera31b1d32014-07-15 08:07:01 +100034};
35
36static inline struct xfs_sysfs_attr *
37to_attr(struct attribute *attr)
38{
39 return container_of(attr, struct xfs_sysfs_attr, attr);
40}
41
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)
Bill O'Donnellbb230c12015-10-12 05:15:45 +110046#define XFS_SYSFS_ATTR_WO(name) \
47 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_WO(name)
Brian Fostera31b1d32014-07-15 08:07:01 +100048
49#define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr
50
Bill O'Donnella27c2642015-10-12 05:18:45 +110051STATIC ssize_t
52xfs_sysfs_object_show(
53 struct kobject *kobject,
54 struct attribute *attr,
55 char *buf)
56{
57 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
58
59 return xfs_attr->show ? xfs_attr->show(kobject, buf) : 0;
60}
61
62STATIC ssize_t
63xfs_sysfs_object_store(
64 struct kobject *kobject,
65 struct attribute *attr,
66 const char *buf,
67 size_t count)
68{
69 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
70
71 return xfs_attr->store ? xfs_attr->store(kobject, buf, count) : 0;
72}
73
74static const struct sysfs_ops xfs_sysfs_ops = {
75 .show = xfs_sysfs_object_show,
76 .store = xfs_sysfs_object_store,
77};
78
Brian Foster801cc4e2016-03-15 11:42:44 +110079/*
80 * xfs_mount kobject. The mp kobject also serves as the per-mount parent object
81 * that is identified by the fsname under sysfs.
82 */
83
84static inline struct xfs_mount *
85to_mp(struct kobject *kobject)
86{
87 struct xfs_kobj *kobj = to_kobj(kobject);
88
89 return container_of(kobj, struct xfs_mount, m_kobj);
90}
91
92#ifdef DEBUG
93
94STATIC ssize_t
95fail_writes_store(
96 struct kobject *kobject,
97 const char *buf,
98 size_t count)
99{
100 struct xfs_mount *mp = to_mp(kobject);
101 int ret;
102 int val;
103
104 ret = kstrtoint(buf, 0, &val);
105 if (ret)
106 return ret;
107
108 if (val == 1)
109 mp->m_fail_writes = true;
110 else if (val == 0)
111 mp->m_fail_writes = false;
112 else
113 return -EINVAL;
114
115 return count;
116}
117
118STATIC ssize_t
119fail_writes_show(
120 struct kobject *kobject,
121 char *buf)
122{
123 struct xfs_mount *mp = to_mp(kobject);
124
125 return snprintf(buf, PAGE_SIZE, "%d\n", mp->m_fail_writes ? 1 : 0);
126}
127XFS_SYSFS_ATTR_RW(fail_writes);
128
129#endif /* DEBUG */
130
131static struct attribute *xfs_mp_attrs[] = {
132#ifdef DEBUG
133 ATTR_LIST(fail_writes),
134#endif
135 NULL,
136};
137
138struct kobj_type xfs_mp_ktype = {
139 .release = xfs_sysfs_release,
140 .sysfs_ops = &xfs_sysfs_ops,
141 .default_attrs = xfs_mp_attrs,
142};
143
Brian Foster65b65732014-09-09 11:52:42 +1000144#ifdef DEBUG
145/* debug */
146
Brian Foster2e227172014-09-09 11:56:13 +1000147STATIC ssize_t
148log_recovery_delay_store(
Bill O'Donnella27c2642015-10-12 05:18:45 +1100149 struct kobject *kobject,
Brian Foster2e227172014-09-09 11:56:13 +1000150 const char *buf,
Bill O'Donnella27c2642015-10-12 05:18:45 +1100151 size_t count)
Brian Foster2e227172014-09-09 11:56:13 +1000152{
153 int ret;
154 int val;
155
156 ret = kstrtoint(buf, 0, &val);
157 if (ret)
158 return ret;
159
160 if (val < 0 || val > 60)
161 return -EINVAL;
162
163 xfs_globals.log_recovery_delay = val;
164
165 return count;
166}
167
168STATIC ssize_t
169log_recovery_delay_show(
Bill O'Donnella27c2642015-10-12 05:18:45 +1100170 struct kobject *kobject,
171 char *buf)
Brian Foster2e227172014-09-09 11:56:13 +1000172{
173 return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.log_recovery_delay);
174}
175XFS_SYSFS_ATTR_RW(log_recovery_delay);
176
Brian Foster65b65732014-09-09 11:52:42 +1000177static struct attribute *xfs_dbg_attrs[] = {
Brian Foster2e227172014-09-09 11:56:13 +1000178 ATTR_LIST(log_recovery_delay),
Brian Foster65b65732014-09-09 11:52:42 +1000179 NULL,
180};
181
Brian Foster65b65732014-09-09 11:52:42 +1000182struct kobj_type xfs_dbg_ktype = {
183 .release = xfs_sysfs_release,
Bill O'Donnella27c2642015-10-12 05:18:45 +1100184 .sysfs_ops = &xfs_sysfs_ops,
Brian Foster65b65732014-09-09 11:52:42 +1000185 .default_attrs = xfs_dbg_attrs,
186};
187
188#endif /* DEBUG */
189
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100190/* stats */
191
Bill O'Donnell80529c42015-10-12 05:19:45 +1100192static inline struct xstats *
193to_xstats(struct kobject *kobject)
194{
195 struct xfs_kobj *kobj = to_kobj(kobject);
196
197 return container_of(kobj, struct xstats, xs_kobj);
198}
199
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100200STATIC ssize_t
201stats_show(
Bill O'Donnella27c2642015-10-12 05:18:45 +1100202 struct kobject *kobject,
203 char *buf)
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100204{
Bill O'Donnell80529c42015-10-12 05:19:45 +1100205 struct xstats *stats = to_xstats(kobject);
206
207 return xfs_stats_format(stats->xs_stats, buf);
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100208}
209XFS_SYSFS_ATTR_RO(stats);
210
211STATIC ssize_t
212stats_clear_store(
Bill O'Donnella27c2642015-10-12 05:18:45 +1100213 struct kobject *kobject,
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100214 const char *buf,
Bill O'Donnella27c2642015-10-12 05:18:45 +1100215 size_t count)
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100216{
217 int ret;
218 int val;
Bill O'Donnell80529c42015-10-12 05:19:45 +1100219 struct xstats *stats = to_xstats(kobject);
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100220
221 ret = kstrtoint(buf, 0, &val);
222 if (ret)
223 return ret;
224
225 if (val != 1)
226 return -EINVAL;
Bill O'Donnell80529c42015-10-12 05:19:45 +1100227
228 xfs_stats_clearall(stats->xs_stats);
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100229 return count;
230}
231XFS_SYSFS_ATTR_WO(stats_clear);
232
233static struct attribute *xfs_stats_attrs[] = {
234 ATTR_LIST(stats),
235 ATTR_LIST(stats_clear),
236 NULL,
237};
238
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100239struct kobj_type xfs_stats_ktype = {
240 .release = xfs_sysfs_release,
Bill O'Donnella27c2642015-10-12 05:18:45 +1100241 .sysfs_ops = &xfs_sysfs_ops,
Bill O'Donnellbb230c12015-10-12 05:15:45 +1100242 .default_attrs = xfs_stats_attrs,
243};
244
Brian Fosterbaff4e42014-07-15 08:07:29 +1000245/* xlog */
246
Bill O'Donnella27c2642015-10-12 05:18:45 +1100247static inline struct xlog *
248to_xlog(struct kobject *kobject)
249{
250 struct xfs_kobj *kobj = to_kobj(kobject);
251
252 return container_of(kobj, struct xlog, l_kobj);
253}
254
Brian Foster80d6d692014-07-15 08:07:48 +1000255STATIC ssize_t
256log_head_lsn_show(
Bill O'Donnella27c2642015-10-12 05:18:45 +1100257 struct kobject *kobject,
258 char *buf)
Brian Foster80d6d692014-07-15 08:07:48 +1000259{
Brian Foster80d6d692014-07-15 08:07:48 +1000260 int cycle;
261 int block;
Bill O'Donnella27c2642015-10-12 05:18:45 +1100262 struct xlog *log = to_xlog(kobject);
Brian Foster80d6d692014-07-15 08:07:48 +1000263
264 spin_lock(&log->l_icloglock);
265 cycle = log->l_curr_cycle;
266 block = log->l_curr_block;
267 spin_unlock(&log->l_icloglock);
268
269 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
270}
271XFS_SYSFS_ATTR_RO(log_head_lsn);
272
273STATIC ssize_t
274log_tail_lsn_show(
Bill O'Donnella27c2642015-10-12 05:18:45 +1100275 struct kobject *kobject,
276 char *buf)
Brian Foster80d6d692014-07-15 08:07:48 +1000277{
Brian Foster80d6d692014-07-15 08:07:48 +1000278 int cycle;
279 int block;
Bill O'Donnella27c2642015-10-12 05:18:45 +1100280 struct xlog *log = to_xlog(kobject);
Brian Foster80d6d692014-07-15 08:07:48 +1000281
282 xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block);
283 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
284}
285XFS_SYSFS_ATTR_RO(log_tail_lsn);
286
287STATIC ssize_t
288reserve_grant_head_show(
Bill O'Donnella27c2642015-10-12 05:18:45 +1100289 struct kobject *kobject,
290 char *buf)
291
Brian Foster80d6d692014-07-15 08:07:48 +1000292{
Brian Foster80d6d692014-07-15 08:07:48 +1000293 int cycle;
294 int bytes;
Bill O'Donnella27c2642015-10-12 05:18:45 +1100295 struct xlog *log = to_xlog(kobject);
Brian Foster80d6d692014-07-15 08:07:48 +1000296
297 xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes);
298 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
299}
300XFS_SYSFS_ATTR_RO(reserve_grant_head);
301
302STATIC ssize_t
303write_grant_head_show(
Bill O'Donnella27c2642015-10-12 05:18:45 +1100304 struct kobject *kobject,
305 char *buf)
Brian Foster80d6d692014-07-15 08:07:48 +1000306{
Brian Foster80d6d692014-07-15 08:07:48 +1000307 int cycle;
308 int bytes;
Bill O'Donnella27c2642015-10-12 05:18:45 +1100309 struct xlog *log = to_xlog(kobject);
Brian Foster80d6d692014-07-15 08:07:48 +1000310
311 xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes);
312 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
313}
314XFS_SYSFS_ATTR_RO(write_grant_head);
315
Brian Foster609adfc2016-01-05 07:41:16 +1100316#ifdef DEBUG
317STATIC ssize_t
318log_badcrc_factor_store(
319 struct kobject *kobject,
320 const char *buf,
321 size_t count)
322{
323 struct xlog *log = to_xlog(kobject);
324 int ret;
325 uint32_t val;
326
327 ret = kstrtouint(buf, 0, &val);
328 if (ret)
329 return ret;
330
331 log->l_badcrc_factor = val;
332
333 return count;
334}
335
336STATIC ssize_t
337log_badcrc_factor_show(
338 struct kobject *kobject,
339 char *buf)
340{
341 struct xlog *log = to_xlog(kobject);
342
343 return snprintf(buf, PAGE_SIZE, "%d\n", log->l_badcrc_factor);
344}
345
346XFS_SYSFS_ATTR_RW(log_badcrc_factor);
347#endif /* DEBUG */
348
Brian Fosterbaff4e42014-07-15 08:07:29 +1000349static struct attribute *xfs_log_attrs[] = {
Brian Foster80d6d692014-07-15 08:07:48 +1000350 ATTR_LIST(log_head_lsn),
351 ATTR_LIST(log_tail_lsn),
352 ATTR_LIST(reserve_grant_head),
353 ATTR_LIST(write_grant_head),
Brian Foster609adfc2016-01-05 07:41:16 +1100354#ifdef DEBUG
355 ATTR_LIST(log_badcrc_factor),
356#endif
Brian Fosterbaff4e42014-07-15 08:07:29 +1000357 NULL,
358};
359
Brian Fosterbaff4e42014-07-15 08:07:29 +1000360struct kobj_type xfs_log_ktype = {
361 .release = xfs_sysfs_release,
Bill O'Donnella27c2642015-10-12 05:18:45 +1100362 .sysfs_ops = &xfs_sysfs_ops,
Brian Fosterbaff4e42014-07-15 08:07:29 +1000363 .default_attrs = xfs_log_attrs,
364};