cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
0a122b
From d5b3c858d7d2d96cf89495c95c2f07eb246b6730 Mon Sep 17 00:00:00 2001
0a122b
From: Kevin Wolf <kwolf@redhat.com>
0a122b
Date: Mon, 2 Dec 2013 15:07:48 +0100
0a122b
Subject: [PATCH 11/37] block: Introduce bdrv_aligned_preadv()
0a122b
0a122b
Message-id: <1392117622-28812-12-git-send-email-kwolf@redhat.com>
0a122b
Patchwork-id: 57176
0a122b
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 11/37] block: Introduce bdrv_aligned_preadv()
0a122b
Bugzilla: 748906
0a122b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
RH-Acked-by: Max Reitz <mreitz@redhat.com>
0a122b
0a122b
This separates the part of bdrv_co_do_readv() that needs to happen
0a122b
before the request is modified to match the backend alignment, and a
0a122b
part that needs to be executed afterwards and passes the request to the
0a122b
BlockDriver.
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
Reviewed-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
0a122b
Reviewed-by: Max Reitz <mreitz@redhat.com>
0a122b
(cherry picked from commit d0c7f642f5eb2cb21d0c3acf766cb375eaaf4666)
0a122b
0a122b
Conflicts:
0a122b
	block.c
0a122b
0a122b
Conflicts because RHEL 7 still has the old I/O throttling code.
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
---
0a122b
 block.c | 59 ++++++++++++++++++++++++++++++++++++++++++-----------------
0a122b
 1 file changed, 42 insertions(+), 17 deletions(-)
0a122b
---
0a122b
 block.c |   59 ++++++++++++++++++++++++++++++++++++++++++-----------------
0a122b
 1 files changed, 42 insertions(+), 17 deletions(-)
0a122b
0a122b
diff --git a/block.c b/block.c
0a122b
index 40a4a34..1787ab0 100644
0a122b
--- a/block.c
0a122b
+++ b/block.c
0a122b
@@ -2723,31 +2723,24 @@ err:
0a122b
 }
0a122b
 
0a122b
 /*
0a122b
- * Handle a read request in coroutine context
0a122b
+ * Forwards an already correctly aligned request to the BlockDriver. This
0a122b
+ * handles copy on read and zeroing after EOF; any other features must be
0a122b
+ * implemented by the caller.
0a122b
  */
0a122b
-static int coroutine_fn bdrv_co_do_readv(BlockDriverState *bs,
0a122b
-    int64_t sector_num, int nb_sectors, QEMUIOVector *qiov,
0a122b
-    BdrvRequestFlags flags)
0a122b
+static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs,
0a122b
+    int64_t offset, unsigned int bytes, QEMUIOVector *qiov, int flags)
0a122b
 {
0a122b
     BlockDriver *drv = bs->drv;
0a122b
     BdrvTrackedRequest req;
0a122b
     int ret;
0a122b
 
0a122b
-    if (!drv) {
0a122b
-        return -ENOMEDIUM;
0a122b
-    }
0a122b
-    if (bdrv_check_request(bs, sector_num, nb_sectors)) {
0a122b
-        return -EIO;
0a122b
-    }
0a122b
+    int64_t sector_num = offset >> BDRV_SECTOR_BITS;
0a122b
+    unsigned int nb_sectors = bytes >> BDRV_SECTOR_BITS;
0a122b
 
0a122b
-    /* throttling disk read I/O */
0a122b
-    if (bs->io_limits_enabled) {
0a122b
-        bdrv_io_limits_intercept(bs, false, nb_sectors);
0a122b
-    }
0a122b
+    assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0);
0a122b
+    assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
0a122b
 
0a122b
-    if (bs->copy_on_read) {
0a122b
-        flags |= BDRV_REQ_COPY_ON_READ;
0a122b
-    }
0a122b
+    /* Handle Copy on Read and associated serialisation */
0a122b
     if (flags & BDRV_REQ_COPY_ON_READ) {
0a122b
         bs->copy_on_read_in_flight++;
0a122b
     }
0a122b
@@ -2772,6 +2765,7 @@ static int coroutine_fn bdrv_co_do_readv(BlockDriverState *bs,
0a122b
         }
0a122b
     }
0a122b
 
0a122b
+    /* Forward the request to the BlockDriver */
0a122b
     if (!(bs->zero_beyond_eof && bs->growable)) {
0a122b
         ret = drv->bdrv_co_readv(bs, sector_num, nb_sectors, qiov);
0a122b
     } else {
0a122b
@@ -2812,6 +2806,37 @@ out:
0a122b
     return ret;
0a122b
 }
0a122b
 
0a122b
+/*
0a122b
+ * Handle a read request in coroutine context
0a122b
+ */
0a122b
+static int coroutine_fn bdrv_co_do_readv(BlockDriverState *bs,
0a122b
+    int64_t sector_num, int nb_sectors, QEMUIOVector *qiov,
0a122b
+    BdrvRequestFlags flags)
0a122b
+{
0a122b
+    BlockDriver *drv = bs->drv;
0a122b
+    int ret;
0a122b
+
0a122b
+    if (!drv) {
0a122b
+        return -ENOMEDIUM;
0a122b
+    }
0a122b
+    if (bdrv_check_request(bs, sector_num, nb_sectors)) {
0a122b
+        return -EIO;
0a122b
+    }
0a122b
+
0a122b
+    if (bs->copy_on_read) {
0a122b
+        flags |= BDRV_REQ_COPY_ON_READ;
0a122b
+    }
0a122b
+
0a122b
+    /* throttling disk I/O */
0a122b
+    if (bs->io_limits_enabled) {
0a122b
+        bdrv_io_limits_intercept(bs, false, nb_sectors);
0a122b
+    }
0a122b
+
0a122b
+    ret = bdrv_aligned_preadv(bs, sector_num << BDRV_SECTOR_BITS,
0a122b
+                             nb_sectors << BDRV_SECTOR_BITS, qiov, flags);
0a122b
+    return ret;
0a122b
+}
0a122b
+
0a122b
 int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
0a122b
     int nb_sectors, QEMUIOVector *qiov)
0a122b
 {
0a122b
-- 
0a122b
1.7.1
0a122b