From c141a31f83dd7e7e47856d26b801e1532e8d70f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 18 Aug 2010 12:23:38 +0000 Subject: [PATCH] * Fixed CID 1447 which was an actual bug which completely voided the whole discard mechanism eventually causing the conflicts between the file cache and the block cache it intended to fix. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38232 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/cache/block_cache.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/system/kernel/cache/block_cache.cpp b/src/system/kernel/cache/block_cache.cpp index 3de9ff8171..063286ccb9 100644 --- a/src/system/kernel/cache/block_cache.cpp +++ b/src/system/kernel/cache/block_cache.cpp @@ -3382,15 +3382,21 @@ block_cache_sync_etc(void* _cache, off_t blockNumber, size_t numBlocks) } +/*! Discards a block from the current transaction or from the cache. + You have to call this function when you no longer use a block, ie. when it + might be reclaimed by the file cache in order to make sure they won't + interfere. +*/ void block_cache_discard(void* _cache, off_t blockNumber, size_t numBlocks) { + // TODO: this could be a nice place to issue the ATA trim command block_cache* cache = (block_cache*)_cache; TransactionLocker locker(cache); BlockWriter writer(cache); - for (; numBlocks > 0; numBlocks--, blockNumber++) { + for (size_t i = 0; i < numBlocks; i++, blockNumber++) { cached_block* block = (cached_block*)hash_lookup(cache->hash, &blockNumber); if (block != NULL && block->previous_transaction != NULL) @@ -3400,7 +3406,7 @@ block_cache_discard(void* _cache, off_t blockNumber, size_t numBlocks) writer.Write(); // TODO: this can fail, too! - for (; numBlocks > 0; numBlocks--, blockNumber++) { + for (size_t i = 0; i < numBlocks; i++, blockNumber++) { cached_block* block = (cached_block*)hash_lookup(cache->hash, &blockNumber); if (block == NULL)