aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs/inode.c
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-06-13 14:45:17 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-07-11 19:09:07 -0400
commitfc9f54b9982e14e6dbe023425c87ffbfd6992c45 (patch)
tree61b828ac694d9e8decb02022a1056a5367bb1bef /fs/sysfs/inode.c
parent7f7cfffe60ed6271c4028ec79ae1c297b44bcb14 (diff)
sysfs: reorganize sysfs_new_indoe() and sysfs_create()
Reorganize/clean up sysfs_new_inode() and sysfs_create(). * sysfs_init_inode() is separated out from sysfs_new_inode() and is responsible for basic initialization. * sysfs_instantiate() replaces the last step of sysfs_create() and is responsible for dentry instantitaion. * type-specific initialization is moved out to the callers. * mode is specified only once when creating a sysfs_dirent. * spurious list_del_init(&sd->s_sibling) dropped from create_dir() This change is to * prepare for inode allocation fix. * separate alloc and init code for synchronization update. * make dentry/inode initialization more flexible for later changes. This patch doesn't introduce visible behavior change. Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs/sysfs/inode.c')
-rw-r--r--fs/sysfs/inode.c108
1 files changed, 57 insertions, 51 deletions
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index 6ad47c13b94d..26d8503c8997 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -133,62 +133,68 @@ static inline void set_inode_attr(struct inode * inode, struct iattr * iattr)
133 */ 133 */
134static struct lock_class_key sysfs_inode_imutex_key; 134static struct lock_class_key sysfs_inode_imutex_key;
135 135
136struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent * sd) 136void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
137{ 137{
138 struct inode * inode = new_inode(sysfs_sb); 138 inode->i_blocks = 0;
139 if (inode) { 139 inode->i_mapping->a_ops = &sysfs_aops;
140 inode->i_blocks = 0; 140 inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
141 inode->i_mapping->a_ops = &sysfs_aops; 141 inode->i_op = &sysfs_inode_operations;
142 inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info; 142 inode->i_ino = sd->s_ino;
143 inode->i_op = &sysfs_inode_operations; 143 lockdep_set_class(&inode->i_mutex, &sysfs_inode_imutex_key);
144 inode->i_ino = sd->s_ino; 144
145 lockdep_set_class(&inode->i_mutex, &sysfs_inode_imutex_key); 145 if (sd->s_iattr) {
146 146 /* sysfs_dirent has non-default attributes
147 if (sd->s_iattr) { 147 * get them for the new inode from persistent copy
148 /* sysfs_dirent has non-default attributes 148 * in sysfs_dirent
149 * get them for the new inode from persistent copy 149 */
150 * in sysfs_dirent 150 set_inode_attr(inode, sd->s_iattr);
151 */ 151 } else
152 set_inode_attr(inode, sd->s_iattr); 152 set_default_inode_attr(inode, sd->s_mode);
153 } else 153}
154 set_default_inode_attr(inode, mode); 154
155 } 155/**
156 * sysfs_new_inode - allocate new inode for sysfs_dirent
157 * @sd: sysfs_dirent to allocate inode for
158 *
159 * Allocate inode for @sd and initialize basics.
160 *
161 * LOCKING:
162 * Kernel thread context (may sleep).
163 *
164 * RETURNS:
165 * Pointer to allocated inode on success, NULL on failure.
166 */
167struct inode * sysfs_new_inode(struct sysfs_dirent *sd)
168{
169 struct inode *inode;
170
171 inode = new_inode(sysfs_sb);
172 if (inode)
173 sysfs_init_inode(sd, inode);
174
156 return inode; 175 return inode;
157} 176}
158 177
159int sysfs_create(struct sysfs_dirent *sd, struct dentry *dentry, int mode, 178/**
160 int (*init)(struct inode *)) 179 * sysfs_instantiate - instantiate dentry
180 * @dentry: dentry to be instantiated
181 * @inode: inode associated with @sd
182 *
183 * Instantiate @dentry with @inode.
184 *
185 * LOCKING:
186 * None.
187 */
188void sysfs_instantiate(struct dentry *dentry, struct inode *inode)
161{ 189{
162 int error = 0; 190 BUG_ON(!dentry || dentry->d_inode);
163 struct inode * inode = NULL; 191
164 if (dentry) { 192 if (dentry->d_parent && dentry->d_parent->d_inode) {
165 if (!dentry->d_inode) { 193 struct inode *p_inode = dentry->d_parent->d_inode;
166 if ((inode = sysfs_new_inode(mode, sd))) { 194 p_inode->i_mtime = p_inode->i_ctime = CURRENT_TIME;
167 if (dentry->d_parent && dentry->d_parent->d_inode) { 195 }
168 struct inode *p_inode = dentry->d_parent->d_inode; 196
169 p_inode->i_mtime = p_inode->i_ctime = CURRENT_TIME; 197 d_instantiate(dentry, inode);
170 }
171 goto Proceed;
172 }
173 else
174 error = -ENOMEM;
175 } else
176 error = -EEXIST;
177 } else
178 error = -ENOENT;
179 goto Done;
180
181 Proceed:
182 if (init)
183 error = init(inode);
184 if (!error) {
185 d_instantiate(dentry, inode);
186 if (S_ISDIR(mode))
187 dget(dentry); /* pin only directory dentry in core */
188 } else
189 iput(inode);
190 Done:
191 return error;
192} 198}
193 199
194/** 200/**