aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/md/dm-thin.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index 75159cd4c7af..088f6b34f599 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -330,14 +330,20 @@ static void requeue_io(struct thin_c *tc)
330 * target. 330 * target.
331 */ 331 */
332 332
333static bool block_size_is_power_of_two(struct pool *pool)
334{
335 return pool->sectors_per_block_shift >= 0;
336}
337
333static dm_block_t get_bio_block(struct thin_c *tc, struct bio *bio) 338static dm_block_t get_bio_block(struct thin_c *tc, struct bio *bio)
334{ 339{
340 struct pool *pool = tc->pool;
335 sector_t block_nr = bio->bi_sector; 341 sector_t block_nr = bio->bi_sector;
336 342
337 if (tc->pool->sectors_per_block_shift < 0) 343 if (block_size_is_power_of_two(pool))
338 (void) sector_div(block_nr, tc->pool->sectors_per_block); 344 block_nr >>= pool->sectors_per_block_shift;
339 else 345 else
340 block_nr >>= tc->pool->sectors_per_block_shift; 346 (void) sector_div(block_nr, pool->sectors_per_block);
341 347
342 return block_nr; 348 return block_nr;
343} 349}
@@ -348,12 +354,12 @@ static void remap(struct thin_c *tc, struct bio *bio, dm_block_t block)
348 sector_t bi_sector = bio->bi_sector; 354 sector_t bi_sector = bio->bi_sector;
349 355
350 bio->bi_bdev = tc->pool_dev->bdev; 356 bio->bi_bdev = tc->pool_dev->bdev;
351 if (tc->pool->sectors_per_block_shift < 0) 357 if (block_size_is_power_of_two(pool))
352 bio->bi_sector = (block * pool->sectors_per_block) +
353 sector_div(bi_sector, pool->sectors_per_block);
354 else
355 bio->bi_sector = (block << pool->sectors_per_block_shift) | 358 bio->bi_sector = (block << pool->sectors_per_block_shift) |
356 (bi_sector & (pool->sectors_per_block - 1)); 359 (bi_sector & (pool->sectors_per_block - 1));
360 else
361 bio->bi_sector = (block * pool->sectors_per_block) +
362 sector_div(bi_sector, pool->sectors_per_block);
357} 363}
358 364
359static void remap_to_origin(struct thin_c *tc, struct bio *bio) 365static void remap_to_origin(struct thin_c *tc, struct bio *bio)
@@ -2425,11 +2431,6 @@ static int pool_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
2425 return min(max_size, q->merge_bvec_fn(q, bvm, biovec)); 2431 return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
2426} 2432}
2427 2433
2428static bool block_size_is_power_of_two(struct pool *pool)
2429{
2430 return pool->sectors_per_block_shift >= 0;
2431}
2432
2433static void set_discard_limits(struct pool_c *pt, struct queue_limits *limits) 2434static void set_discard_limits(struct pool_c *pt, struct queue_limits *limits)
2434{ 2435{
2435 struct pool *pool = pt->pool; 2436 struct pool *pool = pt->pool;