qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-block] VHD footer 'Current Size' field validation failed on Azure


From: wang Jianjian
Subject: [Qemu-block] VHD footer 'Current Size' field validation failed on Azure
Date: Thu, 30 Mar 2017 18:20:08 +0800

Hi,
Recently when I deploy a VM on Azure with a Vhd created by qemu, I hit this error:

ErrorCode: InvalidVhd
ErrorMessage: VHD footer 'Current Size' field validation failed. VHD for disk 'xxx.vhd' with blob https://.....vhd specifies size (268435456) which does not match VHD blob size (270533120) - VHD Footer Size (512).

This issue can easily reproduced, create a vhd with below commands:
qemu-img create -f vpc -o force_size test1.vhd 256M

Then use Azure PowerShell create a VM(include upload Vhd) will have above error.

I check code and found qemu-img use a for-loop to calculate the CHS geometry but this may make its size is slightly larger than required and not align with 1MB boundary(azure requires).
And the comments explain the reason "it ensures qemu-img convert doesn't truncate images but rather rounds up." 
However, vhd specification says "When user creates a hard disk of a certain size, the size of the hard disk image in the virtual machine is smaller than that created by the user. This is because CHS value calculated from the hard disk size is rounded down."

I hack the code by myself and below is my change(just a tmp workaround) and find this work. 
So I think we should resolve the 'qemu-img convert' problem in 'convert' code(like add a special case for vhd) and we should conform vhd specification.
With my fix, above issue disappear and the 1MB alignment issue is also resolved(don't need force_size option for that purpose).
So we just need to change convert code to make it work for Vhd.

I also find this mail about force_size option and look like there are many other considerations. My fix doesn't consider all scenarios mentioned in that mail but seems can resolve part.

This issue really affect me because it makes the dynamic vhd can't be uploaded to azure. But fixed vhd takes too much time.

 Appreciate your comments.

 block/vpc.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/block/vpc.c b/block/vpc.c
index f504536..a4be425 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -815,9 +815,7 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp)
      * the image size from the VHD footer to calculate total_sectors.
      */
     total_sectors = MIN(VHD_MAX_GEOMETRY, total_size / BDRV_SECTOR_SIZE);
-    for (i = 0; total_sectors > (int64_t)cyls * heads * secs_per_cyl; i++) {
-        calculate_geometry(total_sectors + i, &cyls, &heads, &secs_per_cyl);
-    }
+    calculate_geometry(total_sectors, &cyls, &heads, &secs_per_cyl);

     if ((int64_t)cyls * heads * secs_per_cyl == VHD_MAX_GEOMETRY) {
         total_sectors = total_size / BDRV_SECTOR_SIZE;
@@ -828,7 +826,6 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp)
         }
     } else {
         total_sectors = (int64_t)cyls * heads * secs_per_cyl;
-        total_size = total_sectors * BDRV_SECTOR_SIZE;
     }






reply via email to

[Prev in Thread] Current Thread [Next in Thread]