vpc: Don't round up already aligned BAT sizes
PATCH 1/1 vpc: Don't round up already aligned BAT sizes
As reported on Launchpad, Azure apparently doesn't accept images for upload that are not both aligned to 1 MB blocks and have a BAT size that matches the image size exactly.
As far as I can tell, there is no real reason why we create a BAT that is one entry longer than necessary for aligned image sizes, so change that.
(Even though the condition is only mentioned as "should" in the spec and previous products accepted larger BATs - but we'll try to maintain compatibility with as many of Microsoft's ever-changing interpretations of the VHD spec as possible.)
--- block/vpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/vpc.c +1 -1
@@ -835,7 +835,7 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,/* Write the footer (twice: at the beginning and at the end) */ block_size =0x200000 ; - num_bat_entries = (total_sectors + block_size /512 ) / (block_size /512 ); + num_bat_entries =DIV_ROUND_UP (total_sectors, block_size /512 ); ret =blk_pwrite (blk, offset, buf,HEADER_SIZE ,0 );if (ret <0 ) {
Signature · 1 line
2.20.1
Quoted 26 lines · Kevin Wolf
As reported on Launchpad, Azure apparently doesn't accept images for upload that are not both aligned to 1 MB blocks and have a BAT size that matches the image size exactly.
As far as I can tell, there is no real reason why we create a BAT that is one entry longer than necessary for aligned image sizes, so change that.
(Even though the condition is only mentioned as "should" in the spec and previous products accepted larger BATs - but we'll try to maintain compatibility with as many of Microsoft's ever-changing interpretations of the VHD spec as possible.)
Reported-by Tobias WitekSigned-off-by Kevin Wolf <[email protected]>--- block/vpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/vpc.c +0
-0
block/vpc.c static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf, · line 841
Quoted 8 lines
block/vpc.c +1
-1@@ -835,7 +835,7 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,/* Write the footer (twice: at the beginning and at the end) */ block_size =0x200000 ; - num_bat_entries = (total_sectors + block_size /512 ) / (block_size /512 ); + num_bat_entries =DIV_ROUND_UP (total_sectors, block_size /512 ); ret =blk_pwrite (blk, offset, buf,HEADER_SIZE ,0 );if (ret <0 ) {
Quoted 4 lines · Kevin Wolf
As reported on Launchpad, Azure apparently doesn't accept images for upload that are not both aligned to 1 MB blocks and have a BAT size that matches the image size exactly.
Quoted 8 lines
As far as I can tell, there is no real reason why we create a BAT that is one entry longer than necessary for aligned image sizes, so change that.
(Even though the condition is only mentioned as "should" in the spec and previous products accepted larger BATs - but we'll try to maintain compatibility with as many of Microsoft's ever-changing interpretations of the VHD spec as possible.)
So as far as I can tell we still don’t ensure that the image is aligned to 1 MB blocks?
Well, as long as it’s at least possible for the user to create valid images, that’s better.
Quoted 12 lines
Reported-by Tobias WitekSigned-off-by Kevin Wolf <[email protected]>--- block/vpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/vpc.c +0
-0
block/vpc.c static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf, · line 838
Quoted 5 lines
block/vpc.c +1
-1@@ -835,7 +835,7 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,/* Write the footer (twice: at the beginning and at the end) */ block_size =0x200000 ; - num_bat_entries = (total_sectors + block_size /512 ) / (block_size /512 ); + num_bat_entries =DIV_ROUND_UP (total_sectors, block_size /512 );
And the old code just looks like a wrong DIV_ROUND_UP() attempt. So:
Quoted 4 lines
block/vpc.c +0
-0ret =blk_pwrite (blk, offset, buf,HEADER_SIZE ,0 );if (ret <0 ) {
Am 03.04.2020 um 10:55 hat Max Reitz geschrieben:
Quoted 14 lines · Kevin Wolf
Quoted 4 lines
As reported on Launchpad, Azure apparently doesn't accept images for upload that are not both aligned to 1 MB blocks and have a BAT size that matches the image size exactly.
Quoted 8 lines
As far as I can tell, there is no real reason why we create a BAT that is one entry longer than necessary for aligned image sizes, so change that.
(Even though the condition is only mentioned as "should" in the spec and previous products accepted larger BATs - but we'll try to maintain compatibility with as many of Microsoft's ever-changing interpretations of the VHD spec as possible.)
Quoted 5 lines
So as far as I can tell we still don’t ensure that the image is aligned to 1 MB blocks?
Well, as long as it’s at least possible for the user to create valid images, that’s better.
Yes, we still allow other image sizes because Azure is not the only product using VHD images, but it is the only one (to my knowledge) that makes this requirement.
We're trying to stay compatible with at least three different Microsoft products (VirtualPC, HyperV, Azure) that all have their own interpretation of the spec and are inconsistent with each other.
Kevin
Quoted 21 lines · Kevin Wolf
Am 03.04.2020 um 10:55 hat Max Reitz geschrieben:
Quoted 14 lines · Kevin Wolf
Quoted 4 lines
As reported on Launchpad, Azure apparently doesn't accept images for upload that are not both aligned to 1 MB blocks and have a BAT size that matches the image size exactly.
Quoted 8 lines
As far as I can tell, there is no real reason why we create a BAT that is one entry longer than necessary for aligned image sizes, so change that.
(Even though the condition is only mentioned as "should" in the spec and previous products accepted larger BATs - but we'll try to maintain compatibility with as many of Microsoft's ever-changing interpretations of the VHD spec as possible.)
Quoted 5 lines
So as far as I can tell we still don’t ensure that the image is aligned to 1 MB blocks?
Well, as long as it’s at least possible for the user to create valid images, that’s better.
Quoted 7 lines
Yes, we still allow other image sizes because Azure is not the only product using VHD images, but it is the only one (to my knowledge) that makes this requirement.
We're trying to stay compatible with at least three different Microsoft products (VirtualPC, HyperV, Azure) that all have their own interpretation of the spec and are inconsistent with each other.
OK, nice. Thanks for the explanation!
Max