9ae3a8
From 989d971046a36afa7acb67855f565603297ad2e8 Mon Sep 17 00:00:00 2001
9ae3a8
From: Jeffrey Cody <jcody@redhat.com>
9ae3a8
Date: Wed, 20 Nov 2013 19:44:01 +0100
9ae3a8
Subject: [PATCH 18/25] block: vhdx - remove BAT file offset bit shifting
9ae3a8
9ae3a8
RH-Author: Jeffrey Cody <jcody@redhat.com>
9ae3a8
Message-id: <348f6a1952aa68e9a5cfefb56a7e86f5ff1d01c9.1384975172.git.jcody@redhat.com>
9ae3a8
Patchwork-id: 55811
9ae3a8
O-Subject: [RHEL7 qemu-kvm PATCH 18/26] block: vhdx - remove BAT file offset bit shifting
9ae3a8
Bugzilla: 879234
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
9ae3a8
Bit shifting can be fun, but in this case it was unnecessary.  The
9ae3a8
upper 44 bits of the 64-bit BAT entry is specifies the File Offset,
9ae3a8
so we shifted the bits to get access to the value.
9ae3a8
9ae3a8
However, per the spec the value is in MB.  So we dutifully shifted back
9ae3a8
to the left by 20 bits, to convert to a true uint64_t file offset.
9ae3a8
9ae3a8
This replaces those steps with just a bit mask, to get rid of the lower
9ae3a8
20 bits instead.
9ae3a8
9ae3a8
Signed-off-by: Jeff Cody <jcody@redhat.com>
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
(cherry picked from commit 0b7da092b40734538631c3ad461c1753a87535fc)
9ae3a8
---
9ae3a8
 block/vhdx.c | 6 ++----
9ae3a8
 block/vhdx.h | 1 -
9ae3a8
 2 files changed, 2 insertions(+), 5 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/vhdx.c |    6 ++----
9ae3a8
 block/vhdx.h |    1 -
9ae3a8
 2 files changed, 2 insertions(+), 5 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/vhdx.c b/block/vhdx.c
9ae3a8
index baf8970..97099aa 100644
9ae3a8
--- a/block/vhdx.c
9ae3a8
+++ b/block/vhdx.c
9ae3a8
@@ -985,7 +985,7 @@ static void vhdx_block_translate(BDRVVHDXState *s, int64_t sector_num,
9ae3a8
 
9ae3a8
     sinfo->bytes_avail = sinfo->sectors_avail << s->logical_sector_size_bits;
9ae3a8
 
9ae3a8
-    sinfo->file_offset = s->bat[sinfo->bat_idx] >> VHDX_BAT_FILE_OFF_BITS;
9ae3a8
+    sinfo->file_offset = s->bat[sinfo->bat_idx] & VHDX_BAT_FILE_OFF_MASK;
9ae3a8
 
9ae3a8
     sinfo->block_offset = block_offset << s->logical_sector_size_bits;
9ae3a8
 
9ae3a8
@@ -999,7 +999,6 @@ static void vhdx_block_translate(BDRVVHDXState *s, int64_t sector_num,
9ae3a8
      * in the block, and add in the payload data block offset
9ae3a8
      * in the file, in bytes, to get the final read address */
9ae3a8
 
9ae3a8
-    sinfo->file_offset <<= 20;  /* now in bytes, rather than 1MB units */
9ae3a8
     sinfo->file_offset += sinfo->block_offset;
9ae3a8
 }
9ae3a8
 
9ae3a8
@@ -1110,8 +1109,7 @@ static void vhdx_update_bat_table_entry(BlockDriverState *bs, BDRVVHDXState *s,
9ae3a8
 {
9ae3a8
     /* The BAT entry is a uint64, with 44 bits for the file offset in units of
9ae3a8
      * 1MB, and 3 bits for the block state. */
9ae3a8
-    s->bat[sinfo->bat_idx]  = ((sinfo->file_offset>>20) <<
9ae3a8
-                               VHDX_BAT_FILE_OFF_BITS);
9ae3a8
+    s->bat[sinfo->bat_idx]  = sinfo->file_offset;
9ae3a8
 
9ae3a8
     s->bat[sinfo->bat_idx] |= state & VHDX_BAT_STATE_BIT_MASK;
9ae3a8
 
9ae3a8
diff --git a/block/vhdx.h b/block/vhdx.h
9ae3a8
index a85c5c8..7deb7fd 100644
9ae3a8
--- a/block/vhdx.h
9ae3a8
+++ b/block/vhdx.h
9ae3a8
@@ -229,7 +229,6 @@ typedef struct QEMU_PACKED VHDXLogDataSector {
9ae3a8
 /* upper 44 bits are the file offset in 1MB units lower 3 bits are the state
9ae3a8
    other bits are reserved */
9ae3a8
 #define VHDX_BAT_STATE_BIT_MASK 0x07
9ae3a8
-#define VHDX_BAT_FILE_OFF_BITS (64 - 44)
9ae3a8
 #define VHDX_BAT_FILE_OFF_MASK  0xFFFFFFFFFFF00000 /* upper 44 bits */
9ae3a8
 typedef uint64_t VHDXBatEntry;
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8