Debian Codegraph @

fs/xfs/xfs_sysfs.c

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