sys.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 <linux/fs.h>
  31. #include "ocfs2_nodemanager.h"
  32. #include "masklog.h"
  33. #include "sys.h"
  34. static ssize_t version_show(struct kobject *kobj, struct kobj_attribute *attr,
  35. char *buf)
  36. {
  37. return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION);
  38. }
  39. static struct kobj_attribute attr_version =
  40. __ATTR(interface_revision, S_IRUGO, version_show, NULL);
  41. static struct attribute *o2cb_attrs[] = {
  42. &attr_version.attr,
  43. NULL,
  44. };
  45. static struct attribute_group o2cb_attr_group = {
  46. .attrs = o2cb_attrs,
  47. };
  48. static struct kset *o2cb_kset;
  49. void o2cb_sys_shutdown(void)
  50. {
  51. mlog_sys_shutdown();
  52. kset_unregister(o2cb_kset);
  53. }
  54. int o2cb_sys_init(void)
  55. {
  56. int ret;
  57. o2cb_kset = kset_create_and_add("o2cb", NULL, fs_kobj);
  58. if (!o2cb_kset)
  59. return -ENOMEM;
  60. ret = sysfs_create_group(&o2cb_kset->kobj, &o2cb_attr_group);
  61. if (ret)
  62. goto error;
  63. ret = mlog_sys_init(o2cb_kset);
  64. if (ret)
  65. goto error;
  66. return 0;
  67. error:
  68. kset_unregister(o2cb_kset);
  69. return ret;
  70. }