Commit 332ad69d authored by Patrick Mochel's avatar Patrick Mochel

sysfs: kill struct sysfs_dir.

Previously, sysfs read() and write() calls looked for sysfs_ops in the struct 
sysfs_dir, in the kobject. Since objects belong to a subsystem, and is a member
of a group of like devices, the sysfs_ops have been moved to struct subsystem,
and are referenced from there.

The only remaining member of struct sysfs_dir is the dentry of the object's 
directory. That is moved out of the dir struct and directly into struct kobject.
That saves us 4 bytes/object.

All of the sysfs functions that referenced the struct have been changed to just
reference the dentry.
parent a6c066de
...@@ -179,9 +179,8 @@ sysfs_read_file(struct file *file, char *buf, size_t count, loff_t *ppos) ...@@ -179,9 +179,8 @@ sysfs_read_file(struct file *file, char *buf, size_t count, loff_t *ppos)
ssize_t retval = 0; ssize_t retval = 0;
kobj = file->f_dentry->d_parent->d_fsdata; kobj = file->f_dentry->d_parent->d_fsdata;
if (kobj) if (kobj && kobj->subsys)
ops = kobj->dir.ops; ops = kobj->subsys->sysfs_ops;
if (!ops || !ops->show) if (!ops || !ops->show)
return 0; return 0;
...@@ -241,8 +240,8 @@ sysfs_write_file(struct file *file, const char *buf, size_t count, loff_t *ppos) ...@@ -241,8 +240,8 @@ sysfs_write_file(struct file *file, const char *buf, size_t count, loff_t *ppos)
char * page; char * page;
kobj = file->f_dentry->d_parent->d_fsdata; kobj = file->f_dentry->d_parent->d_fsdata;
if (kobj) if (kobj && kobj->subsys)
ops = kobj->dir.ops; ops = kobj->subsys->sysfs_ops;
if (!ops || !ops->store) if (!ops || !ops->store)
return 0; return 0;
...@@ -404,7 +403,7 @@ int sysfs_create_dir(struct kobject * kobj) ...@@ -404,7 +403,7 @@ int sysfs_create_dir(struct kobject * kobj)
return -EINVAL; return -EINVAL;
if (kobj->parent) if (kobj->parent)
parent = kobj->parent->dir.dentry; parent = kobj->parent->dentry;
else if (sysfs_mount && sysfs_mount->mnt_sb) else if (sysfs_mount && sysfs_mount->mnt_sb)
parent = sysfs_mount->mnt_sb->s_root; parent = sysfs_mount->mnt_sb->s_root;
else else
...@@ -414,7 +413,7 @@ int sysfs_create_dir(struct kobject * kobj) ...@@ -414,7 +413,7 @@ int sysfs_create_dir(struct kobject * kobj)
dentry = get_dentry(parent,kobj->name); dentry = get_dentry(parent,kobj->name);
if (!IS_ERR(dentry)) { if (!IS_ERR(dentry)) {
dentry->d_fsdata = (void *)kobj; dentry->d_fsdata = (void *)kobj;
kobj->dir.dentry = dentry; kobj->dentry = dentry;
error = sysfs_mkdir(parent->d_inode,dentry, error = sysfs_mkdir(parent->d_inode,dentry,
(S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO)); (S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO));
} else } else
...@@ -440,10 +439,7 @@ int sysfs_create_file(struct kobject * kobj, struct attribute * attr) ...@@ -440,10 +439,7 @@ int sysfs_create_file(struct kobject * kobj, struct attribute * attr)
if (!kobj || !attr) if (!kobj || !attr)
return -EINVAL; return -EINVAL;
if (kobj->parent) parent = kobj->dentry;
parent = kobj->parent->dir.dentry;
else
return -ENOENT;
down(&parent->d_inode->i_sem); down(&parent->d_inode->i_sem);
dentry = get_dentry(parent,attr->name); dentry = get_dentry(parent,attr->name);
...@@ -499,7 +495,7 @@ static void fill_object_path(struct kobject * kobj, char * buffer, int length) ...@@ -499,7 +495,7 @@ static void fill_object_path(struct kobject * kobj, char * buffer, int length)
*/ */
int sysfs_create_link(struct kobject * kobj, struct kobject * target, char * name) int sysfs_create_link(struct kobject * kobj, struct kobject * target, char * name)
{ {
struct dentry * dentry = kobj->dir.dentry; struct dentry * dentry = kobj->dentry;
struct dentry * d; struct dentry * d;
int error = 0; int error = 0;
int size; int size;
...@@ -562,7 +558,7 @@ static void hash_and_remove(struct dentry * dir, const char * name) ...@@ -562,7 +558,7 @@ static void hash_and_remove(struct dentry * dir, const char * name)
void sysfs_remove_file(struct kobject * kobj, struct attribute * attr) void sysfs_remove_file(struct kobject * kobj, struct attribute * attr)
{ {
hash_and_remove(kobj->dir.dentry,attr->name); hash_and_remove(kobj->dentry,attr->name);
} }
...@@ -574,7 +570,7 @@ void sysfs_remove_file(struct kobject * kobj, struct attribute * attr) ...@@ -574,7 +570,7 @@ void sysfs_remove_file(struct kobject * kobj, struct attribute * attr)
void sysfs_remove_link(struct kobject * kobj, char * name) void sysfs_remove_link(struct kobject * kobj, char * name)
{ {
hash_and_remove(kobj->dir.dentry,name); hash_and_remove(kobj->dentry,name);
} }
...@@ -590,7 +586,7 @@ void sysfs_remove_link(struct kobject * kobj, char * name) ...@@ -590,7 +586,7 @@ void sysfs_remove_link(struct kobject * kobj, char * name)
void sysfs_remove_dir(struct kobject * kobj) void sysfs_remove_dir(struct kobject * kobj)
{ {
struct list_head * node, * next; struct list_head * node, * next;
struct dentry * dentry = kobj->dir.dentry; struct dentry * dentry = kobj->dentry;
struct dentry * parent; struct dentry * parent;
if (!dentry) if (!dentry)
......
...@@ -18,7 +18,7 @@ struct kobject { ...@@ -18,7 +18,7 @@ struct kobject {
struct list_head entry; struct list_head entry;
struct kobject * parent; struct kobject * parent;
struct subsystem * subsys; struct subsystem * subsys;
struct sysfs_dir dir; struct dentry * dentry;
}; };
extern void kobject_init(struct kobject *); extern void kobject_init(struct kobject *);
......
...@@ -18,11 +18,6 @@ struct sysfs_ops { ...@@ -18,11 +18,6 @@ struct sysfs_ops {
ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t, loff_t); ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t, loff_t);
}; };
struct sysfs_dir {
struct dentry * dentry;
struct sysfs_ops * ops;
};
struct attribute { struct attribute {
char * name; char * name;
mode_t mode; mode_t mode;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment