LINUX: consolidate duplicate code in osi_TryEvictDentries
[openafs.git] / src / afs / LINUX / osi_vcache.c
index 3682bdc..1a5012c 100644 (file)
 #include <afsconfig.h>
 #include "afs/param.h"
 
-#include "afs/sysincludes.h"    /*Standard vendor system headers */
-#include "afsincludes.h"        /*AFS-based standard headers */
+#include "afs/sysincludes.h"   /*Standard vendor system headers */
+#include "afsincludes.h"       /*AFS-based standard headers */
 
 #include "osi_compat.h"
 
-void
-osi_TryEvictDentries(struct vcache *avc)
+static void
+TryEvictDentries(struct vcache *avc)
 {
     struct dentry *dentry;
     struct inode *inode = AFSTOV(avc);
@@ -24,28 +24,7 @@ osi_TryEvictDentries(struct vcache *avc)
     struct hlist_node *p;
 #endif
 
-#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)
@@ -63,20 +42,20 @@ 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:
     return;
 }
@@ -95,7 +74,7 @@ osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep)
        ReleaseWriteLock(&afs_xvcache);
        AFS_GUNLOCK();
 
-       osi_TryEvictDentries(avc);
+       TryEvictDentries(avc);
 
        AFS_GLOCK();
        ObtainWriteLock(&afs_xvcache, 733);
@@ -103,7 +82,7 @@ osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep)
     }
 
     /* See if we can evict it from the VLRUQ */
-    if (VREFCOUNT_GT(avc,0) && !VREFCOUNT_GT(avc,1) && avc->opens == 0
+    if (VREFCOUNT_GT(avc, 0) && !VREFCOUNT_GT(avc, 1) && avc->opens == 0
        && (avc->f.states & CUnlinkedDel) == 0) {
        int didsleep = *slept;
 
@@ -145,17 +124,22 @@ osi_NewVnode(void)
 }
 
 void
-osi_PrePopulateVCache(struct vcache *avc) {
+osi_PrePopulateVCache(struct vcache *avc)
+{
     avc->uncred = 0;
     memset(&(avc->f), 0, sizeof(struct fvcache));
     avc->cred = NULL;
 }
 
 void
-osi_AttachVnode(struct vcache *avc, int seq) { /* Nada */ }
+osi_AttachVnode(struct vcache *avc, int seq)
+{
+    /* Nada */
+}
 
 void
-osi_PostPopulateVCache(struct vcache *avc) {
+osi_PostPopulateVCache(struct vcache *avc)
+{
     vSetType(avc, VREG);
 }
 
@@ -192,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);
@@ -207,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);