]> err.no Git - linux-2.6/blobdiff - fs/sysfs/inode.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-rc-fixes-2.6
[linux-2.6] / fs / sysfs / inode.c
index dd1344b007f59baf3b0d5ba05fadecd83f8d0604..5266eec15f6e35766c84939f1c7663690d6c3930 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/backing-dev.h>
 #include <linux/capability.h>
 #include <linux/errno.h>
+#include <linux/sched.h>
 #include <asm/semaphore.h>
 #include "sysfs.h"
 
@@ -140,6 +141,7 @@ struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent * sd)
                inode->i_mapping->a_ops = &sysfs_aops;
                inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
                inode->i_op = &sysfs_inode_operations;
+               inode->i_ino = sd->s_ino;
                lockdep_set_class(&inode->i_mutex, &sysfs_inode_imutex_key);
 
                if (sd->s_iattr) {
@@ -222,11 +224,12 @@ const unsigned char * sysfs_get_name(struct sysfs_dirent *sd)
 
 static inline void orphan_all_buffers(struct inode *node)
 {
-       struct sysfs_buffer_collection *set = node->i_private;
+       struct sysfs_buffer_collection *set;
        struct sysfs_buffer *buf;
 
        mutex_lock_nested(&node->i_mutex, I_MUTEX_CHILD);
-       if (node->i_private) {
+       set = node->i_private;
+       if (set) {
                list_for_each_entry(buf, &set->associates, associates) {
                        down(&buf->sem);
                        buf->orphaned = 1;
@@ -243,13 +246,27 @@ static inline void orphan_all_buffers(struct inode *node)
  */
 void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent)
 {
-       struct dentry * dentry = sd->s_dentry;
+       struct dentry *dentry = NULL;
        struct inode *inode;
 
+       /* We're not holding a reference to ->s_dentry dentry but the
+        * field will stay valid as long as sysfs_lock is held.
+        */
+       spin_lock(&sysfs_lock);
+       spin_lock(&dcache_lock);
+
+       /* dget dentry if it's still alive */
+       if (sd->s_dentry && sd->s_dentry->d_inode)
+               dentry = dget_locked(sd->s_dentry);
+
+       spin_unlock(&dcache_lock);
+       spin_unlock(&sysfs_lock);
+
+       /* drop dentry */
        if (dentry) {
                spin_lock(&dcache_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);
@@ -265,6 +282,8 @@ void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent)
                        spin_unlock(&dentry->d_lock);
                        spin_unlock(&dcache_lock);
                }
+
+               dput(dentry);
        }
 }