xfs_sysfs.c 15 KB

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