dm-buffered: fix _buffered_size Fix the calculation in _buffered_size. The number of blocks must be obtained by subtracting bc->start from bdev_nr_sectors, not from ti->len. Signed-off-by: Mikulas Patocka --- drivers/md/dm-buffered-target.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 @@ -158,8 +158,13 @@ static void _complete_memcpy(void *conte static sector_t _buffered_size(struct dm_target *ti) { struct buffered_c *bc = ti->private; + sector_t s = bdev_nr_sectors(bc->dev->bdev); + if (s >= bc->start) + s -= bc->start; + else + s = 0; - return _to_block(bc, ti->len - bc->start) + (_sector_mod(bc, ti->len) ? 1 : 0); + return _to_block(bc, s) + (_sector_mod(bc, s) ? 1 : 0); } static void _memcpy(struct bio *bio, struct buffered_c *bc, struct dm_buffer *bp,