yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-Switch-BdrvTrackedRequest-to-byte-granularity.patch

9ae3a8
From e0f594c3eac9fb0a89c76de3b77bce03c235b36e Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Tue, 3 Dec 2013 15:31:25 +0100
9ae3a8
Subject: [PATCH 16/37] block: Switch BdrvTrackedRequest to byte granularity
9ae3a8
9ae3a8
Message-id: <1392117622-28812-17-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: 57181
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 16/37] block: Switch BdrvTrackedRequest to byte granularity
9ae3a8
Bugzilla: 748906
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Reviewed-by: Benoit Canet <benoit@irqsave.net>
9ae3a8
(cherry picked from commit 793ed47a7a2b09b67cb2a8863dff531436532b5c)
9ae3a8
9ae3a8
Conflicts:
9ae3a8
	block/backup.c
9ae3a8
	include/block/block_int.h
9ae3a8
9ae3a8
Conflicts because in RHEL 7...
9ae3a8
- ...block-backup doesn't exist
9ae3a8
- ...BdrvTrackedRequest is in block.c rather than block_int.h
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
---
9ae3a8
 block.c | 56 ++++++++++++++++++++++++++++++++++++--------------------
9ae3a8
 1 file changed, 36 insertions(+), 20 deletions(-)
9ae3a8
---
9ae3a8
 block.c |   56 ++++++++++++++++++++++++++++++++++++--------------------
9ae3a8
 1 files changed, 36 insertions(+), 20 deletions(-)
9ae3a8
9ae3a8
diff --git a/block.c b/block.c
9ae3a8
index 7b8131c..09bb127 100644
9ae3a8
--- a/block.c
9ae3a8
+++ b/block.c
9ae3a8
@@ -2036,8 +2036,8 @@ int bdrv_commit_all(void)
9ae3a8
 
9ae3a8
 struct BdrvTrackedRequest {
9ae3a8
     BlockDriverState *bs;
9ae3a8
-    int64_t sector_num;
9ae3a8
-    int nb_sectors;
9ae3a8
+    int64_t offset;
9ae3a8
+    unsigned int bytes;
9ae3a8
     bool is_write;
9ae3a8
     QLIST_ENTRY(BdrvTrackedRequest) list;
9ae3a8
     Coroutine *co; /* owner, used for deadlock detection */
9ae3a8
@@ -2060,13 +2060,13 @@ static void tracked_request_end(BdrvTrackedRequest *req)
9ae3a8
  */
9ae3a8
 static void tracked_request_begin(BdrvTrackedRequest *req,
9ae3a8
                                   BlockDriverState *bs,
9ae3a8
-                                  int64_t sector_num,
9ae3a8
-                                  int nb_sectors, bool is_write)
9ae3a8
+                                  int64_t offset,
9ae3a8
+                                  unsigned int bytes, bool is_write)
9ae3a8
 {
9ae3a8
     *req = (BdrvTrackedRequest){
9ae3a8
         .bs = bs,
9ae3a8
-        .sector_num = sector_num,
9ae3a8
-        .nb_sectors = nb_sectors,
9ae3a8
+        .offset = offset,
9ae3a8
+        .bytes = bytes,
9ae3a8
         .is_write = is_write,
9ae3a8
         .co = qemu_coroutine_self(),
9ae3a8
     };
9ae3a8
@@ -2097,25 +2097,43 @@ void bdrv_round_to_clusters(BlockDriverState *bs,
9ae3a8
     }
9ae3a8
 }
9ae3a8
 
