Remove incorrect critical section use in dnlc_lookup
[openafs.git] / src / afs / afs_osidnlc.c
index 82704a3..d8fea44 100644 (file)
@@ -10,8 +10,6 @@
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID
-    ("$Header$");
 
 #include "afs/sysincludes.h"   /*Standard vendor system headers */
 #include "afsincludes.h"       /*AFS-based standard headers */
@@ -25,7 +23,7 @@ RCSID
  *    look into interactions of dnlc and readdir.
  *    cache larger names, perhaps by using a better,longer key (SHA) and discarding
  *    the actual name itself.
- *    precompute a key and stuff for @sys, and combine the HandleAtName function with
+ *    precompute a key and stuff for \sys, and combine the HandleAtName function with
  *    this, since we're looking at the name anyway.  
  */
 
@@ -63,14 +61,6 @@ int dnlct;
 
 #define dnlcHash(ts, hval) for (hval=0; *ts; ts++) { hval *= 173;  hval  += *ts;   }
 
-#if defined(AFS_FBSD80_ENV) && !defined(UKERNEL)
-#define ma_critical_enter critical_enter
-#define ma_critical_exit critical_exit
-#else
-#define ma_critical_enter() {}
-#define ma_critical_exit() {}
-#endif
-
 static struct nc *
 GetMeAnEntry(void)
 {
@@ -153,7 +143,7 @@ osi_dnlc_enter(struct vcache *adp, char *aname, struct vcache *avc,
     ObtainWriteLock(&afs_xdnlc, 222);
 
     /* Only cache entries from the latest version of the directory */
-    if (!(adp->states & CStatd) || !hsame(*avno, adp->m.DataVersion)) {
+    if (!(adp->f.states & CStatd) || !hsame(*avno, adp->f.m.DataVersion)) {
        ReleaseWriteLock(&afs_xdnlc);
        return 0;
     }
@@ -209,18 +199,12 @@ osi_dnlc_lookup(struct vcache *adp, char *aname, int locktype)
     vnode_t tvp;
 #endif
 
-    ma_critical_enter();
-
-    if (!afs_usednlc) {
-      ma_critical_exit();
+    if (!afs_usednlc)
       return 0;
-    }
 
     dnlcHash(ts, key);         /* leaves ts pointing at the NULL */
-    if (ts - aname >= AFSNCNAMESIZE) {
-      ma_critical_exit();
+    if (ts - aname >= AFSNCNAMESIZE)
       return 0;
-    }
     skey = key & (NHSIZE - 1);
 
     TRACE(osi_dnlc_lookupT, skey);
@@ -244,7 +228,6 @@ osi_dnlc_lookup(struct vcache *adp, char *aname, int locktype)
            ReleaseReadLock(&afs_xdnlc);
            ReleaseReadLock(&afs_xvcache);
            osi_dnlc_purge();
-           ma_critical_exit();
            return (0);
        }
     }
@@ -256,28 +239,23 @@ osi_dnlc_lookup(struct vcache *adp, char *aname, int locktype)
        ReleaseReadLock(&afs_xvcache);
        dnlcstats.misses++;
     } else {
-       if ((tvc->states & CVInit)
+       if ((tvc->f.states & CVInit)
 #ifdef  AFS_DARWIN80_ENV
-           ||(tvc->states & CDeadVnode)
+           ||(tvc->f.states & CDeadVnode)
 #endif
            )      
        {
            ReleaseReadLock(&afs_xvcache);
            dnlcstats.misses++;
            osi_dnlc_remove(adp, aname, tvc);
-           ma_critical_exit();
            return 0;
        }
-#ifdef AFS_OSF_ENV
-       VN_HOLD((vnode_t *) tvc);
-#else
-#ifdef AFS_DARWIN80_ENV
+#if defined(AFS_DARWIN80_ENV)
        tvp = AFSTOV(tvc);
        if (vnode_get(tvp)) {
            ReleaseReadLock(&afs_xvcache);
            dnlcstats.misses++;
            osi_dnlc_remove(adp, aname, tvc);
-           ma_critical_exit();
            return 0;
        }
        if (vnode_ref(tvp)) {
@@ -287,20 +265,9 @@ osi_dnlc_lookup(struct vcache *adp, char *aname, int locktype)
            AFS_GLOCK();
            dnlcstats.misses++;
            osi_dnlc_remove(adp, aname, tvc);
-           ma_critical_exit();
            return 0;
        }
-#else
-#ifdef AFS_FBSD50_ENV
-       /* can't sleep in a critical section */
-       ma_critical_exit();
-       osi_vnhold(tvc, 0);
-       ma_critical_enter();
-#else
        osi_vnhold(tvc, 0);
-#endif /* AFS_FBSD80_ENV */
-#endif
-#endif
        ReleaseReadLock(&afs_xvcache);
 
 #ifdef notdef
@@ -337,7 +304,6 @@ osi_dnlc_lookup(struct vcache *adp, char *aname, int locktype)
 #endif
     }
 
-    ma_critical_exit();
     return tvc;
 }
 
