]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - fs/ocfs2/cluster/sys.c
[PATCH] list: use list_replace_init() instead of list_splice_init()
[mirror_ubuntu-artful-kernel.git] / fs / ocfs2 / cluster / sys.c
CommitLineData
98211489
ZB
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
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
45#define to_o2cb_subsys(k) container_of(to_kset(k), struct subsystem, kset)
46#define to_o2cb_attr(_attr) container_of(_attr, struct o2cb_attribute, attr)
47
48static ssize_t o2cb_interface_revision_show(char *buf)
49{
50 return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION);
51}
52
82353b59 53static O2CB_ATTR(interface_revision, S_IFREG | S_IRUGO, o2cb_interface_revision_show, NULL);
98211489
ZB
54
55static struct attribute *o2cb_attrs[] = {
56 &o2cb_attr_interface_revision.attr,
57 NULL,
58};
59
60static ssize_t
61o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer);
62static ssize_t
63o2cb_store(struct kobject * kobj, struct attribute * attr,
64 const char * buffer, size_t count);
65static struct sysfs_ops o2cb_sysfs_ops = {
66 .show = o2cb_show,
67 .store = o2cb_store,
68};
69
70static struct kobj_type o2cb_subsys_type = {
71 .default_attrs = o2cb_attrs,
72 .sysfs_ops = &o2cb_sysfs_ops,
73};
74
75/* gives us o2cb_subsys */
82353b59 76static decl_subsys(o2cb, NULL, NULL);
98211489
ZB
77
78static ssize_t
79o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer)
80{
81 struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
82 struct subsystem *sbs = to_o2cb_subsys(kobj);
83
84 BUG_ON(sbs != &o2cb_subsys);
85
86 if (o2cb_attr->show)
87 return o2cb_attr->show(buffer);
88 return -EIO;
89}
90
91static ssize_t
92o2cb_store(struct kobject * kobj, struct attribute * attr,
93 const char * buffer, size_t count)
94{
95 struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
96 struct subsystem *sbs = to_o2cb_subsys(kobj);
97
98 BUG_ON(sbs != &o2cb_subsys);
99
100 if (o2cb_attr->store)
101 return o2cb_attr->store(buffer, count);
102 return -EIO;
103}
104
105void o2cb_sys_shutdown(void)
106{
107 mlog_sys_shutdown();
108 subsystem_unregister(&o2cb_subsys);
109}
110
111int o2cb_sys_init(void)
112{
113 int ret;
114
115 o2cb_subsys.kset.kobj.ktype = &o2cb_subsys_type;
116 ret = subsystem_register(&o2cb_subsys);
117 if (ret)
118 return ret;
119
120 ret = mlog_sys_init(&o2cb_subsys);
121 if (ret)
122 subsystem_unregister(&o2cb_subsys);
123 return ret;
124}