xfs_sysfs.c 5.0 KB

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