sysfs: reimplement symlink using sysfs_dirent tree
sysfs symlink is implemented by referencing dentry and kobject from sysfs_dirent - symlink entry references kobject, dentry is used to walk the tree. This complicates object lifetimes rules and is dangerous - for example, there is no way to tell to which module the target of a symlink belongs and referencing that kobject can make it linger after the module is gone. This patch reimplements symlink using only sysfs_dirent tree. sd for a symlink points and holds reference to the target sysfs_dirent and all walking is done using sysfs_dirent tree. Simpler and safer. Please read the following message for more info. http://article.gmane.org/gmane.linux.kernel/510293 Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
aecdcedaab
commit
2b29ac252a
@@ -3,7 +3,7 @@ struct sysfs_elem_dir {
|
||||
};
|
||||
|
||||
struct sysfs_elem_symlink {
|
||||
struct kobject * target_kobj;
|
||||
struct sysfs_dirent * target_sd;
|
||||
};
|
||||
|
||||
struct sysfs_elem_attr {
|
||||
@@ -100,10 +100,11 @@ static inline struct kobject *sysfs_get_kobject(struct dentry *dentry)
|
||||
spin_lock(&dcache_lock);
|
||||
if (!d_unhashed(dentry)) {
|
||||
struct sysfs_dirent * sd = dentry->d_fsdata;
|
||||
|
||||
if (sd->s_type & SYSFS_KOBJ_LINK)
|
||||
kobj = kobject_get(sd->s_elem.symlink.target_kobj);
|
||||
else
|
||||
kobj = kobject_get(sd->s_elem.dir.kobj);
|
||||
sd = sd->s_elem.symlink.target_sd;
|
||||
|
||||
kobj = kobject_get(sd->s_elem.dir.kobj);
|
||||
}
|
||||
spin_unlock(&dcache_lock);
|
||||
|
||||
|
Reference in New Issue
Block a user