mirror of https://gitee.com/openkylin/linux.git
sysfs: kill attribute file orphaning
Now that sysfs_dirent can be disconnected from kobject on deletion, there is no need to orphan each attribute files. All [bin_]attribute nodes are automatically orphaned when the parent node is deleted. Kill attribute file orphaning. Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
0ab66088c8
commit
73107cb3ad
|
@ -50,29 +50,15 @@ static struct sysfs_ops subsys_sysfs_ops = {
|
||||||
.store = subsys_attr_store,
|
.store = subsys_attr_store,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
struct sysfs_buffer {
|
||||||
* add_to_collection - add buffer to a collection
|
size_t count;
|
||||||
* @buffer: buffer to be added
|
loff_t pos;
|
||||||
* @node: inode of set to add to
|
char * page;
|
||||||
*/
|
struct sysfs_ops * ops;
|
||||||
|
struct semaphore sem;
|
||||||
static inline void
|
int needs_read_fill;
|
||||||
add_to_collection(struct sysfs_buffer *buffer, struct inode *node)
|
int event;
|
||||||
{
|
};
|
||||||
struct sysfs_buffer_collection *set = node->i_private;
|
|
||||||
|
|
||||||
mutex_lock(&node->i_mutex);
|
|
||||||
list_add(&buffer->associates, &set->associates);
|
|
||||||
mutex_unlock(&node->i_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
remove_from_collection(struct sysfs_buffer *buffer, struct inode *node)
|
|
||||||
{
|
|
||||||
mutex_lock(&node->i_mutex);
|
|
||||||
list_del(&buffer->associates);
|
|
||||||
mutex_unlock(&node->i_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fill_read_buffer - allocate and fill buffer from object.
|
* fill_read_buffer - allocate and fill buffer from object.
|
||||||
|
@ -144,10 +130,7 @@ sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos)
|
||||||
|
|
||||||
down(&buffer->sem);
|
down(&buffer->sem);
|
||||||
if (buffer->needs_read_fill) {
|
if (buffer->needs_read_fill) {
|
||||||
if (buffer->orphaned)
|
retval = fill_read_buffer(file->f_path.dentry,buffer);
|
||||||
retval = -ENODEV;
|
|
||||||
else
|
|
||||||
retval = fill_read_buffer(file->f_path.dentry,buffer);
|
|
||||||
if (retval)
|
if (retval)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -246,16 +229,11 @@ sysfs_write_file(struct file *file, const char __user *buf, size_t count, loff_t
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
down(&buffer->sem);
|
down(&buffer->sem);
|
||||||
if (buffer->orphaned) {
|
|
||||||
len = -ENODEV;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
len = fill_write_buffer(buffer, buf, count);
|
len = fill_write_buffer(buffer, buf, count);
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
len = flush_write_buffer(file->f_path.dentry, buffer, len);
|
len = flush_write_buffer(file->f_path.dentry, buffer, len);
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
*ppos += len;
|
*ppos += len;
|
||||||
out:
|
|
||||||
up(&buffer->sem);
|
up(&buffer->sem);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
@ -265,7 +243,6 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
|
||||||
struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
|
struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
|
||||||
struct attribute *attr = attr_sd->s_elem.attr.attr;
|
struct attribute *attr = attr_sd->s_elem.attr.attr;
|
||||||
struct kobject *kobj = attr_sd->s_parent->s_elem.dir.kobj;
|
struct kobject *kobj = attr_sd->s_parent->s_elem.dir.kobj;
|
||||||
struct sysfs_buffer_collection *set;
|
|
||||||
struct sysfs_buffer * buffer;
|
struct sysfs_buffer * buffer;
|
||||||
struct sysfs_ops * ops = NULL;
|
struct sysfs_ops * ops = NULL;
|
||||||
int error;
|
int error;
|
||||||
|
@ -289,26 +266,14 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
|
||||||
else
|
else
|
||||||
ops = &subsys_sysfs_ops;
|
ops = &subsys_sysfs_ops;
|
||||||
|
|
||||||
|
error = -EACCES;
|
||||||
|
|
||||||
/* No sysfs operations, either from having no subsystem,
|
/* No sysfs operations, either from having no subsystem,
|
||||||
* or the subsystem have no operations.
|
* or the subsystem have no operations.
|
||||||
*/
|
*/
|
||||||
error = -EACCES;
|
|
||||||
if (!ops)
|
if (!ops)
|
||||||
goto err_mput;
|
goto err_mput;
|
||||||
|
|
||||||
/* make sure we have a collection to add our buffers to */
|
|
||||||
mutex_lock(&inode->i_mutex);
|
|
||||||
if (!(set = inode->i_private)) {
|
|
||||||
error = -ENOMEM;
|
|
||||||
if (!(set = inode->i_private = kmalloc(sizeof(struct sysfs_buffer_collection), GFP_KERNEL)))
|
|
||||||
goto err_mput;
|
|
||||||
else
|
|
||||||
INIT_LIST_HEAD(&set->associates);
|
|
||||||
}
|
|
||||||
mutex_unlock(&inode->i_mutex);
|
|
||||||
|
|
||||||
error = -EACCES;
|
|
||||||
|
|
||||||
/* File needs write support.
|
/* File needs write support.
|
||||||
* The inode's perms must say it's ok,
|
* The inode's perms must say it's ok,
|
||||||
* and we must have a store method.
|
* and we must have a store method.
|
||||||
|
@ -335,11 +300,9 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
goto err_mput;
|
goto err_mput;
|
||||||
|
|
||||||
INIT_LIST_HEAD(&buffer->associates);
|
|
||||||
init_MUTEX(&buffer->sem);
|
init_MUTEX(&buffer->sem);
|
||||||
buffer->needs_read_fill = 1;
|
buffer->needs_read_fill = 1;
|
||||||
buffer->ops = ops;
|
buffer->ops = ops;
|
||||||
add_to_collection(buffer, inode);
|
|
||||||
file->private_data = buffer;
|
file->private_data = buffer;
|
||||||
|
|
||||||
/* open succeeded, put active references and pin attr_sd */
|
/* open succeeded, put active references and pin attr_sd */
|
||||||
|
@ -358,10 +321,8 @@ static int sysfs_release(struct inode * inode, struct file * filp)
|
||||||
{
|
{
|
||||||
struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata;
|
struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata;
|
||||||
struct attribute *attr = attr_sd->s_elem.attr.attr;
|
struct attribute *attr = attr_sd->s_elem.attr.attr;
|
||||||
struct sysfs_buffer * buffer = filp->private_data;
|
struct sysfs_buffer *buffer = filp->private_data;
|
||||||
|
|
||||||
if (buffer)
|
|
||||||
remove_from_collection(buffer, inode);
|
|
||||||
sysfs_put(attr_sd);
|
sysfs_put(attr_sd);
|
||||||
/* After this point, attr should not be accessed. */
|
/* After this point, attr should not be accessed. */
|
||||||
module_put(attr->owner);
|
module_put(attr->owner);
|
||||||
|
|
|
@ -191,24 +191,6 @@ int sysfs_create(struct dentry * dentry, int mode, int (*init)(struct inode *))
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void orphan_all_buffers(struct inode *node)
|
|
||||||
{
|
|
||||||
struct sysfs_buffer_collection *set;
|
|
||||||
struct sysfs_buffer *buf;
|
|
||||||
|
|
||||||
mutex_lock_nested(&node->i_mutex, I_MUTEX_CHILD);
|
|
||||||
set = node->i_private;
|
|
||||||
if (set) {
|
|
||||||
list_for_each_entry(buf, &set->associates, associates) {
|
|
||||||
down(&buf->sem);
|
|
||||||
buf->orphaned = 1;
|
|
||||||
up(&buf->sem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mutex_unlock(&node->i_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unhashes the dentry corresponding to given sysfs_dirent
|
* Unhashes the dentry corresponding to given sysfs_dirent
|
||||||
* Called with parent inode's i_mutex held.
|
* Called with parent inode's i_mutex held.
|
||||||
|
@ -216,7 +198,6 @@ static inline void orphan_all_buffers(struct inode *node)
|
||||||
void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent)
|
void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent)
|
||||||
{
|
{
|
||||||
struct dentry *dentry = NULL;
|
struct dentry *dentry = NULL;
|
||||||
struct inode *inode;
|
|
||||||
|
|
||||||
/* We're not holding a reference to ->s_dentry dentry but the
|
/* We're not holding a reference to ->s_dentry dentry but the
|
||||||
* field will stay valid as long as sysfs_lock is held.
|
* field will stay valid as long as sysfs_lock is held.
|
||||||
|
@ -236,17 +217,11 @@ void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent)
|
||||||
spin_lock(&dcache_lock);
|
spin_lock(&dcache_lock);
|
||||||
spin_lock(&dentry->d_lock);
|
spin_lock(&dentry->d_lock);
|
||||||
if (!d_unhashed(dentry) && dentry->d_inode) {
|
if (!d_unhashed(dentry) && dentry->d_inode) {
|
||||||
inode = dentry->d_inode;
|
|
||||||
spin_lock(&inode->i_lock);
|
|
||||||
__iget(inode);
|
|
||||||
spin_unlock(&inode->i_lock);
|
|
||||||
dget_locked(dentry);
|
dget_locked(dentry);
|
||||||
__d_drop(dentry);
|
__d_drop(dentry);
|
||||||
spin_unlock(&dentry->d_lock);
|
spin_unlock(&dentry->d_lock);
|
||||||
spin_unlock(&dcache_lock);
|
spin_unlock(&dcache_lock);
|
||||||
simple_unlink(parent->d_inode, dentry);
|
simple_unlink(parent->d_inode, dentry);
|
||||||
orphan_all_buffers(inode);
|
|
||||||
iput(inode);
|
|
||||||
} else {
|
} else {
|
||||||
spin_unlock(&dentry->d_lock);
|
spin_unlock(&dentry->d_lock);
|
||||||
spin_unlock(&dcache_lock);
|
spin_unlock(&dcache_lock);
|
||||||
|
|
|
@ -19,12 +19,9 @@ struct vfsmount *sysfs_mount;
|
||||||
struct super_block * sysfs_sb = NULL;
|
struct super_block * sysfs_sb = NULL;
|
||||||
struct kmem_cache *sysfs_dir_cachep;
|
struct kmem_cache *sysfs_dir_cachep;
|
||||||
|
|
||||||
static void sysfs_clear_inode(struct inode *inode);
|
|
||||||
|
|
||||||
static const struct super_operations sysfs_ops = {
|
static const struct super_operations sysfs_ops = {
|
||||||
.statfs = simple_statfs,
|
.statfs = simple_statfs,
|
||||||
.drop_inode = sysfs_delete_inode,
|
.drop_inode = sysfs_delete_inode,
|
||||||
.clear_inode = sysfs_clear_inode,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct sysfs_dirent sysfs_root = {
|
static struct sysfs_dirent sysfs_root = {
|
||||||
|
@ -36,11 +33,6 @@ static struct sysfs_dirent sysfs_root = {
|
||||||
.s_ino = 1,
|
.s_ino = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void sysfs_clear_inode(struct inode *inode)
|
|
||||||
{
|
|
||||||
kfree(inode->i_private);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int sysfs_fill_super(struct super_block *sb, void *data, int silent)
|
static int sysfs_fill_super(struct super_block *sb, void *data, int silent)
|
||||||
{
|
{
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
|
|
|
@ -88,22 +88,6 @@ extern const struct file_operations bin_fops;
|
||||||
extern const struct inode_operations sysfs_dir_inode_operations;
|
extern const struct inode_operations sysfs_dir_inode_operations;
|
||||||
extern const struct inode_operations sysfs_symlink_inode_operations;
|
extern const struct inode_operations sysfs_symlink_inode_operations;
|
||||||
|
|
||||||
struct sysfs_buffer {
|
|
||||||
struct list_head associates;
|
|
||||||
size_t count;
|
|
||||||
loff_t pos;
|
|
||||||
char * page;
|
|
||||||
struct sysfs_ops * ops;
|
|
||||||
struct semaphore sem;
|
|
||||||
int orphaned;
|
|
||||||
int needs_read_fill;
|
|
||||||
int event;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sysfs_buffer_collection {
|
|
||||||
struct list_head associates;
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd)
|
static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd)
|
||||||
{
|
{
|
||||||
if (sd) {
|
if (sd) {
|
||||||
|
|
Loading…
Reference in New Issue