diff options
author | Joe Thornber <ejt@redhat.com> | 2014-11-06 09:38:01 -0500 |
---|---|---|
committer | Mike Snitzer <snitzer@redhat.com> | 2014-11-10 15:25:30 -0500 |
commit | 08b184514f65d160ce66381dafca5962e3d8f785 (patch) | |
tree | f33736579d5c7401524f4deb9af1d3c31cd48ad3 /drivers/md | |
parent | 1bad9bc4ee899a108499e5eac6baafff018b4d0b (diff) |
dm cache: revert "prevent corruption caused by discard_block_size > cache_block_size"
This reverts commit d132cc6d9e92424bb9d4fd35f5bd0e55d583f4be because we
actually do want to allow the discard blocksize to be larger than the
cache blocksize. Further dm-cache discard changes will make this
possible.
Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/dm-cache-target.c | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c index ced7fd4adddb..c2ca74374944 100644 --- a/drivers/md/dm-cache-target.c +++ b/drivers/md/dm-cache-target.c | |||
@@ -238,7 +238,7 @@ struct cache { | |||
238 | */ | 238 | */ |
239 | dm_dblock_t discard_nr_blocks; | 239 | dm_dblock_t discard_nr_blocks; |
240 | unsigned long *discard_bitset; | 240 | unsigned long *discard_bitset; |
241 | uint32_t discard_block_size; | 241 | uint32_t discard_block_size; /* a power of 2 times sectors per block */ |
242 | 242 | ||
243 | /* | 243 | /* |
244 | * Rather than reconstructing the table line for the status we just | 244 | * Rather than reconstructing the table line for the status we just |
@@ -2197,6 +2197,35 @@ static int create_cache_policy(struct cache *cache, struct cache_args *ca, | |||
2197 | return 0; | 2197 | return 0; |
2198 | } | 2198 | } |
2199 | 2199 | ||
2200 | /* | ||
2201 | * We want the discard block size to be a power of two, at least the size | ||
2202 | * of the cache block size, and have no more than 2^14 discard blocks | ||
2203 | * across the origin. | ||
2204 | */ | ||
2205 | #define MAX_DISCARD_BLOCKS (1 << 14) | ||
2206 | |||
2207 | static bool too_many_discard_blocks(sector_t discard_block_size, | ||
2208 | sector_t origin_size) | ||
2209 | { | ||
2210 | (void) sector_div(origin_size, discard_block_size); | ||
2211 | |||
2212 | return origin_size > MAX_DISCARD_BLOCKS; | ||
2213 | } | ||
2214 | |||
2215 | static sector_t calculate_discard_block_size(sector_t cache_block_size, | ||
2216 | sector_t origin_size) | ||
2217 | { | ||
2218 | sector_t discard_block_size; | ||
2219 | |||
2220 | discard_block_size = roundup_pow_of_two(cache_block_size); | ||
2221 | |||
2222 | if (origin_size) | ||
2223 | while (too_many_discard_blocks(discard_block_size, origin_size)) | ||
2224 | discard_block_size *= 2; | ||
2225 | |||
2226 | return discard_block_size; | ||
2227 | } | ||
2228 | |||
2200 | #define DEFAULT_MIGRATION_THRESHOLD 2048 | 2229 | #define DEFAULT_MIGRATION_THRESHOLD 2048 |
2201 | 2230 | ||
2202 | static int cache_create(struct cache_args *ca, struct cache **result) | 2231 | static int cache_create(struct cache_args *ca, struct cache **result) |
@@ -2320,7 +2349,9 @@ static int cache_create(struct cache_args *ca, struct cache **result) | |||
2320 | } | 2349 | } |
2321 | clear_bitset(cache->dirty_bitset, from_cblock(cache->cache_size)); | 2350 | clear_bitset(cache->dirty_bitset, from_cblock(cache->cache_size)); |
2322 | 2351 | ||
2323 | cache->discard_block_size = cache->sectors_per_block; | 2352 | cache->discard_block_size = |
2353 | calculate_discard_block_size(cache->sectors_per_block, | ||
2354 | cache->origin_sectors); | ||
2324 | cache->discard_nr_blocks = oblock_to_dblock(cache, cache->origin_blocks); | 2355 | cache->discard_nr_blocks = oblock_to_dblock(cache, cache->origin_blocks); |
2325 | cache->discard_bitset = alloc_bitset(from_dblock(cache->discard_nr_blocks)); | 2356 | cache->discard_bitset = alloc_bitset(from_dblock(cache->discard_nr_blocks)); |
2326 | if (!cache->discard_bitset) { | 2357 | if (!cache->discard_bitset) { |
@@ -3099,7 +3130,7 @@ static void set_discard_limits(struct cache *cache, struct queue_limits *limits) | |||
3099 | /* | 3130 | /* |
3100 | * FIXME: these limits may be incompatible with the cache device | 3131 | * FIXME: these limits may be incompatible with the cache device |
3101 | */ | 3132 | */ |
3102 | limits->max_discard_sectors = cache->discard_block_size; | 3133 | limits->max_discard_sectors = cache->discard_block_size * 1024; |
3103 | limits->discard_granularity = cache->discard_block_size << SECTOR_SHIFT; | 3134 | limits->discard_granularity = cache->discard_block_size << SECTOR_SHIFT; |
3104 | } | 3135 | } |
3105 | 3136 | ||