mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-03-30 19:07:15 +00:00
sysfs: move sysfs file poll implementation to sysfs_open_dirent
Sysfs file poll implementation is scattered over sysfs and kobject. Event numbering is done in sysfs_dirent but wait itself is done on kobject. This not only unecessarily bloats both kobject and sysfs_dirent but is also buggy - if a sysfs_dirent is removed while there still are pollers, the associaton betwen the kobject and sysfs_dirent breaks and kobject may be freed with the pollers still sleeping on it. This patch moves whole poll implementation into sysfs_open_dirent. Each time a sysfs_open_dirent is created, event number restarts from 1 and pollers sleep on sysfs_open_dirent. As event sequence number is meaningless without any open file and pollers should have open file and thus sysfs_open_dirent, this ephemeral event counting works and is a saner implementation. This patch fixes the dnagling sleepers bug and reduces the sizes of kobject and sysfs_dirent by one pointer. Signed-off-by: Tejun Heo <htejun@gmail.com> Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
85a4ffad3d
commit
a4e8b91254
5 changed files with 19 additions and 10 deletions
|
@ -318,7 +318,6 @@ struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type)
|
||||||
|
|
||||||
atomic_set(&sd->s_count, 1);
|
atomic_set(&sd->s_count, 1);
|
||||||
atomic_set(&sd->s_active, 0);
|
atomic_set(&sd->s_active, 0);
|
||||||
atomic_set(&sd->s_event, 1);
|
|
||||||
|
|
||||||
sd->s_name = name;
|
sd->s_name = name;
|
||||||
sd->s_mode = mode;
|
sd->s_mode = mode;
|
||||||
|
|
|
@ -62,6 +62,8 @@ static spinlock_t sysfs_open_dirent_lock = SPIN_LOCK_UNLOCKED;
|
||||||
|
|
||||||
struct sysfs_open_dirent {
|
struct sysfs_open_dirent {
|
||||||
atomic_t refcnt;
|
atomic_t refcnt;
|
||||||
|
atomic_t event;
|
||||||
|
wait_queue_head_t poll;
|
||||||
struct list_head buffers; /* goes through sysfs_buffer.list */
|
struct list_head buffers; /* goes through sysfs_buffer.list */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -104,7 +106,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
|
||||||
if (!sysfs_get_active_two(attr_sd))
|
if (!sysfs_get_active_two(attr_sd))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
buffer->event = atomic_read(&attr_sd->s_event);
|
buffer->event = atomic_read(&attr_sd->s_attr.open->event);
|
||||||
count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
|
count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
|
||||||
|
|
||||||
sysfs_put_active_two(attr_sd);
|
sysfs_put_active_two(attr_sd);
|
||||||
|
@ -301,6 +303,8 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
atomic_set(&new_od->refcnt, 0);
|
atomic_set(&new_od->refcnt, 0);
|
||||||
|
atomic_set(&new_od->event, 1);
|
||||||
|
init_waitqueue_head(&new_od->poll);
|
||||||
INIT_LIST_HEAD(&new_od->buffers);
|
INIT_LIST_HEAD(&new_od->buffers);
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
|
@ -443,17 +447,17 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
|
||||||
{
|
{
|
||||||
struct sysfs_buffer * buffer = filp->private_data;
|
struct sysfs_buffer * buffer = filp->private_data;
|
||||||
struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata;
|
struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata;
|
||||||
struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
|
struct sysfs_open_dirent *od = attr_sd->s_attr.open;
|
||||||
|
|
||||||
/* need parent for the kobj, grab both */
|
/* need parent for the kobj, grab both */
|
||||||
if (!sysfs_get_active_two(attr_sd))
|
if (!sysfs_get_active_two(attr_sd))
|
||||||
goto trigger;
|
goto trigger;
|
||||||
|
|
||||||
poll_wait(filp, &kobj->poll, wait);
|
poll_wait(filp, &od->poll, wait);
|
||||||
|
|
||||||
sysfs_put_active_two(attr_sd);
|
sysfs_put_active_two(attr_sd);
|
||||||
|
|
||||||
if (buffer->event != atomic_read(&attr_sd->s_event))
|
if (buffer->event != atomic_read(&od->event))
|
||||||
goto trigger;
|
goto trigger;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -474,8 +478,17 @@ void sysfs_notify(struct kobject *k, char *dir, char *attr)
|
||||||
if (sd && attr)
|
if (sd && attr)
|
||||||
sd = sysfs_find_dirent(sd, attr);
|
sd = sysfs_find_dirent(sd, attr);
|
||||||
if (sd) {
|
if (sd) {
|
||||||
atomic_inc(&sd->s_event);
|
struct sysfs_open_dirent *od;
|
||||||
wake_up_interruptible(&k->poll);
|
|
||||||
|
spin_lock(&sysfs_open_dirent_lock);
|
||||||
|
|
||||||
|
od = sd->s_attr.open;
|
||||||
|
if (od) {
|
||||||
|
atomic_inc(&od->event);
|
||||||
|
wake_up_interruptible(&od->poll);
|
||||||
|
}
|
||||||
|
|
||||||
|
spin_unlock(&sysfs_open_dirent_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_unlock(&sysfs_mutex);
|
mutex_unlock(&sysfs_mutex);
|
||||||
|
|
|
@ -46,7 +46,6 @@ struct sysfs_dirent {
|
||||||
ino_t s_ino;
|
ino_t s_ino;
|
||||||
umode_t s_mode;
|
umode_t s_mode;
|
||||||
struct iattr *s_iattr;
|
struct iattr *s_iattr;
|
||||||
atomic_t s_event;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SD_DEACTIVATED_BIAS INT_MIN
|
#define SD_DEACTIVATED_BIAS INT_MIN
|
||||||
|
|
|
@ -66,7 +66,6 @@ struct kobject {
|
||||||
struct kset * kset;
|
struct kset * kset;
|
||||||
struct kobj_type * ktype;
|
struct kobj_type * ktype;
|
||||||
struct sysfs_dirent * sd;
|
struct sysfs_dirent * sd;
|
||||||
wait_queue_head_t poll;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern int kobject_set_name(struct kobject *, const char *, ...)
|
extern int kobject_set_name(struct kobject *, const char *, ...)
|
||||||
|
|
|
@ -131,7 +131,6 @@ void kobject_init(struct kobject * kobj)
|
||||||
return;
|
return;
|
||||||
kref_init(&kobj->kref);
|
kref_init(&kobj->kref);
|
||||||
INIT_LIST_HEAD(&kobj->entry);
|
INIT_LIST_HEAD(&kobj->entry);
|
||||||
init_waitqueue_head(&kobj->poll);
|
|
||||||
kobj->kset = kset_get(kobj->kset);
|
kobj->kset = kset_get(kobj->kset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue