yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
0a122b
From d6a03733e6755d4b59f8009239af8f0a3e12c171 Mon Sep 17 00:00:00 2001
0a122b
From: Kevin Wolf <kwolf@redhat.com>
0a122b
Date: Tue, 3 Dec 2013 14:02:23 +0100
0a122b
Subject: [PATCH 13/37] block: Introduce bdrv_aligned_pwritev()
0a122b
0a122b
Message-id: <1392117622-28812-14-git-send-email-kwolf@redhat.com>
0a122b
Patchwork-id: 57178
0a122b
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 13/37] block: Introduce bdrv_aligned_pwritev()
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_writev() 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: Max Reitz <mreitz@redhat.com>
0a122b
Reviewed-by: Benoit Canet <benoit@irqsave.net>
0a122b
(cherry picked from commit b404f72036716ab8ace04b83a8f0a93be4739a6a)
0a122b
0a122b
Conflicts:
0a122b
	block.c
0a122b
0a122b
Conflict 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 | 62 +++++++++++++++++++++++++++++++++++++++++---------------------
0a122b
 1 file changed, 41 insertions(+), 21 deletions(-)
0a122b
---
0a122b
 block.c |   62 +++++++++++++++++++++++++++++++++++++++++---------------------
0a122b
 1 files changed, 41 insertions(+), 21 deletions(-)
0a122b
0a122b
diff --git a/block.c b/block.c
0a122b
index ce3edb0..e6b6ed4 100644
0a122b
--- a/block.c
0a122b
+++ b/block.c
0a122b
@@ -2982,34 +2982,20 @@ static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
0a122b
 }
0a122b
 
0a122b
 /*
0a122b
- * Handle a write request in coroutine context
0a122b
+ * Forwards an already correctly aligned write request to the BlockDriver.
0a122b
  */
0a122b
-static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs,
0a122b
-    int64_t sector_num, int nb_sectors, QEMUIOVector *qiov,
0a122b
-    BdrvRequestFlags flags)
0a122b
+static int coroutine_fn bdrv_aligned_pwritev(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 (!bs->drv) {
0a122b
-        return -ENOMEDIUM;
0a122b
-    }
0a122b
-    if (bs->read_only) {
0a122b
-        return -EACCES;
0a122b
-    }
0a122b
-    if (bdrv_check_request(bs, sector_num, nb_sectors)) {
0a122b
-        return -EIO;
0a122b
-    }
0a122b
-
0a122b
-    /* throttling disk write I/O */
0a122b
-    if (bs->io_limits_enabled) {
0a122b
-        bdrv_io_limits_intercept(bs, true, nb_sectors);
0a122b
-    }
0a122b
+    int64_t sector_num = offset >> BDRV_SECTOR_BITS;
0a122b
+    unsigned int nb_sectors = bytes >> BDRV_SECTOR_BITS;
0a122b
 
0a122b
-    if (bs->copy_on_read_in_flight) {
0a122b
-        wait_for_overlapping_requests(bs, sector_num, nb_sectors);
0a122b
-    }
0a122b
+    assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0);
0a122b
+    assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
0a122b
 
0a122b
     tracked_request_begin(&req, bs, sector_num, nb_sectors, true);
0a122b
 
0a122b
@@ -3039,6 +3025,40 @@ static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs,
0a122b
     return ret;
0a122b
 }
0a122b
 
0a122b
+/*
0a122b
+ * Handle a write request in coroutine context
0a122b
+ */
0a122b
+static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs,
0a122b
+    int64_t sector_num, int nb_sectors, QEMUIOVector *qiov,
0a122b
+    BdrvRequestFlags flags)
0a122b
+{
0a122b
+    int ret;
0a122b
+
0a122b
+    if (!bs->drv) {
0a122b
+        return -ENOMEDIUM;
0a122b
+    }
0a122b
+    if (bs->read_only) {
0a122b
+        return -EACCES;
0a122b
+    }
0a122b
+    if (bdrv_check_request(bs, sector_num, nb_sectors)) {
0a122b
+        return -EIO;
0a122b
+    }
0a122b
+
0a122b
+    if (bs->copy_on_read_in_flight) {
0a122b
+        wait_for_overlapping_requests(bs, sector_num, nb_sectors);
0a122b
+    }
0a122b
+
0a122b
+    /* throttling disk I/O */
0a122b
+    if (bs->io_limits_enabled) {
0a122b
+        bdrv_io_limits_intercept(bs, true, nb_sectors);
0a122b
+    }
0a122b
+
0a122b
+    ret = bdrv_aligned_pwritev(bs, sector_num << BDRV_SECTOR_BITS,
0a122b
+                               nb_sectors << BDRV_SECTOR_BITS, qiov, flags);
0a122b
+
0a122b
+    return ret;
0a122b
+}
0a122b
+
0a122b
 int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
0a122b
     int nb_sectors, QEMUIOVector *qiov)
0a122b
 {
0a122b
-- 
0a122b
1.7.1
0a122b