sysfs: add sysfs_open_file_mutex
Add a separate mutex to protect sysfs_open_dirent->buffers list. This will allow performing sleepable operations while traversing sysfs_buffers, which will be renamed to sysfs_open_file. Note that currently sysfs_open_dirent->buffers list isn't being used for anything and this patch doesn't make any functional difference. It will be used to merge regular and bin file supports. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
375b611e60
commit
c75ec764cf
@ -25,15 +25,17 @@
|
|||||||
#include "sysfs.h"
|
#include "sysfs.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* There's one sysfs_buffer for each open file and one
|
* There's one sysfs_buffer for each open file and one sysfs_open_dirent
|
||||||
* sysfs_open_dirent for each sysfs_dirent with one or more open
|
* for each sysfs_dirent with one or more open files.
|
||||||
* files.
|
|
||||||
*
|
*
|
||||||
* filp->private_data points to sysfs_buffer and
|
* sysfs_dirent->s_attr.open points to sysfs_open_dirent. s_attr.open is
|
||||||
* sysfs_dirent->s_attr.open points to sysfs_open_dirent. s_attr.open
|
* protected by sysfs_open_dirent_lock.
|
||||||
* is protected by sysfs_open_dirent_lock.
|
*
|
||||||
|
* filp->private_data points to sysfs_buffer which is chained at
|
||||||
|
* sysfs_open_dirent->buffers, which is protected by sysfs_open_file_mutex.
|
||||||
*/
|
*/
|
||||||
static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
|
static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
|
||||||
|
static DEFINE_MUTEX(sysfs_open_file_mutex);
|
||||||
|
|
||||||
struct sysfs_open_dirent {
|
struct sysfs_open_dirent {
|
||||||
atomic_t refcnt;
|
atomic_t refcnt;
|
||||||
@ -272,6 +274,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
|
|||||||
struct sysfs_open_dirent *od, *new_od = NULL;
|
struct sysfs_open_dirent *od, *new_od = NULL;
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
|
mutex_lock(&sysfs_open_file_mutex);
|
||||||
spin_lock_irq(&sysfs_open_dirent_lock);
|
spin_lock_irq(&sysfs_open_dirent_lock);
|
||||||
|
|
||||||
if (!sd->s_attr.open && new_od) {
|
if (!sd->s_attr.open && new_od) {
|
||||||
@ -286,6 +289,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock_irq(&sysfs_open_dirent_lock);
|
spin_unlock_irq(&sysfs_open_dirent_lock);
|
||||||
|
mutex_unlock(&sysfs_open_file_mutex);
|
||||||
|
|
||||||
if (od) {
|
if (od) {
|
||||||
kfree(new_od);
|
kfree(new_od);
|
||||||
@ -321,6 +325,7 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd,
|
|||||||
struct sysfs_open_dirent *od = sd->s_attr.open;
|
struct sysfs_open_dirent *od = sd->s_attr.open;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
|
mutex_lock(&sysfs_open_file_mutex);
|
||||||
spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
|
spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
|
||||||
|
|
||||||
list_del(&buffer->list);
|
list_del(&buffer->list);
|
||||||
@ -330,6 +335,7 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd,
|
|||||||
od = NULL;
|
od = NULL;
|
||||||
|
|
||||||
spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags);
|
spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags);
|
||||||
|
mutex_unlock(&sysfs_open_file_mutex);
|
||||||
|
|
||||||
kfree(od);
|
kfree(od);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user