From: Joe Thornber Date: Fri, 31 Mar 2017 14:09:45 +0000 (-0400) Subject: dm cache: set/clear the cache core's dirty_bitset when loading mappings X-Git-Tag: v4.12-rc1~120^2~33 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=449b668ce0b9069fcaafa6344c7f10fa2ba9632e;p=karo-tx-linux.git dm cache: set/clear the cache core's dirty_bitset when loading mappings When loading metadata make sure to set/clear the dirty bits in the cache core's dirty_bitset as well as the policy. Otherwise the cache core is unaware that any blocks were dirty when the cache was last shutdown. A very serious side-effect being that the cleaner policy would therefore never be tasked with writing back dirty data from a cache that was in writeback mode (e.g. when switching from smq policy to cleaner policy when decommissioning a writeback cache). This fixes a serious data corruption bug associated with writeback mode. Signed-off-by: Joe Thornber Signed-off-by: Mike Snitzer --- diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c index b7de289a10bb..6e747fcbdf0f 100644 --- a/drivers/md/dm-cache-target.c +++ b/drivers/md/dm-cache-target.c @@ -2960,6 +2960,12 @@ static int load_mapping(void *context, dm_oblock_t oblock, dm_cblock_t cblock, int r; struct cache *cache = context; + if (dirty) { + set_bit(from_cblock(cblock), cache->dirty_bitset); + atomic_inc(&cache->nr_dirty); + } else + clear_bit(from_cblock(cblock), cache->dirty_bitset); + r = policy_load_mapping(cache->policy, oblock, cblock, dirty, hint, hint_valid); if (r) return r;