lockdep: annotate dir vs file i_mutex
[safe/jmp/linux-2.6] / fs / inode.c
index 410f235..f97de0a 100644 (file)
@@ -142,10 +142,19 @@ static struct inode *alloc_inode(struct super_block *sb)
                        return NULL;
                }
 
+               spin_lock_init(&inode->i_lock);
+               lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key);
+
+               mutex_init(&inode->i_mutex);
+               lockdep_set_class(&inode->i_mutex, &sb->s_type->i_mutex_key);
+
+               init_rwsem(&inode->i_alloc_sem);
+               lockdep_set_class(&inode->i_alloc_sem, &sb->s_type->i_alloc_sem_key);
+
                mapping->a_ops = &empty_aops;
                mapping->host = inode;
                mapping->flags = 0;
-               mapping_set_gfp_mask(mapping, GFP_HIGHUSER);
+               mapping_set_gfp_mask(mapping, GFP_HIGHUSER_PAGECACHE);
                mapping->assoc_mapping = NULL;
                mapping->backing_dev_info = &default_backing_dev_info;
 
@@ -190,8 +199,6 @@ void inode_init_once(struct inode *inode)
        INIT_HLIST_NODE(&inode->i_hash);
        INIT_LIST_HEAD(&inode->i_dentry);
        INIT_LIST_HEAD(&inode->i_devices);
-       mutex_init(&inode->i_mutex);
-       init_rwsem(&inode->i_alloc_sem);
        INIT_RADIX_TREE(&inode->i_data.page_tree, GFP_ATOMIC);
        rwlock_init(&inode->i_data.tree_lock);
        spin_lock_init(&inode->i_data.i_mmap_lock);
@@ -199,7 +206,6 @@ void inode_init_once(struct inode *inode)
        spin_lock_init(&inode->i_data.private_lock);
        INIT_RAW_PRIO_TREE_ROOT(&inode->i_data.i_mmap);
        INIT_LIST_HEAD(&inode->i_data.i_mmap_nonlinear);
-       spin_lock_init(&inode->i_lock);
        i_size_ordered_init(inode);
 #ifdef CONFIG_INOTIFY
        INIT_LIST_HEAD(&inode->inotify_watches);
@@ -213,8 +219,7 @@ static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flag
 {
        struct inode * inode = (struct inode *) foo;
 
-       if (flags & SLAB_CTOR_CONSTRUCTOR)
-               inode_init_once(inode);
+       inode_init_once(inode);
 }
 
 /*
@@ -463,6 +468,11 @@ static int shrink_icache_memory(int nr, gfp_t gfp_mask)
        return (inodes_stat.nr_unused / 100) * sysctl_vfs_cache_pressure;
 }
 
+static struct shrinker icache_shrinker = {
+       .shrink = shrink_icache_memory,
+       .seeks = DEFAULT_SEEKS,
+};
+
 static void __wait_on_freeing_inode(struct inode *inode);
 /*
  * Called with the inode lock held.
@@ -520,11 +530,22 @@ repeat:
  *     new_inode       - obtain an inode
  *     @sb: superblock
  *
- *     Allocates a new inode for given superblock.
+ *     Allocates a new inode for given superblock. The default gfp_mask
+ *     for allocations related to inode->i_mapping is GFP_HIGHUSER_PAGECACHE.
+ *     If HIGHMEM pages are unsuitable or it is known that pages allocated
+ *     for the page cache are not reclaimable or migratable,
+ *     mapping_set_gfp_mask() must be called with suitable flags on the
+ *     newly created inode's mapping
+ *
  */
 struct inode *new_inode(struct super_block *sb)
 {
-       static unsigned long last_ino;
+       /*
+        * On a 32bit, non LFS stat() call, glibc will generate an EOVERFLOW
+        * error if st_ino won't fit in target struct field. Use 32bit counter
+        * here to attempt to avoid that.
+        */
+       static unsigned int last_ino;
        struct inode * inode;
 
        spin_lock_prefetch(&inode_lock);
@@ -546,6 +567,18 @@ EXPORT_SYMBOL(new_inode);
 
 void unlock_new_inode(struct inode *inode)
 {
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+       struct file_system_type *type = inode->i_sb->s_type;
+       /*
+        * ensure nobody is actually holding i_mutex
+        */
+       mutex_destroy(&inode->i_mutex);
+       mutex_init(&inode->i_mutex);
+       if (inode->i_mode & S_IFDIR)
+               lockdep_set_class(&inode->i_mutex, &type->i_mutex_dir_key);
+       else
+               lockdep_set_class(&inode->i_mutex, &type->i_mutex_key);
+#endif
        /*
         * This is special!  We do not need the spinlock
         * when clearing I_LOCK, because we're guaranteed
@@ -683,7 +716,12 @@ static unsigned long hash(struct super_block *sb, unsigned long hashval)
  */
 ino_t iunique(struct super_block *sb, ino_t max_reserved)
 {
-       static ino_t counter;
+       /*
+        * On a 32bit, non LFS stat() call, glibc will generate an EOVERFLOW
+        * error if st_ino won't fit in target struct field. Use 32bit counter
+        * here to attempt to avoid that.
+        */
+       static unsigned int counter;
        struct inode *inode;
        struct hlist_head *head;
        ino_t res;
@@ -1368,9 +1406,8 @@ void __init inode_init(unsigned long mempages)
                                         0,
                                         (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
                                         SLAB_MEM_SPREAD),
-                                        init_once,
-                                        NULL);
-       set_shrinker(DEFAULT_SEEKS, shrink_icache_memory);
+                                        init_once);
+       register_shrinker(&icache_shrinker);
 
        /* Hash may have been set up in inode_init_early */
        if (!hashdist)