fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / fs / inode.c
index fdf9485..b3fe303 100644 (file)
@@ -4,7 +4,6 @@
  * (C) 1997 Linus Torvalds
  */
 
-#include <linux/config.h>
 #include <linux/fs.h>
 #include <linux/mm.h>
 #include <linux/dcache.h>
 #include <linux/pagemap.h>
 #include <linux/cdev.h>
 #include <linux/bootmem.h>
+#include <linux/inotify.h>
+#include <linux/mount.h>
 
 /*
  * This is needed for the following functions:
  *  - inode_has_buffers
  *  - invalidate_inode_buffers
- *  - fsync_bdev
  *  - invalidate_bdev
  *
  * FIXME: remove all knowledge of the buffer layer from this file
@@ -55,8 +55,8 @@
 #define I_HASHBITS     i_hash_shift
 #define I_HASHMASK     i_hash_mask
 
-static unsigned int i_hash_mask;
-static unsigned int i_hash_shift;
+static unsigned int i_hash_mask __read_mostly;
+static unsigned int i_hash_shift __read_mostly;
 
 /*
  * Each inode can be on two separate lists. One is
@@ -72,7 +72,7 @@ static unsigned int i_hash_shift;
 
 LIST_HEAD(inode_in_use);
 LIST_HEAD(inode_unused);
-static struct hlist_head *inode_hashtable;
+static struct hlist_head *inode_hashtable __read_mostly;
 
 /*
  * A simple spinlock to protect the list manipulations.
@@ -83,33 +83,33 @@ static struct hlist_head *inode_hashtable;
 DEFINE_SPINLOCK(inode_lock);
 
 /*
- * iprune_sem provides exclusion between the kswapd or try_to_free_pages
+ * iprune_mutex provides exclusion between the kswapd or try_to_free_pages
  * icache shrinking path, and the umount path.  Without this exclusion,
  * by the time prune_icache calls iput for the inode whose pages it has
  * been invalidating, or by the time it calls clear_inode & destroy_inode
  * from its final dispose_list, the struct super_block they refer to
  * (for inode->i_sb->s_op) may already have been freed and reused.
  */
-DECLARE_MUTEX(iprune_sem);
+static DEFINE_MUTEX(iprune_mutex);
 
 /*
  * Statistics gathering..
  */
 struct inodes_stat_t inodes_stat;
 
-static kmem_cache_t * inode_cachep;
+static struct kmem_cache * inode_cachep __read_mostly;
 
 static struct inode *alloc_inode(struct super_block *sb)
 {
-       static struct address_space_operations empty_aops;
+       static const struct address_space_operations empty_aops;
        static struct inode_operations empty_iops;
-       static struct file_operations empty_fops;
+       static const struct file_operations empty_fops;
        struct inode *inode;
 
        if (sb->s_op->alloc_inode)
                inode = sb->s_op->alloc_inode(sb);
        else
-               inode = (struct inode *) kmem_cache_alloc(inode_cachep, SLAB_KERNEL);
+               inode = (struct inode *) kmem_cache_alloc(inode_cachep, GFP_KERNEL);
 
        if (inode) {
                struct address_space * const mapping = &inode->i_data;
@@ -117,11 +117,10 @@ static struct inode *alloc_inode(struct super_block *sb)
                inode->i_sb = sb;
 
                /* essential because of inode slab reuse */
-               inode->i_xid = 0;
+               inode->i_tag = 0;
                inode->i_blkbits = sb->s_blocksize_bits;
                inode->i_flags = 0;
                atomic_set(&inode->i_count, 1);
-               inode->i_sock = 0;
                inode->i_op = &empty_iops;
                inode->i_fop = &empty_fops;
                inode->i_nlink = 1;
@@ -137,7 +136,6 @@ static struct inode *alloc_inode(struct super_block *sb)
                inode->i_bdev = NULL;
                inode->i_cdev = NULL;
                inode->i_rdev = 0;
-               inode->i_security = NULL;
                inode->dirtied_when = 0;
                if (security_inode_alloc(inode)) {
                        if (inode->i_sb->s_op->destroy_inode)
@@ -167,7 +165,7 @@ static struct inode *alloc_inode(struct super_block *sb)
                                bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info;
                        mapping->backing_dev_info = bdi;
                }
-               memset(&inode->u, 0, sizeof(inode->u));
+               inode->i_private = NULL;
                inode->i_mapping = mapping;
        }
        return inode;
@@ -175,8 +173,7 @@ static struct inode *alloc_inode(struct super_block *sb)
 
 void destroy_inode(struct inode *inode) 
 {
-       if (inode_has_buffers(inode))
-               BUG();
+       BUG_ON(inode_has_buffers(inode));
        security_inode_free(inode);
        if (inode->i_sb->s_op->destroy_inode)
                inode->i_sb->s_op->destroy_inode(inode);
@@ -196,10 +193,10 @@ 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);
-       sema_init(&inode->i_sem, 1);
+       mutex_init(&inode->i_mutex);
        init_rwsem(&inode->i_alloc_sem);
        INIT_RADIX_TREE(&inode->i_data.page_tree, GFP_ATOMIC);
-       spin_lock_init(&inode->i_data.tree_lock);
+       rwlock_init(&inode->i_data.tree_lock);
        spin_lock_init(&inode->i_data.i_mmap_lock);
        INIT_LIST_HEAD(&inode->i_data.private_list);
        spin_lock_init(&inode->i_data.private_lock);
@@ -207,11 +204,15 @@ void inode_init_once(struct inode *inode)
        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);
