|
|
9ae3a8 |
From 08530984c8ea08a6e0494e91576ff24917c46e14 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
Date: Fri, 31 Oct 2014 16:29:52 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 15/19] virtio-blk: Factor common checks out of
|
|
|
9ae3a8 |
virtio_blk_handle_read/write()
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Message-id: <1414772996-17272-2-git-send-email-armbru@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 62018
|
|
|
9ae3a8 |
O-Subject: [PATCH RHEL-7.1 qemu-kvm 1/5] virtio-blk: Factor common checks out of virtio_blk_handle_read/write()
|
|
|
9ae3a8 |
Bugzilla: 1085232
|
|
|
9ae3a8 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit d0e14376eefc40b07c8fb42c132c2202c66dcb0b)
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
hw/block/virtio-blk.c | 24 ++++++++++++++----------
|
|
|
9ae3a8 |
1 file changed, 14 insertions(+), 10 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
|
|
|
9ae3a8 |
index a96207d..0f1d3ec 100644
|
|
|
9ae3a8 |
--- a/hw/block/virtio-blk.c
|
|
|
9ae3a8 |
+++ b/hw/block/virtio-blk.c
|
|
|
9ae3a8 |
@@ -281,6 +281,18 @@ static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb)
|
|
|
9ae3a8 |
bdrv_aio_flush(req->dev->bs, virtio_blk_flush_complete, req);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+static bool virtio_blk_sect_range_ok(VirtIOBlock *dev,
|
|
|
9ae3a8 |
+ uint64_t sector, size_t size)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ if (sector & dev->sector_mask) {
|
|
|
9ae3a8 |
+ return false;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (size % dev->conf->logical_block_size) {
|
|
|
9ae3a8 |
+ return false;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ return true;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
BlockRequest *blkreq;
|
|
|
9ae3a8 |
@@ -292,11 +304,7 @@ static void virtio_blk_handle_write(VirtIOBlockReq *req, MultiReqBuffer *mrb)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
trace_virtio_blk_handle_write(req, sector, req->qiov.size / 512);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (sector & req->dev->sector_mask) {
|
|
|
9ae3a8 |
- virtio_blk_rw_complete(req, -EIO);
|
|
|
9ae3a8 |
- return;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- if (req->qiov.size % req->dev->conf->logical_block_size) {
|
|
|
9ae3a8 |
+ if (!virtio_blk_sect_range_ok(req->dev, sector, req->qiov.size)) {
|
|
|
9ae3a8 |
virtio_blk_rw_complete(req, -EIO);
|
|
|
9ae3a8 |
return;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -326,11 +334,7 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
trace_virtio_blk_handle_read(req, sector, req->qiov.size / 512);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (sector & req->dev->sector_mask) {
|
|
|
9ae3a8 |
- virtio_blk_rw_complete(req, -EIO);
|
|
|
9ae3a8 |
- return;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- if (req->qiov.size % req->dev->conf->logical_block_size) {
|
|
|
9ae3a8 |
+ if (!virtio_blk_sect_range_ok(req->dev, sector, req->qiov.size)) {
|
|
|
9ae3a8 |
virtio_blk_rw_complete(req, -EIO);
|
|
|
9ae3a8 |
return;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|