Skip to contentSkip to conversation

dm-cache: resize_cache_dev resizing to wrong size ?

PATCH Vincent Pelletier 2 participants 2 messages Nov 30, 2013 – Dec 2, 2013 Device mapper

lore
Share & tools
lore
#0 lore raw

Hi.

CC'ing f494a9c6b1b6dd9a9f21bbb75d9210d478eeb498 author. Please keep me CC'ed in replies, I'm not subscribed.

Wandering aimlessly in dm-cache source as of current linus master (3.13-rc2, dc1ccc48159d63eca5089e507c82c7d22ef60839), I noticed this:

dm-cache-metadata.c:
int dm_cache_resize(struct dm_cache_metadata *cmd, dm_cblock_t new_cache_size)

Note second argument is new_cache_size. But caller is doing:

dm-cache-target.c:
static int resize_cache_dev(struct cache *cache, dm_cblock_t new_size) [...]

    r = dm_cache_resize(cache->cmd, cache->cache_size);
  [...]
    cache->cache_size = new_size;

dm_cache_resize is called with cache->cache_size before it gets updated to new_size, so it looks like a no-op.

Can someone confirm my reading ?

If confirmed, the effect is that a shrink (only ? I'm not familiar with cache metadata) operation can result in metadata inconsistent with cache device size.

See attachment for proposed (untested) fix.
It applies cleanly as of current device-mapper for-next branch.

Regards,

Signature · 1 line
Vincent Pelletier

From 99fe12976eae6abd67be0c39798c61ca9acd683d Mon Sep 17 00:00:00 2001
Message-Id: <99fe12976eae6abd67be0c39798c61ca9acd683d.1385805937.git.plr.vincent@gmail.com>
From: Vincent Pelletier <[email protected]>
Date: Sat, 30 Nov 2013 11:05:12 +0100
Subject: dm cache: actually shrink cache to new size

---
 drivers/md/dm-cache-target.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-cache-target.c +1 -1
index 9efcf10..1b1469e 100644
@@ -2755,7 +2755,7 @@ static int resize_cache_dev(struct cache *cache, dm_cblock_t new_size)
 {
 	int r;
 
-	r = dm_cache_resize(cache->cmd, cache->cache_size);
+	r = dm_cache_resize(cache->cmd, new_size);
 	if (r) {
 		DMERR("could not resize cache metadata");
 		return r;
Signature · 1 line
1.8.4.4
#1 lore raw
Quoted 1 line · Vincent Pelletier

Can someone confirm my reading ?

Confirmed. What confused me for a bit was why the tests were passing:

https://github.com/jthornber/device-mapper-test-suite/blob/master/lib/dmtest/tests/cache/resize_tests.rb

This bug means the superblock *will* record the new cache size, but the arrays will not be resized.

The cache_check tool needs to be improved to spot this. At the moment it just checks that the btree is full of valid array blocks, and determines missing ranges for damaged trees. In our case the trees are fine, just not big enough.

I also think I need to add more tests that force data migration on a newly resized cache.

Thanks,

- Joe