dm-bufio: allow access to the partial buffer at the end of the device If the device size is not divisible by the buffer size, dm-bufio would return an I/O error when accessing the last partial buffer on the device. This commit changes it so that it can access the partial buffer. This change is needed to resolve a dm-buffered error when accessing the last buffer on the device. Signed-off-by: Mikulas Patocka --- drivers/md/dm-bufio.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) Index: linux-2.6/drivers/md/dm-bufio.c =================================================================== --- linux-2.6.orig/drivers/md/dm-bufio.c +++ linux-2.6/drivers/md/dm-bufio.c @@ -1361,7 +1361,7 @@ static void submit_io(struct dm_buffer * void (*end_io)(struct dm_buffer *, blk_status_t)) { unsigned int n_sectors; - sector_t sector; + sector_t sector, sector_limit; unsigned int offset, end; b->end_io = end_io; @@ -1386,6 +1386,19 @@ static void submit_io(struct dm_buffer * n_sectors = (end - offset) >> SECTOR_SHIFT; } + sector_limit = bdev_nr_sectors(b->c->bdev); + if (unlikely(sector + n_sectors <= sector) || + unlikely(sector + n_sectors > sector_limit)) { + if (sector < sector_limit) { + n_sectors = sector_limit - sector; + if (op == REQ_OP_READ) + memset(b->data, 0, b->c->block_size); + } else { + b->end_io(b, BLK_STS_NOSPC); + return; + } + } + if (b->data_mode != DATA_MODE_VMALLOC) use_bio(b, op, sector, n_sectors, offset); else