+       mutex_init(&inode->inotify_mutex);
+#endif
 }
 
 EXPORT_SYMBOL(inode_init_once);
 
-static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
+static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
 {
        struct inode * inode = (struct inode *) foo;
 
@@ -250,19 +251,16 @@ void clear_inode(struct inode *inode)
        might_sleep();
        invalidate_inode_buffers(inode);
        
-       if (inode->i_data.nrpages)
-               BUG();
-       if (!(inode->i_state & I_FREEING))
-               BUG();
-       if (inode->i_state & I_CLEAR)
-               BUG();
+       BUG_ON(inode->i_data.nrpages);
+       BUG_ON(!(inode->i_state & I_FREEING));
+       BUG_ON(inode->i_state & I_CLEAR);
        wait_on_inode(inode);
        DQUOT_DROP(inode);
        if (inode->i_sb && inode->i_sb->s_op->clear_inode)
                inode->i_sb->s_op->clear_inode(inode);
-       if (inode->i_bdev)
+       if (S_ISBLK(inode->i_mode) && inode->i_bdev)
                bd_forget(inode);
-       if (inode->i_cdev)
+       if (S_ISCHR(inode->i_mode) && inode->i_cdev)
                cd_forget(inode);
        inode->i_state = I_CLEAR;
 }
@@ -289,6 +287,13 @@ static void dispose_list(struct list_head *head)
                if (inode->i_data.nrpages)
                        truncate_inode_pages(&inode->i_data, 0);
                clear_inode(inode);
+
+               spin_lock(&inode_lock);
+               hlist_del_init(&inode->i_hash);
+               list_del_init(&inode->i_sb_list);
+               spin_unlock(&inode_lock);
+
+               wake_up_inode(inode);
                destroy_inode(inode);
                nr_disposed++;
        }
@@ -313,7 +318,7 @@ static int invalidate_list(struct list_head *head, struct list_head *dispose)
                /*
                 * We can reschedule here without worrying about the list's
                 * consistency because the per-sb list of inodes must not
-                * change during umount anymore, and because iprune_sem keeps
+                * change during umount anymore, and because iprune_mutex keeps
                 * shrink_icache_memory() away.
                 */
                cond_resched_lock(&inode_lock);
@@ -324,8 +329,6 @@ static int invalidate_list(struct list_head *head, struct list_head *dispose)
                inode = list_entry(tmp, struct inode, i_sb_list);
                invalidate_inode_buffers(inode);
                if (!atomic_read(&inode->i_count)) {
-                       hlist_del_init(&inode->i_hash);
-                       list_del(&inode->i_sb_list);
                        list_move(&inode->i_list, dispose);
                        inode->i_state |= I_FREEING;
                        count++;
@@ -338,14 +341,6 @@ static int invalidate_list(struct list_head *head, struct list_head *dispose)
        return busy;
 }
 
