This patch introduces the kobj_attribute which is added in 2.6.25. It's
a generic attribute. The export isn't there in 2.6.25, but it will be in
2.6.26, allowing all this code to be ripped out if it's ever upstreamed.
It also follows the kernel convention of declaring attributes statically
and placing them in an array compile-time rather than setting it up
at initialization. It's a NULL terminated array, so the enums can be
killed as well.
Signed-off-by: Jeff Mahoney <[EMAIL PROTECTED]>
---
fs/aufs/compat.h | 11 ++++++
fs/aufs/sysaufs.c | 91 +++++++++++++++++++++++++++++++++++++++---------------
2 files changed, 77 insertions(+), 25 deletions(-)
--- /dev/null
+++ b/fs/aufs/compat.h
@@ -0,0 +1,11 @@
+#ifndef _AUFS_COMPAT_H_
+#define _AUFS_COMPAT_H_
+
+struct kobj_attribute {
+ struct attribute attr;
+ ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf);
+ ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t count);
+};
+#endif /* _AUFS_COMPAT_H_ */
--- a/fs/aufs/sysaufs.c
+++ b/fs/aufs/sysaufs.c
@@ -27,6 +27,7 @@
#include <linux/seq_file.h>
#include <linux/sysfs.h>
#include "aufs.h"
+#include "compat.h"
/* ---------------------------------------------------------------------- */
@@ -36,15 +37,46 @@ LIST_HEAD(au_sbilist);
static struct kset aufs_subsys;
-enum {
- Sbi, Stat, Config,
-#ifdef CONFIG_AUFS_DEBUG
- Debug,
-#endif
- _Last
+/* These should go away and be replaced by &kobj_sysfs_ops if this code hits
+ * mainline. -jeffm */
+
+/* default kobject attribute operations */
+static ssize_t kobj_attr_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
+{
+ struct kobj_attribute *kattr;
+ ssize_t ret = -EIO;
+
+ kattr = container_of(attr, struct kobj_attribute, attr);
+ if (kattr->show)
+ ret = kattr->show(kobj, kattr, buf);
+ return ret;
+}
+
+static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr,
+ const char *buf, size_t count)
+{
+ struct kobj_attribute *kattr;
+ ssize_t ret = -EIO;
+
+ kattr = container_of(attr, struct kobj_attribute, attr);
+ if (kattr->store)
+ ret = kattr->store(kobj, kattr, buf, count);
+ return ret;
+}
+
+/* Can't be static due to conflicting declaration in linux/kobject.h */
+struct sysfs_ops kobj_sysfs_ops = {
+ .show = kobj_attr_show,
+ .store = kobj_attr_store,
};
-static ssize_t config_show(struct kset *kset, char *buf)
+static struct kobj_type kobj_ktype = {
+ .sysfs_ops = &kobj_sysfs_ops,
+};
+
+static ssize_t config_show(struct kobject *kobject,
+ struct kobj_attribute *attr, char *buf)
{
#define conf_bool(name) "CONFIG_AUFS_" #name "=y\n"
static const char opt[] =
@@ -139,7 +171,8 @@ static ssize_t config_show(struct kset *
return -EFBIG;
}
-static ssize_t stat_show(struct kset *kset, char *buf)
+static ssize_t stat_show(struct kobject *kobject, struct kobj_attribute *attr,
+ char *buf)
{
char *p = buf;
const char *end = buf + PAGE_SIZE;
@@ -158,7 +191,8 @@ static ssize_t stat_show(struct kset *ks
return -EFBIG;
}
-static ssize_t sbi_show(struct kset *kset, char *buf)
+static ssize_t sbi_show(struct kobject *kobject, struct kobj_attribute *attr,
+ char *buf)
{
char *p = buf;
const char *end = buf + PAGE_SIZE;
@@ -178,36 +212,45 @@ static ssize_t sbi_show(struct kset *kse
}
#ifdef CONFIG_AUFS_DEBUG
-static ssize_t debug_show(struct kset *kset, char *buf)
+static ssize_t debug_show(struct kobject *kobject, struct kobj_attribute *attr,
+ char *buf)
{
return sprintf(buf, "%d\n", au_test_debug());
}
-static ssize_t debug_store(struct kset *kset, const char *buf, size_t sz)
+static ssize_t debug_store(struct kobject *kobject,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
{
- LKTRTrace("%.*s\n", sz, buf);
+ LKTRTrace("%.*s\n", (int)count, buf);
- if (unlikely(!sz || (*buf != '0' && *buf != '1')))
+ if (unlikely(!count || (*buf != '0' && *buf != '1')))
return -EOPNOTSUPP;
if (*buf == '0')
au_debug_off();
else if (*buf == '1')
au_debug_on();
- return sz;
+ return count;
}
+static struct kobj_attribute debug_attr = __ATTR(debug, S_IRUGO | S_IWUSR,
+ debug_show, debug_store);
#endif
-static struct subsys_attribute sysaufs_entry[] = {
- [Config] = __ATTR_RO(config),
- [Stat] = __ATTR_RO(stat),
- [Sbi] = __ATTR_RO(sbi),
+static struct kobj_attribute config_attr = __ATTR_RO(config);
+static struct kobj_attribute stat_attr = __ATTR_RO(stat);
+static struct kobj_attribute sbi_attr = __ATTR_RO(sbi);
+
+static struct attribute *sysaufs_attr[] = {
+ &config_attr.attr,
+ &stat_attr.attr,
+ &sbi_attr.attr,
#ifdef CONFIG_AUFS_DEBUG
- [Debug] = __ATTR(debug, S_IRUGO | S_IWUSR, debug_show,
- debug_store)
+ &debug_attr.attr,
#endif
+ NULL,
};
-static struct attribute *sysaufs_attr[_Last + 1]; /* last NULL */
+
static struct attribute_group sysaufs_attr_group = {
.attrs = sysaufs_attr,
};
@@ -631,13 +674,11 @@ void sysaufs_sbinfo_del(struct super_blo
int __init sysaufs_init(void)
{
- int err, i;
-
- for (i = 0; i < _Last; i++)
- sysaufs_attr[i] = &sysaufs_entry[i].attr;
+ int err;
kobj_set_kset_s(&aufs_subsys, fs_subsys);
kobject_set_name(&aufs_subsys.kobj, "aufs");
+ aufs_subsys.kobj.ktype = &kobj_ktype;
err = kset_register(&aufs_subsys);
if (unlikely(err))
goto out_put;
--
Jeff Mahoney
SUSE Labs
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone