X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=yaffs_guts.c;h=60227dffee59c50da79f5b13754e2dde20e73c26;hp=ff6e9932a769f94185b20b799125b2ebe03bf8f1;hb=69eb82df82adeab5210e170f85d0e08610b728a6;hpb=0c0fee7366b8a5a26ce11cf44675f22ab818cbc8;ds=sidebyside diff --git a/yaffs_guts.c b/yaffs_guts.c index ff6e993..60227df 100644 --- a/yaffs_guts.c +++ b/yaffs_guts.c @@ -12,7 +12,7 @@ */ const char *yaffs_guts_c_version = - "$Id: yaffs_guts.c,v 1.111 2010-03-02 02:29:21 charles Exp $"; + "$Id: yaffs_guts.c,v 1.114 2010-03-07 22:07:03 charles Exp $"; #include "yportenv.h" #include "yaffs_trace.h" @@ -404,16 +404,19 @@ static int yaffs_CountChunkBits(yaffs_Device *dev, int blk) static int yaffs_SkipVerification(yaffs_Device *dev) { + dev=dev; return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY | YAFFS_TRACE_VERIFY_FULL)); } static int yaffs_SkipFullVerification(yaffs_Device *dev) { + dev=dev; return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY_FULL)); } static int yaffs_SkipNANDVerification(yaffs_Device *dev) { + dev=dev; return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY_NAND)); } @@ -1044,6 +1047,75 @@ static int yaffs_WriteNewChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev, return chunk; } + +/* + * Oldest Dirty Sequence Number handling. + */ + +/* yaffs_CalcOldestDirtySequence() + * yaffs_FindOldestDirtySequence() + * Calculate the oldest dirty sequence number if we don't know it. + */ +static int yaffs_CalcOldestDirtySequence(yaffs_Device *dev) +{ + int i; + __u32 seq; + yaffs_BlockInfo *b = 0; + + + /* Find the oldest dirty sequence number. */ + seq = dev->sequenceNumber; + for (i = dev->internalStartBlock; i <= dev->internalEndBlock; i++) { + b = yaffs_GetBlockInfo(dev, i); + if (b->blockState == YAFFS_BLOCK_STATE_FULL && + (b->pagesInUse - b->softDeletions) < dev->param.nChunksPerBlock && + b->sequenceNumber < seq) + seq = b->sequenceNumber; + } + return seq; +} + + +static void yaffs_FindOldestDirtySequence(yaffs_Device *dev) +{ + if(!dev->oldestDirtySequence) + dev->oldestDirtySequence = + yaffs_CalcOldestDirtySequence(dev); + +#if 0 + if(!yaffs_SkipVerification(dev) && + dev->oldestDirtySequence != yaffs_CalcOldestDirtySequence(dev)) + YBUG(); + +#endif +} + +/* + * yaffs_ClearOldestDirtySequence() + * Called when a block is erased or marked bad. (ie. when its sequenceNumber + * becomes invalid). If the value matches the oldest then we clear + * dev->oldestDirtySequence to force its recomputation. + */ +static void yaffs_ClearOldestDirtySequence(yaffs_Device *dev, yaffs_BlockInfo *bi) +{ + + if(!bi || bi->sequenceNumber == dev->oldestDirtySequence) + dev->oldestDirtySequence = 0; +} + +/* + * yaffs_UpdateOldestDirtySequence() + * Update the oldest dirty sequence number whenever we dirty a block. + * Only do this if the oldestDirtySequence is actually being tracked. + */ +static void yaffs_UpdateOldestDirtySequence(yaffs_Device *dev, yaffs_BlockInfo *bi) +{ + if(dev->oldestDirtySequence){ + if(dev->oldestDirtySequence > bi->sequenceNumber) + dev->oldestDirtySequence = bi->sequenceNumber; + } +} + /* * Block retiring for handling a broken block. */ @@ -1053,6 +1125,8 @@ static void yaffs_RetireBlock(yaffs_Device *dev, int blockInNAND) yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, blockInNAND); yaffs_InvalidateCheckpoint(dev); + + yaffs_ClearOldestDirtySequence(dev,bi); if (yaffs_MarkBlockBad(dev, blockInNAND) != YAFFS_OK) { if (yaffs_EraseBlockInNAND(dev, blockInNAND) != YAFFS_OK) { @@ -1094,11 +1168,18 @@ static void yaffs_HandleWriteChunkOk(yaffs_Device *dev, int chunkInNAND, const __u8 *data, const yaffs_ExtendedTags *tags) { + dev=dev; + chunkInNAND=chunkInNAND; + data=data; + tags=tags; } static void yaffs_HandleUpdateChunk(yaffs_Device *dev, int chunkInNAND, const yaffs_ExtendedTags *tags) { + dev=dev; + chunkInNAND=chunkInNAND; + tags=tags; } void yaffs_HandleChunkError(yaffs_Device *dev, yaffs_BlockInfo *bi) @@ -1446,6 +1527,8 @@ static yaffs_Tnode *yaffs_FindLevel0Tnode(yaffs_Device *dev, int requiredTallness; int level = fStruct->topLevel; + dev=dev; + /* Check sane level and chunk Id */ if (level < 0 || level > YAFFS_TNODES_MAX_LEVEL) return NULL; @@ -2653,9 +2736,6 @@ static void yaffs_DeinitialiseBlocks(yaffs_Device *dev) static int yaffs_BlockNotDisqualifiedFromGC(yaffs_Device *dev, yaffs_BlockInfo *bi) { - int i; - __u32 seq; - yaffs_BlockInfo *b; if (!dev->param.isYaffs2) return 1; /* disqualification only applies to yaffs2. */ @@ -2663,23 +2743,7 @@ static int yaffs_BlockNotDisqualifiedFromGC(yaffs_Device *dev, if (!bi->hasShrinkHeader) return 1; /* can gc */ - /* Find the oldest dirty sequence number if we don't know it and save it - * so we don't have to keep recomputing it. - */ - if (!dev->oldestDirtySequence) { - seq = dev->sequenceNumber; - - for (i = dev->internalStartBlock; i <= dev->internalEndBlock; - i++) { - b = yaffs_GetBlockInfo(dev, i); - if (b->blockState == YAFFS_BLOCK_STATE_FULL && - (b->pagesInUse - b->softDeletions) < - dev->param.nChunksPerBlock && b->sequenceNumber < seq) { - seq = b->sequenceNumber; - } - } - dev->oldestDirtySequence = seq; - } + yaffs_FindOldestDirtySequence(dev); /* Can't do gc of this block if there are any blocks older than this one that have * discarded pages. @@ -2847,8 +2911,6 @@ static int yaffs_FindBlockForGarbageCollection(yaffs_Device *dev, dev->param.nChunksPerBlock - pagesInUse, prioritised)); } - dev->oldestDirtySequence = 0; - if (dirtiest > 0) dev->nonAggressiveSkip = 4; @@ -2869,6 +2931,8 @@ static void yaffs_BlockBecameDirty(yaffs_Device *dev, int blockNo) (TSTR("yaffs_BlockBecameDirty block %d state %d %s"TENDSTR), blockNo, bi->blockState, (bi->needsRetiring) ? "needs retiring" : "")); + yaffs_ClearOldestDirtySequence(dev,bi); + bi->blockState = YAFFS_BLOCK_STATE_DIRTY; if (!bi->needsRetiring) { @@ -3741,6 +3805,8 @@ void yaffs_DeleteChunk(yaffs_Device *dev, int chunkId, int markNAND, int lyn) chunkId)); bi = yaffs_GetBlockInfo(dev, block); + + yaffs_UpdateOldestDirtySequence(dev,bi); T(YAFFS_TRACE_DELETION, (TSTR("line %d delete of chunk %d" TENDSTR), lyn, chunkId)); @@ -4315,7 +4381,6 @@ static void yaffs_DeviceToCheckpointDevice(yaffs_CheckpointDevice *cp, cp->nUnlinkedFiles = dev->nUnlinkedFiles; cp->nBackgroundDeletions = dev->nBackgroundDeletions; cp->sequenceNumber = dev->sequenceNumber; - cp->oldestDirtySequence = dev->oldestDirtySequence; } @@ -4331,7 +4396,6 @@ static void yaffs_CheckpointDeviceToDevice(yaffs_Device *dev, dev->nUnlinkedFiles = cp->nUnlinkedFiles; dev->nBackgroundDeletions = cp->nBackgroundDeletions; dev->sequenceNumber = cp->sequenceNumber; - dev->oldestDirtySequence = cp->oldestDirtySequence; } @@ -5207,7 +5271,6 @@ int yaffs_ResizeFile(yaffs_Object *in, loff_t newSize) in->variant.fileVariant.fileSize = newSize; } - /* Write a new object header to reflect the resize. * show we've shrunk the file, if need be * Do this only if the file is not in the deleted directories @@ -7603,6 +7666,7 @@ int yaffs_GutsInitialise(yaffs_Device *dev) dev->nErasedBlocks = 0; dev->isDoingGC = 0; dev->hasPendingPrioritisedGCs = 1; /* Assume the worst for now, will get fixed on first GC */ + dev->oldestDirtySequence = 0; /* Initialise temporary buffers and caches. */ if (!yaffs_InitialiseTempBuffers(dev)) @@ -7685,7 +7749,6 @@ int yaffs_GutsInitialise(yaffs_Device *dev) dev->nDeletedFiles = 0; dev->nUnlinkedFiles = 0; dev->nBackgroundDeletions = 0; - dev->oldestDirtySequence = 0; if (!init_failed && !yaffs_InitialiseBlocks(dev)) init_failed = 1;