diff options
-rw-r--r-- | hw/block/virtio-blk.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 02cd6b059a..075e6e626f 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -288,6 +288,18 @@ static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb) bdrv_aio_flush(req->dev->bs, virtio_blk_flush_complete, req); } +static bool virtio_blk_sect_range_ok(VirtIOBlock *dev, + uint64_t sector, size_t size) +{ + if (sector & dev->sector_mask) { + return false; + } + if (size % dev->conf->logical_block_size) { + return false; + } + return true; +} + static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb) { BlockRequest *blkreq; @@ -299,11 +311,7 @@ static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb) trace_virtio_blk_handle_write(req, sector, req->qiov.size / 512); - if (sector & req->dev->sector_mask) { - virtio_blk_rw_complete(req, -EIO); - return; - } - if (req->qiov.size % req->dev->conf->logical_block_size) { + if (!virtio_blk_sect_range_ok(req->dev, sector, req->qiov.size)) { virtio_blk_rw_complete(req, -EIO); return; } @@ -333,11 +341,7 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req) trace_virtio_blk_handle_read(req, sector, req->qiov.size / 512); - if (sector & req->dev->sector_mask) { - virtio_blk_rw_complete(req, -EIO); - return; - } - if (req->qiov.size % req->dev->conf->logical_block_size) { + if (!virtio_blk_sect_range_ok(req->dev, sector, req->qiov.size)) { virtio_blk_rw_complete(req, -EIO); return; } |