Skip to content

Commit

Permalink
vhdx: DIV_ROUND_UP() in vhdx_calc_bat_entries()
Browse files Browse the repository at this point in the history
We have DIV_ROUND_UP(), so we can use it to produce more easily readable
code. It may be slower than the bit shifting currently performed
(because it actually performs a division), but since
vhdx_calc_bat_entries() is never used in a hot path, this is completely
fine.

Signed-off-by: Max Reitz <[email protected]>
Message-id: [email protected]
Signed-off-by: Jeff Cody <[email protected]>
  • Loading branch information
XanClic authored and codyprime committed Feb 29, 2016
1 parent b189346 commit 939901d
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions block/vhdx.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,14 +857,8 @@ static void vhdx_calc_bat_entries(BDRVVHDXState *s)
{
uint32_t data_blocks_cnt, bitmap_blocks_cnt;

data_blocks_cnt = s->virtual_disk_size >> s->block_size_bits;
if (s->virtual_disk_size - (data_blocks_cnt << s->block_size_bits)) {
data_blocks_cnt++;
}
bitmap_blocks_cnt = data_blocks_cnt >> s->chunk_ratio_bits;
if (data_blocks_cnt - (bitmap_blocks_cnt << s->chunk_ratio_bits)) {
bitmap_blocks_cnt++;
}
data_blocks_cnt = DIV_ROUND_UP(s->virtual_disk_size, s->block_size);
bitmap_blocks_cnt = DIV_ROUND_UP(data_blocks_cnt, s->chunk_ratio);

if (s->parent_entries) {
s->bat_entries = bitmap_blocks_cnt * (s->chunk_ratio + 1);
Expand Down

0 comments on commit 939901d

Please sign in to comment.