@@ -412,10 +378,15 @@ osi_dnlc_remove(struct vcache *adp, char *aname, struct vcache *avc)
     return 0;
 }
 
-/* remove anything pertaining to this directory.  I can invalidate
+/*! 
+ * Remove anything pertaining to this directory.  I can invalidate
  * things without the lock, since I am just looking through the array,
  * but to move things off the lists or into the freelist, I need the
- * write lock */
+ * write lock 
+ *
+ * \param adp vcache entry for the directory to be purged.
+ * \return 0
+ */
 int
 osi_dnlc_purgedp(struct vcache *adp)
 {
@@ -423,7 +394,7 @@ osi_dnlc_purgedp(struct vcache *adp)
     int writelocked;
 
 #ifdef AFS_DARWIN_ENV
-    if (!(adp->states & (CVInit | CVFlushed
+    if (!(adp->f.states & (CVInit | CVFlushed
 #ifdef AFS_DARWIN80_ENV
                         | CDeadVnode
 #endif
@@ -454,7 +425,12 @@ osi_dnlc_purgedp(struct vcache *adp)
     return 0;
 }
 
-/* remove anything pertaining to this file */
+/*! 
+ * Remove anything pertaining to this file 
+ *
+ * \param File vcache entry.
+ * \return 0
+ */
 int
 osi_dnlc_purgevp(struct vcache *avc)
 {
@@ -462,7 +438,7 @@ osi_dnlc_purgevp(struct vcache *avc)
     int writelocked;
 
 #ifdef AFS_DARWIN_ENV
-    if (!(avc->states & (CVInit | CVFlushed
+    if (!(avc->f.states & (CVInit | CVFlushed
 #ifdef AFS_DARWIN80_ENV
                         | CDeadVnode
 #endif
@@ -508,8 +484,8 @@ osi_dnlc_purge(void)
            nameCache[i].dirp = nameCache[i].vp = NULL;
     } else {                   /* did get the lock */
        ncfreelist = NULL;
-       memset((char *)nameCache, 0, sizeof(struct nc) * NCSIZE);
-       memset((char *)nameHash, 0, sizeof(struct nc *) * NHSIZE);
+       memset(nameCache, 0, sizeof(struct nc) * NCSIZE);
+       memset(nameHash, 0, sizeof(struct nc *) * NHSIZE);
        for (i = 0; i < NCSIZE; i++) {
            nameCache[i].next = ncfreelist;
            ncfreelist = &nameCache[i];
@@ -537,13 +513,13 @@ osi_dnlc_init(void)
     int i;
 
     Lock_Init(&afs_xdnlc);
-    memset((char *)&dnlcstats, 0, sizeof(dnlcstats));
-    memset((char *)dnlctracetable, 0, sizeof(dnlctracetable));
+    memset(&dnlcstats, 0, sizeof(dnlcstats));
+    memset(dnlctracetable, 0, sizeof(dnlctracetable));
     dnlct = 0;
     ObtainWriteLock(&afs_xdnlc, 223);
     ncfreelist = NULL;
-    memset((char *)nameCache, 0, sizeof(struct nc) * NCSIZE);
-    memset((char *)nameHash, 0, sizeof(struct nc *) * NHSIZE);
+    memset(nameCache, 0, sizeof(struct nc) * NCSIZE);
+    memset(nameHash, 0, sizeof(struct nc *) * NHSIZE);
     for (i = 0; i < NCSIZE; i++) {
        nameCache[i].next = ncfreelist;
        ncfreelist = &nameCache[i];