提交 5f995323 编写于 作者: T Tejun Heo 提交者: Greg Kroah-Hartman

sysfs: consolidate sysfs spinlocks

Replace sysfs_lock and kobj_sysfs_assoc_lock with sysfs_assoc_lock.
sysfs_lock was originally to be used to protect sysfs_dirent tree but
mutex seems better choice, so there is no reason to keep sysfs_lock
separate.  Merge the two spinlocks into one.
Signed-off-by: NTejun Heo <htejun@gmail.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 608e266a
...@@ -15,8 +15,7 @@ ...@@ -15,8 +15,7 @@
#include "sysfs.h" #include "sysfs.h"
DECLARE_RWSEM(sysfs_rename_sem); DECLARE_RWSEM(sysfs_rename_sem);
spinlock_t sysfs_lock = SPIN_LOCK_UNLOCKED; spinlock_t sysfs_assoc_lock = SPIN_LOCK_UNLOCKED;
spinlock_t kobj_sysfs_assoc_lock = SPIN_LOCK_UNLOCKED;
static spinlock_t sysfs_ino_lock = SPIN_LOCK_UNLOCKED; static spinlock_t sysfs_ino_lock = SPIN_LOCK_UNLOCKED;
static DEFINE_IDA(sysfs_ino_ida); static DEFINE_IDA(sysfs_ino_ida);
...@@ -236,10 +235,10 @@ static void sysfs_d_iput(struct dentry * dentry, struct inode * inode) ...@@ -236,10 +235,10 @@ static void sysfs_d_iput(struct dentry * dentry, struct inode * inode)
struct sysfs_dirent * sd = dentry->d_fsdata; struct sysfs_dirent * sd = dentry->d_fsdata;
if (sd) { if (sd) {
/* sd->s_dentry is protected with sysfs_lock. This /* sd->s_dentry is protected with sysfs_assoc_lock.
* allows sysfs_drop_dentry() to dereference it. * This allows sysfs_drop_dentry() to dereference it.
*/ */
spin_lock(&sysfs_lock); spin_lock(&sysfs_assoc_lock);
/* The dentry might have been deleted or another /* The dentry might have been deleted or another
* lookup could have happened updating sd->s_dentry to * lookup could have happened updating sd->s_dentry to
...@@ -248,7 +247,7 @@ static void sysfs_d_iput(struct dentry * dentry, struct inode * inode) ...@@ -248,7 +247,7 @@ static void sysfs_d_iput(struct dentry * dentry, struct inode * inode)
*/ */
if (sd->s_dentry == dentry) if (sd->s_dentry == dentry)
sd->s_dentry = NULL; sd->s_dentry = NULL;
spin_unlock(&sysfs_lock); spin_unlock(&sysfs_assoc_lock);
sysfs_put(sd); sysfs_put(sd);
} }
iput(inode); iput(inode);
...@@ -298,9 +297,9 @@ static void sysfs_attach_dentry(struct sysfs_dirent *sd, struct dentry *dentry) ...@@ -298,9 +297,9 @@ static void sysfs_attach_dentry(struct sysfs_dirent *sd, struct dentry *dentry)
dentry->d_fsdata = sysfs_get(sd); dentry->d_fsdata = sysfs_get(sd);
/* protect sd->s_dentry against sysfs_d_iput */ /* protect sd->s_dentry against sysfs_d_iput */
spin_lock(&sysfs_lock); spin_lock(&sysfs_assoc_lock);
sd->s_dentry = dentry; sd->s_dentry = dentry;
spin_unlock(&sysfs_lock); spin_unlock(&sysfs_assoc_lock);
d_rehash(dentry); d_rehash(dentry);
} }
...@@ -603,9 +602,9 @@ void sysfs_remove_dir(struct kobject * kobj) ...@@ -603,9 +602,9 @@ void sysfs_remove_dir(struct kobject * kobj)
{ {
struct sysfs_dirent *sd = kobj->sd; struct sysfs_dirent *sd = kobj->sd;
spin_lock(&kobj_sysfs_assoc_lock); spin_lock(&sysfs_assoc_lock);
kobj->sd = NULL; kobj->sd = NULL;
spin_unlock(&kobj_sysfs_assoc_lock); spin_unlock(&sysfs_assoc_lock);
__sysfs_remove_dir(sd); __sysfs_remove_dir(sd);
} }
......
...@@ -211,11 +211,11 @@ void sysfs_instantiate(struct dentry *dentry, struct inode *inode) ...@@ -211,11 +211,11 @@ void sysfs_instantiate(struct dentry *dentry, struct inode *inode)
* parent on entry to this function such that it can't be looked * parent on entry to this function such that it can't be looked
* up anymore. * up anymore.
* *
* @sd->s_dentry which is protected with sysfs_lock points to the * @sd->s_dentry which is protected with sysfs_assoc_lock points
* currently associated dentry but we're not holding a reference * to the currently associated dentry but we're not holding a
* to it and racing with dput(). Grab dcache_lock and verify * reference to it and racing with dput(). Grab dcache_lock and
* dentry before dropping it. If @sd->s_dentry is NULL or dput() * verify dentry before dropping it. If @sd->s_dentry is NULL or
* beats us, no need to bother. * dput() beats us, no need to bother.
*/ */
void sysfs_drop_dentry(struct sysfs_dirent *sd) void sysfs_drop_dentry(struct sysfs_dirent *sd)
{ {
...@@ -224,9 +224,9 @@ void sysfs_drop_dentry(struct sysfs_dirent *sd) ...@@ -224,9 +224,9 @@ void sysfs_drop_dentry(struct sysfs_dirent *sd)
struct inode *inode; 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_assoc_lock is held.
*/ */
spin_lock(&sysfs_lock); spin_lock(&sysfs_assoc_lock);
spin_lock(&dcache_lock); spin_lock(&dcache_lock);
/* drop dentry if it's there and dput() didn't kill it yet */ /* drop dentry if it's there and dput() didn't kill it yet */
...@@ -238,7 +238,7 @@ void sysfs_drop_dentry(struct sysfs_dirent *sd) ...@@ -238,7 +238,7 @@ void sysfs_drop_dentry(struct sysfs_dirent *sd)
} }
spin_unlock(&dcache_lock); spin_unlock(&dcache_lock);
spin_unlock(&sysfs_lock); spin_unlock(&sysfs_assoc_lock);
dput(dentry); dput(dentry);
/* XXX: unpin if directory, this will go away soon */ /* XXX: unpin if directory, this will go away soon */
......
...@@ -82,12 +82,12 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char ...@@ -82,12 +82,12 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char
return -EFAULT; return -EFAULT;
/* target->sd can go away beneath us but is protected with /* target->sd can go away beneath us but is protected with
* kobj_sysfs_assoc_lock. Fetch target_sd from it. * sysfs_assoc_lock. Fetch target_sd from it.
*/ */
spin_lock(&kobj_sysfs_assoc_lock); spin_lock(&sysfs_assoc_lock);
if (target->sd) if (target->sd)
target_sd = sysfs_get(target->sd); target_sd = sysfs_get(target->sd);
spin_unlock(&kobj_sysfs_assoc_lock); spin_unlock(&sysfs_assoc_lock);
if (!target_sd) if (!target_sd)
return -ENOENT; return -ENOENT;
......
...@@ -81,8 +81,7 @@ extern void sysfs_remove_subdir(struct sysfs_dirent *sd); ...@@ -81,8 +81,7 @@ extern void sysfs_remove_subdir(struct sysfs_dirent *sd);
extern void sysfs_drop_dentry(struct sysfs_dirent *sd); extern void sysfs_drop_dentry(struct sysfs_dirent *sd);
extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
extern spinlock_t sysfs_lock; extern spinlock_t sysfs_assoc_lock;
extern spinlock_t kobj_sysfs_assoc_lock;
extern struct rw_semaphore sysfs_rename_sem; extern struct rw_semaphore sysfs_rename_sem;
extern struct super_block * sysfs_sb; extern struct super_block * sysfs_sb;
extern const struct file_operations sysfs_dir_operations; extern const struct file_operations sysfs_dir_operations;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册