LINUX: consolidate duplicate code in osi_TryEvictDentries
[openafs.git] / src / afs / LINUX / osi_vcache.c
index 52830c5..1a5012c 100644 (file)
 static void
 TryEvictDentries(struct vcache *avc)
 {
-#ifndef D_INVALIDATE_IS_VOID
     struct dentry *dentry;
-#endif
     struct inode *inode = AFSTOV(avc);
 #if defined(D_ALIAS_IS_HLIST) && !defined(HLIST_ITERATOR_NO_NODE)
     struct hlist_node *p;
 #endif
 
-#if defined(D_INVALIDATE_IS_VOID)
-    /* At this kernel level, d_invalidate always succeeds;
-     * that is, it will now invalidate even an active directory,
-     * Therefore we must use a different method to evict dentries.
-     */
-    d_prune_aliases(inode);
-#else
-#if defined(HAVE_DCACHE_LOCK)
-    spin_lock(&dcache_lock);
-
-restart:
-    list_for_each_entry(dentry, &inode->i_dentry, d_alias) {
-       if (d_unhashed(dentry))
-           continue;
-       dget_locked(dentry);
-
-       spin_unlock(&dcache_lock);
-       if (d_invalidate(dentry) == -EBUSY) {
-           dput(dentry);
-           /* perhaps lock and try to continue? (use cur as head?) */
-           goto inuse;
-       }
-       dput(dentry);
-       spin_lock(&dcache_lock);
-       goto restart;
-    }
-    spin_unlock(&dcache_lock);
-#else /* HAVE_DCACHE_LOCK */
-    spin_lock(&inode->i_lock);
+    afs_d_alias_lock(inode);
 
 restart:
 #if defined(D_ALIAS_IS_HLIST)
@@ -72,22 +42,21 @@ restart:
            continue;
        }
        spin_unlock(&dentry->d_lock);
-       dget(dentry);
+       afs_linux_dget(dentry);
 
-       spin_unlock(&inode->i_lock);
+       afs_d_alias_unlock(inode);
        if (afs_d_invalidate(dentry) == -EBUSY) {
            dput(dentry);
            /* perhaps lock and try to continue? (use cur as head?) */
            goto inuse;
        }
        dput(dentry);
-       spin_lock(&inode->i_lock);
+       afs_d_alias_lock(inode);
        goto restart;
     }
-    spin_unlock(&inode->i_lock);
-#endif /* HAVE_DCACHE_LOCK */
+    afs_d_alias_unlock(inode);
+
 inuse:
-#endif /* D_INVALIDATE_IS_VOID */
     return;
 }
 
@@ -207,11 +176,8 @@ osi_ResetRootVCache(afs_uint32 volid)
 
     dp = d_find_alias(root);
 
-#if defined(HAVE_DCACHE_LOCK)
-    spin_lock(&dcache_lock);
-#else
-    spin_lock(&AFSTOV(vcp)->i_lock);
-#endif
+    afs_d_alias_lock(AFSTOV(vcp));
+
     spin_lock(&dp->d_lock);
 #if defined(D_ALIAS_IS_HLIST)
     hlist_del_init(&dp->d_alias);
@@ -222,11 +188,9 @@ osi_ResetRootVCache(afs_uint32 volid)
 #endif
     dp->d_inode = AFSTOV(vcp);
     spin_unlock(&dp->d_lock);
-#if defined(HAVE_DCACHE_LOCK)
-    spin_unlock(&dcache_lock);
-#else
-    spin_unlock(&AFSTOV(vcp)->i_lock);
-#endif
+
+    afs_d_alias_unlock(AFSTOV(vcp));
+
     dput(dp);
 
     AFS_RELE(root);