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

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