xfs_sysfs.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. #include "xfs.h"
  19. #include "xfs_sysfs.h"
  20. #include "xfs_log_format.h"
  21. #include "xfs_log.h"
  22. #include "xfs_log_priv.h"
  23. #include "xfs_stats.h"
  24. struct xfs_sysfs_attr {
  25. struct attribute attr;
  26. ssize_t (*show)(struct kobject *kobject, char *buf);
  27. ssize_t (*store)(struct kobject *kobject, const char *buf,
  28. size_t count);
  29. };
  30. static inline struct xfs_sysfs_attr *
  31. to_attr(struct attribute *attr)
  32. {
  33. return container_of(attr, struct xfs_sysfs_attr, attr);
  34. }
  35. #define XFS_SYSFS_ATTR_RW(name) \
  36. static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RW(name)
  37. #define XFS_SYSFS_ATTR_RO(name) \
  38. static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RO(name)
  39. #define XFS_SYSFS_ATTR_WO(name) \
  40. static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_WO(name)
  41. #define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr
  42. /*
  43. * xfs_mount kobject. This currently has no attributes and thus no need for show
  44. * and store helpers. The mp kobject serves as the per-mount parent object that
  45. * is identified by the fsname under sysfs.
  46. */
  47. struct kobj_type xfs_mp_ktype = {
  48. .release = xfs_sysfs_release,
  49. };
  50. STATIC ssize_t
  51. xfs_sysfs_object_show(
  52. struct kobject *kobject,
  53. struct attribute *attr,
  54. char *buf)
  55. {
  56. struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
  57. return xfs_attr->show ? xfs_attr->show(kobject, buf) : 0;
  58. }
  59. STATIC ssize_t
  60. xfs_sysfs_object_store(
  61. struct kobject *kobject,
  62. struct attribute *attr,
  63. const char *buf,
  64. size_t count)
  65. {
  66. struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
  67. return xfs_attr->store ? xfs_attr->store(kobject, buf, count) : 0;
  68. }
  69. static const struct sysfs_ops xfs_sysfs_ops = {
  70. .show = xfs_sysfs_object_show,
  71. .store = xfs_sysfs_object_store,
  72. };
  73. #ifdef DEBUG
  74. /* debug */
  75. STATIC ssize_t
  76. log_recovery_delay_store(
  77. struct kobject *kobject,
  78. const char *buf,
  79. size_t count)
  80. {
  81. int ret;
  82. int val;
  83. ret = kstrtoint(buf, 0, &val);
  84. if (ret)
  85. return ret;
  86. if (val < 0 || val > 60)
  87. return -EINVAL;
  88. xfs_globals.log_recovery_delay = val;
  89. return count;
  90. }
  91. STATIC ssize_t
  92. log_recovery_delay_show(
  93. struct kobject *kobject,
  94. char *buf)
  95. {
  96. return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.log_recovery_delay);
  97. }
  98. XFS_SYSFS_ATTR_RW(log_recovery_delay);
  99. static struct attribute *xfs_dbg_attrs[] = {
  100. ATTR_LIST(log_recovery_delay),
  101. NULL,
  102. };
  103. struct kobj_type xfs_dbg_ktype = {
  104. .release = xfs_sysfs_release,
  105. .sysfs_ops = &xfs_sysfs_ops,
  106. .default_attrs = xfs_dbg_attrs,
  107. };
  108. #endif /* DEBUG */
  109. /* stats */
  110. static inline struct xstats *
  111. to_xstats(struct kobject *kobject)
  112. {
  113. struct xfs_kobj *kobj = to_kobj(kobject);
  114. return container_of(kobj, struct xstats, xs_kobj);
  115. }
  116. STATIC ssize_t
  117. stats_show(
  118. struct kobject *kobject,
  119. char *buf)
  120. {
  121. struct xstats *stats = to_xstats(kobject);
  122. return xfs_stats_format(stats->xs_stats, buf);
  123. }
  124. XFS_SYSFS_ATTR_RO(stats);
  125. STATIC ssize_t
  126. stats_clear_store(
  127. struct kobject *kobject,
  128. const char *buf,
  129. size_t count)
  130. {
  131. int ret;
  132. int val;
  133. struct xstats *stats = to_xstats(kobject);
  134. ret = kstrtoint(buf, 0, &val);
  135. if (ret)
  136. return ret;
  137. if (val != 1)
  138. return -EINVAL;
  139. xfs_stats_clearall(stats->xs_stats);
  140. return count;
  141. }
  142. XFS_SYSFS_ATTR_WO(stats_clear);
  143. static struct attribute *xfs_stats_attrs[] = {
  144. ATTR_LIST(stats),
  145. ATTR_LIST(stats_clear),
  146. NULL,
  147. };
  148. struct kobj_type xfs_stats_ktype = {
  149. .release = xfs_sysfs_release,
  150. .sysfs_ops = &xfs_sysfs_ops,
  151. .default_attrs = xfs_stats_attrs,
  152. };
  153. /* xlog */
  154. static inline struct xlog *
  155. to_xlog(struct kobject *kobject)
  156. {
  157. struct xfs_kobj *kobj = to_kobj(kobject);
  158. return container_of(kobj, struct xlog, l_kobj);
  159. }
  160. STATIC ssize_t
  161. log_head_lsn_show(
  162. struct kobject *kobject,
  163. char *buf)
  164. {
  165. int cycle;
  166. int block;
  167. struct xlog *log = to_xlog(kobject);
  168. spin_lock(&log->l_icloglock);
  169. cycle = log->l_curr_cycle;
  170. block = log->l_curr_block;
  171. spin_unlock(&log->l_icloglock);
  172. return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
  173. }
  174. XFS_SYSFS_ATTR_RO(log_head_lsn);
  175. STATIC ssize_t
  176. log_tail_lsn_show(
  177. struct kobject *kobject,
  178. char *buf)
  179. {
  180. int cycle;
  181. int block;
  182. struct xlog *log = to_xlog(kobject);
  183. xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block);
  184. return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
  185. }
  186. XFS_SYSFS_ATTR_RO(log_tail_lsn);
  187. STATIC ssize_t
  188. reserve_grant_head_show(
  189. struct kobject *kobject,
  190. char *buf)
  191. {
  192. int cycle;
  193. int bytes;
  194. struct xlog *log = to_xlog(kobject);
  195. xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes);
  196. return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
  197. }
  198. XFS_SYSFS_ATTR_RO(reserve_grant_head);
  199. STATIC ssize_t
  200. write_grant_head_show(
  201. struct kobject *kobject,
  202. char *buf)
  203. {
  204. int cycle;
  205. int bytes;
  206. struct xlog *log = to_xlog(kobject);
  207. xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes);
  208. return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
  209. }
  210. XFS_SYSFS_ATTR_RO(write_grant_head);
  211. static struct attribute *xfs_log_attrs[] = {
  212. ATTR_LIST(log_head_lsn),
  213. ATTR_LIST(log_tail_lsn),
  214. ATTR_LIST(reserve_grant_head),
  215. ATTR_LIST(write_grant_head),
  216. NULL,
  217. };
  218. struct kobj_type xfs_log_ktype = {
  219. .release = xfs_sysfs_release,
  220. .sysfs_ops = &xfs_sysfs_ops,
  221. .default_attrs = xfs_log_attrs,
  222. };