xfs_sysfs.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. /* xlog */
  47. STATIC ssize_t
  48. log_head_lsn_show(
  49. char *buf,
  50. void *data)
  51. {
  52. struct xlog *log = data;
  53. int cycle;
  54. int block;
  55. spin_lock(&log->l_icloglock);
  56. cycle = log->l_curr_cycle;
  57. block = log->l_curr_block;
  58. spin_unlock(&log->l_icloglock);
  59. return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
  60. }
  61. XFS_SYSFS_ATTR_RO(log_head_lsn);
  62. STATIC ssize_t
  63. log_tail_lsn_show(
  64. char *buf,
  65. void *data)
  66. {
  67. struct xlog *log = data;
  68. int cycle;
  69. int block;
  70. xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block);
  71. return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
  72. }
  73. XFS_SYSFS_ATTR_RO(log_tail_lsn);
  74. STATIC ssize_t
  75. reserve_grant_head_show(
  76. char *buf,
  77. void *data)
  78. {
  79. struct xlog *log = data;
  80. int cycle;
  81. int bytes;
  82. xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes);
  83. return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
  84. }
  85. XFS_SYSFS_ATTR_RO(reserve_grant_head);
  86. STATIC ssize_t
  87. write_grant_head_show(
  88. char *buf,
  89. void *data)
  90. {
  91. struct xlog *log = data;
  92. int cycle;
  93. int bytes;
  94. xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes);
  95. return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
  96. }
  97. XFS_SYSFS_ATTR_RO(write_grant_head);
  98. static struct attribute *xfs_log_attrs[] = {
  99. ATTR_LIST(log_head_lsn),
  100. ATTR_LIST(log_tail_lsn),
  101. ATTR_LIST(reserve_grant_head),
  102. ATTR_LIST(write_grant_head),
  103. NULL,
  104. };
  105. static inline struct xlog *
  106. to_xlog(struct kobject *kobject)
  107. {
  108. struct xfs_kobj *kobj = to_kobj(kobject);
  109. return container_of(kobj, struct xlog, l_kobj);
  110. }
  111. STATIC ssize_t
  112. xfs_log_show(
  113. struct kobject *kobject,
  114. struct attribute *attr,
  115. char *buf)
  116. {
  117. struct xlog *log = to_xlog(kobject);
  118. struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
  119. return xfs_attr->show ? xfs_attr->show(buf, log) : 0;
  120. }
  121. STATIC ssize_t
  122. xfs_log_store(
  123. struct kobject *kobject,
  124. struct attribute *attr,
  125. const char *buf,
  126. size_t count)
  127. {
  128. struct xlog *log = to_xlog(kobject);
  129. struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
  130. return xfs_attr->store ? xfs_attr->store(buf, count, log) : 0;
  131. }
  132. static struct sysfs_ops xfs_log_ops = {
  133. .show = xfs_log_show,
  134. .store = xfs_log_store,
  135. };
  136. struct kobj_type xfs_log_ktype = {
  137. .release = xfs_sysfs_release,
  138. .sysfs_ops = &xfs_log_ops,
  139. .default_attrs = xfs_log_attrs,
  140. };