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>
This commit is contained in:
parent
1cf7a003b0
commit
2743c515a1
|
@ -66,7 +66,7 @@ extern struct kmem_cache *configfs_dir_cachep;
|
|||
extern int configfs_is_root(struct config_item *item);
|
||||
|
||||
extern struct inode * configfs_new_inode(umode_t mode, struct configfs_dirent *, struct super_block *);
|
||||
extern int configfs_create(struct dentry *, umode_t mode, void (*init)(struct inode *));
|
||||
extern struct inode *configfs_create(struct dentry *, umode_t mode);
|
||||
|
||||
extern int configfs_create_file(struct config_item *, const struct configfs_attribute *);
|
||||
extern int configfs_create_bin_file(struct config_item *,
|
||||
|
|
|
@ -265,32 +265,6 @@ static void configfs_remove_dirent(struct dentry *dentry)
|
|||
configfs_put(sd);
|
||||
}
|
||||
|
||||
static void init_dir(struct inode * inode)
|
||||
{
|
||||
inode->i_op = &configfs_dir_inode_operations;
|
||||
inode->i_fop = &configfs_dir_operations;
|
||||
|
||||
/* directory inodes start off with i_nlink == 2 (for "." entry) */
|
||||
inc_nlink(inode);
|
||||
}
|
||||
|
||||
static void configfs_init_file(struct inode * inode)
|
||||
{
|
||||
inode->i_size = PAGE_SIZE;
|
||||
inode->i_fop = &configfs_file_operations;
|
||||
}
|
||||
|
||||
static void configfs_init_bin_file(struct inode *inode)
|
||||
{
|
||||
inode->i_size = 0;
|
||||
inode->i_fop = &configfs_bin_file_operations;
|
||||
}
|
||||
|
||||
static void init_symlink(struct inode * inode)
|
||||
{
|
||||
inode->i_op = &configfs_symlink_inode_operations;
|
||||
}
|
||||
|
||||
/**
|
||||
* configfs_create_dir - create a directory for an config_item.
|
||||
* @item: config_itemwe're creating directory for.
|
||||
|
@ -306,6 +280,7 @@ static int configfs_create_dir(struct config_item *item, struct dentry *dentry,
|
|||
int error;
|
||||
umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO;
|
||||
struct dentry *p = dentry->d_parent;
|
||||
struct inode *inode;
|
||||
|
||||
BUG_ON(!item);
|
||||
|
||||
|
@ -320,17 +295,24 @@ static int configfs_create_dir(struct config_item *item, struct dentry *dentry,
|
|||
return error;
|
||||
|
||||
configfs_set_dir_dirent_depth(p->d_fsdata, dentry->d_fsdata);
|
||||
error = configfs_create(dentry, mode, init_dir);
|
||||
if (error)
|
||||
inode = configfs_create(dentry, mode);
|
||||
if (IS_ERR(inode))
|
||||
goto out_remove;
|
||||
|
||||
inode->i_op = &configfs_dir_inode_operations;
|
||||
inode->i_fop = &configfs_dir_operations;
|
||||
/* directory inodes start off with i_nlink == 2 (for "." entry) */
|
||||
inc_nlink(inode);
|
||||
d_instantiate(dentry, inode);
|
||||
/* already hashed */
|
||||
dget(dentry); /* pin directory dentries in core */
|
||||
inc_nlink(d_inode(p));
|
||||
item->ci_dentry = dentry;
|
||||
return 0;
|
||||
|
||||
out_remove:
|
||||
configfs_remove_dirent(dentry);
|
||||
return error;
|
||||
return PTR_ERR(inode);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -378,20 +360,25 @@ int configfs_create_link(struct configfs_symlink *sl,
|
|||
int err = 0;
|
||||
umode_t mode = S_IFLNK | S_IRWXUGO;
|
||||
struct configfs_dirent *p = parent->d_fsdata;
|
||||
struct inode *inode;
|
||||
|
||||
err = configfs_make_dirent(p, dentry, sl, mode,
|
||||
CONFIGFS_ITEM_LINK, p->s_frag);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = configfs_create(dentry, mode, init_symlink);
|
||||
if (err)
|
||||
inode = configfs_create(dentry, mode);
|
||||
if (IS_ERR(inode))
|
||||
goto out_remove;
|
||||
|
||||
inode->i_op = &configfs_symlink_inode_operations;
|
||||
d_instantiate(dentry, inode);
|
||||
dget(dentry); /* pin link dentries in core */
|
||||
return 0;
|
||||
|
||||
out_remove:
|
||||
configfs_remove_dirent(dentry);
|
||||
return err;
|
||||
return PTR_ERR(inode);
|
||||
}
|
||||
|
||||
static void remove_dir(struct dentry * d)
|
||||
|
@ -440,20 +427,27 @@ static void configfs_remove_dir(struct config_item * item)
|
|||
static int configfs_attach_attr(struct configfs_dirent * sd, struct dentry * dentry)
|
||||
{
|
||||
struct configfs_attribute * attr = sd->s_element;
|
||||
int error;
|
||||
struct inode *inode;
|
||||
|
||||
spin_lock(&configfs_dirent_lock);
|
||||
dentry->d_fsdata = configfs_get(sd);
|
||||
sd->s_dentry = dentry;
|
||||
spin_unlock(&configfs_dirent_lock);
|
||||
|
||||
error = configfs_create(dentry, (attr->ca_mode & S_IALLUGO) | S_IFREG,
|
||||
(sd->s_type & CONFIGFS_ITEM_BIN_ATTR) ?
|
||||
configfs_init_bin_file :
|
||||
configfs_init_file);
|
||||
if (error)
|
||||
inode = configfs_create(dentry, (attr->ca_mode & S_IALLUGO) | S_IFREG);
|
||||
if (IS_ERR(inode)) {
|
||||
configfs_put(sd);
|
||||
return error;
|
||||
return PTR_ERR(inode);
|
||||
}
|
||||
if (sd->s_type & CONFIGFS_ITEM_BIN_ATTR) {
|
||||
inode->i_size = 0;
|
||||
inode->i_fop = &configfs_bin_file_operations;
|
||||
} else {
|
||||
inode->i_size = PAGE_SIZE;
|
||||
inode->i_fop = &configfs_file_operations;
|
||||
}
|
||||
d_add(dentry, inode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct dentry * configfs_lookup(struct inode *dir,
|
||||
|
|
|
@ -164,41 +164,27 @@ static void configfs_set_inode_lock_class(struct configfs_dirent *sd,
|
|||
|
||||
#endif /* CONFIG_LOCKDEP */
|
||||
|
||||
int configfs_create(struct dentry * dentry, umode_t mode, void (*init)(struct inode *))
|
||||
struct inode *configfs_create(struct dentry *dentry, umode_t mode)
|
||||
{
|
||||
int error = 0;
|
||||
struct inode *inode = NULL;
|
||||
struct configfs_dirent *sd;
|
||||
struct inode *p_inode;
|
||||
|
||||
if (!dentry)
|
||||
return -ENOENT;
|
||||
return ERR_PTR(-ENOENT);
|
||||
|
||||
if (d_really_is_positive(dentry))
|
||||
return -EEXIST;
|
||||
return ERR_PTR(-EEXIST);
|
||||
|
||||
sd = dentry->d_fsdata;
|
||||
inode = configfs_new_inode(mode, sd, dentry->d_sb);
|
||||
if (!inode)
|
||||
return -ENOMEM;
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
p_inode = d_inode(dentry->d_parent);
|
||||
p_inode->i_mtime = p_inode->i_ctime = current_time(p_inode);
|
||||
configfs_set_inode_lock_class(sd, inode);
|
||||
|
||||
init(inode);
|
||||
if (S_ISDIR(mode) || S_ISLNK(mode)) {
|
||||
/*
|
||||
* ->symlink(), ->mkdir(), configfs_register_subsystem() or
|
||||
* create_default_group() - already hashed.
|
||||
*/
|
||||
d_instantiate(dentry, inode);
|
||||
dget(dentry); /* pin link and directory dentries in core */
|
||||
} else {
|
||||
/* ->lookup() */
|
||||
d_add(dentry, inode);
|
||||
}
|
||||
return error;
|
||||
return inode;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue