From 5c808f101e58ef66653de9bdd7e25b0b3b9a9d71 Mon Sep 17 00:00:00 2001 From: Jeffrey Cody Date: Thu, 10 Jul 2014 23:24:23 +0200 Subject: [PATCH 23/44] block: vhdx - remove BAT file offset bit shifting RH-Author: Jeffrey Cody Message-id: <6c55c6a5a5bb64eb0ca033447f49157eb948c80d.1405033137.git.jcody@redhat.com> Patchwork-id: 59759 O-Subject: [RHEL6-6 qemu-kvm PATCH v2 14/24] block: vhdx - remove BAT file offset bit shifting Bugzilla: 1063559 RH-Acked-by: Stefan Hajnoczi RH-Acked-by: Fam Zheng RH-Acked-by: Markus Armbruster Bit shifting can be fun, but in this case it was unnecessary. The upper 44 bits of the 64-bit BAT entry is specifies the File Offset, so we shifted the bits to get access to the value. However, per the spec the value is in MB. So we dutifully shifted back to the left by 20 bits, to convert to a true uint64_t file offset. This replaces those steps with just a bit mask, to get rid of the lower 20 bits instead. Signed-off-by: Jeff Cody Signed-off-by: Stefan Hajnoczi (cherry picked from commit 0b7da092b40734538631c3ad461c1753a87535fc) --- block/vhdx.c | 6 ++---- block/vhdx.h | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) Signed-off-by: Miroslav Rezanina --- block/vhdx.c | 6 ++---- block/vhdx.h | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/block/vhdx.c b/block/vhdx.c index 5741412..1d80b39 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1000,7 +1000,7 @@ static void vhdx_block_translate(BDRVVHDXState *s, int64_t sector_num, sinfo->bytes_avail = sinfo->sectors_avail << s->logical_sector_size_bits; - sinfo->file_offset = s->bat[sinfo->bat_idx] >> VHDX_BAT_FILE_OFF_BITS; + sinfo->file_offset = s->bat[sinfo->bat_idx] & VHDX_BAT_FILE_OFF_MASK; sinfo->block_offset = block_offset << s->logical_sector_size_bits; @@ -1014,7 +1014,6 @@ static void vhdx_block_translate(BDRVVHDXState *s, int64_t sector_num, * in the block, and add in the payload data block offset * in the file, in bytes, to get the final read address */ - sinfo->file_offset <<= 20; /* now in bytes, rather than 1MB units */ sinfo->file_offset += sinfo->block_offset; } @@ -1113,8 +1112,7 @@ static void vhdx_update_bat_table_entry(BlockDriverState *bs, BDRVVHDXState *s, { /* The BAT entry is a uint64, with 44 bits for the file offset in units of * 1MB, and 3 bits for the block state. */ - s->bat[sinfo->bat_idx] = ((sinfo->file_offset>>20) << - VHDX_BAT_FILE_OFF_BITS); + s->bat[sinfo->bat_idx] = sinfo->file_offset; s->bat[sinfo->bat_idx] |= state & VHDX_BAT_STATE_BIT_MASK; diff --git a/block/vhdx.h b/block/vhdx.h index a5e262b..43b90cc 100644 --- a/block/vhdx.h +++ b/block/vhdx.h @@ -234,7 +234,6 @@ typedef struct QEMU_PACKED VHDXLogDataSector { /* upper 44 bits are the file offset in 1MB units lower 3 bits are the state other bits are reserved */ #define VHDX_BAT_STATE_BIT_MASK 0x07 -#define VHDX_BAT_FILE_OFF_BITS (64 - 44) #define VHDX_BAT_FILE_OFF_MASK 0xFFFFFFFFFFF00000 /* upper 44 bits */ typedef uint64_t VHDXBatEntry; -- 1.7.1