diff options
author | Greg Kroah-Hartman <gregkh@suse.de> | 2007-11-02 19:19:59 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-01-24 23:40:23 -0500 |
commit | c60b71787982cefcf9fa09aa281fa8c4c685d557 (patch) | |
tree | d8fb3b9767d44ead9e90c076c854baaf15b0c1f7 /fs | |
parent | f62ed9e33b3ccff54d66b08f82d11940bb9e269b (diff) |
kset: convert ocfs2 to use kset_create
Dynamically create the kset instead of declaring it statically.
Also use the new kobj_attribute which cleans up this file a _lot_.
Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: Mark Fasheh <mark.fasheh@oracle.com>
Cc: Kurt Hackel <kurt.hackel@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ocfs2/cluster/masklog.c | 4 | ||||
-rw-r--r-- | fs/ocfs2/cluster/sys.c | 83 |
2 files changed, 23 insertions, 64 deletions
diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c index dead319932b3..23c732f27529 100644 --- a/fs/ocfs2/cluster/masklog.c +++ b/fs/ocfs2/cluster/masklog.c | |||
@@ -146,7 +146,7 @@ static struct kset mlog_kset = { | |||
146 | .kobj = {.ktype = &mlog_ktype}, | 146 | .kobj = {.ktype = &mlog_ktype}, |
147 | }; | 147 | }; |
148 | 148 | ||
149 | int mlog_sys_init(struct kset *o2cb_subsys) | 149 | int mlog_sys_init(struct kset *o2cb_kset) |
150 | { | 150 | { |
151 | int i = 0; | 151 | int i = 0; |
152 | 152 | ||
@@ -157,7 +157,7 @@ int mlog_sys_init(struct kset *o2cb_subsys) | |||
157 | mlog_attr_ptrs[i] = NULL; | 157 | mlog_attr_ptrs[i] = NULL; |
158 | 158 | ||
159 | kobject_set_name(&mlog_kset.kobj, "logmask"); | 159 | kobject_set_name(&mlog_kset.kobj, "logmask"); |
160 | mlog_kset.kobj.kset = o2cb_subsys; | 160 | mlog_kset.kobj.kset = o2cb_kset; |
161 | return kset_register(&mlog_kset); | 161 | return kset_register(&mlog_kset); |
162 | } | 162 | } |
163 | 163 | ||
diff --git a/fs/ocfs2/cluster/sys.c b/fs/ocfs2/cluster/sys.c index 880d0138bb0a..a4b07730b2e1 100644 --- a/fs/ocfs2/cluster/sys.c +++ b/fs/ocfs2/cluster/sys.c | |||
@@ -28,96 +28,55 @@ | |||
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/kobject.h> | 29 | #include <linux/kobject.h> |
30 | #include <linux/sysfs.h> | 30 | #include <linux/sysfs.h> |
31 | #include <linux/fs.h> | ||
31 | 32 | ||
32 | #include "ocfs2_nodemanager.h" | 33 | #include "ocfs2_nodemanager.h" |
33 | #include "masklog.h" | 34 | #include "masklog.h" |
34 | #include "sys.h" | 35 | #include "sys.h" |
35 | 36 | ||
36 | struct 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) \ | ||
43 | struct o2cb_attribute o2cb_attr_##_name = __ATTR(_name, _mode, _show, _store) | ||
44 | |||
45 | #define to_o2cb_attr(_attr) container_of(_attr, struct o2cb_attribute, attr) | ||
46 | 37 | ||
47 | static ssize_t o2cb_interface_revision_show(char *buf) | 38 | static ssize_t version_show(struct kobject *kobj, struct kobj_attribute *attr, |
39 | char *buf) | ||
48 | { | 40 | { |
49 | return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION); | 41 | return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION); |
50 | } | 42 | } |
51 | 43 | static struct kobj_attribute attr_version = | |
52 | static O2CB_ATTR(interface_revision, S_IFREG | S_IRUGO, o2cb_interface_revision_show, NULL); | 44 | __ATTR(interface_revision, S_IFREG | S_IRUGO, version_show, NULL); |
53 | 45 | ||
54 | static struct attribute *o2cb_attrs[] = { | 46 | static struct attribute *o2cb_attrs[] = { |
55 | &o2cb_attr_interface_revision.attr, | 47 | &attr_version.attr, |
56 | NULL, | 48 | NULL, |
57 | }; | 49 | }; |
58 | 50 | ||
59 | static ssize_t | 51 | static struct attribute_group o2cb_attr_group = { |
60 | o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer); | 52 | .attrs = o2cb_attrs, |
61 | static ssize_t | ||
62 | o2cb_store(struct kobject * kobj, struct attribute * attr, | ||
63 | const char * buffer, size_t count); | ||
64 | static struct sysfs_ops o2cb_sysfs_ops = { | ||
65 | .show = o2cb_show, | ||
66 | .store = o2cb_store, | ||
67 | }; | 53 | }; |
68 | 54 | ||
69 | static struct kobj_type o2cb_subsys_type = { | 55 | static struct kset *o2cb_kset; |
70 | .default_attrs = o2cb_attrs, | ||
71 | .sysfs_ops = &o2cb_sysfs_ops, | ||
72 | }; | ||
73 | |||
74 | /* gives us o2cb_subsys */ | ||
75 | static decl_subsys(o2cb, NULL); | ||
76 | |||
77 | static ssize_t | ||
78 | o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer) | ||
79 | { | ||
80 | struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr); | ||
81 | struct kset *sbs = to_kset(kobj); | ||
82 | |||
83 | BUG_ON(sbs != &o2cb_subsys); | ||
84 | |||
85 | if (o2cb_attr->show) | ||
86 | return o2cb_attr->show(buffer); | ||
87 | return -EIO; | ||
88 | } | ||
89 | |||
90 | static ssize_t | ||
91 | o2cb_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); | ||
95 | struct kset *sbs = to_kset(kobj); | ||
96 | |||
97 | BUG_ON(sbs != &o2cb_subsys); | ||
98 | |||
99 | if (o2cb_attr->store) | ||
100 | return o2cb_attr->store(buffer, count); | ||
101 | return -EIO; | ||
102 | } | ||
103 | 56 | ||
104 | void o2cb_sys_shutdown(void) | 57 | void o2cb_sys_shutdown(void) |
105 | { | 58 | { |
106 | mlog_sys_shutdown(); | 59 | mlog_sys_shutdown(); |
107 | subsystem_unregister(&o2cb_subsys); | 60 | kset_unregister(o2cb_kset); |
108 | } | 61 | } |
109 | 62 | ||
110 | int o2cb_sys_init(void) | 63 | int o2cb_sys_init(void) |
111 | { | 64 | { |
112 | int ret; | 65 | int ret; |
113 | 66 | ||
114 | o2cb_subsys.kobj.ktype = &o2cb_subsys_type; | 67 | o2cb_kset = kset_create_and_add("o2cb", NULL, fs_kobj); |
115 | ret = subsystem_register(&o2cb_subsys); | 68 | if (!o2cb_kset) |
69 | return -ENOMEM; | ||
70 | |||
71 | ret = sysfs_create_group(&o2cb_kset->kobj, &o2cb_attr_group); | ||
116 | if (ret) | 72 | if (ret) |
117 | return ret; | 73 | goto error; |
118 | 74 | ||
119 | ret = mlog_sys_init(&o2cb_subsys); | 75 | ret = mlog_sys_init(o2cb_kset); |
120 | if (ret) | 76 | if (ret) |
121 | subsystem_unregister(&o2cb_subsys); | 77 | goto error; |
78 | return 0; | ||
79 | error: | ||
80 | kset_unregister(o2cb_kset); | ||
122 | return ret; | 81 | return ret; |
123 | } | 82 | } |