-/*
- * This is a two-stage process. First we collect all
- * offending inodes onto the throw-away list, and in
- * the second stage we actually dispose of them. This
- * is because we don't want to sleep while messing
- * with the global lists..
- */
 /**
  *     invalidate_inodes       - discard the inodes on a device
  *     @sb: superblock
@@ -359,45 +354,19 @@ int invalidate_inodes(struct super_block * sb)
        int busy;
        LIST_HEAD(throw_away);
 
-       down(&iprune_sem);
+       mutex_lock(&iprune_mutex);
        spin_lock(&inode_lock);
+       inotify_unmount_inodes(&sb->s_inodes);
        busy = invalidate_list(&sb->s_inodes, &throw_away);
        spin_unlock(&inode_lock);
 
        dispose_list(&throw_away);
-       up(&iprune_sem);
+       mutex_unlock(&iprune_mutex);
 
        return busy;
 }
 
 EXPORT_SYMBOL(invalidate_inodes);
-int __invalidate_device(struct block_device *bdev, int do_sync)
-{
-       struct super_block *sb;
-       int res;
-
-       if (do_sync)
-               fsync_bdev(bdev);
-
-       res = 0;
-       sb = get_super(bdev);
-       if (sb) {
-               /*
-                * no need to lock the super, get_super holds the
-                * read semaphore so the filesystem cannot go away
-                * under us (->put_super runs with the write lock
-                * hold).
-                */
-               shrink_dcache_sb(sb);
-               res = invalidate_inodes(sb);
-               drop_super(sb);
-       }
-       invalidate_bdev(bdev, 0);
-       return res;
-}
-
-EXPORT_SYMBOL(__invalidate_device);
 
 static int can_unuse(struct inode *inode)
 {
@@ -432,7 +401,7 @@ static void prune_icache(int nr_to_scan)
        int nr_scanned;
        unsigned long reap = 0;
 
-       down(&iprune_sem);
+       mutex_lock(&iprune_mutex);
        spin_lock(&inode_lock);
        for (nr_scanned = 0; nr_scanned < nr_to_scan; nr_scanned++) {
                struct inode *inode;
@@ -460,22 +429,19 @@ static void prune_icache(int nr_to_scan)
                        if (!can_unuse(inode))
                                continue;
                }
-               hlist_del_init(&inode->i_hash);
-               list_del_init(&inode->i_sb_list);
                list_move(&inode->i_list, &freeable);
                inode->i_state |= I_FREEING;
                nr_pruned++;
        }
        inodes_stat.nr_unused -= nr_pruned;
+       if (current_is_kswapd())
+               __count_vm_events(KSWAPD_INODESTEAL, reap);
+       else
+               __count_vm_events(PGINODESTEAL, reap);
        spin_unlock(&inode_lock);
 
        dispose_list(&freeable);
-       up(&iprune_sem);
-
-       if (current_is_kswapd())
-               mod_page_state(kswapd_inodesteal, reap);
-       else
-               mod_page_state(pginodesteal, reap);
+       mutex_unlock(&iprune_mutex);
 }
 
 /*
@@ -487,7 +453,7 @@ static void prune_icache(int nr_to_scan)
  * This function is passed the number of inodes to scan, and it returns the
  * total number of remaining possibly-reclaimable inodes.
  */
