block/vhdx: Small cleanups
cover block/vhdx: Small cleanups
Just some bits I discovered while going through the Coverity report.
(The issue reported by Coverity actually was not an issue.)
Max Reitz (2):
vhdx: DIV_ROUND_UP() in vhdx_calc_bat_entries()
vhdx: Simplify vhdx_set_shift_bits()
block/vhdx.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
Signature · 1 line
2.6.4
PATCH 2/2 vhdx: Simplify vhdx_set_shift_bits()
For values which are powers of two (and we do assume all of these to be), sizeof(x) * 8 - 1 - clz(x) == ctz(x). Therefore, use ctz().
--- block/vhdx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
block/vhdx.c +4 -4
@@ -263,10 +263,10 @@ static void vhdx_region_unregister_all(BDRVVHDXState *s)static void vhdx_set_shift_bits (BDRVVHDXState *s) { - s->logical_sector_size_bits =31 -clz32 (s->logical_sector_size); - s->sectors_per_block_bits =31 -clz32 (s->sectors_per_block); - s->chunk_ratio_bits =63 -clz64 (s->chunk_ratio); - s->block_size_bits =31 -clz32 (s->block_size); + s->logical_sector_size_bits =ctz32 (s->logical_sector_size); + s->sectors_per_block_bits =ctz32 (s->sectors_per_block); + s->chunk_ratio_bits =ctz64 (s->chunk_ratio); + s->block_size_bits =ctz32 (s->block_size); }/*
Signature · 1 line
2.6.4
PATCH 1/2 vhdx: DIV_ROUND_UP() in vhdx_calc_bat_entries()
In reply to Max ReitzWe 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.
--- block/vhdx.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
block/vhdx.c +2 -8
@@ -856,14 +856,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 );
Signature · 1 line
2.6.4
Quoted 11 lines · Max Reitz
Just some bits I discovered while going through the Coverity report.
(The issue reported by Coverity actually was not an issue.)
Max Reitz (2):
vhdx:DIV_ROUND_UP()invhdx_calc_bat_entries()
vhdx: Simplifyvhdx_set_shift_bits()block/vhdx.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
Ping
Jeff Cody
AppliedQuoted 6 lines · Max Reitz
Quoted 5 lines · Max Reitz
Just some bits I discovered while going through the Coverity report.
(The issue reported by Coverity actually was not an issue.)
Quoted 9 lines
Quoted 6 lines
Max Reitz (2):
vhdx:DIV_ROUND_UP()invhdx_calc_bat_entries()
vhdx: Simplifyvhdx_set_shift_bits()block/vhdx.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)Ping
Thanks, applied to my block branch
Jeff