9ae3a8
+static void round_bytes_to_clusters(BlockDriverState *bs,
9ae3a8
+                                    int64_t offset, unsigned int bytes,
9ae3a8
+                                    int64_t *cluster_offset,
9ae3a8
+                                    unsigned int *cluster_bytes)
9ae3a8
+{
9ae3a8
+    BlockDriverInfo bdi;
9ae3a8
+
9ae3a8
+    if (bdrv_get_info(bs, &bdi) < 0 || bdi.cluster_size == 0) {
9ae3a8
+        *cluster_offset = offset;
9ae3a8
+        *cluster_bytes = bytes;
9ae3a8
+    } else {
9ae3a8
+        *cluster_offset = QEMU_ALIGN_DOWN(offset, bdi.cluster_size);
9ae3a8
+        *cluster_bytes = QEMU_ALIGN_UP(offset - *cluster_offset + bytes,
9ae3a8
+                                       bdi.cluster_size);
9ae3a8
+    }
9ae3a8
+}
9ae3a8
+
9ae3a8
 static bool tracked_request_overlaps(BdrvTrackedRequest *req,
9ae3a8
-                                     int64_t sector_num, int nb_sectors) {
9ae3a8
+                                     int64_t offset, unsigned int bytes)
9ae3a8
+{
9ae3a8
     /*        aaaa   bbbb */
9ae3a8
-    if (sector_num >= req->sector_num + req->nb_sectors) {
9ae3a8
+    if (offset >= req->offset + req->bytes) {
9ae3a8
         return false;
9ae3a8
     }
9ae3a8
     /* bbbb   aaaa        */
9ae3a8
-    if (req->sector_num >= sector_num + nb_sectors) {
9ae3a8
+    if (req->offset >= offset + bytes) {
9ae3a8
         return false;
9ae3a8
     }
9ae3a8
     return true;
9ae3a8
 }
9ae3a8
 
9ae3a8
 static void coroutine_fn wait_for_overlapping_requests(BlockDriverState *bs,
9ae3a8
-        int64_t sector_num, int nb_sectors)
9ae3a8
+        int64_t offset, unsigned int bytes)
9ae3a8
 {
9ae3a8
     BdrvTrackedRequest *req;
9ae3a8
-    int64_t cluster_sector_num;
9ae3a8
-    int cluster_nb_sectors;
9ae3a8
+    int64_t cluster_offset;
9ae3a8
+    unsigned int cluster_bytes;
9ae3a8
     bool retry;
9ae3a8
 
9ae3a8
     /* If we touch the same cluster it counts as an overlap.  This guarantees
9ae3a8
@@ -2124,14 +2142,12 @@ static void coroutine_fn wait_for_overlapping_requests(BlockDriverState *bs,
9ae3a8
      * CoR read and write operations are atomic and guest writes cannot
9ae3a8
      * interleave between them.
9ae3a8
      */
9ae3a8
-    bdrv_round_to_clusters(bs, sector_num, nb_sectors,
9ae3a8
-                           &cluster_sector_num, &cluster_nb_sectors);
9ae3a8
+    round_bytes_to_clusters(bs, offset, bytes, &cluster_offset, &cluster_bytes);
9ae3a8
 
9ae3a8
     do {
9ae3a8
         retry = false;
9ae3a8
         QLIST_FOREACH(req, &bs->tracked_requests, list) {
9ae3a8
-            if (tracked_request_overlaps(req, cluster_sector_num,
9ae3a8
-                                         cluster_nb_sectors)) {
9ae3a8
+            if (tracked_request_overlaps(req, cluster_offset, cluster_bytes)) {
9ae3a8
                 /* Hitting this means there was a reentrant request, for
9ae3a8
                  * example, a block driver issuing nested requests.  This must
9ae3a8
                  * never happen since it means deadlock.
9ae3a8
@@ -2746,10 +2762,10 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs,
9ae3a8
     }
9ae3a8
 
9ae3a8
     if (bs->copy_on_read_in_flight) {
9ae3a8
-        wait_for_overlapping_requests(bs, sector_num, nb_sectors);
9ae3a8
+        wait_for_overlapping_requests(bs, offset, bytes);
9ae3a8
     }
9ae3a8
 
9ae3a8
-    tracked_request_begin(&req, bs, sector_num, nb_sectors, false);
9ae3a8
+    tracked_request_begin(&req, bs, offset, bytes, false);
9ae3a8
 
9ae3a8
     if (flags & BDRV_REQ_COPY_ON_READ) {
9ae3a8
         int pnum;
9ae3a8
@@ -2998,10 +3014,10 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
9ae3a8
     assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
9ae3a8
 
9ae3a8
     if (bs->copy_on_read_in_flight) {
9ae3a8
-        wait_for_overlapping_requests(bs, sector_num, nb_sectors);
9ae3a8
+        wait_for_overlapping_requests(bs, offset, bytes);
9ae3a8
     }
9ae3a8
 
9ae3a8
-    tracked_request_begin(&req, bs, sector_num, nb_sectors, true);
9ae3a8
+    tracked_request_begin(&req, bs, offset, bytes, true);
9ae3a8
 
9ae3a8
     if (flags & BDRV_REQ_ZERO_WRITE) {
9ae3a8
         ret = bdrv_co_do_write_zeroes(bs, sector_num, nb_sectors, flags);
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8