revert-afs-indextimes-in-dcache-20050125
[openafs.git] / src / afs / afs_dcache.c
index d0323ce..f231db2 100644 (file)
@@ -686,7 +686,7 @@ afs_HashOutDCache(struct dcache *adc)
     AFS_STATCNT(afs_glink);
 #endif
     /* we know this guy's in the LRUQ.  We'll move dude into DCQ below */
-    DZap(&adc->f.inode);
+    DZap(adc);
     /* if this guy is in the hash table, pull him out */
     if (adc->f.fid.Fid.Volume != 0) {
        /* remove entry from first hash chains */
@@ -1199,7 +1199,7 @@ afs_FindDCache(register struct vcache *avc, afs_size_t abyte)
 {
     afs_int32 chunk;
     register afs_int32 i, index;
-    register struct dcache *tdc;
+    register struct dcache *tdc = NULL;
 
     AFS_STATCNT(afs_FindDCache);
     chunk = AFS_CHUNK(abyte);
@@ -1526,7 +1526,7 @@ afs_GetDCache(register struct vcache *avc, afs_size_t abyte,
     register struct osi_file *file;
     register struct conn *tc;
     int downDCount = 0;
-    struct server *newCallback;
+    struct server *newCallback = NULL;
     char setNewCallback;
     char setVcacheStatus;
     char doVcacheUpdate;
@@ -1535,7 +1535,7 @@ afs_GetDCache(register struct vcache *avc, afs_size_t abyte,
     int doReallyAdjustSize = 0;
     int overWriteWholeChunk = 0;
 
-    XSTATS_DECLS
+    XSTATS_DECLS;
 #ifndef AFS_NOSTATS
     struct afs_stats_xferData *xferP;  /* Ptr to this op's xfer struct */
     osi_timeval_t xferStartTime,       /*FS xfer start time */
@@ -2038,7 +2038,7 @@ afs_GetDCache(register struct vcache *avc, afs_size_t abyte,
         * Right now, we only have one tool, and it's a hammer.  So, we
         * fetch the whole file.
         */
-       DZap(&tdc->f.inode);    /* pages in cache may be old */
+       DZap(tdc);      /* pages in cache may be old */
 #ifdef  IHINT
        if (file = tdc->ihint) {
            if (tdc->f.inode == file->inum)
@@ -2415,7 +2415,7 @@ afs_GetDCache(register struct vcache *avc, afs_size_t abyte,
            afs_CFileClose(file);
            ZapDCE(tdc);        /* sets DFEntryMod */
            if (vType(avc) == VDIR) {
-               DZap(&tdc->f.inode);
+               DZap(tdc);
            }
            ReleaseWriteLock(&tdc->lock);
            afs_PutDCache(tdc);
@@ -2582,8 +2582,8 @@ afs_WriteThroughDSlots(void)
 {
     register struct dcache *tdc;
     register afs_int32 i, touchedit = 0;
-    struct dcache **ents;
-    int entmax, entcount;
+
+    struct afs_q DirtyQ, *tq;
 
     AFS_STATCNT(afs_WriteThroughDSlots);
 
@@ -2593,9 +2593,7 @@ afs_WriteThroughDSlots(void)
      * for every dcache entry, and exit xdcache.
      */
     MObtainWriteLock(&afs_xdcache, 283);
-    entmax = afs_cacheFiles;
-    ents = afs_osi_Alloc(entmax * sizeof(struct dcache *));
-    entcount = 0;
+    QInit(&DirtyQ);
     for (i = 0; i < afs_cacheFiles; i++) {
        tdc = afs_indexTable[i];
 
@@ -2605,7 +2603,7 @@ afs_WriteThroughDSlots(void)
            tdc->refCount++;
            ReleaseWriteLock(&tdc->tlock);
 
-           ents[entcount++] = tdc;
+           QAdd(&DirtyQ, &tdc->dirty);
        }
     }
     MReleaseWriteLock(&afs_xdcache);
@@ -2616,9 +2614,11 @@ afs_WriteThroughDSlots(void)
      * afs_cacheInodep, and flush it.  Don't forget to put back
      * the refcounts.
      */
-    for (i = 0; i < entcount; i++) {
-       tdc = ents[i];
 
+#define DQTODC(q)      ((struct dcache *)(((char *) (q)) - sizeof(struct afs_q)))
+
+    for (tq = DirtyQ.prev; tq != &DirtyQ; tq = QPrev(tq)) {
+       tdc = DQTODC(tq);
        if (tdc->dflags & DFEntryMod) {
            int wrLock;
 
@@ -2638,7 +2638,6 @@ afs_WriteThroughDSlots(void)
 
        afs_PutDCache(tdc);
     }
-    afs_osi_Free(ents, entmax * sizeof(struct dcache *));
 
     MObtainWriteLock(&afs_xdcache, 617);
     if (!touchedit && (cacheDiskType != AFS_FCACHE_TYPE_MEM)) {
@@ -3272,6 +3271,8 @@ shutdown_dcache(void)
        afs_dchashTbl[i] = NULLIDX;
     }
 
+    afs_osi_Free(afs_dvhashTbl, afs_dhashsize * sizeof(afs_int32));
+    afs_osi_Free(afs_dchashTbl, afs_dhashsize * sizeof(afs_int32));
 
     afs_blocksUsed = afs_dcentries = 0;
     hzero(afs_indexCounter);