提交 c60b7178 编写于 作者: G Greg Kroah-Hartman

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: NGreg Kroah-Hartman <gregkh@suse.de>
上级 f62ed9e3
...@@ -146,7 +146,7 @@ static struct kset mlog_kset = { ...@@ -146,7 +146,7 @@ static struct kset mlog_kset = {
.kobj = {.ktype = &mlog_ktype}, .kobj = {.ktype = &mlog_ktype},
}; };
int mlog_sys_init(struct kset *o2cb_subsys) int mlog_sys_init(struct kset *o2cb_kset)
{ {
int i = 0; int i = 0;
...@@ -157,7 +157,7 @@ int mlog_sys_init(struct kset *o2cb_subsys) ...@@ -157,7 +157,7 @@ int mlog_sys_init(struct kset *o2cb_subsys)
mlog_attr_ptrs[i] = NULL; mlog_attr_ptrs[i] = NULL;
kobject_set_name(&mlog_kset.kobj, "logmask"); kobject_set_name(&mlog_kset.kobj, "logmask");
mlog_kset.kobj.kset = o2cb_subsys; mlog_kset.kobj.kset = o2cb_kset;
return kset_register(&mlog_kset); return kset_register(&mlog_kset);
} }
......
...@@ -28,96 +28,55 @@ ...@@ -28,96 +28,55 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/kobject.h> #include <linux/kobject.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
#include <linux/fs.h>
#include "ocfs2_nodemanager.h" #include "ocfs2_nodemanager.h"
#include "masklog.h" #include "masklog.h"
#include "sys.h" #include "sys.h"
struct o2cb_attribute {
struct attribute attr;
ssize_t (*show)(char *buf);
ssize_t (*store)(const char *buf, size_t count);
};
#define O2CB_ATTR(_name, _mode, _show, _store) \
struct o2cb_attribute o2cb_attr_##_name = __ATTR(_name, _mode, _show, _store)
#define to_o2cb_attr(_attr) container_of(_attr, struct o2cb_attribute, attr)
static ssize_t o2cb_interface_revision_show(char *buf) static ssize_t version_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{ {
return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION); return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION);
} }
static struct kobj_attribute attr_version =
static O2CB_ATTR(interface_revision, S_IFREG | S_IRUGO, o2cb_interface_revision_show, NULL); __ATTR(interface_revision, S_IFREG | S_IRUGO, version_show, NULL);
static struct attribute *o2cb_attrs[] = { static struct attribute *o2cb_attrs[] = {
&o2cb_attr_interface_revision.attr, &attr_version.attr,
NULL, NULL,
}; };
static ssize_t static struct attribute_group o2cb_attr_group = {
o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer); .attrs = o2cb_attrs,
static ssize_t
o2cb_store(struct kobject * kobj, struct attribute * attr,
const char * buffer, size_t count);
static struct sysfs_ops o2cb_sysfs_ops = {
.show = o2cb_show,
.store = o2cb_store,
}; };
static struct kobj_type o2cb_subsys_type = { static struct kset *o2cb_kset;
.default_attrs = o2cb_attrs,
.sysfs_ops = &o2cb_sysfs_ops,
};
/* gives us o2cb_subsys */
static decl_subsys(o2cb, NULL);
static ssize_t
o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer)
{
struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
struct kset *sbs = to_kset(kobj);
BUG_ON(sbs != &o2cb_subsys);
if (o2cb_attr->show)
return o2cb_attr->show(buffer);
return -EIO;
}
static ssize_t
o2cb_store(struct kobject * kobj, struct attribute * attr,
const char * buffer, size_t count)
{
struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
struct kset *sbs = to_kset(kobj);
BUG_ON(sbs != &o2cb_subsys);
if (o2cb_attr->store)
return o2cb_attr->store(buffer, count);
return -EIO;
}
void o2cb_sys_shutdown(void) void o2cb_sys_shutdown(void)
{ {
mlog_sys_shutdown(); mlog_sys_shutdown();
subsystem_unregister(&o2cb_subsys); kset_unregister(o2cb_kset);
} }
int o2cb_sys_init(void) int o2cb_sys_init(void)
{ {
int ret; int ret;
o2cb_subsys.kobj.ktype = &o2cb_subsys_type; o2cb_kset = kset_create_and_add("o2cb", NULL, fs_kobj);
ret = subsystem_register(&o2cb_subsys); if (!o2cb_kset)
return -ENOMEM;
ret = sysfs_create_group(&o2cb_kset->kobj, &o2cb_attr_group);
if (ret) if (ret)
return ret; goto error;
ret = mlog_sys_init(&o2cb_subsys); ret = mlog_sys_init(o2cb_kset);
if (ret) if (ret)
subsystem_unregister(&o2cb_subsys); goto error;
return 0;
error:
kset_unregister(o2cb_kset);
return ret; return ret;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册