diff options
author | Eric W. Biederman <ebiederm@aristanetworks.com> | 2009-02-11 16:20:23 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2009-03-24 19:38:25 -0400 |
commit | 04256b4a8fc73f54cd14f20867882c299728a446 (patch) | |
tree | 16267f6c77e0fa9f7229a30f66343289b6d1108a /fs | |
parent | 425cb02912d1095febfeaf8d379af7b2ac9e4a89 (diff) |
sysfs: reference sysfs_dirent from sysfs inodes
The sysfs_dirent serves as both an inode and a directory entry
for sysfs. To prevent the sysfs inode numbers from being freed
prematurely hold a reference to sysfs_dirent from the sysfs inode.
[akpm@linux-foundation.org: add comment]
Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/sysfs/inode.c | 17 | ||||
-rw-r--r-- | fs/sysfs/mount.c | 1 | ||||
-rw-r--r-- | fs/sysfs/sysfs.h | 1 |
3 files changed, 19 insertions, 0 deletions
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c index dfa3d94cfc74..555f0ff988df 100644 --- a/fs/sysfs/inode.c +++ b/fs/sysfs/inode.c | |||
@@ -147,6 +147,7 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode) | |||
147 | { | 147 | { |
148 | struct bin_attribute *bin_attr; | 148 | struct bin_attribute *bin_attr; |
149 | 149 | ||
150 | inode->i_private = sysfs_get(sd); | ||
150 | inode->i_mapping->a_ops = &sysfs_aops; | 151 | inode->i_mapping->a_ops = &sysfs_aops; |
151 | inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info; | 152 | inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info; |
152 | inode->i_op = &sysfs_inode_operations; | 153 | inode->i_op = &sysfs_inode_operations; |
@@ -214,6 +215,22 @@ struct inode * sysfs_get_inode(struct sysfs_dirent *sd) | |||
214 | return inode; | 215 | return inode; |
215 | } | 216 | } |
216 | 217 | ||
218 | /* | ||
219 | * The sysfs_dirent serves as both an inode and a directory entry for sysfs. | ||
220 | * To prevent the sysfs inode numbers from being freed prematurely we take a | ||
221 | * reference to sysfs_dirent from the sysfs inode. A | ||
222 | * super_operations.delete_inode() implementation is needed to drop that | ||
223 | * reference upon inode destruction. | ||
224 | */ | ||
225 | void sysfs_delete_inode(struct inode *inode) | ||
226 | { | ||
227 | struct sysfs_dirent *sd = inode->i_private; | ||
228 | |||
229 | truncate_inode_pages(&inode->i_data, 0); | ||
230 | clear_inode(inode); | ||
231 | sysfs_put(sd); | ||
232 | } | ||
233 | |||
217 | int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name) | 234 | int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name) |
218 | { | 235 | { |
219 | struct sysfs_addrm_cxt acxt; | 236 | struct sysfs_addrm_cxt acxt; |
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c index 84ef378673a8..49749955ccaf 100644 --- a/fs/sysfs/mount.c +++ b/fs/sysfs/mount.c | |||
@@ -29,6 +29,7 @@ struct kmem_cache *sysfs_dir_cachep; | |||
29 | static const struct super_operations sysfs_ops = { | 29 | static const struct super_operations sysfs_ops = { |
30 | .statfs = simple_statfs, | 30 | .statfs = simple_statfs, |
31 | .drop_inode = generic_delete_inode, | 31 | .drop_inode = generic_delete_inode, |
32 | .delete_inode = sysfs_delete_inode, | ||
32 | }; | 33 | }; |
33 | 34 | ||
34 | struct sysfs_dirent sysfs_root = { | 35 | struct sysfs_dirent sysfs_root = { |
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h index 93c6d6b27c4d..9055d04e4ab0 100644 --- a/fs/sysfs/sysfs.h +++ b/fs/sysfs/sysfs.h | |||
@@ -145,6 +145,7 @@ static inline void __sysfs_put(struct sysfs_dirent *sd) | |||
145 | * inode.c | 145 | * inode.c |
146 | */ | 146 | */ |
147 | struct inode *sysfs_get_inode(struct sysfs_dirent *sd); | 147 | struct inode *sysfs_get_inode(struct sysfs_dirent *sd); |
148 | void sysfs_delete_inode(struct inode *inode); | ||
148 | int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); | 149 | int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); |
149 | int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name); | 150 | int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name); |
150 | int sysfs_inode_init(void); | 151 | int sysfs_inode_init(void); |