comparison yaffs_guts.c @ 229:24d738c4d7db

Clean up a bit of messy code and potential GC hole
author charles
date Thu, 30 Oct 2008 18:25:21 +0000
parents bc2b0ab2a7be
children 66bdb92cfbde
comparison
equal deleted inserted replaced
228:bc2b0ab2a7be 229:24d738c4d7db
3013 __u8 *buffer = yaffs_GetTempBuffer(dev, __LINE__); 3013 __u8 *buffer = yaffs_GetTempBuffer(dev, __LINE__);
3014 3014
3015 yaffs_VerifyBlock(dev,bi,block); 3015 yaffs_VerifyBlock(dev,bi,block);
3016 3016
3017 for (chunkInBlock = 0, oldChunk = block * dev->nChunksPerBlock; 3017 for (chunkInBlock = 0, oldChunk = block * dev->nChunksPerBlock;
3018 retVal == YAFFS_OK &&
3018 chunkInBlock < dev->nChunksPerBlock 3019 chunkInBlock < dev->nChunksPerBlock
3019 && yaffs_StillSomeChunkBits(dev, block); 3020 && yaffs_StillSomeChunkBits(dev, block);
3020 chunkInBlock++, oldChunk++) { 3021 chunkInBlock++, oldChunk++) {
3021 if (yaffs_CheckChunkBit(dev, block, chunkInBlock)) { 3022 if (yaffs_CheckChunkBit(dev, block, chunkInBlock)) {
3022 3023
3141 newChunk, 0); 3142 newChunk, 0);
3142 } 3143 }
3143 } 3144 }
3144 } 3145 }
3145 3146
3146 yaffs_DeleteChunk(dev, oldChunk, markNAND, __LINE__); 3147 if(retVal == YAFFS_OK)
3148 yaffs_DeleteChunk(dev, oldChunk, markNAND, __LINE__);
3147 3149
3148 } 3150 }
3149 } 3151 }
3150 3152
3151 yaffs_ReleaseTempBuffer(dev, buffer, __LINE__); 3153 yaffs_ReleaseTempBuffer(dev, buffer, __LINE__);
3183 TENDSTR), chunksBefore, chunksAfter)); 3185 TENDSTR), chunksBefore, chunksAfter));
3184 } 3186 }
3185 3187
3186 dev->isDoingGC = 0; 3188 dev->isDoingGC = 0;
3187 3189
3188 return YAFFS_OK; 3190 return retVal;
3189 } 3191 }
3190 3192
3191 /* New garbage collector 3193 /* New garbage collector
3192 * If we're very low on erased blocks then we do aggressive garbage collection 3194 * If we're very low on erased blocks then we do aggressive garbage collection
3193 * otherwise we do "leasurely" garbage collection. 3195 * otherwise we do "leasurely" garbage collection.
3945 * Then look for the least recently used dirty one...., flush and look again. 3947 * Then look for the least recently used dirty one...., flush and look again.
3946 */ 3948 */
3947 static yaffs_ChunkCache *yaffs_GrabChunkCacheWorker(yaffs_Device * dev) 3949 static yaffs_ChunkCache *yaffs_GrabChunkCacheWorker(yaffs_Device * dev)
3948 { 3950 {
3949 int i; 3951 int i;
3950 int usage;
3951 int theOne;
3952 3952
3953 if (dev->nShortOpCaches > 0) { 3953 if (dev->nShortOpCaches > 0) {
3954 for (i = 0; i < dev->nShortOpCaches; i++) { 3954 for (i = 0; i < dev->nShortOpCaches; i++) {
3955 if (!dev->srCache[i].object) 3955 if (!dev->srCache[i].object)
3956 return &dev->srCache[i]; 3956 return &dev->srCache[i];
3957 } 3957 }
3958 3958 }
3959 return NULL; 3959
3960 3960 return NULL;
3961 theOne = -1;
3962 usage = 0; /* just to stop the compiler grizzling */
3963
3964 for (i = 0; i < dev->nShortOpCaches; i++) {
3965 if (!dev->srCache[i].dirty &&
3966 ((dev->srCache[i].lastUse < usage && theOne >= 0) ||
3967 theOne < 0)) {
3968 usage = dev->srCache[i].lastUse;
3969 theOne = i;
3970 }
3971 }
3972
3973
3974 return theOne >= 0 ? &dev->srCache[theOne] : NULL;
3975 } else {
3976 return NULL;
3977 }
3978
3979 } 3961 }
3980 3962
3981 static yaffs_ChunkCache *yaffs_GrabChunkCache(yaffs_Device * dev) 3963 static yaffs_ChunkCache *yaffs_GrabChunkCache(yaffs_Device * dev)
3982 { 3964 {
3983 yaffs_ChunkCache *cache; 3965 yaffs_ChunkCache *cache;