- Update to 2.6.25-rc3.
[linux-flexiantxendom0-3.2.10.git] / fs / ocfs2 / cluster / sys.c
1 /* -*- mode: c; c-basic-offset: 8; -*- * vim: noexpandtab sw=8 ts=8 sts=0:
2  *
3  * sys.c
4  *
5  * OCFS2 cluster sysfs interface
6  *
7  * Copyright (C) 2005 Oracle.  All rights reserved.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation,
12  * version 2 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public
20  * License along with this program; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 021110-1307, USA.
23  *
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
32 #include "ocfs2_nodemanager.h"
33 #include "heartbeat.h"
34 #include "masklog.h"
35 #include "sys.h"
36
37
38 static ssize_t version_show(struct kobject *kobj, struct kobj_attribute *attr,
39                             char *buf)
40 {
41         return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION);
42 }
43 static struct kobj_attribute attr_version =
44         __ATTR(interface_revision, S_IFREG | S_IRUGO, version_show, NULL);
45
46 static ssize_t heartbeat_mode_show(struct kobject *kobj,
47                                    struct kobj_attribute *attr, char *buf)
48 {
49         return snprintf(buf, PAGE_SIZE, "%s\n", o2hb_heartbeat_mode());
50 }
51
52 static ssize_t heartbeat_mode_store(struct kobject *kobj,
53                                     struct kobj_attribute *attr,
54                                     const char *buffer, size_t count)
55 {
56         return o2hb_set_heartbeat_mode(buffer, count);
57 }
58
59 static struct kobj_attribute attr_heartbeat_mode =
60         __ATTR(heartbeat_mode, S_IFREG | S_IRUGO | S_IWUSR,
61                  heartbeat_mode_show, heartbeat_mode_store);
62
63 static struct attribute *o2cb_attrs[] = {
64         &attr_version.attr,
65         &attr_heartbeat_mode.attr,
66         NULL,
67 };
68
69 static struct attribute_group o2cb_attr_group = {
70         .attrs = o2cb_attrs,
71 };
72
73 static struct kset *o2cb_kset;
74
75 void o2cb_sys_shutdown(void)
76 {
77         mlog_sys_shutdown();
78         kset_unregister(o2cb_kset);
79 }
80
81 int o2cb_sys_init(void)
82 {
83         int ret;
84
85         o2cb_kset = kset_create_and_add("o2cb", NULL, NULL);
86         if (!o2cb_kset)
87                 return -ENOMEM;
88
89         ret = sysfs_create_group(&o2cb_kset->kobj, &o2cb_attr_group);
90         if (ret)
91                 goto error;
92
93         ret = mlog_sys_init(o2cb_kset);
94         if (ret)
95                 goto error;
96         return 0;
97 error:
98         kset_unregister(o2cb_kset);
99         return ret;
100 }