sys.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_attr(_attr) container_of(_attr, struct o2cb_attribute, attr)
  41. static ssize_t o2cb_interface_revision_show(char *buf)
  42. {
  43. return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION);
  44. }
  45. static O2CB_ATTR(interface_revision, S_IFREG | S_IRUGO, o2cb_interface_revision_show, NULL);
  46. static struct attribute *o2cb_attrs[] = {
  47. &o2cb_attr_interface_revision.attr,
  48. NULL,
  49. };
  50. static ssize_t
  51. o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer);
  52. static ssize_t
  53. o2cb_store(struct kobject * kobj, struct attribute * attr,
  54. const char * buffer, size_t count);
  55. static struct sysfs_ops o2cb_sysfs_ops = {
  56. .show = o2cb_show,
  57. .store = o2cb_store,
  58. };
  59. static struct kobj_type o2cb_subsys_type = {
  60. .default_attrs = o2cb_attrs,
  61. .sysfs_ops = &o2cb_sysfs_ops,
  62. };
  63. /* gives us o2cb_subsys */
  64. static decl_subsys(o2cb, NULL, NULL);
  65. static ssize_t
  66. o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer)
  67. {
  68. struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
  69. struct kset *sbs = to_kset(kobj);
  70. BUG_ON(sbs != &o2cb_subsys);
  71. if (o2cb_attr->show)
  72. return o2cb_attr->show(buffer);
  73. return -EIO;
  74. }
  75. static ssize_t
  76. o2cb_store(struct kobject * kobj, struct attribute * attr,
  77. const char * buffer, size_t count)
  78. {
  79. struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
  80. struct kset *sbs = to_kset(kobj);
  81. BUG_ON(sbs != &o2cb_subsys);
  82. if (o2cb_attr->store)
  83. return o2cb_attr->store(buffer, count);
  84. return -EIO;
  85. }
  86. void o2cb_sys_shutdown(void)
  87. {
  88. mlog_sys_shutdown();
  89. subsystem_unregister(&o2cb_subsys);
  90. }
  91. int o2cb_sys_init(void)
  92. {
  93. int ret;
  94. o2cb_subsys.kobj.ktype = &o2cb_subsys_type;
  95. ret = subsystem_register(&o2cb_subsys);
  96. if (ret)
  97. return ret;
  98. ret = mlog_sys_init(&o2cb_subsys);
  99. if (ret)
  100. subsystem_unregister(&o2cb_subsys);
  101. return ret;
  102. }