Skip to contentSkip to conversation

vmdk: Fix vmdk_co_get_block_status

PATCH Applied Fam Zheng 3 participants 6 messages Jun 4, 2015 – Jun 8, 2015 Block layer

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

cover vmdk: Fix vmdk_co_get_block_status

The buggy index_in_cluster was missed in b1649fae49a8. Fix that and dedup the calculation.

Fam Zheng (2):
vmdk: Fix index_in_cluster calculation in vmdk_co_get_block_status
vmdk: Use vmdk_find_index_in_cluster everywhere

 block/vmdk.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
Signature · 1 line
2.4.2
author
#1 lore raw

PATCH 1/2 vmdk: Fix index_in_cluster calculation in vmdk_co_get_block_status

It has the similar issue with b1649fae49a8. Since the calculation is repeated for a few times already, introduce a function so it can be reused.

---
 block/vmdk.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
block/vmdk.c +12 -1
index b66745d..3e4d84b 100644
@@ -1248,6 +1248,17 @@ static VmdkExtent *find_extent(BDRVVmdkState *s,
     return NULL;
 }
 
+static inline uint64_t vmdk_find_index_in_cluster(VmdkExtent *extent,
+                                                  int64_t sector_num)
+{
+    uint64_t index_in_cluster, extent_begin_sector, extent_relative_sector_num;
+
+    extent_begin_sector = extent->end_sector - extent->sectors;
+    extent_relative_sector_num = sector_num - extent_begin_sector;
+    index_in_cluster = extent_relative_sector_num % extent->cluster_sectors;
+    return index_in_cluster;
+}
+
 static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs,
         int64_t sector_num, int nb_sectors, int *pnum)
 {
@@ -1285,7 +1296,7 @@ static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs,
         break;
     }
 
-    index_in_cluster = sector_num % extent->cluster_sectors;
+    index_in_cluster = vmdk_find_index_in_cluster(extent, sector_num);
     n = extent->cluster_sectors - index_in_cluster;
     if (n > nb_sectors) {
         n = nb_sectors;
Signature · 1 line
2.4.2
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH 1/2] vmdk: Fix index_in_cluster calculation in vmdk_co_get_block_status

Quoted 8 lines · Fam Zheng

It has the similar issue with b1649fae49a8. Since the calculation is repeated for a few times already, introduce a function so it can be reused.

---
  block/vmdk.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
author
#3 lore raw

PATCH 2/2 vmdk: Use vmdk_find_index_in_cluster everywhere

In reply to Fam Zheng
---
 block/vmdk.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
block/vmdk.c +2 -8
index 3e4d84b..56626b0 100644
@@ -1424,7 +1424,6 @@ static int vmdk_read(BlockDriverState *bs, int64_t sector_num,
     BDRVVmdkState *s = bs->opaque;
     int ret;
     uint64_t n, index_in_cluster;
-    uint64_t extent_begin_sector, extent_relative_sector_num;
     VmdkExtent *extent = NULL;
     uint64_t cluster_offset;
 
@@ -1436,9 +1435,7 @@ static int vmdk_read(BlockDriverState *bs, int64_t sector_num,
         ret = get_cluster_offset(bs, extent, NULL,
                                  sector_num << 9, false, &cluster_offset,
                                  0, 0);
-        extent_begin_sector = extent->end_sector - extent->sectors;
-        extent_relative_sector_num = sector_num - extent_begin_sector;
-        index_in_cluster = extent_relative_sector_num % extent->cluster_sectors;
+        index_in_cluster = vmdk_find_index_in_cluster(extent, sector_num);
         n = extent->cluster_sectors - index_in_cluster;
         if (n > nb_sectors) {
             n = nb_sectors;
@@ -1500,7 +1497,6 @@ static int vmdk_write(BlockDriverState *bs, int64_t sector_num,
     VmdkExtent *extent = NULL;
     int ret;
     int64_t index_in_cluster, n;
-    uint64_t extent_begin_sector, extent_relative_sector_num;
     uint64_t cluster_offset;
     VmdkMetaData m_data;
 
@@ -1516,9 +1512,7 @@ static int vmdk_write(BlockDriverState *bs, int64_t sector_num,
         if (!extent) {
             return -EIO;
         }
-        extent_begin_sector = extent->end_sector - extent->sectors;
-        extent_relative_sector_num = sector_num - extent_begin_sector;
-        index_in_cluster = extent_relative_sector_num % extent->cluster_sectors;
+        index_in_cluster = vmdk_find_index_in_cluster(extent, sector_num);
         n = extent->cluster_sectors - index_in_cluster;
         if (n > nb_sectors) {
             n = nb_sectors;
Signature · 1 line
2.4.2
Applied
#5 lore raw
In reply to Fam Zheng

Am 04.06.2015 um 08:02 hat Fam Zheng geschrieben:

Quoted 2 lines

The buggy index_in_cluster was missed in b1649fae49a8. Fix that and dedup the calculation.

Thanks, applied to the block branch.

Kevin