Merge master.kernel.org:/pub/scm/linux/kernel/git/lethal/sh-2.6
[powerpc.git] / fs / sysfs / inode.c
index 9889e54..ccb7d72 100644 (file)
@@ -12,6 +12,8 @@
 #include <linux/namei.h>
 #include <linux/backing-dev.h>
 #include <linux/capability.h>
+#include <linux/errno.h>
+#include <asm/semaphore.h>
 #include "sysfs.h"
 
 extern struct super_block * sysfs_sb;
@@ -27,10 +29,20 @@ static struct backing_dev_info sysfs_backing_dev_info = {
        .capabilities   = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK,
 };
 
-static struct inode_operations sysfs_inode_operations ={
+static const struct inode_operations sysfs_inode_operations ={
        .setattr        = sysfs_setattr,
 };
 
+void sysfs_delete_inode(struct inode *inode)
+{
+       /* Free the shadowed directory inode operations */
+       if (sysfs_is_shadowed_inode(inode)) {
+               kfree(inode->i_op);
+               inode->i_op = NULL;
+       }
+       return generic_delete_inode(inode);
+}
+
 int sysfs_setattr(struct dentry * dentry, struct iattr * iattr)
 {
        struct inode * inode = dentry->d_inode;
@@ -124,7 +136,6 @@ struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent * sd)
 {
        struct inode * inode = new_inode(sysfs_sb);
        if (inode) {
-               inode->i_blksize = PAGE_CACHE_SIZE;
                inode->i_blocks = 0;
                inode->i_mapping->a_ops = &sysfs_aops;
                inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
@@ -209,6 +220,19 @@ const unsigned char * sysfs_get_name(struct sysfs_dirent *sd)
        return NULL;
 }
 
+static inline void orphan_all_buffers(struct inode *node)
+{
+       struct sysfs_buffer_collection *set = node->i_private;
+       struct sysfs_buffer *buf;
+
+       mutex_lock_nested(&node->i_mutex, I_MUTEX_CHILD);
+       if (node->i_private) {
+               list_for_each_entry(buf, &set->associates, associates)
+                       buf->orphaned = 1;
+       }
+       mutex_unlock(&node->i_mutex);
+}
+
 
 /*
  * Unhashes the dentry corresponding to given sysfs_dirent
@@ -217,16 +241,23 @@ const unsigned char * sysfs_get_name(struct sysfs_dirent *sd)
 void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent)
 {
        struct dentry * dentry = sd->s_dentry;
+       struct inode *inode;
 
        if (dentry) {
                spin_lock(&dcache_lock);
                spin_lock(&dentry->d_lock);
                if (!(d_unhashed(dentry) && dentry->d_inode)) {
+                       inode = dentry->d_inode;
+                       spin_lock(&inode->i_lock);
+                       __iget(inode);
+                       spin_unlock(&inode->i_lock);
                        dget_locked(dentry);
                        __d_drop(dentry);
                        spin_unlock(&dentry->d_lock);
                        spin_unlock(&dcache_lock);
                        simple_unlink(parent->d_inode, dentry);
+                       orphan_all_buffers(inode);
+                       iput(inode);
                } else {
                        spin_unlock(&dentry->d_lock);
                        spin_unlock(&dcache_lock);
@@ -234,20 +265,21 @@ void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent)
        }
 }
 
-void sysfs_hash_and_remove(struct dentry * dir, const char * name)
+int sysfs_hash_and_remove(struct dentry * dir, const char * name)
 {
        struct sysfs_dirent * sd;
        struct sysfs_dirent * parent_sd;
+       int found = 0;
 
        if (!dir)
-               return;
+               return -ENOENT;
 
        if (dir->d_inode == NULL)
                /* no inode means this hasn't been made visible yet */
-               return;
+               return -ENOENT;
 
        parent_sd = dir->d_fsdata;
-       mutex_lock(&dir->d_inode->i_mutex);
+       mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
        list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
                if (!sd->s_element)
                        continue;
@@ -255,8 +287,11 @@ void sysfs_hash_and_remove(struct dentry * dir, const char * name)
                        list_del_init(&sd->s_sibling);
                        sysfs_drop_dentry(sd, dir);
                        sysfs_put(sd);
+                       found = 1;
                        break;
                }
        }
        mutex_unlock(&dir->d_inode->i_mutex);
+
+       return found ? 0 : -ENOENT;
 }