mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-22 06:32:08 +00:00
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>
This commit is contained in:
parent
7f7cfffe60
commit
fc9f54b998
4 changed files with 116 additions and 142 deletions
104
fs/sysfs/inode.c
104
fs/sysfs/inode.c
|
@ -133,62 +133,68 @@ static inline void set_inode_attr(struct inode * inode, struct iattr * iattr)
|
|||
*/
|
||||
static struct lock_class_key sysfs_inode_imutex_key;
|
||||
|
||||
struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent * sd)
|
||||
void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
|
||||
{
|
||||
struct inode * inode = new_inode(sysfs_sb);
|
||||
if (inode) {
|
||||
inode->i_blocks = 0;
|
||||
inode->i_mapping->a_ops = &sysfs_aops;
|
||||
inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
|
||||
inode->i_op = &sysfs_inode_operations;
|
||||
inode->i_ino = sd->s_ino;
|
||||
lockdep_set_class(&inode->i_mutex, &sysfs_inode_imutex_key);
|
||||
inode->i_blocks = 0;
|
||||
inode->i_mapping->a_ops = &sysfs_aops;
|
||||
inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
|
||||
inode->i_op = &sysfs_inode_operations;
|
||||
inode->i_ino = sd->s_ino;
|
||||
lockdep_set_class(&inode->i_mutex, &sysfs_inode_imutex_key);
|
||||
|
||||
if (sd->s_iattr) {
|
||||
/* sysfs_dirent has non-default attributes
|
||||
* get them for the new inode from persistent copy
|
||||
* in sysfs_dirent
|
||||
*/
|
||||
set_inode_attr(inode, sd->s_iattr);
|
||||
} else
|
||||
set_default_inode_attr(inode, sd->s_mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* sysfs_new_inode - allocate new inode for sysfs_dirent
|
||||
* @sd: sysfs_dirent to allocate inode for
|
||||
*
|
||||
* Allocate inode for @sd and initialize basics.
|
||||
*
|
||||
* LOCKING:
|
||||
* Kernel thread context (may sleep).
|
||||
*
|
||||
* RETURNS:
|
||||
* Pointer to allocated inode on success, NULL on failure.
|
||||
*/
|
||||
struct inode * sysfs_new_inode(struct sysfs_dirent *sd)
|
||||
{
|
||||
struct inode *inode;
|
||||
|
||||
inode = new_inode(sysfs_sb);
|
||||
if (inode)
|
||||
sysfs_init_inode(sd, inode);
|
||||
|
||||
if (sd->s_iattr) {
|
||||
/* sysfs_dirent has non-default attributes
|
||||
* get them for the new inode from persistent copy
|
||||
* in sysfs_dirent
|
||||
*/
|
||||
set_inode_attr(inode, sd->s_iattr);
|
||||
} else
|
||||
set_default_inode_attr(inode, mode);
|
||||
}
|
||||
return inode;
|
||||
}
|
||||
|
||||
int sysfs_create(struct sysfs_dirent *sd, struct dentry *dentry, int mode,
|
||||
int (*init)(struct inode *))
|
||||
/**
|
||||
* sysfs_instantiate - instantiate dentry
|
||||
* @dentry: dentry to be instantiated
|
||||
* @inode: inode associated with @sd
|
||||
*
|
||||
* Instantiate @dentry with @inode.
|
||||
*
|
||||
* LOCKING:
|
||||
* None.
|
||||
*/
|
||||
void sysfs_instantiate(struct dentry *dentry, struct inode *inode)
|
||||
{
|
||||
int error = 0;
|
||||
struct inode * inode = NULL;
|
||||
if (dentry) {
|
||||
if (!dentry->d_inode) {
|
||||
if ((inode = sysfs_new_inode(mode, sd))) {
|
||||
if (dentry->d_parent && dentry->d_parent->d_inode) {
|
||||
struct inode *p_inode = dentry->d_parent->d_inode;
|
||||
p_inode->i_mtime = p_inode->i_ctime = CURRENT_TIME;
|
||||
}
|
||||
goto Proceed;
|
||||
}
|
||||
else
|
||||
error = -ENOMEM;
|
||||
} else
|
||||
error = -EEXIST;
|
||||
} else
|
||||
error = -ENOENT;
|
||||
goto Done;
|
||||
BUG_ON(!dentry || dentry->d_inode);
|
||||
|
||||
Proceed:
|
||||
if (init)
|
||||
error = init(inode);
|
||||
if (!error) {
|
||||
d_instantiate(dentry, inode);
|
||||
if (S_ISDIR(mode))
|
||||
dget(dentry); /* pin only directory dentry in core */
|
||||
} else
|
||||
iput(inode);
|
||||
Done:
|
||||
return error;
|
||||
if (dentry->d_parent && dentry->d_parent->d_inode) {
|
||||
struct inode *p_inode = dentry->d_parent->d_inode;
|
||||
p_inode->i_mtime = p_inode->i_ctime = CURRENT_TIME;
|
||||
}
|
||||
|
||||
d_instantiate(dentry, inode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue