[vbox-dev] vhd format not stable?

Huihong Luo huisinro at yahoo.com
Mon Jun 29 23:13:34 GMT 2009


Alex,
 
Thanks, that's very helpful.
 
We have implemented a mini port virtual disk driver, and features to convert between different formats (vdi, vhd, vmdk). 
 
Also doing a p2v converter. Will post as free tool when finished.
 
Huihong

--- On Mon, 6/29/09, Alexander Eichner <Alexander.Eichner at Sun.COM> wrote:


From: Alexander Eichner <Alexander.Eichner at Sun.COM>
Subject: Re: [vbox-dev] vhd format not stable?
To: "Huihong Luo" <huisinro at yahoo.com>
Cc: vbox-dev at virtualbox.org
Date: Monday, June 29, 2009, 1:38 PM


Hi Huihong,

DrvVD is the only example at the moment where you can see how snapshots
are added to the chain but include/VBox/VBoxHDD.h contains documentation
on how to use the API. Your assumption is correct - the first image
which is opened must be a base image. The other ones must be
differencing.

An image can have more than one child disk. VBoxHDD doesn't know if the
diff image really belongs to the base image it was opened with.
For example take the following disk structure.

                   base_image
                /              \
         chain_1_diff_1        chain_2_diff_1
         /          \               |
chain_1_diff_2  chain_1_diff_3 chain_2_diff_2 

To open the chain ending with chain_1_diff_3 you need to do the
following:
1. VDOpen(pDisk, pszBackend, base_image, ...);
2. VDOpen(pDisk, pszBackend, chain_1_diff_1, ...);
3. VDOpen(pDisk, pszBackend, chain_1_diff_3, ...);

And to open the chain ending with chain_2_diff_2:
1. VDOpen(pDisk, pszBackend, base_image, ...);
2. VDOpen(pDisk, pszBackend, chain_2_diff_1, ...);
3. VDOpen(pDisk, pszBackend, chain_2_diff_2, ...);

You could also do the following (VBoxHDD would not complain):
1. VDOpen(pDisk, pszBackend, base_image, ...);
2. VDOpen(pDisk, pszBackend, chain_1_diff_1, ...);
3. VDOpen(pDisk, pszBackend, chain_2_diff_2, ...);

but the data would be inconsistent and the guest would not
operate correctly.

Hope this answers your question (if not just ask again ;) ).

Regards,
Alexander Eichner

Am Montag, den 29.06.2009, 09:00 -0700 schrieb Huihong Luo:
> Alex,
>  
> Great. I will use your new fix.
>  
> By the way, I am trying to read the base disk files, and snapshot
> files, to create a virtual disk.
>  
> It seems 
> drvvdConstruct() in DrvVD.cpp is the code I can ref to. Any other
> clean code?
>  
> Open the base image first, then 1st gen diff file, then 2nd gen
> diff, ...., is this the correct stesp?
>  
> Does one image only have one child disk? If you can provide some code,
> would be really helpful.
>  
> Thanks,
>  
> Huihong
> 
> --- On Sun, 6/28/09, Alexander Eichner <Alexander.Eichner at Sun.COM>
> wrote:
> 
>         
>         From: Alexander Eichner <Alexander.Eichner at Sun.COM>
>         Subject: Re: [vbox-dev] vhd format not stable?
>         To: "Huihong Luo" <huisinro at yahoo.com>
>         Date: Sunday, June 28, 2009, 12:11 PM
>         
>         Hi Huihong,
>         
>         you are right. The code for the 32it alignment is completely
>         wrong
>         and results in the wrong bits tested. I restored the old
>         behavior
>         and just added the allocation of additional bytes. Adding
>         addtional 8
>         bytes should be only necessary on 64bit systems as the BT
>         assembler
>         instruction may read 8 bytes there. Many thanks for pointing
>         that out.
>         The fix should appear in svn soon.
>         
>         Regards,
>         Alexander Eichner
>         
>         Am Samstag, den 27.06.2009, 17:41 -0700 schrieb Huihong Luo:
>         > Hi Alex,
>         >  
>         > If I reverted your changes on vhdRead(), and just simply add
>         8 extra
>         > bytes to pImage->pu8Bitmap, then works.
>         >  
>         > I also included your fix on parentFilename.
>         >  
>         > I've attached the diff (to prev version, not to latest) and
>         the
>         > working VHDHDDCore.cpp for your ref.
>         > There must be something funny about your 32-bit alignment
>         bit calc.
>         >  
>         > This would be very important, as I can't install ac97
>         driver.
>         >  
>         > Huihong
>         > 
>         > 
>         > --- On Wed, 6/24/09, Alexander Eichner
>         <Alexander.Eichner at Sun.COM>
>         > wrote:
>         > 
>         >         
>         >         From: Alexander Eichner <Alexander.Eichner at Sun.COM>
>         >         Subject: Re: [vbox-dev] vhd format not stable?
>         >         To: "Huihong Luo" <huisinro at yahoo.com>
>         >         Date: Wednesday, June 24, 2009, 3:54 PM
>         >         
>         >         Hi Huihong,
>         >         
>         >         yes will do.
>         >         
>         >         Kind regards,
>         >         Alexander Eichner
>         >         
>         >         Am Dienstag, den 23.06.2009, 16:12 -0700 schrieb
>         Huihong Luo:
>         >         > Alex,
>         >         >  
>         >         > Thanks for the fix on the crash.
>         >         >  
>         >         > Can you examine the fix and check if it breaks
>         anything? all
>         >         of
>         >         > sudden, all of the audio drivers are not
>         recognized inside
>         >         vm. When I
>         >         > use the vboxddu.dll before the fix, then works.
>         >         >  
>         >         > Thanks,
>         >         >  
>         >         > - hl
>         >         > 
>         >         > --- On Mon, 6/22/09, Alexander Eichner
>         >         <Alexander.Eichner at Sun.COM>
>         >         > wrote:
>         >         > 
>         >         >         
>         >         >         From: Alexander Eichner
>         <Alexander.Eichner at Sun.COM>
>         >         >         Subject: Re: [vbox-dev] vhd format not
>         stable?
>         >         >         To: "Huihong Luo" <huisinro at yahoo.com>
>         >         >         Cc: vbox-dev at virtualbox.org, "Frank
>         Mehnert"
>         >         >         <Frank.Mehnert at Sun.COM>
>         >         >         Date: Monday, June 22, 2009, 12:25 PM
>         >         >         
>         >         >         Hi Huihong,
>         >         >         
>         >         >         the crash should be really fixed now. I
>         also fixed
>         >         the crash
>         >         >         with
>         >         >         snapshots you reported in another mail.
>         They will
>         >         appear soon
>         >         >         in the
>         >         >         public svn. Thanks again for your help!
>         >         >         
>         >         >         Kind regards,
>         >         >         Alexander Eichner
>         >         >         
>         >         >         Am Montag, den 22.06.2009, 08:59 -0700
>         schrieb
>         >         Huihong Luo:
>         >         >         > Frank,
>         >         >         >  
>         >         >         > Right, that would be the correct fix.
>         >         >         >  
>         >         >         > I was wondering if there are other
>         places that
>         >         have similar
>         >         >         issues.
>         >         >         > This problem would be very rare in
>         happening, as
>         >         the memory
>         >         >         address
>         >         >         > would be still ok to be read even if
>         it's less
>         >         then DWORD in
>         >         >         len.
>         >         >         >  
>         >         >         > Inside kernel mode, this becomes a
>         severe problem,
>         >         throwing
>         >         >         invalid
>         >         >         > memory access crashes.
>         >         >         >  
>         >         >         > - Huihong
>         >         >         > 
>         >         >         > --- On Mon, 6/22/09, Frank Mehnert
>         >         <Frank.Mehnert at Sun.COM>
>         >         >         wrote:
>         >         >         > 
>         >         >         >         
>         >         >         >         From: Frank Mehnert
>         >         <Frank.Mehnert at Sun.COM>
>         >         >         >         Subject: Re: [vbox-dev] vhd
>         format not
>         >         stable?
>         >         >         >         To: vbox-dev at virtualbox.org
>         >         >         >         Date: Monday, June 22, 2009,
>         3:30 AM
>         >         >         >         
>         >         >         >         Huihong,
>         >         >         >         
>         >         >         >         On Friday 19 June 2009, Huihong
>         Luo wrote:
>         >         >         >         > I tested it again, but it
>         still crashed.
>         >         >         >         >  
>         >         >         >         > I think I now found the cause,
>         it's
>         >         quite
>         >         >         delicate, but you
>         >         >         >         should be able
>         >         >         >         > to fix it right away. 
>         >         >         >         > a8bd6ffd ff ff
>         >         >         >
>         >
>         ff ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
>         >         >         >         >  
>         >         >         >         > The above is the bitmap when
>         crashed.
>         >         You can see
>         >         >         the
>         >         >         >         beginnig there are
>         >         >         >         > only 3 bytes are valid, the
>         4th byte
>         >         will cause
>         >         >         crash. 
>         >         >         >         > But when you call
>         >         >         >         > ASMBitTest(const volatile void
>         >         *pvBitmap, int32_t
>         >         >         iBit)
>         >         >         >         >  
>         >         >         >         > it will the 1st 4-byte int,
>         thus caused
>         >         the crash.
>         >         >         >         
>         >         >         >         Good catch!
>         >         >         >         
>         >         >         >         > The easiest fix is to allocate
>         8 byte
>         >         length more
>         >         >         for the
>         >         >         >         bitmap, and zero
>         >         >         >         > fill them, that will
>         definitely solve
>         >         the issue.
>         >         >         You can
>         >         >         >         also change
>         >         >         >         > ASMBitTest method impl. 
>         >         >         >         
>         >         >         >         I think a better fix would be to
>         ensure
>         >         that
>         >         >         ASMBitTest isn't
>         >         >         >         called
>         >         >         >         with non-word-aligned memory
>         addresses.
>         >         >         >         
>         >         >         >         Kind regards,
>         >         >         >         
>         >         >         >         Frank
>         >         >         >         -- 
>         >         >         >         Dr.-Ing. Frank Mehnert    Sun
>         >         Microsystems, Inc.
>         >         >         >         www.sun.com
>         >         >         >         
>         >         >         >         
>         >         >         >         -----Inline Attachment
>         Follows-----
>         >         >         >         
>         >         >         >
>         >            _______________________________________________
>         >         >         >         vbox-dev mailing list
>         >         >         >         vbox-dev at virtualbox.org
>         >         >         >
>         >            http://vbox.innotek.de/mailman/listinfo/vbox-dev
>         >         >         >         
>         >         >         >
>         _______________________________________________
>         >         >         > vbox-dev mailing list
>         >         >         > vbox-dev at virtualbox.org
>         >         >         >
>         http://vbox.innotek.de/mailman/listinfo/vbox-dev
>         >         >         
>         >         >         
>         >         
>         >         
>         
>         

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.virtualbox.org/pipermail/vbox-dev/attachments/20090629/9fa64ade/attachment.html>


More information about the vbox-dev mailing list