diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2019-09-11 02:57:38 -0400 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2019-09-11 06:46:10 -0400 |
commit | 2743c515a1239bb96028bddafef87c0a486f4361 (patch) | |
tree | 19bd60d261eb5c95ec638f8fdda2e56595868bc8 | |
parent | 1cf7a003b044744c06dfa452cd136e71223b5569 (diff) |
configfs: make configfs_create() return inode
Get rid of the callback, deal with that and dentry in callers
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Christoph Hellwig <hch@lst.de>
-rw-r--r-- | fs/configfs/configfs_internal.h | 2 | ||||
-rw-r--r-- | fs/configfs/dir.c | 72 | ||||
-rw-r--r-- | fs/configfs/inode.c | 24 |
3 files changed, 39 insertions, 59 deletions
diff --git a/fs/configfs/configfs_internal.h b/fs/configfs/configfs_internal.h index 520f1813e789..c1f2125acf94 100644 --- a/fs/configfs/configfs_internal.h +++ b/fs/configfs/configfs_internal.h | |||
@@ -66,7 +66,7 @@ extern struct kmem_cache *configfs_dir_cachep; | |||
66 | extern int configfs_is_root(struct config_item *item); | 66 | extern int configfs_is_root(struct config_item *item); |
67 | 67 | ||
68 | extern struct inode * configfs_new_inode(umode_t mode, struct configfs_dirent *, struct super_block *); | 68 | extern struct inode * configfs_new_inode(umode_t mode, struct configfs_dirent *, struct super_block *); |
69 | extern int configfs_create(struct dentry *, umode_t mode, void (*init)(struct inode *)); | 69 | extern struct inode *configfs_create(struct dentry *, umode_t mode); |
70 | 70 | ||
71 | extern int configfs_create_file(struct config_item *, const struct configfs_attribute *); | 71 | extern int configfs_create_file(struct config_item *, const struct configfs_attribute *); |
72 | extern int configfs_create_bin_file(struct config_item *, | 72 | extern int configfs_create_bin_file(struct config_item *, |
diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c index fbd6f9dbe7a6..728d1f1ee6a9 100644 --- a/fs/configfs/dir.c +++ b/fs/configfs/dir.c | |||
@@ -265,32 +265,6 @@ static void configfs_remove_dirent(struct dentry *dentry) | |||
265 | configfs_put(sd); | 265 | configfs_put(sd); |
266 | } | 266 | } |
267 | 267 | ||
268 | static void init_dir(struct inode * inode) | ||
269 | { | ||
270 | inode->i_op = &configfs_dir_inode_operations; | ||
271 | inode->i_fop = &configfs_dir_operations; | ||
272 | |||
273 | /* directory inodes start off with i_nlink == 2 (for "." entry) */ | ||
274 | inc_nlink(inode); | ||
275 | } | ||
276 | |||
277 | static void configfs_init_file(struct inode * inode) | ||
278 | { | ||
279 | inode->i_size = PAGE_SIZE; | ||
280 | inode->i_fop = &configfs_file_operations; | ||
281 | } | ||
282 | |||
283 | static void configfs_init_bin_file(struct inode *inode) | ||
284 | { | ||
285 | inode->i_size = 0; | ||
286 | inode->i_fop = &configfs_bin_file_operations; | ||
287 | } | ||
288 | |||
289 | static void init_symlink(struct inode * inode) | ||
290 | { | ||
291 | inode->i_op = &configfs_symlink_inode_operations; | ||
292 | } | ||
293 | |||
294 | /** | 268 | /** |
295 | * configfs_create_dir - create a directory for an config_item. | 269 | * configfs_create_dir - create a directory for an config_item. |
296 | * @item: config_itemwe're creating directory for. | 270 | * @item: config_itemwe're creating directory for. |
@@ -306,6 +280,7 @@ static int configfs_create_dir(struct config_item *item, struct dentry *dentry, | |||
306 | int error; | 280 | int error; |
307 | umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO; | 281 | umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO; |
308 | struct dentry *p = dentry->d_parent; | 282 | struct dentry *p = dentry->d_parent; |
283 | struct inode *inode; | ||
309 | 284 | ||
310 | BUG_ON(!item); | 285 | BUG_ON(!item); |
311 | 286 | ||
@@ -320,17 +295,24 @@ static int configfs_create_dir(struct config_item *item, struct dentry *dentry, | |||
320 | return error; | 295 | return error; |
321 | 296 | ||
322 | configfs_set_dir_dirent_depth(p->d_fsdata, dentry->d_fsdata); | 297 | configfs_set_dir_dirent_depth(p->d_fsdata, dentry->d_fsdata); |
323 | error = configfs_create(dentry, mode, init_dir); | 298 | inode = configfs_create(dentry, mode); |
324 | if (error) | 299 | if (IS_ERR(inode)) |
325 | goto out_remove; | 300 | goto out_remove; |
326 | 301 | ||
302 | inode->i_op = &configfs_dir_inode_operations; | ||
303 | inode->i_fop = &configfs_dir_operations; | ||
304 | /* directory inodes start off with i_nlink == 2 (for "." entry) */ | ||
305 | inc_nlink(inode); | ||
306 | d_instantiate(dentry, inode); | ||
307 | /* already hashed */ | ||
308 | dget(dentry); /* pin directory dentries in core */ | ||
327 | inc_nlink(d_inode(p)); | 309 | inc_nlink(d_inode(p)); |
328 | item->ci_dentry = dentry; | 310 | item->ci_dentry = dentry; |
329 | return 0; | 311 | return 0; |
330 | 312 | ||
331 | out_remove: | 313 | out_remove: |
332 | configfs_remove_dirent(dentry); | 314 | configfs_remove_dirent(dentry); |
333 | return error; | 315 | return PTR_ERR(inode); |
334 | } | 316 | } |
335 | 317 | ||
336 | /* | 318 | /* |
@@ -378,20 +360,25 @@ int configfs_create_link(struct configfs_symlink *sl, | |||
378 | int err = 0; | 360 | int err = 0; |
379 | umode_t mode = S_IFLNK | S_IRWXUGO; | 361 | umode_t mode = S_IFLNK | S_IRWXUGO; |
380 | struct configfs_dirent *p = parent->d_fsdata; | 362 | struct configfs_dirent *p = parent->d_fsdata; |
363 | struct inode *inode; | ||
381 | 364 | ||
382 | err = configfs_make_dirent(p, dentry, sl, mode, | 365 | err = configfs_make_dirent(p, dentry, sl, mode, |
383 | CONFIGFS_ITEM_LINK, p->s_frag); | 366 | CONFIGFS_ITEM_LINK, p->s_frag); |
384 | if (err) | 367 | if (err) |
385 | return err; | 368 | return err; |
386 | 369 | ||
387 | err = configfs_create(dentry, mode, init_symlink); | 370 | inode = configfs_create(dentry, mode); |
388 | if (err) | 371 | if (IS_ERR(inode)) |
389 | goto out_remove; | 372 | goto out_remove; |
373 | |||
374 | inode->i_op = &configfs_symlink_inode_operations; | ||
375 | d_instantiate(dentry, inode); | ||
376 | dget(dentry); /* pin link dentries in core */ | ||
390 | return 0; | 377 | return 0; |
391 | 378 | ||
392 | out_remove: | 379 | out_remove: |
393 | configfs_remove_dirent(dentry); | 380 | configfs_remove_dirent(dentry); |
394 | return err; | 381 | return PTR_ERR(inode); |
395 | } | 382 | } |
396 | 383 | ||
397 | static void remove_dir(struct dentry * d) | 384 | static void remove_dir(struct dentry * d) |
@@ -440,20 +427,27 @@ static void configfs_remove_dir(struct config_item * item) | |||
440 | static int configfs_attach_attr(struct configfs_dirent * sd, struct dentry * dentry) | 427 | static int configfs_attach_attr(struct configfs_dirent * sd, struct dentry * dentry) |
441 | { | 428 | { |
442 | struct configfs_attribute * attr = sd->s_element; | 429 | struct configfs_attribute * attr = sd->s_element; |
443 | int error; | 430 | struct inode *inode; |
444 | 431 | ||
445 | spin_lock(&configfs_dirent_lock); | 432 | spin_lock(&configfs_dirent_lock); |
446 | dentry->d_fsdata = configfs_get(sd); | 433 | dentry->d_fsdata = configfs_get(sd); |
447 | sd->s_dentry = dentry; | 434 | sd->s_dentry = dentry; |
448 | spin_unlock(&configfs_dirent_lock); | 435 | spin_unlock(&configfs_dirent_lock); |
449 | 436 | ||
450 | error = configfs_create(dentry, (attr->ca_mode & S_IALLUGO) | S_IFREG, | 437 | inode = configfs_create(dentry, (attr->ca_mode & S_IALLUGO) | S_IFREG); |
451 | (sd->s_type & CONFIGFS_ITEM_BIN_ATTR) ? | 438 | if (IS_ERR(inode)) { |
452 | configfs_init_bin_file : | ||
453 | configfs_init_file); | ||
454 | if (error) | ||
455 | configfs_put(sd); | 439 | configfs_put(sd); |
456 | return error; | 440 | return PTR_ERR(inode); |
441 | } | ||
442 | if (sd->s_type & CONFIGFS_ITEM_BIN_ATTR) { | ||
443 | inode->i_size = 0; | ||
444 | inode->i_fop = &configfs_bin_file_operations; | ||
445 | } else { | ||
446 | inode->i_size = PAGE_SIZE; | ||
447 | inode->i_fop = &configfs_file_operations; | ||
448 | } | ||
449 | d_add(dentry, inode); | ||
450 | return 0; | ||
457 | } | 451 | } |
458 | 452 | ||
459 | static struct dentry * configfs_lookup(struct inode *dir, | 453 | static struct dentry * configfs_lookup(struct inode *dir, |
diff --git a/fs/configfs/inode.c b/fs/configfs/inode.c index ab0284321912..9c3d309839a8 100644 --- a/fs/configfs/inode.c +++ b/fs/configfs/inode.c | |||
@@ -164,41 +164,27 @@ static void configfs_set_inode_lock_class(struct configfs_dirent *sd, | |||
164 | 164 | ||
165 | #endif /* CONFIG_LOCKDEP */ | 165 | #endif /* CONFIG_LOCKDEP */ |
166 | 166 | ||
167 | int configfs_create(struct dentry * dentry, umode_t mode, void (*init)(struct inode *)) | 167 | struct inode *configfs_create(struct dentry *dentry, umode_t mode) |
168 | { | 168 | { |
169 | int error = 0; | ||
170 | struct inode *inode = NULL; | 169 | struct inode *inode = NULL; |
171 | struct configfs_dirent *sd; | 170 | struct configfs_dirent *sd; |
172 | struct inode *p_inode; | 171 | struct inode *p_inode; |
173 | 172 | ||
174 | if (!dentry) | 173 | if (!dentry) |
175 | return -ENOENT; | 174 | return ERR_PTR(-ENOENT); |
176 | 175 | ||
177 | if (d_really_is_positive(dentry)) | 176 | if (d_really_is_positive(dentry)) |
178 | return -EEXIST; | 177 | return ERR_PTR(-EEXIST); |
179 | 178 | ||
180 | sd = dentry->d_fsdata; | 179 | sd = dentry->d_fsdata; |
181 | inode = configfs_new_inode(mode, sd, dentry->d_sb); | 180 | inode = configfs_new_inode(mode, sd, dentry->d_sb); |
182 | if (!inode) | 181 | if (!inode) |
183 | return -ENOMEM; | 182 | return ERR_PTR(-ENOMEM); |
184 | 183 | ||
185 | p_inode = d_inode(dentry->d_parent); | 184 | p_inode = d_inode(dentry->d_parent); |
186 | p_inode->i_mtime = p_inode->i_ctime = current_time(p_inode); | 185 | p_inode->i_mtime = p_inode->i_ctime = current_time(p_inode); |
187 | configfs_set_inode_lock_class(sd, inode); | 186 | configfs_set_inode_lock_class(sd, inode); |
188 | 187 | return inode; | |
189 | init(inode); | ||
190 | if (S_ISDIR(mode) || S_ISLNK(mode)) { | ||
191 | /* | ||
192 | * ->symlink(), ->mkdir(), configfs_register_subsystem() or | ||
193 | * create_default_group() - already hashed. | ||
194 | */ | ||
195 | d_instantiate(dentry, inode); | ||
196 | dget(dentry); /* pin link and directory dentries in core */ | ||
197 | } else { | ||
198 | /* ->lookup() */ | ||
199 | d_add(dentry, inode); | ||
200 | } | ||
201 | return error; | ||
202 | } | 188 | } |
203 | 189 | ||
204 | /* | 190 | /* |