yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-virtio-blk-Factor-common-checks-out-of-virtio_blk_ha.patch

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