Blame SOURCES/kvm-vmdk-Fix-index_in_cluster-calculation-in-vmdk_co_get.patch

9ae3a8
From 32791762f04b3342e9b10d1f553326cd01ea451f Mon Sep 17 00:00:00 2001
9ae3a8
From: Fam Zheng <famz@redhat.com>
9ae3a8
Date: Mon, 15 Feb 2016 09:28:26 +0100
9ae3a8
Subject: [PATCH 13/18] vmdk: Fix index_in_cluster calculation in
9ae3a8
 vmdk_co_get_block_status
9ae3a8
9ae3a8
RH-Author: Fam Zheng <famz@redhat.com>
9ae3a8
Message-id: <1455528511-9357-14-git-send-email-famz@redhat.com>
9ae3a8
Patchwork-id: 69179
9ae3a8
O-Subject: [RHEL-7.3 qemu-kvm PATCH 13/18] vmdk: Fix index_in_cluster calculation in vmdk_co_get_block_status
9ae3a8
Bugzilla: 1299250
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
9ae3a8
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1299250
9ae3a8
9ae3a8
It has the similar issue with b1649fae49a8. Since the calculation
9ae3a8
is repeated for a few times already, introduce a function so it can be
9ae3a8
reused.
9ae3a8
9ae3a8
Signed-off-by: Fam Zheng <famz@redhat.com>
9ae3a8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit 61f0ed1d54601b91b8195c1a30d7046f83283b40)
9ae3a8
Signed-off-by: Fam Zheng <famz@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/vmdk.c | 13 ++++++++++++-
9ae3a8
 1 file changed, 12 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
diff --git a/block/vmdk.c b/block/vmdk.c
9ae3a8
index dd8b638..10c08f3 100644
9ae3a8
--- a/block/vmdk.c
9ae3a8
+++ b/block/vmdk.c
9ae3a8
@@ -1242,6 +1242,17 @@ static VmdkExtent *find_extent(BDRVVmdkState *s,
9ae3a8
     return NULL;
9ae3a8
 }
9ae3a8
 
9ae3a8
+static inline uint64_t vmdk_find_index_in_cluster(VmdkExtent *extent,
9ae3a8
+                                                  int64_t sector_num)
9ae3a8
+{
9ae3a8
+    uint64_t index_in_cluster, extent_begin_sector, extent_relative_sector_num;
9ae3a8
+
9ae3a8
+    extent_begin_sector = extent->end_sector - extent->sectors;
9ae3a8
+    extent_relative_sector_num = sector_num - extent_begin_sector;
9ae3a8
+    index_in_cluster = extent_relative_sector_num % extent->cluster_sectors;
9ae3a8
+    return index_in_cluster;
9ae3a8
+}
9ae3a8
+
9ae3a8
 static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs,
9ae3a8
         int64_t sector_num, int nb_sectors, int *pnum)
9ae3a8
 {
9ae3a8
@@ -1279,7 +1290,7 @@ static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs,
9ae3a8
         break;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    index_in_cluster = sector_num % extent->cluster_sectors;
9ae3a8
+    index_in_cluster = vmdk_find_index_in_cluster(extent, sector_num);
9ae3a8
     n = extent->cluster_sectors - index_in_cluster;
9ae3a8
     if (n > nb_sectors) {
9ae3a8
         n = nb_sectors;
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8