]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/proc/generic.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6-omap-h63xx.git] / fs / proc / generic.c
index 8a40e15f5ecb90333f7eca84ede39c40e7adb945..8d49838e5554bd96e5b9106aafd6f03383cba890 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/namei.h>
 #include <linux/bitops.h>
 #include <linux/spinlock.h>
+#include <linux/completion.h>
 #include <asm/uaccess.h>
 
 #include "internal.h"
@@ -73,7 +74,7 @@ proc_file_read(struct file *file, char __user *buf, size_t nbytes,
                nbytes = MAX_NON_LFS - pos;
 
        dp = PDE(inode);
-       if (!(page = (char*) __get_free_page(GFP_KERNEL)))
+       if (!(page = (char*) __get_free_page(GFP_TEMPORARY)))
                return -ENOMEM;
 
        while ((nbytes > 0) && !eof) {
@@ -373,9 +374,16 @@ static int proc_delete_dentry(struct dentry * dentry)
        return 1;
 }
 
+static int proc_revalidate_dentry(struct dentry *dentry, struct nameidata *nd)
+{
+       d_drop(dentry);
+       return 0;
+}
+
 static struct dentry_operations proc_dentry_operations =
 {
        .d_delete       = proc_delete_dentry,
+       .d_revalidate   = proc_revalidate_dentry,
 };
 
 /*
@@ -396,8 +404,11 @@ struct dentry *proc_lookup(struct inode * dir, struct dentry *dentry, struct nam
                        if (de->namelen != dentry->d_name.len)
                                continue;
                        if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
-                               unsigned int ino = de->low_ino;
+                               unsigned int ino;
 
+                               if (de->shadow_proc)
+                                       de = de->shadow_proc(current, de);
+                               ino = de->low_ino;
                                de_get(de);
                                spin_unlock(&proc_subdir_lock);
                                error = -EINVAL;
@@ -529,12 +540,6 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
                return -EAGAIN;
        dp->low_ino = i;
 
-       spin_lock(&proc_subdir_lock);
-       dp->next = dir->subdir;
-       dp->parent = dir;
-       dir->subdir = dp;
-       spin_unlock(&proc_subdir_lock);
-
        if (S_ISDIR(dp->mode)) {
                if (dp->proc_iops == NULL) {
                        dp->proc_fops = &proc_dir_operations;
@@ -550,37 +555,14 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
                if (dp->proc_iops == NULL)
                        dp->proc_iops = &proc_file_inode_operations;
        }
-       return 0;
-}
 
-/*
- * Kill an inode that got unregistered..
- */
-static void proc_kill_inodes(struct proc_dir_entry *de)
-{
-       struct list_head *p;
-       struct super_block *sb = proc_mnt->mnt_sb;
+       spin_lock(&proc_subdir_lock);
+       dp->next = dir->subdir;
+       dp->parent = dir;
+       dir->subdir = dp;
+       spin_unlock(&proc_subdir_lock);
 
-       /*
-        * Actually it's a partial revoke().
-        */
-       file_list_lock();
-       list_for_each(p, &sb->s_files) {
-               struct file * filp = list_entry(p, struct file, f_u.fu_list);
-               struct dentry * dentry = filp->f_path.dentry;
-               struct inode * inode;
-               const struct file_operations *fops;
-
-               if (dentry->d_op != &proc_dentry_operations)
-                       continue;
-               inode = dentry->d_inode;
-               if (PDE(inode) != de)
-                       continue;
-               fops = filp->f_op;
-               filp->f_op = NULL;
-               fops_put(fops);
-       }
-       file_list_unlock();
+       return 0;
 }
 
 static struct proc_dir_entry *proc_create(struct proc_dir_entry **parent,
@@ -613,6 +595,10 @@ static struct proc_dir_entry *proc_create(struct proc_dir_entry **parent,
        ent->namelen = len;
        ent->mode = mode;
        ent->nlink = nlink;
+       atomic_set(&ent->count, 1);
+       ent->pde_users = 0;
+       spin_lock_init(&ent->pde_unload_lock);
+       ent->pde_unload_completion = NULL;
  out:
        return ent;
 }
@@ -649,9 +635,6 @@ struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode,
 
        ent = proc_create(&parent, name, S_IFDIR | mode, 2);
        if (ent) {
-               ent->proc_fops = &proc_dir_operations;
-               ent->proc_iops = &proc_dir_inode_operations;
-
                if (proc_register(parent, ent) < 0) {
                        kfree(ent);
                        ent = NULL;
@@ -686,10 +669,6 @@ struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
 
        ent = proc_create(&parent,name,mode,nlink);
        if (ent) {
-               if (S_ISDIR(mode)) {
-                       ent->proc_fops = &proc_dir_operations;
-                       ent->proc_iops = &proc_dir_inode_operations;
-               }
                if (proc_register(parent, ent) < 0) {
                        kfree(ent);
                        ent = NULL;
@@ -714,7 +693,6 @@ void free_proc_entry(struct proc_dir_entry *de)
 
 /*
  * Remove a /proc entry and free it if it's not currently in use.
- * If it is in use, we set the 'deleted' flag.
  */
 void remove_proc_entry(const char *name, struct proc_dir_entry *parent)
 {
@@ -734,18 +712,37 @@ void remove_proc_entry(const char *name, struct proc_dir_entry *parent)
                de = *p;
                *p = de->next;
                de->next = NULL;
+
+               spin_lock(&de->pde_unload_lock);
+               /*
+                * Stop accepting new callers into module. If you're
+                * dynamically allocating ->proc_fops, save a pointer somewhere.
+                */
+               de->proc_fops = NULL;
+               /* Wait until all existing callers into module are done. */
+               if (de->pde_users > 0) {
+                       DECLARE_COMPLETION_ONSTACK(c);
+
+                       if (!de->pde_unload_completion)
+                               de->pde_unload_completion = &c;
+
+                       spin_unlock(&de->pde_unload_lock);
+                       spin_unlock(&proc_subdir_lock);
+
+                       wait_for_completion(de->pde_unload_completion);
+
+                       spin_lock(&proc_subdir_lock);
+                       goto continue_removing;
+               }
+               spin_unlock(&de->pde_unload_lock);
+
+continue_removing:
                if (S_ISDIR(de->mode))
                        parent->nlink--;
-               proc_kill_inodes(de);
                de->nlink = 0;
                WARN_ON(de->subdir);
-               if (!atomic_read(&de->count))
+               if (atomic_dec_and_test(&de->count))
                        free_proc_entry(de);
-               else {
-                       de->deleted = 1;
-                       printk("remove_proc_entry: %s/%s busy, count=%d\n",
-                               parent->name, de->name, atomic_read(&de->count));
-               }
                break;
        }
        spin_unlock(&proc_subdir_lock);