@@ -469,8 +469,11 @@ static void dentry_lru_add(struct dentry *dentry)
* reason (NFS timeouts or autofs deletes).
*
* __d_drop requires dentry->d_lock.
+ * ___d_drop takes an extra @moving argument.
+ * If true, d_hash.pprev is not cleared, so there is no transient d_unhashed()
+ * state.
*/
-void __d_drop(struct dentry *dentry)
+static void inline ___d_drop(struct dentry *dentry, bool moving)
{
if (!d_unhashed(dentry)) {
struct hlist_bl_head *b;
@@ -486,12 +489,18 @@ void __d_drop(struct dentry *dentry)
hlist_bl_lock(b);
__hlist_bl_del(&dentry->d_hash);
- dentry->d_hash.pprev = NULL;
+ if (likely(!moving))
+ dentry->d_hash.pprev = NULL;
hlist_bl_unlock(b);
/* After this call, in-progress rcu-walk path lookup will fail. */
write_seqcount_invalidate(&dentry->d_seq);
}
}
+
+void __d_drop(struct dentry *dentry)
+{
+ ___d_drop(dentry, false);
+}
EXPORT_SYMBOL(__d_drop);
void d_drop(struct dentry *dentry)
@@ -2378,10 +2387,10 @@ void d_delete(struct dentry * dentry)
}
EXPORT_SYMBOL(d_delete);
-static void __d_rehash(struct dentry *entry)
+static void __d_rehash(struct dentry *entry, bool moving)
{
struct hlist_bl_head *b = d_hash(entry->d_name.hash);
- BUG_ON(!d_unhashed(entry));
+ BUG_ON(!moving && !d_unhashed(entry));
hlist_bl_lock(b);
hlist_bl_add_head_rcu(&entry->d_hash, b);
hlist_bl_unlock(b);
@@ -2397,7 +2406,7 @@ static void __d_rehash(struct dentry *entry)
void d_rehash(struct dentry * entry)
{
spin_lock(&entry->d_lock);
- __d_rehash(entry);
+ __d_rehash(entry, false);
spin_unlock(&entry->d_lock);
}
EXPORT_SYMBOL(d_rehash);
@@ -2571,7 +2580,7 @@ static inline void __d_add(struct dentry *dentry, struct inode *inode)
raw_write_seqcount_end(&dentry->d_seq);
fsnotify_update_flags(dentry);
}
- __d_rehash(dentry);
+ __d_rehash(dentry, false);
if (dir)
end_dir_add(dir, n);
spin_unlock(&dentry->d_lock);
@@ -2633,7 +2642,7 @@ struct dentry *d_exact_alias(struct dentry *entry, struct inode *inode)
alias = NULL;
} else {
__dget_dlock(alias);
- __d_rehash(alias);
+ __d_rehash(alias, false);
spin_unlock(&alias->d_lock);
}
spin_unlock(&inode->i_lock);
@@ -2819,8 +2828,8 @@ static void __d_move(struct dentry *dentry, struct dentry *target,
/* unhash both */
/* __d_drop does write_seqcount_barrier, but they're OK to nest. */
- __d_drop(dentry);
- __d_drop(target);
+ ___d_drop(dentry, true);
+ ___d_drop(target, exchange);
/* Switch the names.. */
if (exchange)
@@ -2829,9 +2838,9 @@ static void __d_move(struct dentry *dentry, struct dentry *target,
copy_name(dentry, target);
/* rehash in new place(s) */
- __d_rehash(dentry);
+ __d_rehash(dentry, true);
if (exchange)
- __d_rehash(target);
+ __d_rehash(target, true);
/* ... and switch them in the tree */
if (IS_ROOT(dentry)) {