blob: 64f6f378fd097d4dd33a740b82a8df35224cf7e3 [file] [log] [blame]
Zach Brown98211482005-12-15 14:31:23 -08001/* -*- 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
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/kobject.h>
30#include <linux/sysfs.h>
31
32#include "ocfs2_nodemanager.h"
33#include "masklog.h"
34#include "sys.h"
35
36struct o2cb_attribute {
37 struct attribute attr;
38 ssize_t (*show)(char *buf);
39 ssize_t (*store)(const char *buf, size_t count);
40};
41
42#define O2CB_ATTR(_name, _mode, _show, _store) \
43struct o2cb_attribute o2cb_attr_##_name = __ATTR(_name, _mode, _show, _store)
44
Zach Brown98211482005-12-15 14:31:23 -080045#define to_o2cb_attr(_attr) container_of(_attr, struct o2cb_attribute, attr)
46
47static ssize_t o2cb_interface_revision_show(char *buf)
48{
49 return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION);
50}
51
Adrian Bunk82353b52005-12-19 11:16:07 -080052static O2CB_ATTR(interface_revision, S_IFREG | S_IRUGO, o2cb_interface_revision_show, NULL);
Zach Brown98211482005-12-15 14:31:23 -080053
54static struct attribute *o2cb_attrs[] = {
55 &o2cb_attr_interface_revision.attr,
56 NULL,
57};
58
59static ssize_t
60o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer);
61static ssize_t
62o2cb_store(struct kobject * kobj, struct attribute * attr,
63 const char * buffer, size_t count);
64static struct sysfs_ops o2cb_sysfs_ops = {
65 .show = o2cb_show,
66 .store = o2cb_store,
67};
68
69static struct kobj_type o2cb_subsys_type = {
70 .default_attrs = o2cb_attrs,
71 .sysfs_ops = &o2cb_sysfs_ops,
72};
73
74/* gives us o2cb_subsys */
Adrian Bunk82353b52005-12-19 11:16:07 -080075static decl_subsys(o2cb, NULL, NULL);
Zach Brown98211482005-12-15 14:31:23 -080076
77static ssize_t
78o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer)
79{
80 struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -070081 struct kset *sbs = to_kset(kobj);
Zach Brown98211482005-12-15 14:31:23 -080082
83 BUG_ON(sbs != &o2cb_subsys);
84
85 if (o2cb_attr->show)
86 return o2cb_attr->show(buffer);
87 return -EIO;
88}
89
90static ssize_t
91o2cb_store(struct kobject * kobj, struct attribute * attr,
92 const char * buffer, size_t count)
93{
94 struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -070095 struct kset *sbs = to_kset(kobj);
Zach Brown98211482005-12-15 14:31:23 -080096
97 BUG_ON(sbs != &o2cb_subsys);
98
99 if (o2cb_attr->store)
100 return o2cb_attr->store(buffer, count);
101 return -EIO;
102}
103
104void o2cb_sys_shutdown(void)
105{
106 mlog_sys_shutdown();
107 subsystem_unregister(&o2cb_subsys);
108}
109
110int o2cb_sys_init(void)
111{
112 int ret;
113
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700114 o2cb_subsys.kobj.ktype = &o2cb_subsys_type;
Zach Brown98211482005-12-15 14:31:23 -0800115 ret = subsystem_register(&o2cb_subsys);
116 if (ret)
117 return ret;
118
119 ret = mlog_sys_init(&o2cb_subsys);
120 if (ret)
121 subsystem_unregister(&o2cb_subsys);
122 return ret;
123}