aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs/dir.c
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-06-13 14:45:14 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-07-11 19:09:04 -0400
commita26cd7226c24c3be5dd5f48a74832fe64beb8489 (patch)
tree0dfb4a15d800494a06a4ddf83c4d33812c404fac /fs/sysfs/dir.c
parent996b73764e9bb9d5e751fd15b130ba38637d66a8 (diff)
sysfs: consolidate sysfs_dirent creation functions
Currently there are four functions to create sysfs_dirent - __sysfs_new_dirent(), sysfs_new_dirent(), __sysfs_make_dirent() and sysfs_make_dirent(). Other than sysfs_make_dirent(), no function has two users if calls to implement other functions are excluded. This patch consolidates sysfs_dirent creation functions into the following two. * sysfs_new_dirent() : allocate and initialize * sysfs_attach_dirent() : attach to sysfs_dirent hierarchy and/or associate with dentry This simplifies interface and gives callers more flexibility. 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/dir.c')
-rw-r--r--fs/sysfs/dir.c82
1 files changed, 25 insertions, 57 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 90bed5df254f..f16aa7e3eafc 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -85,10 +85,7 @@ static struct dentry_operations sysfs_dentry_ops = {
85 .d_iput = sysfs_d_iput, 85 .d_iput = sysfs_d_iput,
86}; 86};
87 87
88/* 88struct sysfs_dirent *sysfs_new_dirent(void *element, umode_t mode, int type)
89 * Allocates a new sysfs_dirent and links it to the parent sysfs_dirent
90 */
91static struct sysfs_dirent * __sysfs_new_dirent(void * element)
92{ 89{
93 struct sysfs_dirent * sd; 90 struct sysfs_dirent * sd;
94 91
@@ -105,25 +102,25 @@ static struct sysfs_dirent * __sysfs_new_dirent(void * element)
105 atomic_set(&sd->s_event, 1); 102 atomic_set(&sd->s_event, 1);
106 INIT_LIST_HEAD(&sd->s_children); 103 INIT_LIST_HEAD(&sd->s_children);
107 INIT_LIST_HEAD(&sd->s_sibling); 104 INIT_LIST_HEAD(&sd->s_sibling);
105
108 sd->s_element = element; 106 sd->s_element = element;
107 sd->s_mode = mode;
108 sd->s_type = type;
109 109
110 return sd; 110 return sd;
111} 111}
112 112
113static void __sysfs_list_dirent(struct sysfs_dirent *parent_sd, 113void sysfs_attach_dirent(struct sysfs_dirent *sd,
114 struct sysfs_dirent *sd) 114 struct sysfs_dirent *parent_sd, struct dentry *dentry)
115{ 115{
116 if (sd) 116 if (dentry) {
117 list_add(&sd->s_sibling, &parent_sd->s_children); 117 sd->s_dentry = dentry;
118} 118 dentry->d_fsdata = sysfs_get(sd);
119 dentry->d_op = &sysfs_dentry_ops;
120 }
119 121
120static struct sysfs_dirent * sysfs_new_dirent(struct sysfs_dirent *parent_sd, 122 if (parent_sd)
121 void * element) 123 list_add(&sd->s_sibling, &parent_sd->s_children);
122{
123 struct sysfs_dirent *sd;
124 sd = __sysfs_new_dirent(element);
125 __sysfs_list_dirent(parent_sd, sd);
126 return sd;
127} 124}
128 125
129/* 126/*
@@ -151,39 +148,6 @@ int sysfs_dirent_exist(struct sysfs_dirent *parent_sd,
151 return 0; 148 return 0;
152} 149}
153 150
154
155static struct sysfs_dirent *
156__sysfs_make_dirent(struct dentry *dentry, void *element, mode_t mode, int type)
157{
158 struct sysfs_dirent * sd;
159
160 sd = __sysfs_new_dirent(element);
161 if (!sd)
162 goto out;
163
164 sd->s_mode = mode;
165 sd->s_type = type;
166 sd->s_dentry = dentry;
167 if (dentry) {
168 dentry->d_fsdata = sysfs_get(sd);
169 dentry->d_op = &sysfs_dentry_ops;
170 }
171
172out:
173 return sd;
174}
175
176int sysfs_make_dirent(struct sysfs_dirent * parent_sd, struct dentry * dentry,
177 void * element, umode_t mode, int type)
178{
179 struct sysfs_dirent *sd;
180
181 sd = __sysfs_make_dirent(dentry, element, mode, type);
182 __sysfs_list_dirent(parent_sd, sd);
183
184 return sd ? 0 : -ENOMEM;
185}
186
187static int init_dir(struct inode * inode) 151static int init_dir(struct inode * inode)
188{ 152{
189 inode->i_op = &sysfs_dir_inode_operations; 153 inode->i_op = &sysfs_dir_inode_operations;
@@ -227,10 +191,11 @@ static int create_dir(struct kobject *kobj, struct dentry *parent,
227 if (sysfs_dirent_exist(parent->d_fsdata, name)) 191 if (sysfs_dirent_exist(parent->d_fsdata, name))
228 goto out_dput; 192 goto out_dput;
229 193
230 error = sysfs_make_dirent(parent->d_fsdata, dentry, kobj, mode, 194 error = -ENOMEM;
231 SYSFS_DIR); 195 sd = sysfs_new_dirent(kobj, mode, SYSFS_DIR);
232 if (error) 196 if (!sd)
233 goto out_drop; 197 goto out_drop;
198 sysfs_attach_dirent(sd, parent->d_fsdata, dentry);
234 199
235 error = sysfs_create(dentry, mode, init_dir); 200 error = sysfs_create(dentry, mode, init_dir);
236 if (error) 201 if (error)
@@ -245,7 +210,6 @@ static int create_dir(struct kobject *kobj, struct dentry *parent,
245 goto out_dput; 210 goto out_dput;
246 211
247 out_sput: 212 out_sput:
248 sd = dentry->d_fsdata;
249 list_del_init(&sd->s_sibling); 213 list_del_init(&sd->s_sibling);
250 sysfs_put(sd); 214 sysfs_put(sd);
251 out_drop: 215 out_drop:
@@ -557,13 +521,16 @@ static int sysfs_dir_open(struct inode *inode, struct file *file)
557{ 521{
558 struct dentry * dentry = file->f_path.dentry; 522 struct dentry * dentry = file->f_path.dentry;
559 struct sysfs_dirent * parent_sd = dentry->d_fsdata; 523 struct sysfs_dirent * parent_sd = dentry->d_fsdata;
524 struct sysfs_dirent * sd;
560 525
561 mutex_lock(&dentry->d_inode->i_mutex); 526 mutex_lock(&dentry->d_inode->i_mutex);
562 file->private_data = sysfs_new_dirent(parent_sd, NULL); 527 sd = sysfs_new_dirent(NULL, 0, 0);
528 if (sd)
529 sysfs_attach_dirent(sd, parent_sd, NULL);
563 mutex_unlock(&dentry->d_inode->i_mutex); 530 mutex_unlock(&dentry->d_inode->i_mutex);
564 531
565 return file->private_data ? 0 : -ENOMEM; 532 file->private_data = sd;
566 533 return sd ? 0 : -ENOMEM;
567} 534}
568 535
569static int sysfs_dir_close(struct inode *inode, struct file *file) 536static int sysfs_dir_close(struct inode *inode, struct file *file)
@@ -736,9 +703,10 @@ struct dentry *sysfs_create_shadow_dir(struct kobject *kobj)
736 if (!shadow) 703 if (!shadow)
737 goto nomem; 704 goto nomem;
738 705
739 sd = __sysfs_make_dirent(shadow, kobj, inode->i_mode, SYSFS_DIR); 706 sd = sysfs_new_dirent(kobj, inode->i_mode, SYSFS_DIR);
740 if (!sd) 707 if (!sd)
741 goto nomem; 708 goto nomem;
709 sysfs_attach_dirent(sd, NULL, shadow);
742 710
743 d_instantiate(shadow, igrab(inode)); 711 d_instantiate(shadow, igrab(inode));
744 inc_nlink(inode); 712 inc_nlink(inode);