fold swapping ->d_name.hash into switch_names()
[pandora-kernel.git] / fs / dcache.c
index d30ce69..7599d35 100644 (file)
@@ -106,8 +106,7 @@ static inline struct hlist_bl_head *d_hash(const struct dentry *parent,
                                        unsigned int hash)
 {
        hash += (unsigned long) parent / L1_CACHE_BYTES;
-       hash = hash + (hash >> d_hash_shift);
-       return dentry_hashtable + (hash & d_hash_mask);
+       return dentry_hashtable + hash_32(hash, d_hash_shift);
 }
 
 /* Statistics gathering. */
@@ -2413,7 +2412,7 @@ static void switch_names(struct dentry *dentry, struct dentry *target)
                        }
                }
        }
-       swap(dentry->d_name.len, target->d_name.len);
+       swap(dentry->d_name.hash_len, target->d_name.hash_len);
 }
 
 static void dentry_lock_for_move(struct dentry *dentry, struct dentry *target)
@@ -2443,13 +2442,14 @@ static void dentry_lock_for_move(struct dentry *dentry, struct dentry *target)
        }
 }
 
-static void dentry_unlock_parents_for_move(struct dentry *dentry,
-                                       struct dentry *target)
+static void dentry_unlock_for_move(struct dentry *dentry, struct dentry *target)
 {
        if (target->d_parent != dentry->d_parent)
                spin_unlock(&dentry->d_parent->d_lock);
        if (target->d_parent != target)
                spin_unlock(&target->d_parent->d_lock);
+       spin_unlock(&target->d_lock);
+       spin_unlock(&dentry->d_lock);
 }
 
 /*
@@ -2507,36 +2507,31 @@ static void __d_move(struct dentry *dentry, struct dentry *target,
                           d_hash(dentry->d_parent, dentry->d_name.hash));
        }
 
-       list_del(&dentry->d_u.d_child);
-       list_del(&target->d_u.d_child);
 
        /* Switch the names.. */
        switch_names(dentry, target);
-       swap(dentry->d_name.hash, target->d_name.hash);
 
-       /* ... and switch the parents */
+       /* ... and switch them in the tree */
        if (IS_ROOT(dentry)) {
+               /* splicing a tree */
                dentry->d_parent = target->d_parent;
                target->d_parent = target;
-               INIT_LIST_HEAD(&target->d_u.d_child);
+               list_del_init(&target->d_u.d_child);
+               list_move(&dentry->d_u.d_child, &dentry->d_parent->d_subdirs);
        } else {
+               /* swapping two dentries */
                swap(dentry->d_parent, target->d_parent);
-
-               /* And add them back to the (new) parent lists */
-               list_add(&target->d_u.d_child, &target->d_parent->d_subdirs);
+               list_move(&target->d_u.d_child, &target->d_parent->d_subdirs);
+               list_move(&dentry->d_u.d_child, &dentry->d_parent->d_subdirs);
+               if (exchange)
+                       fsnotify_d_move(target);
+               fsnotify_d_move(dentry);
        }
 
-       list_add(&dentry->d_u.d_child, &dentry->d_parent->d_subdirs);
-
        write_seqcount_end(&target->d_seq);
        write_seqcount_end(&dentry->d_seq);
 
-       dentry_unlock_parents_for_move(dentry, target);
-       if (exchange)
-               fsnotify_d_move(target);
-       spin_unlock(&target->d_lock);
-       fsnotify_d_move(dentry);
-       spin_unlock(&dentry->d_lock);
+       dentry_unlock_for_move(dentry, target);
 }
 
 /*
@@ -2634,39 +2629,6 @@ out_err:
        return ret;
 }
 
-/*
- * Prepare an anonymous dentry for life in the superblock's dentry tree as a
- * named dentry in place of the dentry to be replaced.
- * returns with anon->d_lock held!
- */
-static void __d_materialise_dentry(struct dentry *dentry, struct dentry *anon)
-{
-       struct dentry *dparent;
-
-       dentry_lock_for_move(anon, dentry);
-
-       write_seqcount_begin(&dentry->d_seq);
-       write_seqcount_begin_nested(&anon->d_seq, DENTRY_D_LOCK_NESTED);
-
-       dparent = dentry->d_parent;
-
-       switch_names(dentry, anon);
-       swap(dentry->d_name.hash, anon->d_name.hash);
-
-       dentry->d_parent = dentry;
-       list_del_init(&dentry->d_u.d_child);
-       anon->d_parent = dparent;
-       list_move(&anon->d_u.d_child, &dparent->d_subdirs);
-
-       write_seqcount_end(&dentry->d_seq);
-       write_seqcount_end(&anon->d_seq);
-
-       dentry_unlock_parents_for_move(anon, dentry);
-       spin_unlock(&dentry->d_lock);
-
-       /* anon->d_lock still locked, returns locked */
-}
-
 /**
  * d_splice_alias - splice a disconnected dentry into the tree if one exists
  * @inode:  the inode which may have a disconnected dentry
@@ -2712,11 +2674,8 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
                                return ERR_PTR(-EIO);
                        }
                        write_seqlock(&rename_lock);
-                       __d_materialise_dentry(dentry, new);
+                       __d_move(new, dentry, false);
                        write_sequnlock(&rename_lock);
-                       __d_drop(new);
-                       _d_rehash(new);
-                       spin_unlock(&new->d_lock);
                        spin_unlock(&inode->i_lock);
                        security_d_instantiate(new, inode);
                        iput(inode);
@@ -2776,9 +2735,8 @@ struct dentry *d_materialise_unique(struct dentry *dentry, struct inode *inode)
                        } else if (IS_ROOT(alias)) {
                                /* Is this an anonymous mountpoint that we
                                 * could splice into our tree? */
-                               __d_materialise_dentry(dentry, alias);
+                               __d_move(alias, dentry, false);
                                write_sequnlock(&rename_lock);
-                               __d_drop(alias);
                                goto found;
                        } else {
                                /* Nope, but we must(!) avoid directory
@@ -2804,13 +2762,9 @@ struct dentry *d_materialise_unique(struct dentry *dentry, struct inode *inode)
        actual = __d_instantiate_unique(dentry, inode);
        if (!actual)
                actual = dentry;
-       else
-               BUG_ON(!d_unhashed(actual));
 
-       spin_lock(&actual->d_lock);
+       d_rehash(actual);
 found:
-       _d_rehash(actual);
-       spin_unlock(&actual->d_lock);
        spin_unlock(&inode->i_lock);
 out_nolock:
        if (actual == dentry) {