yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-Change-coroutine-wrapper-to-byte-granularity.patch

0a122b
From 72bba55d794ac3e3ecaadb8e0bc382947b6f17ea Mon Sep 17 00:00:00 2001
0a122b
From: Kevin Wolf <kwolf@redhat.com>
0a122b
Date: Thu, 5 Dec 2013 12:09:38 +0100
0a122b
Subject: [PATCH 27/37] block: Change coroutine wrapper to byte granularity
0a122b
0a122b
Message-id: <1392117622-28812-28-git-send-email-kwolf@redhat.com>
0a122b
Patchwork-id: 57192
0a122b
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 27/37] block: Change coroutine wrapper to byte granularity
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
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
Reviewed-by: Max Reitz <mreitz@redhat.com>
0a122b
(cherry picked from commit 775aa8b6e0ea25f8cca74d0fcb1e30a764cf624f)
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
---
0a122b
 block.c | 48 ++++++++++++++++++++++++++----------------------
0a122b
 1 file changed, 26 insertions(+), 22 deletions(-)
0a122b
---
0a122b
 block.c |   48 ++++++++++++++++++++++++++----------------------
0a122b
 1 files changed, 26 insertions(+), 22 deletions(-)
0a122b
0a122b
diff --git a/block.c b/block.c
0a122b
index 76de7d2..3b5b706 100644
0a122b
--- a/block.c
0a122b
+++ b/block.c
0a122b
@@ -64,11 +64,11 @@ static int coroutine_fn bdrv_co_readv_em(BlockDriverState *bs,
0a122b
 static int coroutine_fn bdrv_co_writev_em(BlockDriverState *bs,
0a122b
                                          int64_t sector_num, int nb_sectors,
0a122b
                                          QEMUIOVector *iov);
0a122b
-static int coroutine_fn bdrv_co_do_readv(BlockDriverState *bs,
0a122b
-    int64_t sector_num, int nb_sectors, QEMUIOVector *qiov,
0a122b
+static int coroutine_fn bdrv_co_do_preadv(BlockDriverState *bs,
0a122b
+    int64_t offset, unsigned int bytes, QEMUIOVector *qiov,
0a122b
     BdrvRequestFlags flags);
0a122b
-static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs,
0a122b
-    int64_t sector_num, int nb_sectors, QEMUIOVector *qiov,
0a122b
+static int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs,
0a122b
+    int64_t offset, unsigned int bytes, QEMUIOVector *qiov,
0a122b
     BdrvRequestFlags flags);
0a122b
 static BlockDriverAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs,
0a122b
                                                int64_t sector_num,
0a122b
@@ -2404,8 +2404,7 @@ static int bdrv_check_request(BlockDriverState *bs, int64_t sector_num,
0a122b
 
0a122b
 typedef struct RwCo {
0a122b
     BlockDriverState *bs;
0a122b
-    int64_t sector_num;
0a122b
-    int nb_sectors;
0a122b
+    int64_t offset;
0a122b
     QEMUIOVector *qiov;
0a122b
     bool is_write;
0a122b
     int ret;
0a122b
@@ -2417,34 +2416,32 @@ static void coroutine_fn bdrv_rw_co_entry(void *opaque)
0a122b
     RwCo *rwco = opaque;
0a122b
 
0a122b
     if (!rwco->is_write) {
0a122b
-        rwco->ret = bdrv_co_do_readv(rwco->bs, rwco->sector_num,
0a122b
-                                     rwco->nb_sectors, rwco->qiov,
0a122b
-                                     rwco->flags);
0a122b
-    } else {
0a122b
-        rwco->ret = bdrv_co_do_writev(rwco->bs, rwco->sector_num,
0a122b
-                                      rwco->nb_sectors, rwco->qiov,
0a122b
+        rwco->ret = bdrv_co_do_preadv(rwco->bs, rwco->offset,
0a122b
+                                      rwco->qiov->size, rwco->qiov,
0a122b
                                       rwco->flags);
0a122b
+    } else {
0a122b
+        rwco->ret = bdrv_co_do_pwritev(rwco->bs, rwco->offset,
0a122b
+                                       rwco->qiov->size, rwco->qiov,
0a122b
+                                       rwco->flags);
0a122b
     }
0a122b
 }
0a122b
 
0a122b
 /*
0a122b
  * Process a vectored synchronous request using coroutines
0a122b
  */
0a122b
-static int bdrv_rwv_co(BlockDriverState *bs, int64_t sector_num,
0a122b
-                       QEMUIOVector *qiov, bool is_write,
0a122b
-                       BdrvRequestFlags flags)
0a122b
+static int bdrv_prwv_co(BlockDriverState *bs, int64_t offset,
0a122b
+                        QEMUIOVector *qiov, bool is_write,
0a122b
+                        BdrvRequestFlags flags)
0a122b
 {
0a122b
     Coroutine *co;
0a122b
     RwCo rwco = {
0a122b
         .bs = bs,
0a122b
-        .sector_num = sector_num,
0a122b
-        .nb_sectors = qiov->size >> BDRV_SECTOR_BITS,
0a122b
+        .offset = offset,
0a122b
         .qiov = qiov,
0a122b
         .is_write = is_write,
0a122b
         .ret = NOT_DONE,
0a122b
         .flags = flags,
0a122b
     };
0a122b
-    assert((qiov->size & (BDRV_SECTOR_SIZE - 1)) == 0);
0a122b
 
0a122b
     /**
0a122b
      * In sync call context, when the vcpu is blocked, this throttling timer
0a122b
@@ -2483,7 +2480,8 @@ static int bdrv_rw_co(BlockDriverState *bs, int64_t sector_num, uint8_t *buf,
0a122b
     };
0a122b
 
0a122b
     qemu_iovec_init_external(&qiov, &iov, 1);
0a122b
-    return bdrv_rwv_co(bs, sector_num, &qiov, is_write, flags);
0a122b
+    return bdrv_prwv_co(bs, sector_num << BDRV_SECTOR_BITS,
0a122b
+                        &qiov, is_write, flags);
0a122b
 }
0a122b
 
0a122b
 /* return < 0 if error. See bdrv_write() for the return codes */
0a122b
@@ -2521,7 +2519,7 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num,
0a122b
 
0a122b
 int bdrv_writev(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov)
0a122b
 {
0a122b
-    return bdrv_rwv_co(bs, sector_num, qiov, true, 0);
0a122b
+    return bdrv_prwv_co(bs, sector_num << BDRV_SECTOR_BITS, qiov, true, 0);
0a122b
 }
0a122b
 
0a122b
 int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,
0a122b
@@ -4793,9 +4791,15 @@ int bdrv_flush(BlockDriverState *bs)
0a122b
     return rwco.ret;
0a122b
 }
0a122b
 
0a122b
+typedef struct DiscardCo {
0a122b
+    BlockDriverState *bs;
0a122b
+    int64_t sector_num;
0a122b
+    int nb_sectors;
0a122b
+    int ret;
0a122b
+} DiscardCo;
0a122b
 static void coroutine_fn bdrv_discard_co_entry(void *opaque)
0a122b
 {
0a122b
-    RwCo *rwco = opaque;
0a122b
+    DiscardCo *rwco = opaque;
0a122b
 
0a122b
     rwco->ret = bdrv_co_discard(rwco->bs, rwco->sector_num, rwco->nb_sectors);
0a122b
 }
0a122b
@@ -4881,7 +4885,7 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
0a122b
 int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
0a122b
 {
0a122b
     Coroutine *co;
0a122b
-    RwCo rwco = {
0a122b
+    DiscardCo rwco = {
0a122b
         .bs = bs,
0a122b
         .sector_num = sector_num,
0a122b
         .nb_sectors = nb_sectors,
0a122b
-- 
0a122b
1.7.1
0a122b