drm: remove drm_init.c it is no longer needed
[pandora-kernel.git] / fs / file_table.c
index 43e9e17..c3a5e2f 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/fs.h>
 #include <linux/security.h>
 #include <linux/eventpoll.h>
+#include <linux/rcupdate.h>
 #include <linux/mount.h>
 #include <linux/cdev.h>
 #include <linux/fsnotify.h>
@@ -34,7 +35,7 @@ static DEFINE_SPINLOCK(filp_count_lock);
  * context and must be fully threaded - use a local spinlock
  * to protect files_stat.nr_files
  */
-void filp_ctor(void * objp, struct kmem_cache_s *cachep, unsigned long cflags)
+void filp_ctor(void *objp, struct kmem_cache *cachep, unsigned long cflags)
 {
        if ((cflags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
            SLAB_CTOR_CONSTRUCTOR) {
@@ -45,7 +46,7 @@ void filp_ctor(void * objp, struct kmem_cache_s *cachep, unsigned long cflags)
        }
 }
 
-void filp_dtor(void * objp, struct kmem_cache_s *cachep, unsigned long dflags)
+void filp_dtor(void *objp, struct kmem_cache *cachep, unsigned long dflags)
 {
        unsigned long flags;
        spin_lock_irqsave(&filp_count_lock, flags);
@@ -53,11 +54,17 @@ void filp_dtor(void * objp, struct kmem_cache_s *cachep, unsigned long dflags)
        spin_unlock_irqrestore(&filp_count_lock, flags);
 }
 
-static inline void file_free(struct file *f)
+static inline void file_free_rcu(struct rcu_head *head)
 {
+       struct file *f =  container_of(head, struct file, f_u.fu_rcuhead);
        kmem_cache_free(filp_cachep, f);
 }
 
+static inline void file_free(struct file *f)
+{
+       call_rcu(&f->f_u.fu_rcuhead, file_free_rcu);
+}
+
 /* Find an unused file structure and return a pointer to it.
  * Returns NULL, if there are no more free file structures or
  * we run out of memory.
@@ -88,7 +95,7 @@ struct file *get_empty_filp(void)
        f->f_gid = current->fsgid;
        rwlock_init(&f->f_owner.lock);
        /* f->f_version: 0 */
-       INIT_LIST_HEAD(&f->f_list);
+       INIT_LIST_HEAD(&f->f_u.fu_list);
        return f;
 
 over:
@@ -110,7 +117,7 @@ EXPORT_SYMBOL(get_empty_filp);
 
 void fastcall fput(struct file *file)
 {
-       if (atomic_dec_and_test(&file->f_count))
+       if (rcuref_dec_and_test(&file->f_count))
                __fput(file);
 }
 
@@ -156,11 +163,17 @@ struct file fastcall *fget(unsigned int fd)
        struct file *file;
        struct files_struct *files = current->files;
 
-       spin_lock(&files->file_lock);
+       rcu_read_lock();
        file = fcheck_files(files, fd);
-       if (file)
-               get_file(file);
-       spin_unlock(&files->file_lock);
+       if (file) {
+               if (!rcuref_inc_lf(&file->f_count)) {
+                       /* File object ref couldn't be taken */
+                       rcu_read_unlock();
+                       return NULL;
+               }
+       }
+       rcu_read_unlock();
+
        return file;
 }
 
@@ -182,21 +195,25 @@ struct file fastcall *fget_light(unsigned int fd, int *fput_needed)
        if (likely((atomic_read(&files->count) == 1))) {
                file = fcheck_files(files, fd);
        } else {
-               spin_lock(&files->file_lock);
+               rcu_read_lock();
                file = fcheck_files(files, fd);
                if (file) {
-                       get_file(file);
-                       *fput_needed = 1;
+                       if (rcuref_inc_lf(&file->f_count))
+                               *fput_needed = 1;
+                       else
+                               /* Didn't get the reference, someone's freed */
+                               file = NULL;
                }
-               spin_unlock(&files->file_lock);
+               rcu_read_unlock();
        }
+
        return file;
 }
 
 
 void put_filp(struct file *file)
 {
-       if (atomic_dec_and_test(&file->f_count)) {
+       if (rcuref_dec_and_test(&file->f_count)) {
                security_file_free(file);
                file_kill(file);
                file_free(file);
@@ -208,15 +225,15 @@ void file_move(struct file *file, struct list_head *list)
        if (!list)
                return;
        file_list_lock();
-       list_move(&file->f_list, list);
+       list_move(&file->f_u.fu_list, list);
        file_list_unlock();
 }
 
 void file_kill(struct file *file)
 {
-       if (!list_empty(&file->f_list)) {
+       if (!list_empty(&file->f_u.fu_list)) {
                file_list_lock();
-               list_del_init(&file->f_list);
+               list_del_init(&file->f_u.fu_list);
                file_list_unlock();
        }
 }
@@ -228,7 +245,7 @@ int fs_may_remount_ro(struct super_block *sb)
        /* Check that no files are currently opened for writing. */
        file_list_lock();
        list_for_each(p, &sb->s_files) {
-               struct file *file = list_entry(p, struct file, f_list);
+               struct file *file = list_entry(p, struct file, f_u.fu_list);
                struct inode *inode = file->f_dentry->d_inode;
 
                /* File with pending delete? */
@@ -257,4 +274,5 @@ void __init files_init(unsigned long mempages)
        files_stat.max_files = n; 
        if (files_stat.max_files < NR_FILE)
                files_stat.max_files = NR_FILE;
+       files_defer_init();
 }