virtio-blk: Treat read/write beyond end as invalid
The block layer fails such reads and writes just fine. However, they then get treated like valid operations that fail: the error action gets executed. Unwanted; reporting the error to the guest is the only sensible action. Reject them before passing them to the block layer. This bypasses the error action and I/O accounting. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
42e38c1fd0
commit
3c2daac0b9
@ -291,12 +291,19 @@ static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb)
|
||||
static bool virtio_blk_sect_range_ok(VirtIOBlock *dev,
|
||||
uint64_t sector, size_t size)
|
||||
{
|
||||
uint64_t nb_sectors = size >> BDRV_SECTOR_BITS;
|
||||
uint64_t total_sectors;
|
||||
|
||||
if (sector & dev->sector_mask) {
|
||||
return false;
|
||||
}
|
||||
if (size % dev->conf->logical_block_size) {
|
||||
return false;
|
||||
}
|
||||
bdrv_get_geometry(dev->bs, &total_sectors);
|
||||
if (sector > total_sectors || nb_sectors > total_sectors - sector) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user