dm-buffered: fix calculations for prefetch Fix the calculation of "start" and "blocks" when calling dm_bufio_prefetch. Signed-off-by: Mikulas Patocka --- drivers/md/dm-buffered-target.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) Index: linux-2.6/drivers/md/dm-buffered-target.c =================================================================== --- linux-2.6.orig/drivers/md/dm-buffered-target.c +++ linux-2.6/drivers/md/dm-buffered-target.c @@ -272,7 +272,7 @@ static void _process_bio(struct work_str struct buffered_c *bc = container_of(work, struct buffered_c, buffered_ws); struct bio *bio; bool write, queue; - sector_t blocks, start, end; + sector_t blocks, sectors, start, end; spin_lock(&bc->lock); bio = bio_list_pop(&bc->bios); @@ -287,8 +287,11 @@ static void _process_bio(struct work_str /* Prefetch read and partial write buffers */ switch (bio_op(bio)) { case REQ_OP_READ: - blocks = _to_block(bc, bio_end_sector(bio) - bio->bi_iter.bi_sector); - dm_bufio_prefetch(bc->bufio, start, blocks ?: 1); + sectors = bio_end_sector(bio) - (start << bc->block_shift); + blocks = _to_block(bc, sectors); + if (_sector_mod(bc, sectors)) + blocks++; + dm_bufio_prefetch(bc->bufio, start, blocks); break; case REQ_OP_WRITE: write = true;