aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-06-13 15:27:23 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-07-11 19:09:08 -0400
commit5f9953237f684ea1778adb9d26162da00b282225 (patch)
tree962bbe5fe2483876caa74943875cbef432db6945
parent608e266a2d4e62c1b98c1c573064b6afe8c06a58 (diff)
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: Tejun Heo <htejun@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--fs/sysfs/dir.c19
-rw-r--r--fs/sysfs/inode.c16
-rw-r--r--fs/sysfs/symlink.c6
-rw-r--r--fs/sysfs/sysfs.h3
4 files changed, 21 insertions, 23 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 31b6cf30636d..1b5643407a95 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -15,8 +15,7 @@
15#include "sysfs.h" 15#include "sysfs.h"
16 16
17DECLARE_RWSEM(sysfs_rename_sem); 17DECLARE_RWSEM(sysfs_rename_sem);
18spinlock_t sysfs_lock = SPIN_LOCK_UNLOCKED; 18spinlock_t sysfs_assoc_lock = SPIN_LOCK_UNLOCKED;
19spinlock_t kobj_sysfs_assoc_lock = SPIN_LOCK_UNLOCKED;
20 19
21static spinlock_t sysfs_ino_lock = SPIN_LOCK_UNLOCKED; 20static spinlock_t sysfs_ino_lock = SPIN_LOCK_UNLOCKED;
22static DEFINE_IDA(sysfs_ino_ida); 21static DEFINE_IDA(sysfs_ino_ida);
@@ -236,10 +235,10 @@ static void sysfs_d_iput(struct dentry * dentry, struct inode * inode)
236 struct sysfs_dirent * sd = dentry->d_fsdata; 235 struct sysfs_dirent * sd = dentry->d_fsdata;
237 236
238 if (sd) { 237 if (sd) {
239 /* sd->s_dentry is protected with sysfs_lock. This 238 /* sd->s_dentry is protected with sysfs_assoc_lock.
240 * allows sysfs_drop_dentry() to dereference it. 239 * This allows sysfs_drop_dentry() to dereference it.
241 */ 240 */
242 spin_lock(&sysfs_lock); 241 spin_lock(&sysfs_assoc_lock);
243 242
244 /* The dentry might have been deleted or another 243 /* The dentry might have been deleted or another
245 * lookup could have happened updating sd->s_dentry to 244 * 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 */ 247 */
249 if (sd->s_dentry == dentry) 248 if (sd->s_dentry == dentry)
250 sd->s_dentry = NULL; 249 sd->s_dentry = NULL;
251 spin_unlock(&sysfs_lock); 250 spin_unlock(&sysfs_assoc_lock);
252 sysfs_put(sd); 251 sysfs_put(sd);
253 } 252 }
254 iput(inode); 253 iput(inode);
@@ -298,9 +297,9 @@ static void sysfs_attach_dentry(struct sysfs_dirent *sd, struct dentry *dentry)
298 dentry->d_fsdata = sysfs_get(sd); 297 dentry->d_fsdata = sysfs_get(sd);
299 298
300 /* protect sd->s_dentry against sysfs_d_iput */ 299 /* protect sd->s_dentry against sysfs_d_iput */
301 spin_lock(&sysfs_lock); 300 spin_lock(&sysfs_assoc_lock);
302 sd->s_dentry = dentry; 301 sd->s_dentry = dentry;
303 spin_unlock(&sysfs_lock); 302 spin_unlock(&sysfs_assoc_lock);
304 303
305 d_rehash(dentry); 304 d_rehash(dentry);
306} 305}
@@ -603,9 +602,9 @@ void sysfs_remove_dir(struct kobject * kobj)
603{ 602{
604 struct sysfs_dirent *sd = kobj->sd; 603 struct sysfs_dirent *sd = kobj->sd;
605 604
606 spin_lock(&kobj_sysfs_assoc_lock); 605 spin_lock(&sysfs_assoc_lock);
607 kobj->sd = NULL; 606 kobj->sd = NULL;
608 spin_unlock(&kobj_sysfs_assoc_lock); 607 spin_unlock(&sysfs_assoc_lock);
609 608
610 __sysfs_remove_dir(sd); 609 __sysfs_remove_dir(sd);
611} 610}
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index 1be853706e99..e4c23939fb36 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -211,11 +211,11 @@ void sysfs_instantiate(struct dentry *dentry, struct inode *inode)
211 * parent on entry to this function such that it can't be looked 211 * parent on entry to this function such that it can't be looked
212 * up anymore. 212 * up anymore.
213 * 213 *
214 * @sd->s_dentry which is protected with sysfs_lock points to the 214 * @sd->s_dentry which is protected with sysfs_assoc_lock points
215 * currently associated dentry but we're not holding a reference 215 * to the currently associated dentry but we're not holding a
216 * to it and racing with dput(). Grab dcache_lock and verify 216 * reference to it and racing with dput(). Grab dcache_lock and
217 * dentry before dropping it. If @sd->s_dentry is NULL or dput() 217 * verify dentry before dropping it. If @sd->s_dentry is NULL or
218 * beats us, no need to bother. 218 * dput() beats us, no need to bother.
219 */ 219 */
220void sysfs_drop_dentry(struct sysfs_dirent *sd) 220void sysfs_drop_dentry(struct sysfs_dirent *sd)
221{ 221{
@@ -224,9 +224,9 @@ void sysfs_drop_dentry(struct sysfs_dirent *sd)
224 struct inode *inode; 224 struct inode *inode;
225 225
226 /* We're not holding a reference to ->s_dentry dentry but the 226 /* We're not holding a reference to ->s_dentry dentry but the
227 * field will stay valid as long as sysfs_lock is held. 227 * field will stay valid as long as sysfs_assoc_lock is held.
228 */ 228 */
229 spin_lock(&sysfs_lock); 229 spin_lock(&sysfs_assoc_lock);
230 spin_lock(&dcache_lock); 230 spin_lock(&dcache_lock);
231 231
232 /* drop dentry if it's there and dput() didn't kill it yet */ 232 /* 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 } 238 }
239 239
240 spin_unlock(&dcache_lock); 240 spin_unlock(&dcache_lock);
241 spin_unlock(&sysfs_lock); 241 spin_unlock(&sysfs_assoc_lock);
242 242
243 dput(dentry); 243 dput(dentry);
244 /* XXX: unpin if directory, this will go away soon */ 244 /* XXX: unpin if directory, this will go away soon */
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 43cc5222f136..cbd95a4109de 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -82,12 +82,12 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char
82 return -EFAULT; 82 return -EFAULT;
83 83
84 /* target->sd can go away beneath us but is protected with 84 /* target->sd can go away beneath us but is protected with
85 * kobj_sysfs_assoc_lock. Fetch target_sd from it. 85 * sysfs_assoc_lock. Fetch target_sd from it.
86 */ 86 */
87 spin_lock(&kobj_sysfs_assoc_lock); 87 spin_lock(&sysfs_assoc_lock);
88 if (target->sd) 88 if (target->sd)
89 target_sd = sysfs_get(target->sd); 89 target_sd = sysfs_get(target->sd);
90 spin_unlock(&kobj_sysfs_assoc_lock); 90 spin_unlock(&sysfs_assoc_lock);
91 91
92 if (!target_sd) 92 if (!target_sd)
93 return -ENOENT; 93 return -ENOENT;
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index 27a5f4b4e3b0..457267721f4e 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -81,8 +81,7 @@ extern void sysfs_remove_subdir(struct sysfs_dirent *sd);
81extern void sysfs_drop_dentry(struct sysfs_dirent *sd); 81extern void sysfs_drop_dentry(struct sysfs_dirent *sd);
82extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); 82extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
83 83
84extern spinlock_t sysfs_lock; 84extern spinlock_t sysfs_assoc_lock;
85extern spinlock_t kobj_sysfs_assoc_lock;
86extern struct rw_semaphore sysfs_rename_sem; 85extern struct rw_semaphore sysfs_rename_sem;
87extern struct super_block * sysfs_sb; 86extern struct super_block * sysfs_sb;
88extern const struct file_operations sysfs_dir_operations; 87extern const struct file_operations sysfs_dir_operations;