dns-and-server-ref-counts-20040530
[openafs.git] / src / WINNT / afsd / cm_scache.c
index d3add60..2b8eaf7 100644 (file)
@@ -22,6 +22,8 @@
 
 #include "afsd.h"
 
+/*extern void afsi_log(char *pattern, ...);*/
+
 extern osi_hyper_t hzero;
 
 /* hash table stuff */
@@ -305,7 +307,7 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp,
 
                lock_ObtainMutex(&cm_Freelance_Lock);
                scp->length.LowPart = strlen(mp)+4;
-               scp->mountPointStringp=malloc(strlen(mp));
+               scp->mountPointStringp=malloc(strlen(mp)+1);
                strcpy(scp->mountPointStringp,mp);
                lock_ReleaseMutex(&cm_Freelance_Lock);
 
@@ -642,12 +644,14 @@ sleep:
 
                /* wait here, then try again */
                osi_Log1(afsd_logp, "CM SyncOp sleeping scp %x", (long) scp);
+        if ( scp->flags & CM_SCACHEFLAG_WAITING ) 
+            osi_Log1(afsd_logp, "CM SyncOp CM_SCACHEFLAG_WAITING already set for 0x%x", scp);
                scp->flags |= CM_SCACHEFLAG_WAITING;
                if (bufLocked) lock_ReleaseMutex(&bufp->mx);
-                osi_SleepM((long) &scp->flags, &scp->mx);
-                osi_Log0(afsd_logp, "CM SyncOp woke!");
-               if (bufLocked) lock_ObtainMutex(&bufp->mx);
-                lock_ObtainMutex(&scp->mx);
+        osi_SleepM((long) &scp->flags, &scp->mx);
+        osi_Log0(afsd_logp, "CM SyncOp woke!");
+        if (bufLocked) lock_ObtainMutex(&bufp->mx);
+        lock_ObtainMutex(&scp->mx);
         } /* big while loop */
         
         /* now, update the recorded state for RPC-type calls */
@@ -806,7 +810,7 @@ void cm_MergeStatus(cm_scache_t *scp, AFSFetchStatus *statusp, AFSVolSync *volp,
                statusp->UnixModeBits = 0x1ff;
                statusp->ParentVnode = 0x1;
                statusp->ParentUnique = 0x1;
-               statusp->SegSize = 0;
+               statusp->ResidencyMask = 0;
                statusp->ClientModTime = 0x3b49f6e2;
                statusp->ServerModTime = 0x3b49f6e2;
                statusp->Group = 0;
@@ -964,5 +968,60 @@ int cm_FindFileType(cm_fid_t *fidp)
                 }
         }
         lock_ReleaseWrite(&cm_scacheLock);
-        return NULL;
+        return 0;
+}
+
+/* dump all scp's that have reference count > 0 to a file. 
+ * cookie is used to identify this batch for easy parsing, 
+ * and it a string provided by a caller 
+ */
+int cm_DumpSCache(FILE *outputFile, char *cookie)
+{
+    int zilch;
+    cm_scache_t *scp;
+    char output[1024];
+    int i;
+  
+    lock_ObtainRead(&cm_scacheLock);
+  
+    sprintf(output, "%s - dumping scache - cm_currentSCaches=%d, cm_maxSCaches=%d\n", cookie, cm_currentSCaches, cm_maxSCaches);
+    WriteFile(outputFile, output, strlen(output), &zilch, NULL);
+  
+    for (scp = cm_scacheLRULastp; scp; scp = (cm_scache_t *) osi_QPrev(&scp->q)) 
+    {
+        if (scp->refCount != 0)
+        {
+            sprintf(output, "%s fid (cell=%d, volume=%d, vnode=%d, unique=%d) refCount=%d\n", 
+                    cookie, scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique, 
+                    scp->refCount);
+            WriteFile(outputFile, output, strlen(output), &zilch, NULL);
+        }
+    }
+  
+    sprintf(output, "%s - dumping cm_hashTable - cm_hashTableSize=%d\n", cookie, cm_hashTableSize);
+    WriteFile(outputFile, output, strlen(output), &zilch, NULL);
+  
+    for (i = 0; i < cm_hashTableSize; i++)
+    {
+        for(scp = cm_hashTablep[i]; scp; scp=scp->nextp) 
+        {
+            if (scp)
+            {
+                if (scp->refCount)
+                {
+                    sprintf(output, "%s scp=0x%08X, hash=%d, fid (cell=%d, volume=%d, vnode=%d, unique=%d) refCount=%d\n", 
+                            cookie, (void *)scp, i, scp->fid.cell, scp->fid.volume, scp->fid.vnode, 
+                            scp->fid.unique, scp->refCount);
+                    WriteFile(outputFile, output, strlen(output), &zilch, NULL);
+                }
+            }
+        }
+    }
+
+    sprintf(output, "%s - Done dumping scache.\n", cookie);
+    WriteFile(outputFile, output, strlen(output), &zilch, NULL);
+  
+    lock_ReleaseRead(&cm_scacheLock);       
+    return (0);     
 }
+