diff options
author | Tejun Heo <htejun@gmail.com> | 2007-06-13 14:45:15 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-07-11 19:09:04 -0400 |
commit | 3e5190380ebef77f2b015c9e7a4ca225a3d75021 (patch) | |
tree | 08d17cd0562acf5101063e93c649f5f71f80b3b9 /fs/sysfs/sysfs.h | |
parent | 0c096b507f15397da890051ee73de4266d3941fb (diff) |
sysfs: make sysfs_dirent->s_element a union
Make sd->s_element a union of sysfs_elem_{dir|symlink|attr|bin_attr}
and rename it to s_elem. This is to achieve...
* some level of type checking : changing symlink to point to
sysfs_dirent instead of kobject is much safer and less painful now.
* easier / standardized dereferencing
* allow sysfs_elem_* to contain more than one entry
Where possible, pointer is obtained by directly deferencing from sd
instead of going through other entities. This reduces dependencies to
dentry, inode and kobject. to_attr() and to_bin_attr() are unused now
and removed.
This is in preparation of object reference simplification.
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs/sysfs/sysfs.h')
-rw-r--r-- | fs/sysfs/sysfs.h | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h index d34b008537d5..39ab0481379c 100644 --- a/fs/sysfs/sysfs.h +++ b/fs/sysfs/sysfs.h | |||
@@ -1,10 +1,33 @@ | |||
1 | struct sysfs_elem_dir { | ||
2 | struct kobject * kobj; | ||
3 | }; | ||
4 | |||
5 | struct sysfs_elem_symlink { | ||
6 | struct kobject * target_kobj; | ||
7 | }; | ||
8 | |||
9 | struct sysfs_elem_attr { | ||
10 | struct attribute * attr; | ||
11 | }; | ||
12 | |||
13 | struct sysfs_elem_bin_attr { | ||
14 | struct bin_attribute * bin_attr; | ||
15 | }; | ||
16 | |||
1 | struct sysfs_dirent { | 17 | struct sysfs_dirent { |
2 | atomic_t s_count; | 18 | atomic_t s_count; |
3 | struct sysfs_dirent * s_parent; | 19 | struct sysfs_dirent * s_parent; |
4 | struct list_head s_sibling; | 20 | struct list_head s_sibling; |
5 | struct list_head s_children; | 21 | struct list_head s_children; |
6 | const char * s_name; | 22 | const char * s_name; |
7 | void * s_element; | 23 | |
24 | union { | ||
25 | struct sysfs_elem_dir dir; | ||
26 | struct sysfs_elem_symlink symlink; | ||
27 | struct sysfs_elem_attr attr; | ||
28 | struct sysfs_elem_bin_attr bin_attr; | ||
29 | } s_elem; | ||
30 | |||
8 | int s_type; | 31 | int s_type; |
9 | umode_t s_mode; | 32 | umode_t s_mode; |
10 | ino_t s_ino; | 33 | ino_t s_ino; |
@@ -22,8 +45,8 @@ extern int sysfs_create(struct dentry *, int mode, int (*init)(struct inode *)); | |||
22 | 45 | ||
23 | extern void release_sysfs_dirent(struct sysfs_dirent * sd); | 46 | extern void release_sysfs_dirent(struct sysfs_dirent * sd); |
24 | extern int sysfs_dirent_exist(struct sysfs_dirent *, const unsigned char *); | 47 | extern int sysfs_dirent_exist(struct sysfs_dirent *, const unsigned char *); |
25 | extern struct sysfs_dirent *sysfs_new_dirent(const char *name, void *element, | 48 | extern struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, |
26 | umode_t mode, int type); | 49 | int type); |
27 | extern void sysfs_attach_dirent(struct sysfs_dirent *sd, | 50 | extern void sysfs_attach_dirent(struct sysfs_dirent *sd, |
28 | struct sysfs_dirent *parent_sd, | 51 | struct sysfs_dirent *parent_sd, |
29 | struct dentry *dentry); | 52 | struct dentry *dentry); |
@@ -47,10 +70,6 @@ extern const struct file_operations bin_fops; | |||
47 | extern const struct inode_operations sysfs_dir_inode_operations; | 70 | extern const struct inode_operations sysfs_dir_inode_operations; |
48 | extern const struct inode_operations sysfs_symlink_inode_operations; | 71 | extern const struct inode_operations sysfs_symlink_inode_operations; |
49 | 72 | ||
50 | struct sysfs_symlink { | ||
51 | struct kobject * target_kobj; | ||
52 | }; | ||
53 | |||
54 | struct sysfs_buffer { | 73 | struct sysfs_buffer { |
55 | struct list_head associates; | 74 | struct list_head associates; |
56 | size_t count; | 75 | size_t count; |
@@ -70,19 +89,7 @@ struct sysfs_buffer_collection { | |||
70 | static inline struct kobject * to_kobj(struct dentry * dentry) | 89 | static inline struct kobject * to_kobj(struct dentry * dentry) |
71 | { | 90 | { |
72 | struct sysfs_dirent * sd = dentry->d_fsdata; | 91 | struct sysfs_dirent * sd = dentry->d_fsdata; |
73 | return ((struct kobject *) sd->s_element); | 92 | return sd->s_elem.dir.kobj; |
74 | } | ||
75 | |||
76 | static inline struct attribute * to_attr(struct dentry * dentry) | ||
77 | { | ||
78 | struct sysfs_dirent * sd = dentry->d_fsdata; | ||
79 | return ((struct attribute *) sd->s_element); | ||
80 | } | ||
81 | |||
82 | static inline struct bin_attribute * to_bin_attr(struct dentry * dentry) | ||
83 | { | ||
84 | struct sysfs_dirent * sd = dentry->d_fsdata; | ||
85 | return ((struct bin_attribute *) sd->s_element); | ||
86 | } | 93 | } |
87 | 94 | ||
88 | static inline struct kobject *sysfs_get_kobject(struct dentry *dentry) | 95 | static inline struct kobject *sysfs_get_kobject(struct dentry *dentry) |
@@ -92,11 +99,10 @@ static inline struct kobject *sysfs_get_kobject(struct dentry *dentry) | |||
92 | spin_lock(&dcache_lock); | 99 | spin_lock(&dcache_lock); |
93 | if (!d_unhashed(dentry)) { | 100 | if (!d_unhashed(dentry)) { |
94 | struct sysfs_dirent * sd = dentry->d_fsdata; | 101 | struct sysfs_dirent * sd = dentry->d_fsdata; |
95 | if (sd->s_type & SYSFS_KOBJ_LINK) { | 102 | if (sd->s_type & SYSFS_KOBJ_LINK) |
96 | struct sysfs_symlink * sl = sd->s_element; | 103 | kobj = kobject_get(sd->s_elem.symlink.target_kobj); |
97 | kobj = kobject_get(sl->target_kobj); | 104 | else |
98 | } else | 105 | kobj = kobject_get(sd->s_elem.dir.kobj); |
99 | kobj = kobject_get(sd->s_element); | ||
100 | } | 106 | } |
101 | spin_unlock(&dcache_lock); | 107 | spin_unlock(&dcache_lock); |
102 | 108 | ||