xfs: add configurable error support to metadata buffers
[deliverable/linux.git] / fs / xfs / xfs_sysfs.c
CommitLineData
a31b1d3d
BF
1/*
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"
192852be 20#include "xfs_shared.h"
801cc4e1 21#include "xfs_format.h"
baff4e44 22#include "xfs_log_format.h"
801cc4e1 23#include "xfs_trans_resv.h"
192852be 24#include "xfs_sysfs.h"
baff4e44
BF
25#include "xfs_log.h"
26#include "xfs_log_priv.h"
bb230c12 27#include "xfs_stats.h"
801cc4e1 28#include "xfs_mount.h"
a31b1d3d
BF
29
30struct xfs_sysfs_attr {
31 struct attribute attr;
a27c2640
BD
32 ssize_t (*show)(struct kobject *kobject, char *buf);
33 ssize_t (*store)(struct kobject *kobject, const char *buf,
34 size_t count);
a31b1d3d
BF
35};
36
37static inline struct xfs_sysfs_attr *
38to_attr(struct attribute *attr)
39{
40 return container_of(attr, struct xfs_sysfs_attr, attr);
41}
42
43#define XFS_SYSFS_ATTR_RW(name) \
44 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RW(name)
45#define XFS_SYSFS_ATTR_RO(name) \
46 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RO(name)
bb230c12
BD
47#define XFS_SYSFS_ATTR_WO(name) \
48 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_WO(name)
a31b1d3d
BF
49
50#define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr
51
a27c2640
BD
52STATIC ssize_t
53xfs_sysfs_object_show(
54 struct kobject *kobject,
55 struct attribute *attr,
56 char *buf)
57{
58 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
59
60 return xfs_attr->show ? xfs_attr->show(kobject, buf) : 0;
61}
62
63STATIC ssize_t
64xfs_sysfs_object_store(
65 struct kobject *kobject,
66 struct attribute *attr,
67 const char *buf,
68 size_t count)
69{
70 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
71
72 return xfs_attr->store ? xfs_attr->store(kobject, buf, count) : 0;
73}
74
75static const struct sysfs_ops xfs_sysfs_ops = {
76 .show = xfs_sysfs_object_show,
77 .store = xfs_sysfs_object_store,
78};
79
801cc4e1
BF
80/*
81 * xfs_mount kobject. The mp kobject also serves as the per-mount parent object
82 * that is identified by the fsname under sysfs.
83 */
84
85static inline struct xfs_mount *
86to_mp(struct kobject *kobject)
87{
88 struct xfs_kobj *kobj = to_kobj(kobject);
89
90 return container_of(kobj, struct xfs_mount, m_kobj);
91}
92
93#ifdef DEBUG
94
95STATIC ssize_t
96fail_writes_store(
97 struct kobject *kobject,
98 const char *buf,
99 size_t count)
100{
101 struct xfs_mount *mp = to_mp(kobject);
102 int ret;
103 int val;
104
105 ret = kstrtoint(buf, 0, &val);
106 if (ret)
107 return ret;
108
109 if (val == 1)
110 mp->m_fail_writes = true;
111 else if (val == 0)
112 mp->m_fail_writes = false;
113 else
114 return -EINVAL;
115
116 return count;
117}
118
119STATIC ssize_t
120fail_writes_show(
121 struct kobject *kobject,
122 char *buf)
123{
124 struct xfs_mount *mp = to_mp(kobject);
125
126 return snprintf(buf, PAGE_SIZE, "%d\n", mp->m_fail_writes ? 1 : 0);
127}
128XFS_SYSFS_ATTR_RW(fail_writes);
129
130#endif /* DEBUG */
131
132static struct attribute *xfs_mp_attrs[] = {
133#ifdef DEBUG
134 ATTR_LIST(fail_writes),
135#endif
136 NULL,
137};
138
139struct kobj_type xfs_mp_ktype = {
140 .release = xfs_sysfs_release,
141 .sysfs_ops = &xfs_sysfs_ops,
142 .default_attrs = xfs_mp_attrs,
143};
144
65b65735
BF
145#ifdef DEBUG
146/* debug */
147
2e227178
BF
148STATIC ssize_t
149log_recovery_delay_store(
a27c2640 150 struct kobject *kobject,
2e227178 151 const char *buf,
a27c2640 152 size_t count)
2e227178
BF
153{
154 int ret;
155 int val;
156
157 ret = kstrtoint(buf, 0, &val);
158 if (ret)
159 return ret;
160
161 if (val < 0 || val > 60)
162 return -EINVAL;
163
164 xfs_globals.log_recovery_delay = val;
165
166 return count;
167}
168
169STATIC ssize_t
170log_recovery_delay_show(
a27c2640
BD
171 struct kobject *kobject,
172 char *buf)
2e227178
BF
173{
174 return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.log_recovery_delay);
175}
176XFS_SYSFS_ATTR_RW(log_recovery_delay);
177
65b65735 178static struct attribute *xfs_dbg_attrs[] = {
2e227178 179 ATTR_LIST(log_recovery_delay),
65b65735
BF
180 NULL,
181};
182
65b65735
BF
183struct kobj_type xfs_dbg_ktype = {
184 .release = xfs_sysfs_release,
a27c2640 185 .sysfs_ops = &xfs_sysfs_ops,
65b65735
BF
186 .default_attrs = xfs_dbg_attrs,
187};
188
189#endif /* DEBUG */
190
bb230c12
BD
191/* stats */
192
80529c45
BD
193static inline struct xstats *
194to_xstats(struct kobject *kobject)
195{
196 struct xfs_kobj *kobj = to_kobj(kobject);
197
198 return container_of(kobj, struct xstats, xs_kobj);
199}
200
bb230c12
BD
201STATIC ssize_t
202stats_show(
a27c2640
BD
203 struct kobject *kobject,
204 char *buf)
bb230c12 205{
80529c45
BD
206 struct xstats *stats = to_xstats(kobject);
207
208 return xfs_stats_format(stats->xs_stats, buf);
bb230c12
BD
209}
210XFS_SYSFS_ATTR_RO(stats);
211
212STATIC ssize_t
213stats_clear_store(
a27c2640 214 struct kobject *kobject,
bb230c12 215 const char *buf,
a27c2640 216 size_t count)
bb230c12
BD
217{
218 int ret;
219 int val;
80529c45 220 struct xstats *stats = to_xstats(kobject);
bb230c12
BD
221
222 ret = kstrtoint(buf, 0, &val);
223 if (ret)
224 return ret;
225
226 if (val != 1)
227 return -EINVAL;
80529c45
BD
228
229 xfs_stats_clearall(stats->xs_stats);
bb230c12
BD
230 return count;
231}
232XFS_SYSFS_ATTR_WO(stats_clear);
233
234static struct attribute *xfs_stats_attrs[] = {
235 ATTR_LIST(stats),
236 ATTR_LIST(stats_clear),
237 NULL,
238};
239
bb230c12
BD
240struct kobj_type xfs_stats_ktype = {
241 .release = xfs_sysfs_release,
a27c2640 242 .sysfs_ops = &xfs_sysfs_ops,
bb230c12
BD
243 .default_attrs = xfs_stats_attrs,
244};
245
baff4e44
BF
246/* xlog */
247
a27c2640
BD
248static inline struct xlog *
249to_xlog(struct kobject *kobject)
250{
251 struct xfs_kobj *kobj = to_kobj(kobject);
252
253 return container_of(kobj, struct xlog, l_kobj);
254}
255
80d6d698
BF
256STATIC ssize_t
257log_head_lsn_show(
a27c2640
BD
258 struct kobject *kobject,
259 char *buf)
80d6d698 260{
80d6d698
BF
261 int cycle;
262 int block;
a27c2640 263 struct xlog *log = to_xlog(kobject);
80d6d698
BF
264
265 spin_lock(&log->l_icloglock);
266 cycle = log->l_curr_cycle;
267 block = log->l_curr_block;
268 spin_unlock(&log->l_icloglock);
269
270 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
271}
272XFS_SYSFS_ATTR_RO(log_head_lsn);
273
274STATIC ssize_t
275log_tail_lsn_show(
a27c2640
BD
276 struct kobject *kobject,
277 char *buf)
80d6d698 278{
80d6d698
BF
279 int cycle;
280 int block;
a27c2640 281 struct xlog *log = to_xlog(kobject);
80d6d698
BF
282
283 xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block);
284 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
285}
286XFS_SYSFS_ATTR_RO(log_tail_lsn);
287
288STATIC ssize_t
289reserve_grant_head_show(
a27c2640
BD
290 struct kobject *kobject,
291 char *buf)
292
80d6d698 293{
80d6d698
BF
294 int cycle;
295 int bytes;
a27c2640 296 struct xlog *log = to_xlog(kobject);
80d6d698
BF
297
298 xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes);
299 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
300}
301XFS_SYSFS_ATTR_RO(reserve_grant_head);
302
303STATIC ssize_t
304write_grant_head_show(
a27c2640
BD
305 struct kobject *kobject,
306 char *buf)
80d6d698 307{
80d6d698
BF
308 int cycle;
309 int bytes;
a27c2640 310 struct xlog *log = to_xlog(kobject);
80d6d698
BF
311
312 xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes);
313 return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
314}
315XFS_SYSFS_ATTR_RO(write_grant_head);
316
609adfc2
BF
317#ifdef DEBUG
318STATIC ssize_t
319log_badcrc_factor_store(
320 struct kobject *kobject,
321 const char *buf,
322 size_t count)
323{
324 struct xlog *log = to_xlog(kobject);
325 int ret;
326 uint32_t val;
327
328 ret = kstrtouint(buf, 0, &val);
329 if (ret)
330 return ret;
331
332 log->l_badcrc_factor = val;
333
334 return count;
335}
336
337STATIC ssize_t
338log_badcrc_factor_show(
339 struct kobject *kobject,
340 char *buf)
341{
342 struct xlog *log = to_xlog(kobject);
343
344 return snprintf(buf, PAGE_SIZE, "%d\n", log->l_badcrc_factor);
345}
346
347XFS_SYSFS_ATTR_RW(log_badcrc_factor);
348#endif /* DEBUG */
349
baff4e44 350static struct attribute *xfs_log_attrs[] = {
80d6d698
BF
351 ATTR_LIST(log_head_lsn),
352 ATTR_LIST(log_tail_lsn),
353 ATTR_LIST(reserve_grant_head),
354 ATTR_LIST(write_grant_head),
609adfc2
BF
355#ifdef DEBUG
356 ATTR_LIST(log_badcrc_factor),
357#endif
baff4e44
BF
358 NULL,
359};
360
baff4e44
BF
361struct kobj_type xfs_log_ktype = {
362 .release = xfs_sysfs_release,
a27c2640 363 .sysfs_ops = &xfs_sysfs_ops,
baff4e44
BF
364 .default_attrs = xfs_log_attrs,
365};
192852be
CM
366
367/*
368 * Metadata IO error configuration
369 *
370 * The sysfs structure here is:
371 * ...xfs/<dev>/error/<class>/<errno>/<error_attrs>
372 *
373 * where <class> allows us to discriminate between data IO and metadata IO,
374 * and any other future type of IO (e.g. special inode or directory error
375 * handling) we care to support.
376 */
377static struct attribute *xfs_error_attrs[] = {
378 NULL,
379};
380
381static inline struct xfs_error_cfg *
382to_error_cfg(struct kobject *kobject)
383{
384 struct xfs_kobj *kobj = to_kobj(kobject);
385 return container_of(kobj, struct xfs_error_cfg, kobj);
386}
387
388struct kobj_type xfs_error_cfg_ktype = {
389 .release = xfs_sysfs_release,
390 .sysfs_ops = &xfs_sysfs_ops,
391 .default_attrs = xfs_error_attrs,
392};
393
394struct kobj_type xfs_error_ktype = {
395 .release = xfs_sysfs_release,
396};
397
398int
399xfs_error_sysfs_init(
400 struct xfs_mount *mp)
401{
ffd40ef6 402 struct xfs_error_cfg *cfg;
192852be
CM
403 int error;
404
405 /* .../xfs/<dev>/error/ */
406 error = xfs_sysfs_init(&mp->m_error_kobj, &xfs_error_ktype,
407 &mp->m_kobj, "error");
ffd40ef6
CM
408 if (error)
409 return error;
410
411 /* .../xfs/<dev>/error/metadata/ */
412 error = xfs_sysfs_init(&mp->m_error_meta_kobj, &xfs_error_ktype,
413 &mp->m_error_kobj, "metadata");
414 if (error)
415 goto out_error;
416
417 cfg = &mp->m_error_cfg[XFS_ERR_METADATA][XFS_ERR_DEFAULT];
418 error = xfs_sysfs_init(&cfg->kobj, &xfs_error_cfg_ktype,
419 &mp->m_error_meta_kobj, "default");
420 if (error)
421 goto out_error_meta;
422 cfg->max_retries = -1;
423
424 return 0;
425
426out_error_meta:
427 xfs_sysfs_del(&mp->m_error_meta_kobj);
428out_error:
429 xfs_sysfs_del(&mp->m_error_kobj);
192852be
CM
430 return error;
431}
432
433void
434xfs_error_sysfs_del(
435 struct xfs_mount *mp)
436{
ffd40ef6
CM
437 struct xfs_error_cfg *cfg;
438 int i, j;
439
440 for (i = 0; i < XFS_ERR_CLASS_MAX; i++) {
441 for (j = 0; j < XFS_ERR_ERRNO_MAX; j++) {
442 cfg = &mp->m_error_cfg[i][j];
443
444 xfs_sysfs_del(&cfg->kobj);
445 }
446 }
447 xfs_sysfs_del(&mp->m_error_meta_kobj);
192852be
CM
448 xfs_sysfs_del(&mp->m_error_kobj);
449}
df309390
CM
450
451struct xfs_error_cfg *
452xfs_error_get_cfg(
453 struct xfs_mount *mp,
454 int error_class,
455 int error)
456{
457 struct xfs_error_cfg *cfg;
458
459 switch (error) {
460 default:
461 cfg = &mp->m_error_cfg[error_class][XFS_ERR_DEFAULT];
462 break;
463 }
464
465 return cfg;
466}
This page took 0.097544 seconds and 5 git commands to generate.