xfs_sysfs.c 17 KB

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