-static int shrink_icache_memory(int nr, unsigned int gfp_mask)
+static int shrink_icache_memory(int nr, gfp_t gfp_mask)
 {
        if (nr) {
                /*
@@ -521,7 +487,7 @@ repeat:
                        continue;
                if (!test(inode, data))
                        continue;
-               if (inode->i_state & (I_FREEING|I_CLEAR)) {
+               if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) {
                        __wait_on_freeing_inode(inode);
                        goto repeat;
                }
@@ -546,7 +512,7 @@ repeat:
                        continue;
                if (inode->i_sb != sb)
                        continue;
-               if (inode->i_state & (I_FREEING|I_CLEAR)) {
+               if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) {
                        __wait_on_freeing_inode(inode);
                        goto repeat;
                }
@@ -696,7 +662,7 @@ static struct inode * get_new_inode_fast(struct super_block *sb, struct hlist_he
        return inode;
 }
 
-static inline unsigned long hash(struct super_block *sb, unsigned long hashval)
+static unsigned long hash(struct super_block *sb, unsigned long hashval)
 {
        unsigned long tmp;
 
@@ -748,7 +714,7 @@ EXPORT_SYMBOL(iunique);
 struct inode *igrab(struct inode *inode)
 {
        spin_lock(&inode_lock);
-       if (!(inode->i_state & I_FREEING))
+       if (!(inode->i_state & (I_FREEING|I_WILL_FREE)))
                __iget(inode);
        else
                /*
@@ -769,6 +735,7 @@ EXPORT_SYMBOL(igrab);
  * @head:       the head of the list to search
  * @test:      callback used for comparisons between inodes
  * @data:      opaque data pointer to pass to @test
+ * @wait:      if true wait for the inode to be unlocked, if false do not
  *
  * ifind() searches for the inode specified by @data in the inode
  * cache. This is a generalized version of ifind_fast() for file systems where
@@ -781,9 +748,9 @@ EXPORT_SYMBOL(igrab);
  *
  * Note, @test is called with the inode_lock held, so can't sleep.
  */
-static inline struct inode *ifind(struct super_block *sb,
+static struct inode *ifind(struct super_block *sb,
                struct hlist_head *head, int (*test)(struct inode *, void *),
-               void *data)
+               void *data, const int wait)
 {
        struct inode *inode;
 
@@ -792,7 +759,8 @@ static inline struct inode *ifind(struct super_block *sb,
        if (inode) {
                __iget(inode);
                spin_unlock(&inode_lock);
-               wait_on_inode(inode);
+               if (likely(wait))
+                       wait_on_inode(inode);
                return inode;
        }
        spin_unlock(&inode_lock);
@@ -814,7 +782,7 @@ static inline struct inode *ifind(struct super_block *sb,
  *
  * Otherwise NULL is returned.
  */
-static inline struct inode *ifind_fast(struct super_block *sb,
+static struct inode *ifind_fast(struct super_block *sb,
                struct hlist_head *head, unsigned long ino)
 {
        struct inode *inode;
@@ -832,7 +800,7 @@ static inline struct inode *ifind_fast(struct super_block *sb,
 }
 
 /**
- * ilookup5 - search for an inode in the inode cache
+ * ilookup5_nowait - search for an inode in the inode cache
  * @sb:                super block of file system to search
  * @hashval:   hash value (usually inode number) to search for
  * @test:      callback used for comparisons between inodes
@@ -844,7 +812,38 @@ static inline struct inode *ifind_fast(struct super_block *sb,
  * identification of an inode.
  *
  * If the inode is in the cache, the inode is returned with an incremented
- * reference count.
+ * reference count.  Note, the inode lock is not waited upon so you have to be
+ * very careful what you do with the returned inode.  You probably should be
+ * using ilookup5() instead.
+ *
+ * Otherwise NULL is returned.
+ *
+ * Note, @test is called with the inode_lock held, so can't sleep.
+ */
+struct inode *ilookup5_nowait(struct super_block *sb, unsigned long hashval,
+               int (*test)(struct inode *, void *), void *data)
+{
+       struct hlist_head *head = inode_hashtable + hash(sb, hashval);
+
+       return ifind(sb, head, test, data, 0);
+}
+
+EXPORT_SYMBOL(ilookup5_nowait);
+
+/**
+ * ilookup5 - search for an inode in the inode cache
+ * @sb:                super block of file system to search
+ * @hashval:   hash value (usually inode number) to search for
+ * @test:      callback used for comparisons between inodes
+ * @data:      opaque data pointer to pass to @test
+ *
+ * ilookup5() uses ifind() to search for the inode specified by @hashval and
+ * @data in the inode cache. This is a generalized version of ilookup() for
+ * file systems where the inode number is not sufficient for unique
+ * identification of an inode.
+ *
+ * If the inode is in the cache, the inode lock is waited upon and the inode is
+ * returned with an incremented reference count.
  *
  * Otherwise NULL is returned.
  *
@@ -855,7 +854,7 @@ struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
 {
        struct hlist_head *head = inode_hashtable + hash(sb, hashval);
 
-       return ifind(sb, head, test, data);
+       return ifind(sb, head, test, data, 1);
 }
 
 EXPORT_SYMBOL(ilookup5);
@@ -912,7 +911,7 @@ struct inode *iget5_locked(struct super_block *sb, unsigned long hashval,
        struct hlist_head *head = inode_hashtable + hash(sb, hashval);
        struct inode *inode;
 
-       inode = ifind(sb, head, test, data);
+       inode = ifind(sb, head, test, data, 1);
        if (inode)
                return inode;
        /*
@@ -1009,29 +1008,30 @@ void generic_delete_inode(struct inode *inode)
 
        list_del_init(&inode->i_list);
        list_del_init(&inode->i_sb_list);
-       inode->i_state|=I_FREEING;
+       inode->i_state |= I_FREEING;
        inodes_stat.nr_inodes--;
        spin_unlock(&inode_lock);
 
-       if (inode->i_data.nrpages)
-               truncate_inode_pages(&inode->i_data, 0);
-
        security_inode_delete(inode);
 
        if (op->delete_inode) {
                void (*delete)(struct inode *) = op->delete_inode;
                if (!is_bad_inode(inode))
                        DQUOT_INIT(inode);
-               /* s_op->delete_inode internally recalls clear_inode() */
+               /* Filesystems implementing their own
+                * s_op->delete_inode are required to call
+                * truncate_inode_pages and clear_inode()
+                * internally */
                delete(inode);
-       } else
+       } else {
+               truncate_inode_pages(&inode->i_data, 0);
                clear_inode(inode);
+       }
        spin_lock(&inode_lock);
        hlist_del_init(&inode->i_hash);
        spin_unlock(&inode_lock);
        wake_up_inode(inode);
-       if (inode->i_state != I_CLEAR)
-               BUG();
+       BUG_ON(inode->i_state != I_CLEAR);
        destroy_inode(inode);
 }
 
@@ -1045,22 +1045,27 @@ static void generic_forget_inode(struct inode *inode)
                if (!(inode->i_state & (I_DIRTY|I_LOCK)))
                        list_move(&inode->i_list, &inode_unused);
                inodes_stat.nr_unused++;
-               spin_unlock(&inode_lock);
-               if (!sb || (sb->s_flags & MS_ACTIVE))
+               if (!sb || (sb->s_flags & MS_ACTIVE)) {
+                       spin_unlock(&inode_lock);
                        return;
+               }
+               inode->i_state |= I_WILL_FREE;
+               spin_unlock(&inode_lock);
                write_inode_now(inode, 1);
                spin_lock(&inode_lock);
+               inode->i_state &= ~I_WILL_FREE;
                inodes_stat.nr_unused--;
                hlist_del_init(&inode->i_hash);
        }
        list_del_init(&inode->i_list);
        list_del_init(&inode->i_sb_list);
-       inode->i_state|=I_FREEING;
+       inode->i_state |= I_FREEING;
        inodes_stat.nr_inodes--;
        spin_unlock(&inode_lock);
        if (inode->i_data.nrpages)
                truncate_inode_pages(&inode->i_data, 0);
        clear_inode(inode);
+       wake_up_inode(inode);
        destroy_inode(inode);
 }
 
@@ -1069,7 +1074,7 @@ static void generic_forget_inode(struct inode *inode)
  * inode when the usage count drops to zero, and
  * i_nlink is zero.
  */
-static void generic_drop_inode(struct inode *inode)
+void generic_drop_inode(struct inode *inode)
 {
        if (!inode->i_nlink)
                generic_delete_inode(inode);
@@ -1077,6 +1082,8 @@ static void generic_drop_inode(struct inode *inode)
                generic_forget_inode(inode);
 }
 
+EXPORT_SYMBOL_GPL(generic_drop_inode);
+
 /*
  * Called when we're dropping the last reference
  * to an inode. 
@@ -1103,15 +1110,16 @@ static inline void iput_final(struct inode *inode)
  *     @inode: inode to put
  *
  *     Puts an inode, dropping its usage count. If the inode use count hits
- *     zero the inode is also then freed and may be destroyed.
+ *     zero, the inode is then freed and may also be destroyed.
+ *
+ *     Consequently, iput() can sleep.
  */
 void iput(struct inode *inode)
 {
        if (inode) {
                struct super_operations *op = inode->i_sb->s_op;
 
-               if (inode->i_state == I_CLEAR)
-                       BUG();
+               BUG_ON(inode->i_state == I_CLEAR);
 
                if (op && op->put_inode)
                        op->put_inode(inode);
@@ -1141,51 +1149,78 @@ sector_t bmap(struct inode * inode, sector_t block)
                res = inode->i_mapping->a_ops->bmap(inode->i_mapping, block);
        return res;
 }
-
 EXPORT_SYMBOL(bmap);
 
 /**
- *     update_atime    -       update the access time
- *     @inode: inode accessed
+ *     touch_atime     -       update the access time
+ *     @mnt: mount the inode is accessed on
+ *     @dentry: dentry accessed
  *
  *     Update the accessed time on an inode and mark it for writeback.
  *     This function automatically handles read only file systems and media,
  *     as well as the "noatime" flag and inode specific "noatime" markers.
  */
-void update_atime(struct inode *inode)
+void touch_atime(struct vfsmount *mnt, struct dentry *dentry)
 {
+       struct inode *inode = dentry->d_inode;
        struct timespec now;
 
-       if (IS_NOATIME(inode))
+       if (IS_RDONLY(inode))
                return;
-       if (IS_NODIRATIME(inode) && S_ISDIR(inode->i_mode))
+       if (inode->i_flags & S_NOATIME)
                return;
-       if (IS_RDONLY(inode))
+       if (inode->i_sb->s_flags & MS_NOATIME)
+               return;
+       if ((inode->i_sb->s_flags & MS_NODIRATIME) && S_ISDIR(inode->i_mode))
                return;
 
-       now = current_fs_time(inode->i_sb);
-       if (!timespec_equal(&inode->i_atime, &now)) {
-               inode->i_atime = now;
-               mark_inode_dirty_sync(inode);
-       } else {
-               if (!timespec_equal(&inode->i_atime, &now))
-                       inode->i_atime = now;
+       /*
+        * We may have a NULL vfsmount when coming from NFSD
+        */
+       if (mnt) {
+               if (mnt->mnt_flags & MNT_NOATIME)
+                       return;
+               if ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode))
+                       return;
+
+               if (mnt->mnt_flags & MNT_RELATIME) {
+                       /*
+                        * With relative atime, only update atime if the
+                        * previous atime is earlier than either the ctime or
+                        * mtime.
+                        */
+                       if (timespec_compare(&inode->i_mtime,
+                                               &inode->i_atime) < 0 &&
+                           timespec_compare(&inode->i_ctime,
+                                               &inode->i_atime) < 0)
+                               return;
+               }
        }
-}
 
-EXPORT_SYMBOL(update_atime);
+       now = current_fs_time(inode->i_sb);
+       if (timespec_equal(&inode->i_atime, &now))
+               return;
+
+       inode->i_atime = now;
+       mark_inode_dirty_sync(inode);
+}
+EXPORT_SYMBOL(touch_atime);
 
 /**
- *     inode_update_time       -       update mtime and ctime time
- *     @inode: inode accessed
- *     @ctime_too: update ctime too
+ *     file_update_time        -       update mtime and ctime time
+ *     @file: file accessed
  *
- *     Update the mtime time on an inode and mark it for writeback.
- *     When ctime_too is specified update the ctime too.
+ *     Update the mtime and ctime members of an inode and mark the inode
+ *     for writeback.  Note that this function is meant exclusively for
+ *     usage in the file write path of filesystems, and filesystems may
+ *     choose to explicitly ignore update via this function with the
+ *     S_NOCTIME inode flag, e.g. for network filesystem where these
+ *     timestamps are handled by the server.
  */
 
-void inode_update_time(struct inode *inode, int ctime_too)
+void file_update_time(struct file *file)
 {
+       struct inode *inode = file->f_path.dentry->d_inode;
        struct timespec now;
        int sync_it = 0;
 
@@ -1195,20 +1230,21 @@ void inode_update_time(struct inode *inode, int ctime_too)
                return;
 
        now = current_fs_time(inode->i_sb);
-       if (!timespec_equal(&inode->i_mtime, &now))
+       if (!timespec_equal(&inode->i_mtime, &now)) {
+               inode->i_mtime = now;
                sync_it = 1;
-       inode->i_mtime = now;
+       }
 
-       if (ctime_too) {
-               if (!timespec_equal(&inode->i_ctime, &now))
-                       sync_it = 1;
+       if (!timespec_equal(&inode->i_ctime, &now)) {
                inode->i_ctime = now;
+               sync_it = 1;
        }
+
        if (sync_it)
                mark_inode_dirty_sync(inode);
 }
 
-EXPORT_SYMBOL(inode_update_time);
+EXPORT_SYMBOL(file_update_time);
 
 int inode_needs_sync(struct inode *inode)
 {
@@ -1226,9 +1262,6 @@ EXPORT_SYMBOL(inode_needs_sync);
  */
 #ifdef CONFIG_QUOTA
 
-/* Function back in dquot.c */
-int remove_inode_dquot_ref(struct inode *, int, struct list_head *);
-
 void remove_dquot_ref(struct super_block *sb, int type,
                        struct list_head *tofree_head)
 {
@@ -1258,29 +1291,21 @@ int inode_wait(void *word)
 }
 
 /*
- * If we try to find an inode in the inode hash while it is being deleted, we
- * have to wait until the filesystem completes its deletion before reporting
- * that it isn't found.  This is because iget will immediately call
- * ->read_inode, and we want to be sure that evidence of the deletion is found
- * by ->read_inode.
+ * If we try to find an inode in the inode hash while it is being
+ * deleted, we have to wait until the filesystem completes its
+ * deletion before reporting that it isn't found.  This function waits
+ * until the deletion _might_ have completed.  Callers are responsible
+ * to recheck inode state.
+ *
+ * It doesn't matter if I_LOCK is not set initially, a call to
+ * wake_up_inode() after removing from the hash list will DTRT.
+ *
  * This is called with inode_lock held.
  */
 static void __wait_on_freeing_inode(struct inode *inode)
 {
        wait_queue_head_t *wq;
        DEFINE_WAIT_BIT(wait, &inode->i_state, __I_LOCK);
-
-       /*
-        * I_FREEING and I_CLEAR are cleared in process context under
-        * inode_lock, so we have to give the tasks who would clear them
-        * a chance to run and acquire inode_lock.
-        */
-       if (!(inode->i_state & I_LOCK)) {
-               spin_unlock(&inode_lock);
-               yield();
-               spin_lock(&inode_lock);
-               return;
-       }
        wq = bit_waitqueue(&inode->i_state, __I_LOCK);
        prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE);
        spin_unlock(&inode_lock);
@@ -1298,6 +1323,42 @@ void wake_up_inode(struct inode *inode)
        wake_up_bit(&inode->i_state, __I_LOCK);
 }
 
+/*
+ * We rarely want to lock two inodes that do not have a parent/child
+ * relationship (such as directory, child inode) simultaneously. The
+ * vast majority of file systems should be able to get along fine
+ * without this. Do not use these functions except as a last resort.
+ */
+void inode_double_lock(struct inode *inode1, struct inode *inode2)
+{
+       if (inode1 == NULL || inode2 == NULL || inode1 == inode2) {
+               if (inode1)
+                       mutex_lock(&inode1->i_mutex);
+               else if (inode2)
+                       mutex_lock(&inode2->i_mutex);
+               return;
+       }
+
+       if (inode1 < inode2) {
+               mutex_lock_nested(&inode1->i_mutex, I_MUTEX_PARENT);
+               mutex_lock_nested(&inode2->i_mutex, I_MUTEX_CHILD);
+       } else {
+               mutex_lock_nested(&inode2->i_mutex, I_MUTEX_PARENT);
+               mutex_lock_nested(&inode1->i_mutex, I_MUTEX_CHILD);
+       }
+}
+EXPORT_SYMBOL(inode_double_lock);
+
+void inode_double_unlock(struct inode *inode1, struct inode *inode2)
+{
+       if (inode1)
+               mutex_unlock(&inode1->i_mutex);
+
+       if (inode2 && inode2 != inode1)
+               mutex_unlock(&inode2->i_mutex);
+}
+EXPORT_SYMBOL(inode_double_unlock);
+
 static __initdata unsigned long ihash_entries;
 static int __init set_ihash_entries(char *str)
 {
@@ -1340,8 +1401,13 @@ void __init inode_init(unsigned long mempages)
        int loop;
 
        /* inode slab cache */
-       inode_cachep = kmem_cache_create("inode_cache", sizeof(struct inode),
-                               0, SLAB_PANIC, init_once, NULL);
+       inode_cachep = kmem_cache_create("inode_cache",
+                                        sizeof(struct inode),
+                                        0,
+                                        (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
+                                        SLAB_MEM_SPREAD),
+                                        init_once,
+                                        NULL);
        set_shrinker(DEFAULT_SEEKS, shrink_icache_memory);
 
        /* Hash may have been set up in inode_init_early */