Merge tag 'xfs-6.9-merge-8' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[linux-block.git] / fs / xfs / xfs_sysfs.c
CommitLineData
0b61f8a4 1// SPDX-License-Identifier: GPL-2.0
a31b1d3d
BF
2/*
3 * Copyright (c) 2014 Red Hat, Inc.
4 * All Rights Reserved.
a31b1d3d
BF
5 */
6
7#include "xfs.h"
192852be 8#include "xfs_shared.h"
801cc4e1 9#include "xfs_format.h"
baff4e44 10#include "xfs_log_format.h"
801cc4e1 11#include "xfs_trans_resv.h"
192852be 12#include "xfs_sysfs.h"
0020a190 13#include "xfs_log.h"
baff4e44 14#include "xfs_log_priv.h"
801cc4e1 15#include "xfs_mount.h"
a31b1d3d
BF
16
17struct xfs_sysfs_attr {
18 struct attribute attr;
a27c2640
BD
19 ssize_t (*show)(struct kobject *kobject, char *buf);
20 ssize_t (*store)(struct kobject *kobject, const char *buf,
21 size_t count);
a31b1d3d
BF
22};
23
24static inline struct xfs_sysfs_attr *
25to_attr(struct attribute *attr)
26{
27 return container_of(attr, struct xfs_sysfs_attr, attr);
28}
29
30#define XFS_SYSFS_ATTR_RW(name) \
31 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RW(name)
32#define XFS_SYSFS_ATTR_RO(name) \
33 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RO(name)
bb230c12
BD
34#define XFS_SYSFS_ATTR_WO(name) \
35 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_WO(name)
a31b1d3d
BF
36
37#define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr
38
a27c2640
BD
39STATIC ssize_t
40xfs_sysfs_object_show(
41 struct kobject *kobject,
42 struct attribute *attr,
43 char *buf)
44{
45 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
46
47 return xfs_attr->show ? xfs_attr->show(kobject, buf) : 0;
48}
49
50STATIC ssize_t
51xfs_sysfs_object_store(
52 struct kobject *kobject,
53 struct attribute *attr,
54 const char *buf,
55 size_t count)
56{
57 struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
58
59 return xfs_attr->store ? xfs_attr->store(kobject, buf, count) : 0;
60}
61
62static const struct sysfs_ops xfs_sysfs_ops = {
63 .show = xfs_sysfs_object_show,
64 .store = xfs_sysfs_object_store,
65};
66
801cc4e1 67static struct attribute *xfs_mp_attrs[] = {
801cc4e1
BF
68 NULL,
69};
219aac5d 70ATTRIBUTE_GROUPS(xfs_mp);
801cc4e1 71
2ee83335 72const struct kobj_type xfs_mp_ktype = {
801cc4e1
BF
73 .release = xfs_sysfs_release,
74 .sysfs_ops = &xfs_sysfs_ops,
219aac5d 75 .default_groups = xfs_mp_groups,
801cc4e1
BF
76};
77
65b65735
BF
78#ifdef DEBUG
79/* debug */
80
ccdab3d6
BF
81STATIC ssize_t
82bug_on_assert_store(
83 struct kobject *kobject,
84 const char *buf,
85 size_t count)
86{
87 int ret;
88 int val;
89
90 ret = kstrtoint(buf, 0, &val);
91 if (ret)
92 return ret;
93
94 if (val == 1)
95 xfs_globals.bug_on_assert = true;
96 else if (val == 0)
97 xfs_globals.bug_on_assert = false;
98 else
99 return -EINVAL;
100
101 return count;
102}
103
104STATIC ssize_t
105bug_on_assert_show(
106 struct kobject *kobject,
107 char *buf)
108{
53eb47b4 109 return sysfs_emit(buf, "%d\n", xfs_globals.bug_on_assert);
ccdab3d6
BF
110}
111XFS_SYSFS_ATTR_RW(bug_on_assert);
112
2e227178
BF
113STATIC ssize_t
114log_recovery_delay_store(
a27c2640 115 struct kobject *kobject,
2e227178 116 const char *buf,
a27c2640 117 size_t count)
2e227178
BF
118{
119 int ret;
120 int val;
121
122 ret = kstrtoint(buf, 0, &val);
123 if (ret)
124 return ret;
125
126 if (val < 0 || val > 60)
127 return -EINVAL;
128
129 xfs_globals.log_recovery_delay = val;
130
131 return count;
132}
133
134STATIC ssize_t
135log_recovery_delay_show(
a27c2640
BD
136 struct kobject *kobject,
137 char *buf)
2e227178 138{
53eb47b4 139 return sysfs_emit(buf, "%d\n", xfs_globals.log_recovery_delay);
2e227178
BF
140}
141XFS_SYSFS_ATTR_RW(log_recovery_delay);
142
dae5cd81
DC
143STATIC ssize_t
144mount_delay_store(
145 struct kobject *kobject,
146 const char *buf,
147 size_t count)
148{
149 int ret;
150 int val;
151
152 ret = kstrtoint(buf, 0, &val);
153 if (ret)
154 return ret;
155
156 if (val < 0 || val > 60)
157 return -EINVAL;
158
159 xfs_globals.mount_delay = val;
160
161 return count;
162}
163
164STATIC ssize_t
165mount_delay_show(
166 struct kobject *kobject,
167 char *buf)
168{
53eb47b4 169 return sysfs_emit(buf, "%d\n", xfs_globals.mount_delay);
dae5cd81
DC
170}
171XFS_SYSFS_ATTR_RW(mount_delay);
172
66ae56a5
CH
173static ssize_t
174always_cow_store(
175 struct kobject *kobject,
176 const char *buf,
177 size_t count)
178{
179 ssize_t ret;
180
181 ret = kstrtobool(buf, &xfs_globals.always_cow);
182 if (ret < 0)
183 return ret;
184 return count;
185}
186
187static ssize_t
188always_cow_show(
189 struct kobject *kobject,
190 char *buf)
191{
53eb47b4 192 return sysfs_emit(buf, "%d\n", xfs_globals.always_cow);
66ae56a5
CH
193}
194XFS_SYSFS_ATTR_RW(always_cow);
195
40786717
DW
196/*
197 * Override how many threads the parallel work queue is allowed to create.
198 * This has to be a debug-only global (instead of an errortag) because one of
199 * the main users of parallel workqueues is mount time quotacheck.
200 */
201STATIC ssize_t
202pwork_threads_store(
203 struct kobject *kobject,
204 const char *buf,
205 size_t count)
206{
207 int ret;
208 int val;
209
210 ret = kstrtoint(buf, 0, &val);
211 if (ret)
212 return ret;
213
214 if (val < -1 || val > num_possible_cpus())
215 return -EINVAL;
216
217 xfs_globals.pwork_threads = val;
218
219 return count;
220}
221
222STATIC ssize_t
223pwork_threads_show(
224 struct kobject *kobject,
225 char *buf)
226{
53eb47b4 227 return sysfs_emit(buf, "%d\n", xfs_globals.pwork_threads);
40786717
DW
228}
229XFS_SYSFS_ATTR_RW(pwork_threads);
535e2f75 230
94da54d5
DW
231/*
232 * The "LARP" (Logged extended Attribute Recovery Persistence) debugging knob
233 * sets the XFS_DA_OP_LOGGED flag on all xfs_attr_set operations performed on
234 * V5 filesystems. As a result, the intermediate progress of all setxattr and
235 * removexattr operations are tracked via the log and can be restarted during
236 * recovery. This is useful for testing xattr recovery prior to merging of the
237 * parent pointer feature which requires it to maintain consistency, and may be
238 * enabled for userspace xattrs in the future.
239 */
535e2f75
AH
240static ssize_t
241larp_store(
242 struct kobject *kobject,
243 const char *buf,
244 size_t count)
245{
246 ssize_t ret;
247
248 ret = kstrtobool(buf, &xfs_globals.larp);
249 if (ret < 0)
250 return ret;
251 return count;
252}
253
254STATIC ssize_t
255larp_show(
256 struct kobject *kobject,
257 char *buf)
258{
259 return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.larp);
260}
261XFS_SYSFS_ATTR_RW(larp);
40786717 262
a20ffa7d
DW
263STATIC ssize_t
264bload_leaf_slack_store(
265 struct kobject *kobject,
266 const char *buf,
267 size_t count)
268{
269 int ret;
270 int val;
271
272 ret = kstrtoint(buf, 0, &val);
273 if (ret)
274 return ret;
275
276 xfs_globals.bload_leaf_slack = val;
277 return count;
278}
279
280STATIC ssize_t
281bload_leaf_slack_show(
282 struct kobject *kobject,
283 char *buf)
284{
285 return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.bload_leaf_slack);
286}
287XFS_SYSFS_ATTR_RW(bload_leaf_slack);
288
289STATIC ssize_t
290bload_node_slack_store(
291 struct kobject *kobject,
292 const char *buf,
293 size_t count)
294{
295 int ret;
296 int val;
297
298 ret = kstrtoint(buf, 0, &val);
299 if (ret)
300 return ret;
301
302 xfs_globals.bload_node_slack = val;
303 return count;
304}
305
306STATIC ssize_t
307bload_node_slack_show(
308 struct kobject *kobject,
309 char *buf)
310{
311 return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.bload_node_slack);
312}
313XFS_SYSFS_ATTR_RW(bload_node_slack);
314
65b65735 315static struct attribute *xfs_dbg_attrs[] = {
ccdab3d6 316 ATTR_LIST(bug_on_assert),
2e227178 317 ATTR_LIST(log_recovery_delay),
dae5cd81 318 ATTR_LIST(mount_delay),
66ae56a5 319 ATTR_LIST(always_cow),
40786717 320 ATTR_LIST(pwork_threads),
535e2f75 321 ATTR_LIST(larp),
a20ffa7d
DW
322 ATTR_LIST(bload_leaf_slack),
323 ATTR_LIST(bload_node_slack),
65b65735
BF
324 NULL,
325};
219aac5d 326ATTRIBUTE_GROUPS(xfs_dbg);
65b65735 327
2ee83335 328const struct kobj_type xfs_dbg_ktype = {
65b65735 329 .release = xfs_sysfs_release,
a27c2640 330 .sysfs_ops = &xfs_sysfs_ops,
219aac5d 331 .default_groups = xfs_dbg_groups,
65b65735
BF
332};
333
334#endif /* DEBUG */
335
bb230c12
BD
336/* stats */
337
80529c45
BD
338static inline struct xstats *
339to_xstats(struct kobject *kobject)
340{
341 struct xfs_kobj *kobj = to_kobj(kobject);
342
343 return container_of(kobj, struct xstats, xs_kobj);
344}
345
bb230c12
BD
346STATIC ssize_t
347stats_show(
a27c2640
BD
348 struct kobject *kobject,
349 char *buf)
bb230c12 350{
80529c45
BD
351 struct xstats *stats = to_xstats(kobject);
352
353 return xfs_stats_format(stats->xs_stats, buf);
bb230c12
BD
354}
355XFS_SYSFS_ATTR_RO(stats);
356
357STATIC ssize_t
358stats_clear_store(
a27c2640 359 struct kobject *kobject,
bb230c12 360 const char *buf,
a27c2640 361 size_t count)
bb230c12
BD
362{
363 int ret;
364 int val;
80529c45 365 struct xstats *stats = to_xstats(kobject);
bb230c12
BD
366
367 ret = kstrtoint(buf, 0, &val);
368 if (ret)
369 return ret;
370
371 if (val != 1)
372 return -EINVAL;
80529c45
BD
373
374 xfs_stats_clearall(stats->xs_stats);
bb230c12
BD
375 return count;
376}
377XFS_SYSFS_ATTR_WO(stats_clear);
378
379static struct attribute *xfs_stats_attrs[] = {
380 ATTR_LIST(stats),
381 ATTR_LIST(stats_clear),
382 NULL,
383};
219aac5d 384ATTRIBUTE_GROUPS(xfs_stats);
bb230c12 385
2ee83335 386const struct kobj_type xfs_stats_ktype = {
bb230c12 387 .release = xfs_sysfs_release,
a27c2640 388 .sysfs_ops = &xfs_sysfs_ops,
219aac5d 389 .default_groups = xfs_stats_groups,
bb230c12
BD
390};
391
baff4e44
BF
392/* xlog */
393
a27c2640
BD
394static inline struct xlog *
395to_xlog(struct kobject *kobject)
396{
397 struct xfs_kobj *kobj = to_kobj(kobject);
398
399 return container_of(kobj, struct xlog, l_kobj);
400}
401
80d6d698
BF
402STATIC ssize_t
403log_head_lsn_show(
a27c2640
BD
404 struct kobject *kobject,
405 char *buf)
80d6d698 406{
80d6d698
BF
407 int cycle;
408 int block;
a27c2640 409 struct xlog *log = to_xlog(kobject);
80d6d698
BF
410
411 spin_lock(&log->l_icloglock);
412 cycle = log->l_curr_cycle;
413 block = log->l_curr_block;
414 spin_unlock(&log->l_icloglock);
415
53eb47b4 416 return sysfs_emit(buf, "%d:%d\n", cycle, block);
80d6d698
BF
417}
418XFS_SYSFS_ATTR_RO(log_head_lsn);
419
420STATIC ssize_t
421log_tail_lsn_show(
a27c2640
BD
422 struct kobject *kobject,
423 char *buf)
80d6d698 424{
80d6d698
BF
425 int cycle;
426 int block;
a27c2640 427 struct xlog *log = to_xlog(kobject);
80d6d698
BF
428
429 xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block);
53eb47b4 430 return sysfs_emit(buf, "%d:%d\n", cycle, block);
80d6d698
BF
431}
432XFS_SYSFS_ATTR_RO(log_tail_lsn);
433
434STATIC ssize_t
435reserve_grant_head_show(
a27c2640
BD
436 struct kobject *kobject,
437 char *buf)
438
80d6d698 439{
80d6d698
BF
440 int cycle;
441 int bytes;
a27c2640 442 struct xlog *log = to_xlog(kobject);
80d6d698
BF
443
444 xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes);
53eb47b4 445 return sysfs_emit(buf, "%d:%d\n", cycle, bytes);
80d6d698
BF
446}
447XFS_SYSFS_ATTR_RO(reserve_grant_head);
448
449STATIC ssize_t
450write_grant_head_show(
a27c2640
BD
451 struct kobject *kobject,
452 char *buf)
80d6d698 453{
80d6d698
BF
454 int cycle;
455 int bytes;
a27c2640 456 struct xlog *log = to_xlog(kobject);
80d6d698
BF
457
458 xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes);
53eb47b4 459 return sysfs_emit(buf, "%d:%d\n", cycle, bytes);
80d6d698
BF
460}
461XFS_SYSFS_ATTR_RO(write_grant_head);
462
baff4e44 463static struct attribute *xfs_log_attrs[] = {
80d6d698
BF
464 ATTR_LIST(log_head_lsn),
465 ATTR_LIST(log_tail_lsn),
466 ATTR_LIST(reserve_grant_head),
467 ATTR_LIST(write_grant_head),
baff4e44
BF
468 NULL,
469};
219aac5d 470ATTRIBUTE_GROUPS(xfs_log);
baff4e44 471
2ee83335 472const struct kobj_type xfs_log_ktype = {
baff4e44 473 .release = xfs_sysfs_release,
a27c2640 474 .sysfs_ops = &xfs_sysfs_ops,
219aac5d 475 .default_groups = xfs_log_groups,
baff4e44 476};
192852be
CM
477
478/*
479 * Metadata IO error configuration
480 *
481 * The sysfs structure here is:
482 * ...xfs/<dev>/error/<class>/<errno>/<error_attrs>
483 *
484 * where <class> allows us to discriminate between data IO and metadata IO,
485 * and any other future type of IO (e.g. special inode or directory error
486 * handling) we care to support.
487 */
192852be
CM
488static inline struct xfs_error_cfg *
489to_error_cfg(struct kobject *kobject)
490{
491 struct xfs_kobj *kobj = to_kobj(kobject);
492 return container_of(kobj, struct xfs_error_cfg, kobj);
493}
494
e6b3bb78
CM
495static inline struct xfs_mount *
496err_to_mp(struct kobject *kobject)
497{
498 struct xfs_kobj *kobj = to_kobj(kobject);
499 return container_of(kobj, struct xfs_mount, m_error_kobj);
500}
501
a5ea70d2
CM
502static ssize_t
503max_retries_show(
504 struct kobject *kobject,
505 char *buf)
506{
77169812 507 int retries;
a5ea70d2
CM
508 struct xfs_error_cfg *cfg = to_error_cfg(kobject);
509
ff97f239 510 if (cfg->max_retries == XFS_ERR_RETRY_FOREVER)
77169812
ES
511 retries = -1;
512 else
513 retries = cfg->max_retries;
514
53eb47b4 515 return sysfs_emit(buf, "%d\n", retries);
a5ea70d2
CM
516}
517
518static ssize_t
519max_retries_store(
520 struct kobject *kobject,
521 const char *buf,
522 size_t count)
523{
524 struct xfs_error_cfg *cfg = to_error_cfg(kobject);
525 int ret;
526 int val;
527
528 ret = kstrtoint(buf, 0, &val);
529 if (ret)
530 return ret;
531
532 if (val < -1)
533 return -EINVAL;
534
77169812 535 if (val == -1)
ff97f239 536 cfg->max_retries = XFS_ERR_RETRY_FOREVER;
77169812
ES
537 else
538 cfg->max_retries = val;
a5ea70d2
CM
539 return count;
540}
541XFS_SYSFS_ATTR_RW(max_retries);
542
543static ssize_t
544retry_timeout_seconds_show(
545 struct kobject *kobject,
546 char *buf)
547{
77169812 548 int timeout;
a5ea70d2
CM
549 struct xfs_error_cfg *cfg = to_error_cfg(kobject);
550
77169812
ES
551 if (cfg->retry_timeout == XFS_ERR_RETRY_FOREVER)
552 timeout = -1;
553 else
554 timeout = jiffies_to_msecs(cfg->retry_timeout) / MSEC_PER_SEC;
555
53eb47b4 556 return sysfs_emit(buf, "%d\n", timeout);
a5ea70d2
CM
557}
558
559static ssize_t
560retry_timeout_seconds_store(
561 struct kobject *kobject,
562 const char *buf,
563 size_t count)
564{
565 struct xfs_error_cfg *cfg = to_error_cfg(kobject);
566 int ret;
567 int val;
568
569 ret = kstrtoint(buf, 0, &val);
570 if (ret)
571 return ret;
572
77169812
ES
573 /* 1 day timeout maximum, -1 means infinite */
574 if (val < -1 || val > 86400)
a5ea70d2
CM
575 return -EINVAL;
576
77169812
ES
577 if (val == -1)
578 cfg->retry_timeout = XFS_ERR_RETRY_FOREVER;
579 else {
580 cfg->retry_timeout = msecs_to_jiffies(val * MSEC_PER_SEC);
581 ASSERT(msecs_to_jiffies(val * MSEC_PER_SEC) < LONG_MAX);
582 }
a5ea70d2
CM
583 return count;
584}
585XFS_SYSFS_ATTR_RW(retry_timeout_seconds);
586
e6b3bb78
CM
587static ssize_t
588fail_at_unmount_show(
589 struct kobject *kobject,
590 char *buf)
591{
592 struct xfs_mount *mp = err_to_mp(kobject);
593
53eb47b4 594 return sysfs_emit(buf, "%d\n", mp->m_fail_unmount);
e6b3bb78
CM
595}
596
597static ssize_t
598fail_at_unmount_store(
599 struct kobject *kobject,
600 const char *buf,
601 size_t count)
602{
603 struct xfs_mount *mp = err_to_mp(kobject);
604 int ret;
605 int val;
606
607 ret = kstrtoint(buf, 0, &val);
608 if (ret)
609 return ret;
610
611 if (val < 0 || val > 1)
612 return -EINVAL;
613
614 mp->m_fail_unmount = val;
615 return count;
616}
617XFS_SYSFS_ATTR_RW(fail_at_unmount);
618
a5ea70d2
CM
619static struct attribute *xfs_error_attrs[] = {
620 ATTR_LIST(max_retries),
621 ATTR_LIST(retry_timeout_seconds),
622 NULL,
623};
219aac5d 624ATTRIBUTE_GROUPS(xfs_error);
a5ea70d2 625
2ee83335 626static const struct kobj_type xfs_error_cfg_ktype = {
192852be
CM
627 .release = xfs_sysfs_release,
628 .sysfs_ops = &xfs_sysfs_ops,
219aac5d 629 .default_groups = xfs_error_groups,
192852be
CM
630};
631
2ee83335 632static const struct kobj_type xfs_error_ktype = {
192852be 633 .release = xfs_sysfs_release,
e6b3bb78 634 .sysfs_ops = &xfs_sysfs_ops,
192852be
CM
635};
636
ef6a50fb
CM
637/*
638 * Error initialization tables. These need to be ordered in the same
639 * order as the enums used to index the array. All class init tables need to
640 * define a "default" behaviour as the first entry, all other entries can be
641 * empty.
642 */
643struct xfs_error_init {
644 char *name;
645 int max_retries;
a5ea70d2 646 int retry_timeout; /* in seconds */
ef6a50fb
CM
647};
648
649static const struct xfs_error_init xfs_error_meta_init[XFS_ERR_ERRNO_MAX] = {
650 { .name = "default",
e0a431b3 651 .max_retries = XFS_ERR_RETRY_FOREVER,
77169812 652 .retry_timeout = XFS_ERR_RETRY_FOREVER,
ef6a50fb 653 },
e0a431b3
CM
654 { .name = "EIO",
655 .max_retries = XFS_ERR_RETRY_FOREVER,
77169812 656 .retry_timeout = XFS_ERR_RETRY_FOREVER,
e0a431b3
CM
657 },
658 { .name = "ENOSPC",
659 .max_retries = XFS_ERR_RETRY_FOREVER,
77169812 660 .retry_timeout = XFS_ERR_RETRY_FOREVER,
e0a431b3
CM
661 },
662 { .name = "ENODEV",
77169812
ES
663 .max_retries = 0, /* We can't recover from devices disappearing */
664 .retry_timeout = 0,
e0a431b3 665 },
ef6a50fb
CM
666};
667
668static int
669xfs_error_sysfs_init_class(
670 struct xfs_mount *mp,
671 int class,
672 const char *parent_name,
673 struct xfs_kobj *parent_kobj,
674 const struct xfs_error_init init[])
675{
676 struct xfs_error_cfg *cfg;
677 int error;
678 int i;
679
680 ASSERT(class < XFS_ERR_CLASS_MAX);
681
682 error = xfs_sysfs_init(parent_kobj, &xfs_error_ktype,
683 &mp->m_error_kobj, parent_name);
684 if (error)
685 return error;
686
687 for (i = 0; i < XFS_ERR_ERRNO_MAX; i++) {
688 cfg = &mp->m_error_cfg[class][i];
689 error = xfs_sysfs_init(&cfg->kobj, &xfs_error_cfg_ktype,
690 parent_kobj, init[i].name);
691 if (error)
692 goto out_error;
693
694 cfg->max_retries = init[i].max_retries;
77169812
ES
695 if (init[i].retry_timeout == XFS_ERR_RETRY_FOREVER)
696 cfg->retry_timeout = XFS_ERR_RETRY_FOREVER;
697 else
698 cfg->retry_timeout = msecs_to_jiffies(
a5ea70d2 699 init[i].retry_timeout * MSEC_PER_SEC);
ef6a50fb
CM
700 }
701 return 0;
702
703out_error:
704 /* unwind the entries that succeeded */
705 for (i--; i >= 0; i--) {
706 cfg = &mp->m_error_cfg[class][i];
707 xfs_sysfs_del(&cfg->kobj);
708 }
709 xfs_sysfs_del(parent_kobj);
710 return error;
711}
712
192852be
CM
713int
714xfs_error_sysfs_init(
715 struct xfs_mount *mp)
716{
717 int error;
718
719 /* .../xfs/<dev>/error/ */
720 error = xfs_sysfs_init(&mp->m_error_kobj, &xfs_error_ktype,
721 &mp->m_kobj, "error");
ffd40ef6
CM
722 if (error)
723 return error;
724
e6b3bb78
CM
725 error = sysfs_create_file(&mp->m_error_kobj.kobject,
726 ATTR_LIST(fail_at_unmount));
727
728 if (error)
729 goto out_error;
730
ffd40ef6 731 /* .../xfs/<dev>/error/metadata/ */
ef6a50fb
CM
732 error = xfs_error_sysfs_init_class(mp, XFS_ERR_METADATA,
733 "metadata", &mp->m_error_meta_kobj,
734 xfs_error_meta_init);
ffd40ef6
CM
735 if (error)
736 goto out_error;
737
ffd40ef6
CM
738 return 0;
739
ffd40ef6
CM
740out_error:
741 xfs_sysfs_del(&mp->m_error_kobj);
192852be
CM
742 return error;
743}
744
745void
746xfs_error_sysfs_del(
747 struct xfs_mount *mp)
748{
ffd40ef6
CM
749 struct xfs_error_cfg *cfg;
750 int i, j;
751
752 for (i = 0; i < XFS_ERR_CLASS_MAX; i++) {
753 for (j = 0; j < XFS_ERR_ERRNO_MAX; j++) {
754 cfg = &mp->m_error_cfg[i][j];
755
756 xfs_sysfs_del(&cfg->kobj);
757 }
758 }
759 xfs_sysfs_del(&mp->m_error_meta_kobj);
192852be
CM
760 xfs_sysfs_del(&mp->m_error_kobj);
761}
df309390
CM
762
763struct xfs_error_cfg *
764xfs_error_get_cfg(
765 struct xfs_mount *mp,
766 int error_class,
767 int error)
768{
769 struct xfs_error_cfg *cfg;
770
e97f6c54
ES
771 if (error < 0)
772 error = -error;
773
df309390 774 switch (error) {
e0a431b3
CM
775 case EIO:
776 cfg = &mp->m_error_cfg[error_class][XFS_ERR_EIO];
777 break;
778 case ENOSPC:
779 cfg = &mp->m_error_cfg[error_class][XFS_ERR_ENOSPC];
780 break;
781 case ENODEV:
782 cfg = &mp->m_error_cfg[error_class][XFS_ERR_ENODEV];
783 break;
df309390
CM
784 default:
785 cfg = &mp->m_error_cfg[error_class][XFS_ERR_DEFAULT];
786 break;
787 }
788
789 return cfg;
790}