sys.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * sys.c
  5. *
  6. * OCFS2 cluster sysfs interface
  7. *
  8. * Copyright (C) 2005 Oracle. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation,
  13. * version 2 of the License.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. * Boston, MA 021110-1307, USA.
  24. *
  25. */
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/kobject.h>
  29. #include <linux/sysfs.h>
  30. #include "ocfs2_nodemanager.h"
  31. #include "masklog.h"
  32. #include "sys.h"
  33. struct o2cb_attribute {
  34. struct attribute attr;
  35. ssize_t (*show)(char *buf);
  36. ssize_t (*store)(const char *buf, size_t count);
  37. };
  38. #define O2CB_ATTR(_name, _mode, _show, _store) \
  39. struct o2cb_attribute o2cb_attr_##_name = __ATTR(_name, _mode, _show, _store)
  40. #define to_o2cb_subsys(k) container_of(to_kset(k), struct subsystem, kset)
  41. #define to_o2cb_attr(_attr) container_of(_attr, struct o2cb_attribute, attr)
  42. static ssize_t o2cb_interface_revision_show(char *buf)
  43. {
  44. return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION);
  45. }
  46. static O2CB_ATTR(interface_revision, S_IFREG | S_IRUGO, o2cb_interface_revision_show, NULL);
  47. static struct attribute *o2cb_attrs[] = {
  48. &o2cb_attr_interface_revision.attr,
  49. NULL,
  50. };
  51. static ssize_t
  52. o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer);
  53. static ssize_t
  54. o2cb_store(struct kobject * kobj, struct attribute * attr,
  55. const char * buffer, size_t count);
  56. static struct sysfs_ops o2cb_sysfs_ops = {
  57. .show = o2cb_show,
  58. .store = o2cb_store,
  59. };
  60. static struct kobj_type o2cb_subsys_type = {
  61. .default_attrs = o2cb_attrs,
  62. .sysfs_ops = &o2cb_sysfs_ops,
  63. };
  64. /* gives us o2cb_subsys */
  65. static decl_subsys(o2cb, NULL, NULL);
  66. static ssize_t
  67. o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer)
  68. {
  69. struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
  70. struct subsystem *sbs = to_o2cb_subsys(kobj);
  71. BUG_ON(sbs != &o2cb_subsys);
  72. if (o2cb_attr->show)
  73. return o2cb_attr->show(buffer);
  74. return -EIO;
  75. }
  76. static ssize_t
  77. o2cb_store(struct kobject * kobj, struct attribute * attr,
  78. const char * buffer, size_t count)
  79. {
  80. struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
  81. struct subsystem *sbs = to_o2cb_subsys(kobj);
  82. BUG_ON(sbs != &o2cb_subsys);
  83. if (o2cb_attr->store)
  84. return o2cb_attr->store(buffer, count);
  85. return -EIO;
  86. }
  87. void o2cb_sys_shutdown(void)
  88. {
  89. mlog_sys_shutdown();
  90. subsystem_unregister(&o2cb_subsys);
  91. }
  92. int o2cb_sys_init(void)
  93. {
  94. int ret;
  95. o2cb_subsys.kset.kobj.ktype = &o2cb_subsys_type;
  96. ret = subsystem_register(&o2cb_subsys);
  97. if (ret)
  98. return ret;
  99. ret = mlog_sys_init(&o2cb_subsys);
  100. if (ret)
  101. subsystem_unregister(&o2cb_subsys);
  102. return ret;
  103. }