From 1c97fda42576367e263f8c928c060271787ad1c1 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Thu, 26 Apr 2018 13:13:27 +0100 Subject: [PATCH] [bcache] get all unit tests passing again --- lib/device/bcache.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/lib/device/bcache.c b/lib/device/bcache.c index ea8f70299..641838f14 100644 --- a/lib/device/bcache.c +++ b/lib/device/bcache.c @@ -537,29 +537,16 @@ static void _complete_io(void *context, int err) */ dm_list_del(&b->list); - if (b->error) - memset(b->data, 0, cache->block_sectors << SECTOR_SHIFT); - /* Things don't work with this block of code, but work without it. */ -#if 0 if (b->error) { log_warn("bcache io error %d fd %d", b->error, b->fd); - if (b->io_dir == DIR_READ) { - // We can just forget about this block, since there's - // no dirty data to be written back. - _hash_remove(b); - dm_list_add(&cache->free, &b->list); - } else - dm_list_add(&cache->errored, &b->list); + dm_list_add(&cache->errored, &b->list); } else { _clear_flags(b, BF_DIRTY); _link_block(b); } -#endif - _clear_flags(b, BF_DIRTY); - _link_block(b); } /* @@ -908,17 +895,23 @@ bool bcache_get(struct bcache *cache, int fd, block_address index, b = _lookup_or_read_block(cache, fd, index, flags); if (b) { + if (b->error) { + if (b->io_dir == DIR_READ) { + // Now we know the read failed we can just forget + // about this block, since there's no dirty data to + // be written back. + _hash_remove(b); + dm_list_add(&cache->free, &b->list); + } + *error = b->error; + return false; + } + if (!b->ref_count) cache->nr_locked++; b->ref_count++; *result = b; - - if (error) - *error = b->error; - - if (b->error) - return false; return true; }